AWARE SYSTEMS
TIFF and LibTiff Mail List Archive

2019.01.22 15:14 "[Tiff] Unable to write inkName - libTiff 4.0.9", by SM

Hello,

I am trying a small code snippet, with libTIFF 4.0.9, which is trying to
write the InkNames tag in a separated image but I am hitting the following
error:

TIFFSetField: test.tif: Invalid InkNames value; expecting 4 names, found 3.

I have attached the standalone code to this email. Please note that I have
set the EXTRASAMPLES tag so I believe I can set the rest 3 values that can
be used with SamplesPerPixel.

Can you please confirm if it is a bug?

Also, I noted that the documentation page mentions that "The number of
strings must be equal to NumberOfInks":

https://www.awaresystems.be/imaging/tiff/tifftags/inknames.html

But I found that I can set any value for the tag TIFFTAG_NUMBEROFINKS and
code would still work.

Thanks

Upanita

#include <tiffio.h>

int main()
{

const char *ink_names = "Red\0Green\0Blue\0";
const int ink_names_size = 15;
printf("Entering main()\n");
TIFF *out=TIFFOpen("test.tif", "w");
int status;

status = TIFFSetField(out, TIFFTAG_IMAGEWIDTH, 10); // set the width of the image printf("Status = %d\n", status);

status = TIFFSetField(out, TIFFTAG_IMAGELENGTH, 7); // set the height of the image printf("Status = %d\n", status);

status = TIFFSetField(out, TIFFTAG_SAMPLESPERPIXEL, 4); // set number of channels per pixel printf("Status = %d\n", status);

status = TIFFSetField(out, TIFFTAG_BITSPERSAMPLE, 8); // set the size of the channels printf("Status = %d\n", status);

status = TIFFSetField(out, TIFFTAG_COMPRESSION, COMPRESSION_NONE); printf("Status = %d\n", status);

status = TIFFSetField(out, TIFFTAG_ROWSPERSTRIP, 2); printf("Status = %d\n", status);

status = TIFFSetField(out, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); printf("Status = %d\n", status);

status = TIFFSetField(out, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_SEPARATED); // Separated image printf("Status = %d\n", status);

uint16 extra[1];
extra[0] = EXTRASAMPLE_UNSPECIFIED;

status = TIFFSetField(out, TIFFTAG_EXTRASAMPLES, 1, &extra); // Extrasample is Unspecified printf("Status = %d\n", status);

TIFFSetField(out, TIFFTAG_NUMBEROFINKS, 3); status = TIFFSetField(out, TIFFTAG_INKNAMES, ink_names_size, ink_names); printf("Status = %d\n", status);

if(status==0)
{
printf("Error");
}
TIFFClose(out);
        printf("Exiting main()\n");

}