IM writes and reads integers with an offset of Quantum/2, but negative values are written as zero. Thus writing a Lab txt file and reading it back in will yield different values.
When reading txt files, any values < 0 or > 32767 are treated as negative, and this is reasonable.
Test cases (IM v6.8.6-0, Windows):
Text file lab_test_neg contains:
Code: Select all
# ImageMagick pixel enumeration: 10,1,65535,cielab
0,0: (59712, 0, 0)
1,0: (59712, 10, 0)
2,0: (59712, 100, 0)
3,0: (59712, 1000, 0)
4,0: (59712, -10, 0)
5,0: (59712, -100, 0)
6,0: (59712, -1000, 0)
7,0: (59712, 32767, 0)
8,0: (59712, 32768, 0)
9,0: (59712, 0, 0)
Code: Select all
%I%convert ^
txt:lab_test_neg.txt ^
-set colorspace Lab ^
txt:
Code: Select all
D:\web\im>c:\im\ImageMagick-6.8.6-Q16fix\convert txt:lab_test_neg.txt -set colorspace Lab txt:
# ImageMagick pixel enumeration: 10,1,65535,cielab
0,0: (59712, 0, 0) #E94000000000 cielab(91.1147%,0%,0%)
1,0: (59712, 10, 0) #E940000A0000 cielab(91.1147%,0.015259%,0%)
2,0: (59712, 100, 0) #E94000640000 cielab(91.1147%,0.15259%,0%)
3,0: (59712, 1000, 0) #E94003E80000 cielab(91.1147%,1.5259%,0%)
4,0: (59712, 0, 0) #E94000000000 cielab(91.1147%,-0.015259%,0%)
5,0: (59712, 0, 0) #E94000000000 cielab(91.1147%,-0.15259%,0%)
6,0: (59712, 0, 0) #E94000000000 cielab(91.1147%,-1.5259%,0%)
7,0: (59712,32767, 0) #E9407FFF0000 cielab(91.1147%,49.9992%,0%)
8,0: (59712, 0, 0) #E94000000000 cielab(91.1147%,-50.0008%,0%)
9,0: (59712, 0, 0) #E94000000000 cielab(91.1147%,0%,0%)
Writing test:
Code: Select all
%I%convert ^
-size 1x10 ^
gradient:rgb(0%%,100%%,100%%)-rgb(100%%,100%%,0%%) ^
-colorspace Lab ^
-write txt: ^
-colorspace sRGB ^
txt:
Code: Select all
D:\web\im>c:\im\ImageMagick-6.8.6-Q16fix\convert -size 1x10 gradient:rgb(0%,100%,100%)-rgb(100%,100%,0%) -colorspace Lab -write txt: -colorspace sRGB txt:
# ImageMagick pixel enumeration: 1,10,65535,cielab
0,0: (59712, 0, 0) #E94000000000 cielab(91.1147%,-18.8556%,-5.54665%)
0,1: (59282, 0, 0) #E79200000000 cielab(90.4585%,-21.5946%,-0.158694%)
0,2: (59032, 0, 3529) #E69800000DC9 cielab(90.0771%,-23.5309%,5.38491%)
0,3: (58996, 0, 7242) #E67400001C4A cielab(90.0221%,-24.4221%,11.0506%)
0,4: (59190, 0,10978) #E73600002AE2 cielab(90.3182%,-24.1459%,16.7514%)
0,5: (59623, 0,14625) #E8E700003921 cielab(90.9789%,-22.6978%,22.3163%)
0,6: (60296, 0,18005) #EB8800004655 cielab(92.0058%,-20.1923%,27.4739%)
0,7: (61203, 0,20870) #EF1300005186 cielab(93.3898%,-16.8276%,31.8456%)
0,8: (62330, 0,22971) #F37A000059BB cielab(95.1095%,-12.8344%,35.0515%)
0,9: (63658, 0,24281) #F8AA00005ED9 cielab(97.1359%,-8.45197%,37.0504%)
# ImageMagick pixel enumeration: 1,10,65535,srgb
0,0: ( 0,65535,65534) #0000FFFFFFFE srgb(0%,100%,99.9985%)
0,1: ( 7291,65535,58254) #1C7BFFFFE38E srgb(11.1254%,100%,88.8899%)
0,2: (14565,65535,50972) #38E5FFFFC71C srgb(22.2248%,100%,77.7783%)
0,3: (21845,65535,43691) #5555FFFFAAAB srgb(33.3333%,100%,66.6682%)
0,4: (29126,65535,36408) #71C6FFFF8E38 srgb(44.4434%,100%,55.555%)
0,5: (36407,65535,29127) #8E37FFFF71C7 srgb(55.5535%,100%,44.445%)
0,6: (43690,65535,21846) #AAAAFFFF5556 srgb(66.6667%,100%,33.3349%)
0,7: (50972,65535,14563) #C71CFFFF38E3 srgb(77.7783%,100%,22.2217%)
0,8: (58254,65535, 7284) #E38EFFFF1C74 srgb(88.8899%,100%,11.1147%)
0,9: (65534,65535, 2) #FFFEFFFF0002 srgb(99.9985%,100%,0.0030518%)
The cielab percentages are more or less correct, remembering that mid-values in a and b channels are 0%. But all negative a or b percentages are shown with integer zero.
So the bug I'd like fixing is that negative integers when written shouldn't be clipped to zero.
(The Luv colorspace isn't offset by Quantum/2, so never goes negative and doesn't have this problem.)