Bug 447240 - After saving a .jp2 file the file could not be open.
Summary: After saving a .jp2 file the file could not be open.
Status: RESOLVED FIXED
Alias: None
Product: digikam
Classification: Applications
Component: Plugin-DImg-JP2K (show other bugs)
Version: 7.4.0
Platform: Microsoft Windows Microsoft Windows
: NOR grave
Target Milestone: ---
Assignee: Digikam Developers
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-12-19 20:35 UTC by Paul
Modified: 2022-01-08 04:23 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In: 7.5.0
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul 2021-12-19 20:35:05 UTC
SUMMARY
***
NOTE: If you are reporting a crash, please try to attach a backtrace with debug symbols.
See https://community.kde.org/Guidelines_and_HOWTOs/Debugging/How_to_create_useful_crash_reports
***


STEPS TO REPRODUCE
1. In image editor setting - Versioning - set save file as jpeg 2000
2. Edit some file
3. Save file as new version

OBSERVED RESULT
Saved file cannot be open. Thumbnail viewer shows no preview (only green thumbnail placeholder). Trying to open in IrfanView = decode error.

EXPECTED RESULT
Normal thumbnail + normal file opening with .jp2 extension in any (supported) software.

SOFTWARE/OS VERSIONS
Windows: 10 build 19044
macOS: 
Linux/KDE Plasma: 
(available in About System)
KDE Plasma Version: 
KDE Frameworks Version: 
Qt Version: 5.15.2

ADDITIONAL INFORMATION
Comment 1 Maik Qualmann 2021-12-19 21:36:35 UTC
When i google this error seems to be a problem in libjasper:

maximum number of samples exceeded (72480768 > 67108864)
error: cannot decode code stream

Gimp can open the JPEG2000 files created by digiKam.

Maik
Comment 2 caulier.gilles 2021-12-19 22:31:21 UTC
gimp use OpenJPEG, not Jasper : https://github.com/GNOME/gimp/blob/master/plug-ins/common/file-jp2-load.c#L88

MXE build Jasper version 2.0.33 : https://github.com/mxe/mxe/blob/master/src/jasper.mk#L7

So we use the last stable version in digiKam for Windows : https://github.com/jasper-software/jasper/releases
Comment 3 caulier.gilles 2021-12-19 22:36:48 UTC
GDal project use openjpeg to wrap around this issue :

https://github.com/OSGeo/gdal/issues/2198

...
Comment 4 Maik Qualmann 2021-12-19 22:36:56 UTC
The whole thing seems to be dependent on the image size, images with 2000x3000px work, with 4000x6000px the problem occurs.

Maik
Comment 5 caulier.gilles 2021-12-19 22:41:00 UTC
A little bit old but interesting :

https://bbs.archlinux.org/viewtopic.php?pid=1700769#p1700769

I recommend to UPSTREAM this bug to Jasper project in github.

Gilles Caulier
Comment 6 caulier.gilles 2021-12-19 22:42:54 UTC
Seriously, Jasper codec do not support image size of 24Mpx ? (:-)))...
Comment 7 caulier.gilles 2021-12-25 17:05:01 UTC
This problem is also reproducible under Linux. too weird !
Comment 8 caulier.gilles 2021-12-25 17:07:22 UTC
Paul,

This problem from JPEG2000 codec must be reported to Jasper library project as UPSTREAM bug here :

https://github.com/jasper-software/jasper/issues

Thanks in advance

Gilles Caulier
Comment 9 caulier.gilles 2021-12-29 16:20:41 UTC
UPSTREAM bug : https://github.com/jasper-software/jasper/issues/315
Comment 10 caulier.gilles 2022-01-04 06:44:41 UTC
Maik, 

We receive a response : https://github.com/jasper-software/jasper/issues/315#issuecomment-1004465646

To resume : it miss a Jasper setting call in DImg::JP2Loader to configure a data size limit before to decode image.

Gilles
Comment 11 Maik Qualmann 2022-01-04 07:43:54 UTC
Hi Gilles,

The function should be "jas_conf_set_dec_default_max_samples (0);" being. The 
zero ignores the size, could be dangerous. It just doesn't compile for me 
because my Libjasper doesn't yet contain the function. 

Maik

Am Dienstag, 4. Januar 2022, 07:44:41 CET schrieben Sie:
> https://bugs.kde.org/show_bug.cgi?id=447240
> 
> --- Comment #10 from caulier.gilles@gmail.com ---
> Maik,
> 
> We receive a response :
> https://github.com/jasper-software/jasper/issues/315#issuecomment-1004465646
> 
> To resume : it miss a Jasper setting call in DImg::JP2Loader to configure a
> data size limit before to decode image.
> 
> Gilles
Comment 12 Maik Qualmann 2022-01-04 07:48:43 UTC
I have Libjasper 2.0.33 here and it is still a fixed compiled size there. 

#if !defined(JAS_DEC_DEFAULT_MAX_SAMPLES)
#define JAS_DEC_DEFAULT_MAX_SAMPLES (64 * ((size_t) 1048576))
#endif

Maik

Am Dienstag, 4. Januar 2022, 08:43:45 CET schrieben Sie:
> Hi Gilles,
> 
> The function should be "jas_conf_set_dec_default_max_samples (0);" being.
> The zero ignores the size, could be dangerous. It just doesn't compile for
> me because my Libjasper doesn't yet contain the function.
> 
> Maik
> 
> Am Dienstag, 4. Januar 2022, 07:44:41 CET schrieben Sie:
> > https://bugs.kde.org/show_bug.cgi?id=447240
> > 
> > --- Comment #10 from caulier.gilles@gmail.com ---
> > Maik,
> > 
> > We receive a response :
> > https://github.com/jasper-software/jasper/issues/315#issuecomment-10044656
> > 46
> > 
> > To resume : it miss a Jasper setting call in DImg::JP2Loader to configure
> > a
> > data size limit before to decode image.
> > 
> > Gilles
Comment 13 caulier.gilles 2022-01-08 04:23:09 UTC
Git commit 440951f977929d90b06141d23d03e84a5bd83d00 by Gilles Caulier.
Committed on 08/01/2022 at 04:20.
Pushed by cgilles into branch 'master'.

Pass JP2 decoder option string with max samples value to prevent broken load image in preview and image editor.
See UPSTREAM bug details : https://github.com/jasper-software/jasper/issues/315#issuecomment-1007872809
FIXED-IN: 7.5.0

M  +32   -21   core/dplugins/dimg/jpeg2000/dimgjpeg2000loader_load.cpp
M  +10   -7    core/dplugins/dimg/jpeg2000/dimgjpeg2000loader_save.cpp

https://invent.kde.org/graphics/digikam/commit/440951f977929d90b06141d23d03e84a5bd83d00