TIFF and LibTiff Mail List Archive

# 2001.10.26 13:28 "Re: 16-bit ICC L*a*b* ?", by Martí Maria

Hi Joris,

Lab TIFF of 8 bits are encoded using:

L: 0...FF -> 0..100
a,b: 0..FF -> -128...127

To decode to float, you need to divide L by 2.55. For the a, b parts, substract 128 if greater that 127.

I'm sorry, but this must be a typo or something. If you substract 128 if >127, you end up with two ways to encode the range 0 to 127, and no way to encode negative values.

Ops, sorry. A typo. Substract *256* from the a,b parts if bit 8 is set, otherwise leave them alone. This give us an encodeable range of -128.0 to +127.0 If you use 255, there would be two values for 0, 0 itself and 255.

On 16 bits is pretty same... Just divide by 256 and then apply previous algorithm, this gives an encodeable range of -128.0 to +127.9961

0  / 256                 =  0
\$7FFF / 256         =  127.9961
\$8000 / 256 -256 = -128
\$FFFF / 256-256 =  -0.00390625

The low byte on 16 bit representation is the fractionary part.

Let's try my oxidized pascal, I don't forget to avoid ';' before end! (pascal fellows does hate this) *:^)

procedure XPVtifflab24ToVlabf(const al,aa,ab: Integer; var bl,ba,bb: Cft);
begin
bl:=al/2.55;

if aa<128 then
ba:=aa
else
ba:=aa-256;

if ab<128 then
bb:=ab
else
bb:=ab-256

end;

procedure XPVtifflab48iToVlabf(const al,aa,ab: Integer; var bl,ba,bb: Cft);
begin
bl:=al/256/2.55;

if aa < \$8000 then
ba:=aa/256
else
ba:=aa/256-256;

if ab< \$8000 then
bb:=ab/256
else
bb:=ab/256-256

end;

Best Regards,
Marti.