Bug 376950 - Krita doesn't read alpha channel from tiff files
Summary: Krita doesn't read alpha channel from tiff files
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: File formats (show other bugs)
Version: 5.1.5
Platform: Other All
: NOR normal
Target Milestone: ---
Assignee: Halla Rempt
URL:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2017-02-26 14:18 UTC by Alex
Modified: 2023-07-26 10:26 UTC (History)
3 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Tiff without transparency (379.31 KB, image/tiff)
2017-02-26 14:18 UTC, Alex
Details
TIFF with alpha (900.52 KB, image/tiff)
2018-09-28 06:48 UTC, Alex
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alex 2017-02-26 14:18:35 UTC
Created attachment 104232 [details]
Tiff without transparency

When tiff file is saved with alpha but without transparency option Krita doesn't read alpha. Example file attached.
Comment 1 Halla Rempt 2017-02-26 16:00:34 UTC
Did you save the file from Krita?
Comment 2 Halla Rempt 2017-02-26 16:01:47 UTC
And if you unchecked the save transparency option, then the behaviour is as intended.
Comment 3 Alex 2017-02-26 21:13:43 UTC
File was saved with photoshop with transparency off, with transparency on behaviour in Krita is as intended. Photoshop opens with transparency regardless off that option. Should I check with file saved by Krita?
Comment 4 Halla Rempt 2017-02-26 21:39:50 UTC
Well, if transparency is disabled then the alpha channel shouldn't be saved -- unless I'm misreading the spec completely. Sounds like a bug in Photoshop to me...
Comment 5 Alex 2017-02-26 23:11:50 UTC
Could be. I reported this because PS reads transparency from that file and Krita doesn't... Also in PS you can save file without alpha channel and turn off transparency and transparency will be still there (and no alpha ofcourse). Maybe PS is saving transparency "elsewhere" when transparency option is off.
To discard transparency from that file I had to save without layers.
Comment 6 Halla Rempt 2017-02-27 08:53:17 UTC
but transparency and the alpha channel are one an the same thing -- you cannot have transparency without an alpha channel. I know that photoshop does some weird things with tiff, that aren't according to the spec, though.
Comment 7 Andrew Crouthamel 2018-09-28 02:42:45 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least 15 days. Please provide the requested information as soon as possible and set the bug status as REPORTED. Due to regular bug tracker maintenance, if the bug is still in NEEDSINFO status with no change in 30 days, the bug will be closed as RESOLVED > WORKSFORME due to lack of needed information.

For more information about our bug triaging procedures please read the wiki located here: https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please set the bug status as REPORTED so that the KDE team knows that the bug is ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 8 Alex 2018-09-28 06:48:39 UTC
Created attachment 115287 [details]
TIFF with alpha

I've added one more example, it's not saved by me. Seems like GMIC and Windows picture viewer both read alpha channel (GMIC shows 4th value 255 on man and 0 around). Take a look, Krita can't read alpha channel here. Maybe you can look into GMIC code how it's done there.
Comment 9 Andrew Crouthamel 2018-09-28 17:02:25 UTC
I'll move this to Reported, thanks.
Comment 10 Halla Rempt 2018-10-09 08:51:15 UTC
Well, the problem is that these files are not well-formed. Apparently, everyone thinks they can do whatever they want when writing tiff files, and that an extrasample field is always alpha. 

If an extrasample field is supposed to be alpha, it should be marked either as EXTRASAMPLE_ASSOCALPHA or EXTRASAMPLE_UNASSALPHA. In these files, it's marked as EXTRASAMPLE_UNSPECIFIED, which means exactly nothing.

Krita is strict, but correct. The application you've used to generate these files is flawed.

Let me check the source code of some other open source applications to see what they did about this.
Comment 11 Halla Rempt 2018-10-09 08:51:40 UTC
Okay, gimp also assumes that EXTRASAMPLE_UNSPECIFIED is alpha: 

      /* test if the extrasample represents an associated alpha channel... */
      if (extra > 0 && (extra_types[0] == EXTRASAMPLE_ASSOCALPHA))
        {
          alpha = TRUE;
          tsvals.save_transp_pixels = FALSE;
          extra--;
        }
      else if (extra > 0 && (extra_types[0] == EXTRASAMPLE_UNASSALPHA))
        {
          alpha = TRUE;
          tsvals.save_transp_pixels = TRUE;
          extra--;
        }
      else if (extra > 0 && (extra_types[0] == EXTRASAMPLE_UNSPECIFIED))
        {
          /* assuming unassociated alpha if unspecified */
          g_message ("alpha channel type not defined for file %s. "
                     "Assuming alpha is not premultiplied",
                     gimp_file_get_utf8_name (file));
          alpha = TRUE;
          tsvals.save_transp_pixels = TRUE;
          extra--;
        }
