Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HasAlpha property set incorrectly on TIFF sRGB file #1429

Open
pablojmp opened this issue Aug 16, 2023 · 7 comments
Open

HasAlpha property set incorrectly on TIFF sRGB file #1429

pablojmp opened this issue Aug 16, 2023 · 7 comments

Comments

@pablojmp
Copy link

Magick.NET version

Magick.NET-Q8-x64 13.1.2

Environment (Operating system, version and so on)

Windows 10 22H2 Build 19045.3324

Description

TIFF file with sRGB colorspace fails to detect the alpha channel. It was correctly detected on version 12.3.0

Also, MagickImage.ChannelCount and MagickImage.Channels.Count are not equal for this sample

The file: 2001022-fullcolor.zip

Steps to Reproduce

    using ImageMagick; 
    using System.Linq;

    static void Main()
    {
      using(var lIM = new MagickImage(testFile))
      {
        var lHasAlpha = lIM.HasAlpha;
        var lChannels_Count = lIM.Channels.Count();
        var lChannelsCount = lIM.ChannelCount;
      }
    }
@pablojmp
Copy link
Author

ColorType is detected as TrueColor on 13.1.2 and as TrueColorAlpha on 12.3.0

@dlemstra
Copy link
Owner

dlemstra commented Aug 18, 2023

The recent version of ImageMagick has made some improvements to read additional channels. The tiff library that is being used reports the following warning:

Sum of Photometric type-related color channels and ExtraSamples doesn't match SamplesPerPixel. Defining non-color channels as ExtraSamples.

In earlier versions of ImageMagick we would not check this and assume the image has an alpha channel. But looking at the output image we probably fixed reading it? It now shows a colored image and it looks like the extra sample/channel contains a mask for certain areas of the image?

@pablojmp
Copy link
Author

how should i access the extra samples channel in the new version? i was doing image.Separate(Channels.Alpha).First();. how should i detect the non-color channels?

@dlemstra
Copy link
Owner

There is no proper api to do that at this time. I will be going to add this but that will be going to take me a while because I am working on some big internal changes related to those flags. For now you can probably do this: image.Separate((Channels) 1024).First();

@pablojmp
Copy link
Author

i think it's better in my use case to revert to 12.3.0 for the moment. is there an issue i can subscribe to so i know when you're done with the changes?

@pablojmp
Copy link
Author

@dlemstra hi! i've looked into version 13.5.0 and channels.count and channelscount now match (4 for both), but hasalpha is still false on 13.5. i'd like to update as 12.3 is marked as vulnerable. is there any way to detect the channel as an alpha channel? new updated test code:


public static class Program
{
  public static void Main()
  {
    var testFile = @"../../../../2001022-fullcolor.tif";

    using (var lIM = new MagickImage(testFile))
    {
      var lHasAlpha = lIM.HasAlpha;
      var lChannels = lIM.Channels.ToList();
      var lChannelCount = lIM.ChannelCount;

      Console.WriteLine($"Channels: {string.Join(", ", lChannels.Cast<int>())}");
      Console.WriteLine($"HasAlpha: {lHasAlpha}. Channels.Count {lChannels.Count}. ChannelsCount {lChannelCount}");
    }
  }
}

Output with 12.3:

Channels: 0, 1, 2, 4
HasAlpha: True. Channels.Count 4. ChannelsCount 4

Output with 13.5:

Channels: 0, 1, 2, 10
HasAlpha: False. Channels.Count 4. ChannelsCount 4

@dlemstra
Copy link
Owner

There is no option yet to directly assume that the 4th channel is an alpha channel so you will need to do this really expensive "trick":

using (var lIM = new MagickImage(testFile))
{
    using (var images = new MagickImageCollection(lIM.Separate()))
    {
        using (var image = images.Combine())
        {
        }
    }
}

I haven't made time yet to figure out how I can add an option for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants