2005.05.25 09:52 "[Tiff] How to Write a tif file with compression = COMPRESSION_JPEG & photometric = PHOTOMETRIC_YCBCR ?", by Kelvin Zhong

2005.05.26 01:50 "Re: [Tiff] How to Write a tif file with c ompression = COMPRESSION_JPEG & photometr ic = PHOTOMETRIC_YCBCR ?", by Kelvin Zhong

Thanks Jean-Yves,

I have already done the things like you said,comment the TIFFSetFiled(m_tif,TIFFTAG_JPEGCOLORMODE,JPEGCOLORMODE_RGB)...,but still doesn't work.

I created a JPEG-IN-TIFF file with ACDSEE. (FILE 1) WITH tiffdump,i see follows:

Magic: 0x4949 <little-endian> Version: 0x2a
Directory 0: offset 12576 (0x3120) next 0 (0)
ImageWidth (256) SHORT (3) 1 <422>
ImageLength (257) SHORT (3) 1 <158>
BitsPerSample (258) SHORT (3) 3 <8 8 8>
Compression (259) SHORT (3) 1 <7>
Photometric (262) SHORT (3) 1 <6>
StripOffsets (273) LONG (4) 1 <8>
Orientation (274) SHORT (3) 1 <1>
SamplesPerPixel (277) SHORT (3) 1 <3>
StripByteCounts (279) LONG (4) 1 <12567>
XResolution (282) RATIONAL (5) 1 <96>
YResolution (283) RATIONAL (5) 1 <96>
PlanarConfig (284) SHORT (3) 1 <1>
ResolutionUnit (296) SHORT (3) 1 <2>
347 (0x15b) UNDEFINED (7) 574 <0xff 0xd8 0xff 0xdb 00 0x43 00 0x8 0x6 0x6 0x7 0x6 0x5 0x8 0x7 0x7 0x7 0x9 0x9 0x8 0xa 0xc 0x14 0xd ...>
YCbCrSubsampling (530) SHORT (3) 2 <1 1>
ReferenceBlackWhite (532) RATIONAL (5) 6 <0 255 128 255 128 255>

then i use my code to read this pic,
and save it with compression = COMPRESSION_JPEG & photometric = PHOTOMETRIC_YCBCR
with tiffdump,i saw follows:(FILE 2)

Magic: 0x4949 <little-endian> Version: 0x2a
Directory 0: offset 19642 (0x4cba) next 0 (0)
ImageWidth (256) SHORT (3) 1 <422>
ImageLength (257) SHORT (3) 1 <158>
BitsPerSample (258) SHORT (3) 3 <8 8 8>
Compression (259) SHORT (3) 1 <7>
Photometric (262) SHORT (3) 1 <6>
StripOffsets (273) LONG (4) 1 <8>
Orientation (274) SHORT (3) 1 <1>
SamplesPerPixel (277) SHORT (3) 1 <3>
RowsPerStrip (278) SHORT (3) 1 <158>
StripByteCounts (279) LONG (4) 1 <19633>
XResolution (282) RATIONAL (5) 1 <96.512>
YResolution (283) RATIONAL (5) 1 <96.512>
PlanarConfig (284) SHORT (3) 1 <1>
ResolutionUnit (296) SHORT (3) 1 <2>
347 (0x15b) UNDEFINED (7) 574 <0xff 0xd8 0xff 0xdb 00 0x43 00 0x8 0x6 0x6 0x7 0x6 0x5 0x8 0x7 0x7 0x7 0x9 0x9 0x8 0xa 0xc 0x14 0xd ...>
YCbCrSubsampling (530) SHORT (3) 2 <1 1>
ReferenceBlackWhite (532) RATIONAL (5) 6 <0 255 128 255 128 255>

After doing some comparing things,i found almost every tag is same. except for the StripBytesCounts ,and the file i created has one tag RowsPerStrip which the file ACDSEE created didn't have. but this file(i created) still can't be opened by ACDSEE5.

I opened this file(I created,file 2) in LeadTools ,the image color seems changed a lot. so i modify the Photometric tag value from 6 to 2,(PHOTOMETRIC_YCBCR =6,& PHOTOMETRIC_RGB=2),this time the color seemed right.(in Leadtools,ACDSEE can't open it).

so I doubt if the libtiff really write the image data as i want to write? with compression = COMPRESSION_JPEG & photometric = PHOTOMETRIC_YCBCR? (as i think, even if i set photometric = PHOTOMETRIC_YCBCR ,it still write the image data as photometric = PHOTOMETRIC_RGB,... so when i changed the Photometric tag value from 6 to 2, the color seems right...)

related codes & similar questions can be found with title:
2005.5.24:"Question about Jpeg-in-tiff, JPEG IN TIFF created by libtiff can't be read by acdsee", by <yourpattern@126.com>

thanks in advance,

Kingore@126.com
Kelvin Zhong