Tuesday, December 6, 2011

Help - color loss when transparency...

hi, i'm writing filter plug-in which makes a pink rectangle on the layer,
only differs in transparency each column.

So all pixel color must be same, regardless of transparency.
you see it by 1)making a solid rect on layer, 2) make alpha layer mask and put gradient on it,
3) and apply alpha layer mask.

i expected the same result, but actual result was very strange.
i fill the rectangle in (249, 125, 125) color, but the blue and green color
dramatically drop to zero when transparency value gets lower, here's sample value:

alpha value 0 : (0, 0, 0)
alpha value 40 : (218, 0, 0)
alpha value 160 : (245, 49, 49)

and here's the code:
{
// make 255x10 rect
int32 w = 0xff;
int32 h = 10;
VRect write_rect = {0, 0, h, w};

char* planeBuffer = sPSBuffer-%26gt;New(NULL, w * h);
PixelMemoryDesc destination;
destination.data = planeBuffer;
destination.depth = 8;
destination.rowBits = w * 8;
destination.colBits = 8;
destination.bitOffset = 0 ;

// fill R/G/B #f97d7d
ReadChannelDesc* chR = gFilterRecord-%26gt;documentInfo-%26gt;targetCompositeChannels;
memset(planeBuffer, 0xf9, w * h);
sPSChannelProcs-%26gt;WritePixelsToBaseLevel(chR-%26gt;writePort, %26amp;write_rect, %26amp;destination);

ReadChannelDesc* chG = chR-%26gt;next;
memset(planeBuffer, 0x7d, w * h);
sPSChannelProcs-%26gt;WritePixelsToBaseLevel(chG-%26gt;writePort, %26amp;write_rect, %26amp;destination);

ReadChannelDesc* chB = chG-%26gt;next;
memset(planeBuffer, 0x7d, w * h);
sPSChannelProcs-%26gt;WritePixelsToBaseLevel(chB-%26gt;writePort, %26amp;write_rect, %26amp;destination);

// fill alpha channel 0~0xff
ReadChannelDesc* chA = gFilterRecord-%26gt;documentInfo-%26gt;targetTransparency;
for (int32 y=0; y %26lt; h; y++)
{
for (int32 x=0; x %26lt; w; x++)
{
planeBuffer[y*w+x] = (x % 0xff);
}
}
sPSChannelProcs-%26gt;WritePixelsToBaseLevel(chA-%26gt;writePort, %26amp;write_rect, %26amp;destination);

// dispose.
sPSBuffer-%26gt;Dispose(%26amp;planeBuffer);
}

Am i doing something wrong?Help - color loss when transparency...
Looks good to me. A couple of minor problems:

1) pad the rows to an even number of bytes.
2) experiment with writing different constant alpha values

I spent more than a few minutes puzzling over this, and would be curious to
know what the eventual problem was.
  • help blackheads
  • grey hair
  • No comments:

    Post a Comment