83be9e
Backport of upstream commit:
83be9e
83be9e
From dee11ec440d7908d1daf69f40a3324b27cf213ba Mon Sep 17 00:00:00 2001
83be9e
From: Michael Adams <mdadams@ece.uvic.ca>
83be9e
Date: Mon, 24 Oct 2016 07:26:40 -0700
83be9e
Subject: [PATCH] The component domains must be the same for the ICT/RCT in the
83be9e
 JPC codec. This was previously enforced with an assertion. Now, it is handled
83be9e
 in a more graceful manner.
83be9e
83be9e
diff -pruN jasper-1.900.1.orig/src/libjasper/jpc/jpc_dec.c jasper-1.900.1/src/libjasper/jpc/jpc_dec.c
83be9e
--- jasper-1.900.1.orig/src/libjasper/jpc/jpc_dec.c	2017-03-31 22:20:39.000000000 +0200
83be9e
+++ jasper-1.900.1/src/libjasper/jpc/jpc_dec.c	2017-03-31 22:48:55.368931732 +0200
83be9e
@@ -1014,6 +1014,24 @@ if (!prc->cblks) {
83be9e
 	return 0;
83be9e
 }
83be9e
 
83be9e
+static int jas_image_cmpt_domains_same(jas_image_t *image)
83be9e
+{
83be9e
+	int cmptno;
83be9e
+	jas_image_cmpt_t *cmpt;
83be9e
+	jas_image_cmpt_t *cmpt0;
83be9e
+
83be9e
+	cmpt0 = image->cmpts_[0];
83be9e
+	for (cmptno = 1; cmptno < image->numcmpts_; ++cmptno) {
83be9e
+		cmpt = image->cmpts_[cmptno];
83be9e
+		if (cmpt->tlx_ != cmpt0->tlx_ || cmpt->tly_ != cmpt0->tly_ ||
83be9e
+		  cmpt->hstep_ != cmpt0->hstep_ || cmpt->vstep_ != cmpt0->vstep_ ||
83be9e
+		  cmpt->width_ != cmpt0->width_ || cmpt->height_ != cmpt0->height_) {
83be9e
+			return 0;
83be9e
+		}
83be9e
+	}
83be9e
+	return 1;
83be9e
+}
83be9e
+
83be9e
 static int jpc_dec_tiledecode(jpc_dec_t *dec, jpc_dec_tile_t *tile)
83be9e
 {
83be9e
 	int i;
83be9e
@@ -1074,6 +1092,10 @@ static int jpc_dec_tiledecode(jpc_dec_t
83be9e
 			jas_eprintf("RCT requires at least three components\n");
83be9e
 			return -1;
83be9e
 		}
83be9e
+		if (!jas_image_cmpt_domains_same(dec->image)) {
83be9e
+			jas_eprintf("RCT requires all components have the same domain\n");
83be9e
+			return -1;
83be9e
+		}
83be9e
 		jpc_irct(tile->tcomps[0].data, tile->tcomps[1].data,
83be9e
 		  tile->tcomps[2].data);
83be9e
 		break;
83be9e
@@ -1082,6 +1104,10 @@ static int jpc_dec_tiledecode(jpc_dec_t
83be9e
 			jas_eprintf("ICT requires at least three components\n");
83be9e
 			return -1;
83be9e
 		}
83be9e
+		if (!jas_image_cmpt_domains_same(dec->image)) {
83be9e
+			jas_eprintf("RCT requires all components have the same domain\n");
83be9e
+			return -1;
83be9e
+		}
83be9e
 		jpc_iict(tile->tcomps[0].data, tile->tcomps[1].data,
83be9e
 		  tile->tcomps[2].data);
83be9e
 		break;