Skip to content

Commit 2d6b6e8

Browse files
committed
Fixes #383.
Added some missing checks to the jas_heic_decode function in the HEIC codec. Added support for handling HEIC images in the run_test_1 script. Added a HEIC image to the test set.
1 parent 29154a5 commit 2d6b6e8

File tree

3 files changed

+25
-5
lines changed

3 files changed

+25
-5
lines changed

data/test/bad/383.heic

7.24 KB
Binary file not shown.

src/libjasper/heic/heic_dec.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,20 @@ jas_image_t *jas_heic_decode(jas_stream_t *in, const char *optstr)
188188
jas_logerrorf("heif_context_alloc failed\n");
189189
goto error;
190190
}
191-
#if 0
192-
#endif
193-
heif_context_read_from_memory_without_copy(ctx, ptr, size, 0);
191+
192+
struct heif_error err;
193+
err = heif_context_read_from_memory_without_copy(ctx, ptr, size, 0);
194+
if (err.code != 0) {
195+
jas_logerrorf("heif_context_read_from_memory_without_copy failed\n");
196+
goto error;
197+
}
194198

195199
/* Get a handle to the primary image. */
196-
heif_context_get_primary_image_handle(ctx, &handle);
200+
err = heif_context_get_primary_image_handle(ctx, &handle);
201+
if (err.code != 0) {
202+
jas_logerrorf("heif_context_get_primary_image_handle failed\n");
203+
goto error;
204+
}
197205

198206
int width = heif_image_handle_get_width(handle);
199207
int height = heif_image_handle_get_height(handle);
@@ -218,7 +226,6 @@ jas_image_t *jas_heic_decode(jas_stream_t *in, const char *optstr)
218226

219227
/* Decode the image and convert the colorspace to RGB,
220228
saved as 24bit interleaved. */
221-
struct heif_error err;
222229
err = heif_decode_image(handle, &img, heif_colorspace_RGB,
223230
heif_chroma_interleaved_RGB, 0);
224231
if (err.code != 0) {
@@ -247,6 +254,7 @@ jas_image_t *jas_heic_decode(jas_stream_t *in, const char *optstr)
247254
for (cmptno = 0; cmptno < numcmpts; ++cmptno) {
248255
if (width > JAS_IMAGE_COORD_MAX ||
249256
height > JAS_IMAGE_COORD_MAX) {
257+
jas_logerrorf("image size too large\n");
250258
goto error;
251259
}
252260
cmptparm.tlx = 0;
@@ -290,6 +298,8 @@ jas_image_t *jas_heic_decode(jas_stream_t *in, const char *optstr)
290298
data[3 * width * y + 3 * x + cmptno]);
291299
}
292300
if (jas_image_writecmpt(image, cmptno, 0, y, width, 1, matrix)) {
301+
jas_logerrorf("jas_image_writecmpt failed\n");
302+
goto error;
293303
}
294304
}
295305
}

test/bin/run_test_1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,15 @@ has_jpg="$(is_supported_format jpg)" || \
4646
panic "cannot determine if JPG is supported format"
4747
has_mif="$(is_supported_format mif)" || \
4848
panic "cannot determine if MIF is supported format"
49+
has_heic="$(is_supported_format heic)" || \
50+
panic "cannot determine if HEIF is supported format"
4951

5052
if [ "$internal_testing_mode" -ne 0 -a "$has_mif" -eq 0 ]; then
5153
echo "warning: MIF support is missing"
5254
fi
55+
if [ "$internal_testing_mode" -ne 0 -a "$has_heic" -eq 0 ]; then
56+
echo "warning: HEIF support is missing"
57+
fi
5358
if [ "$has_jpg" -eq 0 ]; then
5459
echo "warning: JPEG support is missing"
5560
fi
@@ -70,6 +75,11 @@ for file in "$data_dir"/test/good/*.*; do
7075
skip=1
7176
fi
7277
;;
78+
*.heic)
79+
if [ "$has_heic" -eq 0 ]; then
80+
skip=1
81+
fi
82+
;;
7383
*.txt)
7484
skip=1
7585
;;

0 commit comments

Comments
 (0)