# 2001.10.29 22:15 "TIFF L*a*b* encoding", by Martí_Maria

Hi,

Joris Van Damme and me have been struggling against the TIFF CIE L*a*b* encoding. All flavors seems clear with one notable exception: 16 bits on Photometric=8. It seems there is a lot of confusion on such format. Surprising Joris has a sample and me another, but both are encoded in totally incompatible way. And what is worst, there is no way to know in advance which encoding to choose.

I must add working with Joris has been a true pleasure. With his commendable modesty, He did a post assuming my sample was right and his one was wrong. However, after thinking a bit on this, we both agree the ICC encoding should be regarded as the correct one. So, many thanks Joris for your great assist!

I will resume here the different encodings:

__Lab 8 bits, Photometric=8 (TIFF encoding)__

This partially documented on TIFF 6.0, dated June 1992

White point is D65. White point tag DOES NOT apply.

To convert to float

L: divide L by 2.55

a, b: substract 256 if greater that 127

Notes: Photoshop 5.xx does use D50 instead of D65

__Lab 8 bits, Photometric=9 (ICC encoding)__

This is fully documented on ICC spec, and indirectly documented on Adobe PageMaker ® 6.0 TIFF Technical Notes.

White point is D50. White point tag DOES apply

to convert to float:

L: divide L by 2.55

a, b: substract 128

__Lab 16 bits, Photometric=9 (ICC encoding)__

This is fully documented on ICC spec, and indirectly documented on Adobe PageMaker ® 6.0 TIFF Technical Notes.

White point is D50. White point tag DOES apply

L, is encoded as unsigned 8.8 fixed point, scaled by 255/100. a, b are encoded as signed 7.8 fixed point.

To convert to float:

L: divide L by 652.8 (0xFF00 / 100)

a, b: divide by 256 and then substract 128

__Lab 16 bits, photometric=8__

This is SPECIFICALLY FORBIDDEN in TIFF 6.0 spec, however, Joris and me does have samples using this combination. Unfortunately, they are contradictory. So, somewhat arbitrarily, we have adopted the ICC encoding (equal to Photometric=9) because following reasons:

- The TIFF 6.0 spec forbids this combination, so it should be taken as a posterior addition.
- Further additions of Adobe (in Adobe PageMaker ® 6.0 TIFF Technical Notes) does use ICC encoding.
- ICC encoding has technical advantages over "old" encoding.
- ITU/Fax seems to be using also same method.
- The technical advantaged of ICC encoding are (among others)
- Is continuous when changing from negative to positive, a very desirable feature when interpolation is used.
- Is an standard being used in ICC profiles PCS.
- Because its fixed point nature, it has efficient math.
- Addition and subtraction of two Lab values can be done by simply adding in integer arithmetic.
- Multiplication can be done by integer multiplication followed by a shift right 16. This is amazing, but it works. (Note than temporary storage of 64 bits is needed) (<< = shift left, >> = shift right)

result = (a * b) >> 16

- Division can be done by

tmp = Dividend << 32

result = (tmp / Divisor) >> 16

Provided tmp is 64 bits wide. Again, a big deal, since its computational

cost is low (1 integer division, 2 shifts)

- It can be reduced to 8 bits representation by a simple >> 8, or promoted to 16 bits by a simple << 8. Rounding can be done by adding 0x0080 before shift.

OK, these are our conclusions. However, we would be happy to know if anyone has more samples on this format, or any opinion on how to interpret this stuff.

Regards

Marti Maria.