Skip to content

Reading incorrect color data when JpegColorType is Rgb. #2141

@CryShana

Description

@CryShana

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

2.1.2

Other ImageSharp packages and versions

SixLabors.ImageSharp 2.1.2

Environment (Operating system, version and so on)

Windows 11 and Ubuntu 20.04.4 LTS

.NET Framework version

.NET 6 (SDK 6.0.300)

Description

JPEG images with ColorType value of JpegColorType.Rgb have their color values read/parsed incorrectly.

Though such images are rare, I encountered multiple such images already and all of them were read incorrectly. Other image readers and tools read them correctly.

Example code:

using var image = Image.Load(filePath);

var colorType = image.Metadata.GetJpegMetadata().ColorType;
if (colorType == JpegColorType.Rgb)
{
    // colors will be read wrong
}

// you can save it as anything, doesn't matter
image.SaveAsJpeg("output.jpg");

Just to get an idea of how colors change with an example input image. This is the original:
input

The output is this:
output

Steps to Reproduce

This works on any JPEG image that has ColorType = JpegColorType.Rgb

  • Load any such image by using Image.Load(filepath); or Image.Load<Rgba32>(filepath);
  • You can try reading some pixels to confirm the colors are off
  • Save image using any method, I used image.SaveAsJpeg(outputPath);

The output should be very different from the input.

Images

Original (input image):
input

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