Bug 310359 - Krita doesn't properly save a tif created in the Lab color space. Neutral gray turns brilliant blue or red.
Summary: Krita doesn't properly save a tif created in the Lab color space. Neutral gra...
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Color models (show other bugs)
Version: unspecified
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: Dmitry Kazakov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-19 17:35 UTC by Elle Stone
Modified: 2015-09-19 12:28 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Elle Stone 2012-11-19 17:35:56 UTC
I used krita to create a middle gray color block in the Lab color space (L=a=b=32767), saved it as a tif, and closed krita. Then I opened the tif with Cinepaint. It was brilliant blue. It eyedropperd as L=32767, a=b=0. I used Cinepaint curves to make the block gray again and saved it under a new name. Then I restarted krita and opened both tifs. Krita agreed with Cinepaint that the original tif saved by krita was indeed brilliant blue, and also agreed with Cinepaint that the new tif created by Cinepaint was neutral gray.  

Reproducible: Always

Steps to Reproduce:
1. Open krita and create a new 16-bit 100px by 100px image in the
built-in lab color space.

2. Using the specific color selector, making sure the sliders are set to
use built-in lab, set L=a=b=32767, which is nearest integer to
midpoint between 0 and 65535. Presumably this is equal to Lab (50,0,0)
on a scale where L runs from 0 to 100 and a and b run from -whatever
to +whatever, with 0 being the midpoint.

3. Select the entire square and fill it with the selected Lab color. The
resulting square will look neutral gray.

4. Save the image as kr1.kra. Then save the image as kr1.tif. Export and
Save both produce the same problem. Saving with or without the alpha
channel also produces the same problem.
Using krita, open kr1.tif. It will look brilliant blue and it will
eyedropper as L=32767, a=b=0.

5. Using krita, save kr1.tif as kr1-krita-open-save.tif. Close and then
reopen kr1-krita-open-save.tif. Now it will look neutral gray and will
eyedropper as L=32767, a=b=32769. Save it again, as
kr1-krita-open-save-again.tif. Close and reopen
kr1-krita-open-save-again.tif and now it's brilliant blue again. Etc.

5. Going back to kr1.tif, open kr1.tif with Cinepaint. It will look
brilliant red (red, not blue) and it will eyedropper as L=32767,
a=b=65535. Now still using Cinepaint, save kr1.tif as
kr1-cp-open-save.tif.

6. Open kr1-cp-open-save.tif with Krita (you may need to close and reopen
krita, because krita doesn't seem to reliably refresh the image list
when trying to open or save a file). It will look brilliant red and it
will eyedropper as L=32767, a=b=65535.

7. Going back to Cinepaint, open kr1-cp-open-save.tif again. Using
curves, set the a and b channel curves both as a horizontal straight
line running through the midpoint. This is the equivalent of setting
a=0 and b=0, for neutral gray, on a Lab scale that runs from 0 to 100,
with a and b midpoints being 0. Now the image looks neutral gray.
Cinepaint eyedroppers as L=32767, a=b=32640 - perhaps I didn't get the
litte bitty Cinepaint curve to go exactly through the midpoint of the
curve, or perhaps Cinepaint doesn't use 32767 as the midpoint of a or
b or maybe even L. Regardless, save the resulting file as
kr1-cp-open-save-cp-setabto0.tif.

8. Using krita, open kr1-cp-open-save-cp-setabto0.tif. It looks
neutral gray. It eyedroppers exactly the same values as Cinepaint. Now
save as kr1-cp-open-save-cp-setabto0-krita-open-save.tif and as
kr1-cp-open-save-cp-setabto0-krita-open-save.kra. Close krita, reopen
krita, reopen both documents, the tif and the kra. The kra file will
still be neutral gray and will still eyedropper the same values. The
tif file is now brilliant red and eyedroppers as L=32767, a=b=65409.

Actual Results:  
When creating a neutral gray color block and saving it as a tif, then when reopening the color block with krita, and also when opening it with Cinepaint, the color block ought to still be neutral gray

Expected Results:  
The color block turns brilliant blue, and sometimes brilliant red, probably depending on whether the initial a and b settings are just above or just below the exact center value between 0 and 65535.

I saved a kra file at the same time that I saved the original tif. Krita Lab kra files open and save correctly. It's only the Lab tif files that are saved incorrectly, with the a and be sliders shoved all the way to 0 or 65535, depending on the initial values near the mid-point between 0 and 65535.

I compiled krita from git on Nov 15, 2012.

Sample tif and kra files can be downloaded here:
http://ninedegreesbelow.com/temp/digikam/krita-lab.tar.gz
Comment 1 Elle Stone 2013-01-31 18:39:00 UTC
Using krita, I opened Lindbloom's Lab-space profile evaluation images from here:

http://www.brucelindbloom.com/index.html?ProfileEvaluation.html

My goal to was to put the evaluation images in one image file so I could see them all at once.  Upon reopening the saved tif file with krita, the image had turned brilliant blue. So krita still can't correctly save a lab tif. I really wish it could, because the only other alternative is Cinepaint, and Cinepaint is flaky about assembling layers.

I'm using krita Version 2.6 RC2
Using KDE Development Platform 4.9.5 "release 3" from the opensuse repository.
Comment 2 Halla Rempt 2013-03-31 09:40:46 UTC
Hi Elle,

Thanks for your report. I'm not sure what we're doing wrong, but there's something pretty weird going on with our support for Lab.
Comment 3 Halla Rempt 2015-05-27 19:10:34 UTC
It's bright red in photoshop...
Comment 4 Halla Rempt 2015-09-19 12:26:56 UTC
Git commit f4ac4cd2e553bb86b711fa77701953e7a13bac7b by Boudewijn Rempt.
Committed on 19/09/2015 at 12:23.
Pushed by rempt into branch 'calligra/2.9'.

Internally, Krita uses the ICCLAB definition, not the CIELAB
definition, so we shouldn't convert what we read to CIELAB, and
should save what we save tagged as ICCLAB.

Photoshop CS2 and CC can now load our TIFF Lab images! (We don't have
a gimp devel build to test with atm.)

M  +3    -3    krita/plugins/formats/tiff/kis_tiff_converter.cc
M  +6    -6    krita/plugins/formats/tiff/kis_tiff_reader.h
M  +2    -2    krita/plugins/formats/tiff/kis_tiff_writer_visitor.cpp

http://commits.kde.org/calligra/f4ac4cd2e553bb86b711fa77701953e7a13bac7b
Comment 5 Halla Rempt 2015-09-19 12:28:15 UTC
Git commit 63dcea5c0e7877ed5cb53d805f9126706ef5271e by Boudewijn Rempt.
Committed on 19/09/2015 at 12:27.
Pushed by rempt into branch 'master'.

Internally, Krita uses the ICCLAB definition, not the CIELAB
definition, so we shouldn't convert what we read to CIELAB, and
should save what we save tagged as ICCLAB.

Photoshop CS2 and CC can now load our TIFF Lab images! (We don't have
a gimp devel build to test with atm.)

M  +3    -3    krita/plugins/formats/tiff/kis_tiff_converter.cc
M  +6    -6    krita/plugins/formats/tiff/kis_tiff_reader.h
M  +2    -2    krita/plugins/formats/tiff/kis_tiff_writer_visitor.cpp

http://commits.kde.org/calligra/63dcea5c0e7877ed5cb53d805f9126706ef5271e