Skip to content

Commit ff9d9ef

Browse files
authored
Merge pull request #458 from ATrivialAtomic/cmpto-j2k-lossless
cmpto_j2k: vcomp/vdec lossless additional features/cleanup
2 parents b899dbe + 98e320f commit ff9d9ef

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

src/video_compress/cmpto_j2k.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -442,14 +442,19 @@ static bool configure_with(struct state_video_compress_j2k *s, struct video_desc
442442

443443
CHECK_OK(cmpto_j2k_enc_cfg_create(s->context, &s->enc_settings),
444444
"Creating context configuration:", return false);
445-
CHECK_OK(cmpto_j2k_enc_cfg_set_quantization(
445+
446+
if (s->lossless) {
447+
MSG(INFO, "Lossless compression selected. Ignoring quality parameter.\n");
448+
CHECK_OK(cmpto_j2k_enc_cfg_set_lossless(
449+
s->enc_settings, s->lossless),
450+
"Setting lossless mode", NOOP);
451+
} else {
452+
CHECK_OK(cmpto_j2k_enc_cfg_set_quantization(
446453
s->enc_settings,
447454
s->quality /* 0.0 = poor quality, 1.0 = full quality */
448455
),
449456
"Setting quantization", NOOP);
450-
CHECK_OK(cmpto_j2k_enc_cfg_set_lossless(
451-
s->enc_settings, s->lossless),
452-
"Setting lossless mode", NOOP);
457+
}
453458

454459
CHECK_OK(cmpto_j2k_enc_cfg_set_resolutions(s->enc_settings, 6),
455460
"Setting DWT levels", NOOP);
@@ -772,10 +777,12 @@ static struct module * j2k_compress_init(struct module *parent, const char *c_cf
772777
}
773778
}
774779

775-
if (s->quality < 0.0 || s->quality > 1.0) {
776-
LOG(LOG_LEVEL_ERROR) << "[J2K] Quality should be in interval [0-1]!\n";
777-
j2k_compress_done((struct module *) s);
778-
return nullptr;
780+
if (!s->lossless) {
781+
if (s->quality < 0.0 || s->quality > 1.0) {
782+
LOG(LOG_LEVEL_ERROR) << "[J2K] Quality should be in interval [0-1]!\n";
783+
j2k_compress_done((struct module *) s);
784+
return nullptr;
785+
}
779786
}
780787

781788
s->tech = get_supported_technology(req_technology);

src/video_decompress/cmpto_j2k.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,22 @@ static decompress_status j2k_probe_internal_codec(codec_t in_codec, unsigned cha
632632
int msg_level = internal_prop->subsampling == 0 ? LOG_LEVEL_WARNING /* bogus? */ : LOG_LEVEL_VERBOSE;
633633
log_msg(msg_level, "J2K stream properties: %s\n", get_pixdesc_desc(*internal_prop));
634634

635+
// Attempt to get the lossiness info of the image
636+
enum cmpto_codestream_lossiness lossiness;
637+
if (cmpto_j2k_dec_cstream_get_ext_img_info(buffer, len, &info, &lossiness) != CMPTO_OK) {
638+
MSG(WARNING, "J2K failed to get image extended attributes. Unable to read image lossiness info.\n");
639+
} else {
640+
static auto get_lossiness_string = [&lossiness]() {
641+
switch (lossiness) {
642+
case CMPTO_LOSSLESS: return "Lossless";
643+
case CMPTO_LOSSY: return "Lossy";
644+
case CMPTO_MIXED_LOSSINESS: return "Mixed";
645+
default: return "Unknown";
646+
}
647+
};
648+
MSG(INFO, "J2K codestream lossiness: %s\n", get_lossiness_string());
649+
}
650+
635651
return DECODER_GOT_CODEC;
636652
}
637653

0 commit comments

Comments
 (0)