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

Output file image has artifacts #11

Open
Msey opened this issue Dec 20, 2024 · 3 comments
Open

Output file image has artifacts #11

Msey opened this issue Dec 20, 2024 · 3 comments

Comments

@Msey
Copy link

Msey commented Dec 20, 2024

To convert heic image to number of png frames or just one jpg file i'm using examples from your main page like this one:

using (var fs = new FileStream("filename.heic", FileMode.Open))
{
    HeicImage image = HeicImage.Load(fs);
     
    var pixels = image.GetByteArray(Heic.Decoder.PixelFormat.Bgra32);
    var width = (int)image.Width;
    var height = (int)image.Height;
     
    var wbitmap = new WriteableBitmap(width, height, 72, 72, PixelFormats.Bgra32, null);
    var rect = new Int32Rect(0, 0, width, height);
    wbitmap.WritePixels(rect, pixels, 4 * width, 0);
    
    using FileStream saveStream = new FileStream("output.jpg", FileMode.OpenOrCreate);
    JpegBitmapEncoder encoder = new JpegBitmapEncoder();
    encoder.Frames.Add(BitmapFrame.Create(wbitmap));
    encoder.Save(saveStream);
}

But the output image is tiled with strange squares

image

What the cause of it and how to solve the problem?

@Horodep
Copy link
Member

Horodep commented Dec 20, 2024

@Msey this looks like the miscalculations in cabac context variables. It's library issue, not the incorrent usage. Can you provide the original file for the futher research?

If you are interested in details, the image inside is represented as multiple 512*512 images, and each block is decoded separately. As a result even if there are miscalculations during decoding, the next square will start decoding with correct colors. This brings us this tile view.

@Msey
Copy link
Author

Msey commented Dec 23, 2024

@Horodep
image3.zip
Sure. Here's the archive with mentioned image

@Horodep
Copy link
Member

Horodep commented Dec 23, 2024

@Msey
We'll research it and fix in the next versions.
We'll try to deliver this patch in Q1 2025, but there no real ETA untill the proper research is done.
Thank you for your patience!

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