aboutsummaryrefslogtreecommitdiff
path: root/lib/src
diff options
context:
space:
mode:
authorRam Mohan <ram.mohan@ittiam.com>2024-03-23 06:14:20 +0530
committerDichenZhang1 <140119224+DichenZhang1@users.noreply.github.com>2024-03-25 13:22:51 -0700
commit578fa271487f1d3a96b4e9f457709bfa8ea89e21 (patch)
tree555256c71769c6560f37e6539aa8e239870f76fb /lib/src
parent8036e0410599f86e1387a221db0ba0145340842f (diff)
downloadlibultrahdr-578fa271487f1d3a96b4e9f457709bfa8ea89e21.tar.gz
For deps, use pre-installed packages if available
Test: ./ultrahdr_unit_test
Diffstat (limited to 'lib/src')
-rw-r--r--lib/src/jpegdecoderhelper.cpp26
-rw-r--r--lib/src/jpegr.cpp18
2 files changed, 41 insertions, 3 deletions
diff --git a/lib/src/jpegdecoderhelper.cpp b/lib/src/jpegdecoderhelper.cpp
index 70efb87..b787687 100644
--- a/lib/src/jpegdecoderhelper.cpp
+++ b/lib/src/jpegdecoderhelper.cpp
@@ -270,9 +270,15 @@ bool JpegDecoderHelper::decode(const void* image, int length, decode_mode_t deco
ALOGE("%s: decodeToRGBA unexpected primary image sub-sampling", __func__);
goto CleanUp;
}
+#ifdef JCS_ALPHA_EXTENSIONS
// 4 bytes per pixel
mResultBuffer.resize(cinfo.image_width * cinfo.image_height * 4);
cinfo.out_color_space = JCS_EXT_RGBA;
+#else
+ // 3 bytes per pixel
+ mResultBuffer.resize(cinfo.image_width * cinfo.image_height * 3);
+ cinfo.out_color_space = JCS_RGB;
+#endif
} else if (decodeTo == DECODE_TO_YCBCR) {
if (cinfo.jpeg_color_space == JCS_YCbCr) {
if (cinfo.comp_info[0].h_samp_factor != 2 || cinfo.comp_info[0].v_samp_factor != 2 ||
@@ -315,9 +321,19 @@ CleanUp:
bool JpegDecoderHelper::decompress(jpeg_decompress_struct* cinfo, const uint8_t* dest,
bool isSingleChannel) {
- return isSingleChannel ? decompressSingleChannel(cinfo, dest)
- : ((cinfo->out_color_space == JCS_EXT_RGBA) ? decompressRGBA(cinfo, dest)
- : decompressYUV(cinfo, dest));
+ if (isSingleChannel) {
+ return decompressSingleChannel(cinfo, dest);
+ } else {
+#ifdef JCS_ALPHA_EXTENSIONS
+ if (cinfo->out_color_space == JCS_EXT_RGBA) {
+#else
+ if (cinfo->out_color_space == JCS_RGB) {
+#endif
+ return decompressRGBA(cinfo, dest);
+ } else {
+ return decompressYUV(cinfo, dest);
+ }
+ }
}
bool JpegDecoderHelper::getCompressedImageParameters(const void* image, int length) {
@@ -329,7 +345,11 @@ bool JpegDecoderHelper::decompressRGBA(jpeg_decompress_struct* cinfo, const uint
while (cinfo->output_scanline < cinfo->image_height) {
if (1 != jpeg_read_scanlines(cinfo, &out, 1)) return false;
+#ifdef JCS_ALPHA_EXTENSIONS
out += cinfo->image_width * 4;
+#else
+ out += cinfo->image_width * 3;
+#endif
}
return true;
}
diff --git a/lib/src/jpegr.cpp b/lib/src/jpegr.cpp
index db015f5..e9252c5 100644
--- a/lib/src/jpegr.cpp
+++ b/lib/src/jpegr.cpp
@@ -676,11 +676,19 @@ status_t JpegR::decodeJPEGR(jr_compressed_ptr jpegr_image_ptr, jr_uncompressed_p
}
if (output_format == ULTRAHDR_OUTPUT_SDR) {
+#ifdef JCS_ALPHA_EXTENSIONS
if ((jpeg_dec_obj_yuv420.getDecompressedImageWidth() *
jpeg_dec_obj_yuv420.getDecompressedImageHeight() * 4) >
jpeg_dec_obj_yuv420.getDecompressedImageSize()) {
return ERROR_JPEGR_DECODE_ERROR;
}
+#else
+ if ((jpeg_dec_obj_yuv420.getDecompressedImageWidth() *
+ jpeg_dec_obj_yuv420.getDecompressedImageHeight() * 3) >
+ jpeg_dec_obj_yuv420.getDecompressedImageSize()) {
+ return ERROR_JPEGR_DECODE_ERROR;
+ }
+#endif
} else {
if ((jpeg_dec_obj_yuv420.getDecompressedImageWidth() *
jpeg_dec_obj_yuv420.getDecompressedImageHeight() * 3 / 2) >
@@ -741,8 +749,18 @@ status_t JpegR::decodeJPEGR(jr_compressed_ptr jpegr_image_ptr, jr_uncompressed_p
if (output_format == ULTRAHDR_OUTPUT_SDR) {
dest->width = jpeg_dec_obj_yuv420.getDecompressedImageWidth();
dest->height = jpeg_dec_obj_yuv420.getDecompressedImageHeight();
+#ifdef JCS_ALPHA_EXTENSIONS
memcpy(dest->data, jpeg_dec_obj_yuv420.getDecompressedImagePtr(),
dest->width * dest->height * 4);
+#else
+ uint32_t* pixelDst = static_cast<uint32_t*>(dest->data);
+ uint8_t* pixelSrc = static_cast<uint8_t*>(jpeg_dec_obj_yuv420.getDecompressedImagePtr());
+ for (int i = 0; i < dest->width * dest->height; i++) {
+ *pixelDst = pixelSrc[0] | (pixelSrc[1] << 8) | (pixelSrc[2] << 16) | (0xff << 24);
+ pixelSrc += 3;
+ pixelDst += 1;
+ }
+#endif
dest->colorGamut = IccHelper::readIccColorGamut(jpeg_dec_obj_yuv420.getICCPtr(),
jpeg_dec_obj_yuv420.getICCSize());
return JPEGR_NO_ERROR;