Comment 12 Halla Rempt 2018-10-09 08:55:43 UTC
Git commit dbc50b47f101282690b0db2497773ef32b639de5 by Boudewijn Rempt.
Committed on 09/10/2018 at 08:53.
Pushed by rempt into branch 'master'.

Fix loading the alpha channel from Photoshop TIFF files

Photoshop apparently thinks that EXTRASAMPLE_UNSPECIFIED specifies
correctly that the extra sample is an alpha channel. This is not
true, but everyone thinks they can mess with the tiff standard, so
just read it like that.

M  +6    -1    plugins/impex/tiff/kis_tiff_converter.cc

https://commits.kde.org/krita/dbc50b47f101282690b0db2497773ef32b639de5
Comment 13 Halla Rempt 2018-10-10 09:57:33 UTC
Git commit 15c4692c7599cf150a72296aaf07363c963e12ff by Boudewijn Rempt.
Committed on 10/10/2018 at 07:42.
Pushed by rempt into branch 'krita/4.1'.

Fix loading the alpha channel from Photoshop TIFF files

Photoshop apparently thinks that EXTRASAMPLE_UNSPECIFIED specifies
correctly that the extra sample is an alpha channel. This is not
true, but everyone thinks they can mess with the tiff standard, so
just read it like that.
(cherry picked from commit dbc50b47f101282690b0db2497773ef32b639de5)

M  +6    -1    plugins/impex/tiff/kis_tiff_converter.cc

https://commits.kde.org/krita/15c4692c7599cf150a72296aaf07363c963e12ff
Comment 14 Hrofti 2023-03-20 18:58:21 UTC
I bought a 3D asset in stock and it contains TIFF. As I can see the problem still hasn't been solved. As a final user, I ask you please resolve this problem. Because we live in a not perfect world so we can't expect only the right exported tiff files. Exactly for this reason PH and GIMP and all other programs can read alpha mask correctly.  The file example https://disk.yandex.ru/i/nV6mHMGvxTK3YQ
Comment 15 Dmitry Kazakov 2023-07-26 10:22:32 UTC
Git commit 89ccdfb467fe0d68c26b9cc54dde272b66967253 by Dmitry Kazakov.
Committed on 26/07/2023 at 12:22.
Pushed by dkazakov into branch 'master'.

[string-freeze exception] Fix loading TIFF images with embedded PSD data

In some cases the embedded PSD data may be loaded incorrectly into
Krita, in such cases we should let the user to choose, which form
he/she wants to load.

The patch breaks the string freeze, since it adds a dialog allowing
the user to choose between the two options.
CC:kimageshop@kde.org
CC:kde-i18n-doc@kde.org

M  +118  -84   plugins/impex/tiff/kis_tiff_import.cc
M  +9    -1    plugins/impex/tiff/kis_tiff_import.h

https://invent.kde.org/graphics/krita/-/commit/89ccdfb467fe0d68c26b9cc54dde272b66967253
Comment 16 Halla Rempt 2023-07-26 10:26:39 UTC
Git commit 5fd1e7669b642de51391ce86994c1e44553b9bf0 by Halla Rempt, on behalf of Dmitry Kazakov.
Committed on 26/07/2023 at 12:26.
Pushed by rempt into branch 'krita/5.2'.

[string-freeze exception] Fix loading TIFF images with embedded PSD data

In some cases the embedded PSD data may be loaded incorrectly into
Krita, in such cases we should let the user to choose, which form
he/she wants to load.

The patch breaks the string freeze, since it adds a dialog allowing
the user to choose between the two options.
CC:kimageshop@kde.org
CC:kde-i18n-doc@kde.org
(cherry picked from commit 89ccdfb467fe0d68c26b9cc54dde272b66967253)

M  +118  -84   plugins/impex/tiff/kis_tiff_import.cc
M  +9    -1    plugins/impex/tiff/kis_tiff_import.h

https://invent.kde.org/graphics/krita/-/commit/5fd1e7669b642de51391ce86994c1e44553b9bf0