2008.04.23 13:58 "[Tiff] transparent tiff", by Roman Kazmin
Hi everybody. I'm trying to create transparent tiff file. But I receive
usual tiff file. Where is my mistake? I'm trying to make following - red
screen with transparent green rectange at the center. Below is my code:
int main(int argc, char **argv)
{
TIFF *tif;
char buffer[4*1024];
int width = 1024, height = 768, row;
uint32 temp = EXTRASAMPLE_ASSOCALPHA;
tif = TIFFOpen("3d.tif", "w");
TIFFSetField (tif, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField (tif, TIFFTAG_IMAGELENGTH, height);
TIFFSetField (tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG);
TIFFSetField (tif, TIFFTAG_SAMPLESPERPIXEL, 4);
TIFFSetField (tif, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField (tif, TIFFTAG_EXTRASAMPLES, 1, &temp);
TIFFSetField (tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField (tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB);
TIFFSetField (tif, TIFFTAG_IMAGEDESCRIPTION, "3D Simulation");
TIFFSetField (tif, TIFFTAG_COMPRESSION, COMPRESSION_PACKBITS);
TIFFSetField (tif, TIFFTAG_ROWSPERSTRIP, 16);
for (row = 0; row < 768; row++)
{
for (int i = 0; i < 1024; i++)
{
if(row > 234 && row < 530
&& i > 350 && i <
700)
{ // Here I'm trying to draw
transparent
green rectangle
buffer[4*i] = 0;
buffer[4*i+1] = 200;
buffer[4*i+2] = 0;
buffer[4*i+3] = 200; // transparency
}
else
{
buffer[4*i] = 200;
buffer[4*i+1] = 0;
buffer[4*i+2] = 0;
buffer[4*i+3] = 0;
}
}
TIFFWriteScanline(tif, buffer, row, 0);
}
TIFFClose(tif); tif = NULL;
return 0;
}