Opening JPEG2000 images is very slow
Thank you for posting this issue, @Charltsing . You are right - this file opens too slowly in PhotoDemon.
I'm currently using the OpenJPEG library (via FreeImage) to load JPEG2000 images.
I will look at switching to an alternate library in the coming days.
Hello @Charltsing . I have now written my own OpenJPEG interface in the latest PhotoDemon nightly builds. JPEG-2000 support is greatly improved with this change.
The image above (JPXDecode) has gone from taking ~10 seconds to load, to just ~1 second on my test laptop. I hope you see similar results on your end.
Thank you so much for submitting this bug report!
Thank you for your excellent work. This picture took less than two seconds to open on my computer
BTW: Perhaps you can introduce your optimization ideas to me, which can help other open source projects
Thank you for the follow-up testing, @Charltsing ! I'm happy the performance improvements were noticeable.
Most of my code for importing JPEG-2000 images is found in this file:
https://github.com/tannerhelland/PhotoDemon/blob/main/Modules/Plugin_OpenJPEG.bas
There is nothing especially unique to PhotoDemon's new JPEG-2000 import code. (If anything, other developers could achieve even greater performance, since I am currently limited to single-threaded behavior.) I simply iterated many small performance tweaks, profiling as I went, and kept any that demonstrated meaningful improvements.
JPEG-2000 image data can be very complex to import. There are many different combinations of settings, and I've tried to separate out handling where I can so that JP2 images with simply formatted data (like the one you provided) are not hurt by the additional computations required by more complex JP2 settings (HDR, subsampled data, etc). So perhaps PhotoDemon's good performance on your test image is simply because it skips many extra steps required for other JP2 images.
Like Magick.NET, I also have to copy the OpenJPEG data into a custom format+container, and I have to do it pixel-by-pixel (the slowest copy mechanism). So I don't think that is necessarily a barrier, and they will also achieve excellent performance in the future, possibly much better than my work. I look forward to their changes!
Thank you again for your help!