Home > Software engineering >  Libtiff for how to write in the (increase) the color channel and data?
Libtiff for how to write in the (increase) the color channel and data?

Time:11-20

//Open the output image
If ((the output=TIFFOpen (" 123456 tif ", "w"))==NULL)
{
//fprintf (stderr, "Could not open outgoing image \ n");
return false;
}
//Write the tiff tags to the file
TIFFSetField (output, TIFFTAG_IMAGEWIDTH, width);
TIFFSetField (output, TIFFTAG_IMAGELENGTH, height);

TIFFSetField (output, TIFFTAG_PLANARCONFIG PLANARCONFIG_CONTIG);
//given pixel CMYK information together in the stripe of image data, another option is to PLANARCONFIG_SEPARATE, image C samples exist together, M samples exist together, finally Y samples exist together,

//TIFFSetField (output, TIFFTAG_PHOTOMETRIC PHOTOMETRIC_RGB);//PHOTOMETRIC_RGB tag statement image data is stored in the stripe itself (rather than through the palette)
TIFFSetField (output, TIFFTAG_PHOTOMETRIC PHOTOMETRIC_SEPARATED);

//TIFFSetField (output, TIFFTAG_BITSPERSAMPLE, 8, 8, 8, 8).//each sample takes bit
TIFFSetField (output, TIFFTAG_BITSPERSAMPLE, 8);//each sample takes bit
//TIFFSetField (output, TIFFTAG_SAMPLESPERPIXEL, 4);//each pixel has several sample sample
TIFFSetField (output, TIFFTAG_SAMPLESPERPIXEL, channelNum);//each pixel has several sample sample
//TIFFSetField (output, TIFFTAG_INKNAMES, "red");

Uint8 info [8]={0};//the 2016-12-13 error saving more than six channel TIF image, set the array [8], support to the 8 + 4=12 channel
Uint8 AlphaChannelNumer=channelNum - 4;
//TIFFSetField (output, TIFFTAG_EXTRASAMPLES AlphaChannelNumer, info).

TIFFSetField (output, TIFFTAG_INKSET INKSET_CMYK);//set up here, but no effect
TIFFSetField (output, TIFFTAG_NUMBEROFINKS, 1);
TIFFSetField (output, TIFFTAG_INKNAMES, "red");
TIFFSetField (output, TIFFTAG_IMAGEBASECOLOR, 255);

//later for the image
//if (TIFFWriteEncodedStrip (output, 0, raster, height width * * 4)==0) {
If (TIFFWriteRawStrip (output, 0, the memory, height width * * channelNum)==0) {
//fprintf (stderr, "Could not write image \ n");
return 1;
}
TIFFClose (output);
  • Related