Skip to content

Commit

Permalink
Fixes #383.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mdadams committed Apr 27, 2024
1 parent 29154a5 commit 2d6b6e8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Binary file added data/test/bad/383.heic
Binary file not shown.
20 changes: 15 additions & 5 deletions src/libjasper/heic/heic_dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,20 @@ jas_image_t *jas_heic_decode(jas_stream_t *in, const char *optstr)
jas_logerrorf("heif_context_alloc failed\n");
goto error;
}
#if 0
#endif
heif_context_read_from_memory_without_copy(ctx, ptr, size, 0);

struct heif_error err;
err = heif_context_read_from_memory_without_copy(ctx, ptr, size, 0);
if (err.code != 0) {
jas_logerrorf("heif_context_read_from_memory_without_copy failed\n");
goto error;
}

/* Get a handle to the primary image. */
heif_context_get_primary_image_handle(ctx, &handle);
err = heif_context_get_primary_image_handle(ctx, &handle);
if (err.code != 0) {
jas_logerrorf("heif_context_get_primary_image_handle failed\n");
goto error;
}

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

/* Decode the image and convert the colorspace to RGB,
saved as 24bit interleaved. */
struct heif_error err;
err = heif_decode_image(handle, &img, heif_colorspace_RGB,
heif_chroma_interleaved_RGB, 0);
if (err.code != 0) {
Expand Down Expand Up @@ -247,6 +254,7 @@ jas_image_t *jas_heic_decode(jas_stream_t *in, const char *optstr)
for (cmptno = 0; cmptno < numcmpts; ++cmptno) {
if (width > JAS_IMAGE_COORD_MAX ||
height > JAS_IMAGE_COORD_MAX) {
jas_logerrorf("image size too large\n");
goto error;
}
cmptparm.tlx = 0;
Expand Down Expand Up @@ -290,6 +298,8 @@ jas_image_t *jas_heic_decode(jas_stream_t *in, const char *optstr)
data[3 * width * y + 3 * x + cmptno]);
}
if (jas_image_writecmpt(image, cmptno, 0, y, width, 1, matrix)) {
jas_logerrorf("jas_image_writecmpt failed\n");
goto error;
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions test/bin/run_test_1
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,15 @@ has_jpg="$(is_supported_format jpg)" || \
panic "cannot determine if JPG is supported format"
has_mif="$(is_supported_format mif)" || \
panic "cannot determine if MIF is supported format"
has_heic="$(is_supported_format heic)" || \
panic "cannot determine if HEIF is supported format"

if [ "$internal_testing_mode" -ne 0 -a "$has_mif" -eq 0 ]; then
echo "warning: MIF support is missing"
fi
if [ "$internal_testing_mode" -ne 0 -a "$has_heic" -eq 0 ]; then
echo "warning: HEIF support is missing"
fi
if [ "$has_jpg" -eq 0 ]; then
echo "warning: JPEG support is missing"
fi
Expand All @@ -70,6 +75,11 @@ for file in "$data_dir"/test/good/*.*; do
skip=1
fi
;;
*.heic)
if [ "$has_heic" -eq 0 ]; then
skip=1
fi
;;
*.txt)
skip=1
;;
Expand Down

0 comments on commit 2d6b6e8

Please sign in to comment.