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

Some old jpg images are saved with glitches (regression in alpha) #1978

Closed
3 of 4 tasks
botinko opened this issue Feb 5, 2022 · 4 comments · Fixed by #1979
Closed
3 of 4 tasks

Some old jpg images are saved with glitches (regression in alpha) #1978

botinko opened this issue Feb 5, 2022 · 4 comments · Fixed by #1979

Comments

@botinko
Copy link

botinko commented Feb 5, 2022

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

Description

Some pictures of our clients get corrupted when resizing and even when simply resaving by ImageSharp.
Issue exists in 2.0.0-alpha.0.168 but doesn't exists in v1.0.4.

Steps to Reproduce

            var img = Image.Load(@"issue.jpg");
            img.Save("copy.jpg");

before
issue
after
copy

Link to original image and image after resaving https://drive.google.com/file/d/1_k54RFuPciKeKBtFDLftIKetOPsWkOFO/view?usp=sharing

If you resave the image in any editor, the problem stops reproducing. So you need an original image from archive to reproduce.

System Configuration

  • Other ImageSharp packages and versions: 2.0.0-alpha.0.168
  • Environment (Operating system, version and so on): Windows 10, docker
  • .NET Framework version: dotnet 5, 6
  • Additional information: issue doesn't exists in v1.0.4.
@br3aker
Copy link
Contributor

br3aker commented Feb 5, 2022

Can confirm on my machine. Will work on it asap.

@br3aker
Copy link
Contributor

br3aker commented Feb 5, 2022

I've found error leading to this. It was broken in #1694 which did spectral -> color conversion withing spectral strides instead of full image.

Everything does work in current tests because we don't have a single component jpeg with non 1x1 sampling factors in current test suite. ITU spec says that any single component jpeg must be decoded as 'non-interleaved' jpeg:

When Ns = 1 (where Ns is the number of components in a scan), the order of data units within a scan shall be left-to-right
and top-to-bottom, as shown in Figure A.2. This ordering applies whenever Ns = 1, regardless of the values of
H1 and V1.
image

Current decoder implementation decodes single-component jpegs int interleaved mode and it works for 1x1/2x1/4x1 sampling jpegs but vertical sampling factors break it due to interleaved 'traversal':
image

Fix should be fairly simple, will try to create a PR today.

P.S.
@botinko can we include your example image in out test suite? It would help a lot as we don't have such exotic image right now :)

@botinko
Copy link
Author

botinko commented Feb 6, 2022

@br3aker Thank you very much for such a quick response! Sure, you can use it for your tests.

@br3aker
Copy link
Contributor

br3aker commented Feb 6, 2022

@botinko thanks! Fix is ready and should be available in the nearest nightly build after merge, thanks for pointing this one :)

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

Successfully merging a pull request may close this issue.

2 participants