Skip to content

Commit dee11ec

Browse files
committed
The component domains must be the same for the ICT/RCT in the JPC codec.
This was previously enforced with an assertion. Now, it is handled in a more graceful manner.
1 parent 411a406 commit dee11ec

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

Diff for: src/libjasper/base/jas_image.c

+19
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
#include <assert.h>
7878
#include <ctype.h>
7979
#include <inttypes.h>
80+
#include <stdbool.h>
8081

8182
#include "jasper/jas_math.h"
8283
#include "jasper/jas_image.h"
@@ -655,6 +656,24 @@ int jas_image_fmtfromname(char *name)
655656
* Miscellaneous operations.
656657
\******************************************************************************/
657658

659+
bool jas_image_cmpt_domains_same(jas_image_t *image)
660+
{
661+
int cmptno;
662+
jas_image_cmpt_t *cmpt;
663+
jas_image_cmpt_t *cmpt0;
664+
665+
cmpt0 = image->cmpts_[0];
666+
for (cmptno = 1; cmptno < image->numcmpts_; ++cmptno) {
667+
cmpt = image->cmpts_[cmptno];
668+
if (cmpt->tlx_ != cmpt0->tlx_ || cmpt->tly_ != cmpt0->tly_ ||
669+
cmpt->hstep_ != cmpt0->hstep_ || cmpt->vstep_ != cmpt0->vstep_ ||
670+
cmpt->width_ != cmpt0->width_ || cmpt->height_ != cmpt0->height_) {
671+
return 0;
672+
}
673+
}
674+
return 1;
675+
}
676+
658677
uint_fast32_t jas_image_rawsize(jas_image_t *image)
659678
{
660679
uint_fast32_t rawsize;

Diff for: src/libjasper/include/jasper/jas_image.h

+4
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@
7979
#include <jasper/jas_seq.h>
8080
#include <jasper/jas_cm.h>
8181
#include <stdio.h>
82+
#include <stdbool.h>
8283

8384
#ifdef __cplusplus
8485
extern "C" {
@@ -399,6 +400,9 @@ void jas_image_destroy(jas_image_t *image);
399400
((image)->cmpts_[cmptno]->tly_ + (image)->cmpts_[cmptno]->height_ * \
400401
(image)->cmpts_[cmptno]->vstep_)
401402

403+
// Test if all components are specified at the same positions in space. */
404+
bool jas_image_cmpt_domains_same(jas_image_t *image);
405+
402406
/* Get the raw size of an image (i.e., the nominal size of the image without
403407
any compression. */
404408
uint_fast32_t jas_image_rawsize(jas_image_t *image);

Diff for: src/libjasper/jpc/jpc_dec.c

+8
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,10 @@ static int jpc_dec_tiledecode(jpc_dec_t *dec, jpc_dec_tile_t *tile)
10911091
jas_eprintf("RCT requires at least three components\n");
10921092
return -1;
10931093
}
1094+
if (!jas_image_cmpt_domains_same(dec->image)) {
1095+
jas_eprintf("RCT requires all components have the same domain\n");
1096+
return -1;
1097+
}
10941098
jpc_irct(tile->tcomps[0].data, tile->tcomps[1].data,
10951099
tile->tcomps[2].data);
10961100
break;
@@ -1099,6 +1103,10 @@ static int jpc_dec_tiledecode(jpc_dec_t *dec, jpc_dec_tile_t *tile)
10991103
jas_eprintf("ICT requires at least three components\n");
11001104
return -1;
11011105
}
1106+
if (!jas_image_cmpt_domains_same(dec->image)) {
1107+
jas_eprintf("RCT requires all components have the same domain\n");
1108+
return -1;
1109+
}
11021110
jpc_iict(tile->tcomps[0].data, tile->tcomps[1].data,
11031111
tile->tcomps[2].data);
11041112
break;

0 commit comments

Comments
 (0)