2004.01.15 17:16 "[Tiff] How to determine number of colors in the colormap", by Bill Cassanova
I have an 8-bit tiff image which I have been able to confirm has only 18 colors. Is there some tag within the tiff itself that says how many colors are actually present? The value that is being returned when I have ( 2**bits_per_sample ) or from another example I saw (( 1 << bitspersample ) -1 ) is 255 which is the number of colors that I would expect are possible although not necessarily present.
Also Using the code below which I think is correct I am not seeing any of my known colors.....Instead I am seeing values that seem to indicate I am deferencing the pointers incorrectly....Can you point out my mistake?
int num_entries = (1 << bitspersample) - 1;
cout << "num_entries: " << num_entries << endl;
// get the photmetric interpretation
if ((result =
TIFFGetField(image_in, TIFFTAG_COLORMAP, &red, &green, &blue)) != 1)
for (int i = 0; i < num_entries; i++)
cout << red[i] << "\t" << green[i] << "\t" << blue[i] << endl;