From 4df3a270ebf96b01ac33805fb42e4661d5aa12ad Mon Sep 17 00:00:00 2001 From: Aang23 Date: Sun, 6 Aug 2023 11:52:06 +0200 Subject: [PATCH] J2K fixes --- src-core/common/image/image_j2kio.cpp | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/src-core/common/image/image_j2kio.cpp b/src-core/common/image/image_j2kio.cpp index 78028e1ec..07f3e8702 100644 --- a/src-core/common/image/image_j2kio.cpp +++ b/src-core/common/image/image_j2kio.cpp @@ -21,6 +21,7 @@ namespace image OPJ_CODEC_FORMAT codec_format = OPJ_CODEC_J2K; opj_set_default_encoder_parameters(¶meters); + parameters.numresolution = 5; { opj_image_cmptparm_t comp_params[4]; @@ -162,10 +163,30 @@ namespace image } // Parse into image + int depth = image->comps[0].prec; init(image->x1, image->y1, image->numcomps); - for (int c = 0; c < d_channels; c++) - for (int i = 0; i < int(image->x1 * image->y1); i++) - channel(c)[i] = image->comps[c].data[i]; + + if (d_depth == 16) + { + for (int c = 0; c < d_channels; c++) + for (int i = 0; i < int(image->x1 * image->y1); i++) + channel(c)[i] = image->comps[c].data[i] << (16 - depth); + } + else if (d_depth == 8) + { + if (depth >= 8) + { + for (int c = 0; c < d_channels; c++) + for (int i = 0; i < int(image->x1 * image->y1); i++) + channel(c)[i] = image->comps[c].data[i] >> (depth - 8); + } + else + { + for (int c = 0; c < d_channels; c++) + for (int i = 0; i < int(image->x1 * image->y1); i++) + channel(c)[i] = image->comps[c].data[i] << (8 - depth); + } + } // Free everything up opj_destroy_codec(l_codec);