Skip to content

Load-Save TGA wiping alpha channel #2629

Description

@AN3Orik

Prerequisites

  • I have written a descriptive issue title
  • I have verified that I am running the latest version of ImageSharp
  • I have verified if the problem exist in both DEBUG and RELEASE mode
  • I have searched open and closed issues to ensure it has not already been reported

ImageSharp version

3.0.0

Other ImageSharp packages and versions

3.0.0

Environment (Operating system, version and so on)

Windows 10

.NET Framework version

.NET 8

Description

Loading 32bit RGBA TGA and saving after wiping Alpha channel to white (255) color.

Steps to Reproduce

using (Image<Rgba32> image = Image.Load<Rgba32>("test.tga"))
{
   image.Save("test_output.tga");
}

Before:
image

After:
image

Images

test.zip

Activity

  1. AN3Orik commented on Dec 26, 2023

    @AN3Orik
    Author

    Sorry, library version is 3.1.1

  2. brianpopow commented on Jan 3, 2024

    @brianpopow
    Collaborator

    The image descriptor byte in the file header of the provided image is 0. Usually bits 0-3 indicate designated as alpha channel bits.
    Since the descriptor is 0, the decoder assumes there is no alpha channel.

    That is the reason it is lost when decoding and encoding again.

  3. brianpopow commented on Jan 6, 2024

    @brianpopow
    Collaborator

    I still believe the provided image does not follow the spec with omitting the image descriptor, when there is alpha data.
    Other decoders have problems with it too, like irfanview:
    edit: not sure why this image renders so weird in github, looks different when you click on it.

    test

    I think one solution in handling this is to assume true color images with 32 bits per pixel to always have a alpha channel with 8 bit. @JimBobSquarePants What do you think about this? Would anyone write a 32 bits per pixel image without a alpha channel?

  4. JimBobSquarePants commented on Jan 7, 2024

    @JimBobSquarePants
    Member

    Yeah @brianpopow good idea! I think that’s a safe assumption and it’s non-destructive. We should add it to the v3.1.x branch and then main.

  5. brianpopow commented on Jan 8, 2024

    @brianpopow
    Collaborator

    @AN3Orik can I use the image you have provided in a unit test?

  6. AN3Orik commented on Jan 8, 2024

    @AN3Orik
    Author

    @AN3Orik can I use the image you have provided in a unit test?

    It's a texture from very old game, so i think it's not a problem at all if you care about license or something.

  7. brianpopow commented on Jan 13, 2024

    @brianpopow
    Collaborator

    We should add it to the v3.1.x branch

    @JimBobSquarePants I have opened a PR for this Issue. I am not sure how the procedure is to add it to the v3.1.x, I think, it would be better if you do that, so I dont break stuff. Also I am not totally sure this should go into a hotfix, since the image is not following the spec correctly and this PR only adds a workaround to deal with those kind of images.

  8. JimBobSquarePants commented on Jan 14, 2024

    @JimBobSquarePants
    Member

    I’m happy to skip adding to 3.1.x I’ve only been doing so because v4 is so far away.

  9. brianpopow commented on Jan 18, 2024

    @brianpopow
    Collaborator

    closing this now with #2643 merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions