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

Jp2ksaveStream throws an error: Is Jpeg 2000 not fully implemented? #147

Closed
michael-scott-phoseon opened this issue Oct 9, 2021 · 5 comments
Labels
question Further information is requested

Comments

@michael-scott-phoseon
Copy link

We have images in a pyramidal tiff file that are of 81920 x 98304, so using JpegsaveStream won't work, as it has a 65500 x 65500 size limit. So we are trying to use Jp2ksaveSteam instead. However, it throws this error:

      NetVips.VipsException: 'no such operation jp2ksave_target VipsOperation: class "jp2ksave_target" not found

Does libvips and / or NetVips not support Jpeg 2000? We are trying to insert a libvips Image into a WPF Window, so are trying to move the stream into a BitmapSource. But I am even willing to place it into a Windows Forms Bitmap. Here is the method I'm using:

    private static BitmapImage NetVipsToImageSource(NetVips.Image img)
    {
        using (MemoryStream memory = new MemoryStream())
        {
            img.Jp2ksaveStream(memory);
            //img.JpegsaveStream(memory);
            //img.WriteToStream(memory, ".jpg");
            memory.Position = 0;
            BitmapImage bitmapImage = new BitmapImage();
            bitmapImage.BeginInit();
            bitmapImage.StreamSource = memory;
            bitmapImage.CacheOption = BitmapCacheOption.OnLoad;
            bitmapImage.EndInit();

            return bitmapImage;
        }
    }

Am I doing something wrong? Is Jpeg 2000 not supported? Is there another way to do this?

Michael

@kleisauke kleisauke added the question Further information is requested label Oct 9, 2021
@kleisauke
Copy link
Owner

See #142 (comment) for the reason why saving to JPEG 2000 isn't supported by default.

You could use the NetVips.Extensions NuGet package for converting a GDI+ bitmap to NetVips and vice versa (with the ToBitmap() and ToVips() functions). It should be faster than encoding/decoding the image to a JPEG (or PNG, TIFF, etc.) memory stream. Note that the conversion to a WPF image isn't supported by this package (see #81).

@michael-scott-phoseon
Copy link
Author

michael-scott-phoseon commented Oct 11, 2021 via email

@michael-scott-phoseon
Copy link
Author

Sadly, ToBitmap isn't working. The method is failing on this line in your code:

 Bitmap bitmap = new Bitmap(src.Width, src.Height, format);

Which is equivalent to

 Bitmap bitmap = new Bitmap(28672, 28672, PixelFormat.Format24bppRgb);

This line fails because the image is too big.

So unless you guys have another idea, I'm looking into how I can load each individual tile on a Page instead of the entire page in a pyramidal file structure. Do you have any examples of that, instead of loading each page at once?

@kleisauke
Copy link
Owner

I'm not sure if there is a workaround for this GDI+ limitation other than avoiding System.Drawing or cropping and stitching the image (as John said in libvips/libvips#2478 (reply in thread)).

@kleisauke
Copy link
Owner

I hope this information helped. Please feel free to re-open if questions remain.

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

No branches or pull requests

2 participants