Bug 408755 - Cannot save multiple layers with different colorspaces to tiff
Summary: Cannot save multiple layers with different colorspaces to tiff
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: File formats (show other bugs)
Version: git master (please specify the git hash!)
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: amyspark
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-06-15 20:48 UTC by Tiar
Modified: 2021-08-27 07:59 UTC (History)
4 users (show)

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


Attachments
Test .kra file (113.36 KB, application/x-krita)
2019-06-15 20:48 UTC, Tiar
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tiar 2019-06-15 20:48:37 UTC
Created attachment 120900 [details]
Test .kra file

SUMMARY
Multiple layers in tiff seem to work... if all the layers are of the same colorspace or if all the layers are of supported colorspaces (I don't know which one is the case). Otherwise the content is skewed or missing or lost and all the layers have the same colorspace.


STEPS TO REPRODUCE
1. Open the attached file.
2. Save as tiff (don't flatten, yes, save ICC profile).
3. Open the file in another tab.
4. Convert the bottom layer colorspace to the same as the top one (XYZ, but I don't remember the bit depth).
5. Save as tiff (the same options).
6. Compare the results with .kra and with the tiff file saved previously.


OBSERVED RESULT
File saved in 2. looks differently; doesn't have the pink stroke.


EXPECTED RESULT
All files look at least similar to each other, no content is missing.
(The tiff file saved in 5. is different from .kra, but that's because of the colorspace conversion; you'll see the same results if you convert the image colorspace in .kra file to the colorspace tiff exporter converted to).


SOFTWARE/OS VERSIONS
Linux Mint
Qt Version: 5.12.3

ADDITIONAL INFORMATION
Using Krita git master 0893c1a784
Comment 1 Halla Rempt 2019-06-17 07:50:36 UTC
I guess that we'd best convert every layer to the image colorspace if the layer colorspace is different. I don't think tiff actually supports heterogenous images.
Comment 2 wolthera 2019-09-21 15:42:44 UTC
I am setting this to confirmed, given two developers seem to agree it is a bug that is being buggy.
Comment 3 ch-bartz 2021-07-08 20:19:26 UTC
(In reply to Halla Rempt from comment #1)
> I guess that we'd best convert every layer to the image colorspace if the
> layer colorspace is different. I don't think tiff actually supports
> heterogenous images.

I have read the standard differently. The specification ICC.1:2010 (Profile version 4.3.0.0) (http://color.org/icc_specs2.xalter) says:

"A  TIFF  file  may  contain  more  than  one  image,  and  so,  more  than  one  IFD.  Each  IFD  may  have  its  own embedded profile. Note, however, that Baseline TIFF readers are not required to read any IFDs beyond the first one."

So it should be able to assign different ICC color profiles to layers and KRITA's TIFF export should embed individual ICC color profiles to all TIFF pages, if assigned profiles differ. 

TIFF import should idealy respect individual color profiles for all pages. If importing a multi-page TIFF where only the first page has an embedded color profile, the TIFF import should apply this color profile to all TIFF pages (layers).
Comment 4 amyspark 2021-07-09 02:31:39 UTC
(In reply to ch-bartz from comment #3)
> (In reply to Halla Rempt from comment #1)
> > I guess that we'd best convert every layer to the image colorspace if the
> > layer colorspace is different. I don't think tiff actually supports
> > heterogenous images.
> 
> I have read the standard differently. The specification ICC.1:2010 (Profile
> version 4.3.0.0) (http://color.org/icc_specs2.xalter) says:
> 
> "A  TIFF  file  may  contain  more  than  one  image,  and  so,  more  than 
> one  IFD.  Each  IFD  may  have  its  own embedded profile. Note, however,
> that Baseline TIFF readers are not required to read any IFDs beyond the
> first one."
> 
> So it should be able to assign different ICC color profiles to layers and
> KRITA's TIFF export should embed individual ICC color profiles to all TIFF
> pages, if assigned profiles differ. 
> 
> TIFF import should idealy respect individual color profiles for all pages.
> If importing a multi-page TIFF where only the first page has an embedded
> color profile, the TIFF import should apply this color profile to all TIFF
> pages (layers).

Can confirm; see the TIFF v6 standard, page 16, last paragraph, then page 101, 3rd paragraph of the current ICC.1:2010.
Comment 5 amyspark 2021-08-26 22:04:05 UTC
Hm, upon reading the log, it's not that they aren't saved correctly, on loading the KisDocument applies a single colorspace and ICC profile to the entire image.
Comment 6 Bug Janitor Service 2021-08-27 01:43:15 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/krita/-/merge_requests/1019
Comment 7 amyspark 2021-08-27 07:59:31 UTC
Git commit 6ce9aadc4b1e4584d0cf5730c481c4663f6ac7cc by L. E. Segovia.
Committed on 27/08/2021 at 01:31.
Pushed by rempt into branch 'master'.

TIFF: initialize the layer being read with its IFD's color space

M  +1    -1    plugins/impex/tiff/kis_tiff_converter.cc
A  +-    --    plugins/impex/tiff/tests/data/results/multilayercs.tif.png
A  +-    --    plugins/impex/tiff/tests/data/sources/multilayercs.tif

https://invent.kde.org/graphics/krita/commit/6ce9aadc4b1e4584d0cf5730c481c4663f6ac7cc