diff options
author | Aayush Soni <aayush.soni@ittiam.com> | 2023-12-07 19:49:06 +0530 |
---|---|---|
committer | Aayush Soni <aayush.soni@ittiam.com> | 2023-12-11 18:07:35 +0530 |
commit | 5ab56043eb3f42ebcc3f807ace62eb641cab52bf (patch) | |
tree | 6e354ba5cbd3844f777277859fde538efdc228f2 /lib | |
parent | 808963b5177ad5219f780908e5f2cabc5cc84d80 (diff) | |
download | libultrahdr-5ab56043eb3f42ebcc3f807ace62eb641cab52bf.tar.gz |
Add support for integer map scale factor values for ultrahdr decoder
Diffstat (limited to 'lib')
-rw-r--r-- | lib/include/ultrahdr/jpegr.h | 1 | ||||
-rw-r--r-- | lib/src/jpegr.cpp | 42 |
2 files changed, 25 insertions, 18 deletions
diff --git a/lib/include/ultrahdr/jpegr.h b/lib/include/ultrahdr/jpegr.h index 8ac227d..56be834 100644 --- a/lib/include/ultrahdr/jpegr.h +++ b/lib/include/ultrahdr/jpegr.h @@ -61,6 +61,7 @@ typedef enum { ERROR_JPEGR_METADATA_ERROR = JPEGR_RUNTIME_ERROR_BASE - 5, ERROR_JPEGR_NO_IMAGES_FOUND = JPEGR_RUNTIME_ERROR_BASE - 6, ERROR_JPEGR_MULTIPLE_EXIFS_RECEIVED = JPEGR_RUNTIME_ERROR_BASE - 7, + ERROR_JPEGR_UNSUPPORTED_MAP_SCALE_FACTOR = JPEGR_RUNTIME_ERROR_BASE - 8, ERROR_JPEGR_UNSUPPORTED_FEATURE = -30000, } status_t; diff --git a/lib/src/jpegr.cpp b/lib/src/jpegr.cpp index ed4fef1..55ec1a2 100644 --- a/lib/src/jpegr.cpp +++ b/lib/src/jpegr.cpp @@ -1010,29 +1010,39 @@ status_t JpegR::applyGainMap(jr_uncompressed_ptr yuv420_image_ptr, return ERROR_JPEGR_BAD_METADATA; } - // TODO: remove once map scaling factor is computed based on actual map dims - size_t image_width = yuv420_image_ptr->width; - size_t image_height = yuv420_image_ptr->height; - size_t map_width = image_width / kMapDimensionScaleFactor; - size_t map_height = image_height / kMapDimensionScaleFactor; - if (map_width != gainmap_image_ptr->width || map_height != gainmap_image_ptr->height) { + if (yuv420_image_ptr->width % gainmap_image_ptr->width != 0 || + yuv420_image_ptr->height % gainmap_image_ptr->height != 0) { ALOGE( - "gain map dimensions and primary image dimensions are not to scale, computed gain map " - "resolution is %zux%zu, received gain map resolution is %zux%zu", - map_width, map_height, gainmap_image_ptr->width, gainmap_image_ptr->height); - return ERROR_JPEGR_RESOLUTION_MISMATCH; + "gain map dimensions scale factor value is not an integer, primary image resolution is " + "%zux%zu, received gain map resolution is %zux%zu", + yuv420_image_ptr->width, yuv420_image_ptr->height, gainmap_image_ptr->width, + gainmap_image_ptr->height); + return ERROR_JPEGR_UNSUPPORTED_MAP_SCALE_FACTOR; + } + + if (yuv420_image_ptr->width * gainmap_image_ptr->height != + yuv420_image_ptr->height * gainmap_image_ptr->width) { + ALOGE( + "gain map dimensions scale factor values for height and width are different, \n primary " + "image resolution is %zux%zu, received gain map resolution is %zux%zu", + yuv420_image_ptr->width, yuv420_image_ptr->height, gainmap_image_ptr->width, + gainmap_image_ptr->height); + return ERROR_JPEGR_UNSUPPORTED_MAP_SCALE_FACTOR; } + // TODO: Currently map_scale_factor is of type size_t, but it could be changed to a float + // later. + size_t map_scale_factor = yuv420_image_ptr->width / gainmap_image_ptr->width; dest->width = yuv420_image_ptr->width; dest->height = yuv420_image_ptr->height; - ShepardsIDW idwTable(kMapDimensionScaleFactor); + ShepardsIDW idwTable(map_scale_factor); float display_boost = (std::min)(max_display_boost, metadata->maxContentBoost); GainLUT gainLUT(metadata, display_boost); JobQueue jobQueue; std::function<void()> applyRecMap = [yuv420_image_ptr, gainmap_image_ptr, dest, &jobQueue, - &idwTable, output_format, &gainLUT, - display_boost]() -> void { + &idwTable, output_format, &gainLUT, display_boost, + map_scale_factor]() -> void { size_t width = yuv420_image_ptr->width; size_t rowStart, rowEnd; @@ -1049,11 +1059,7 @@ status_t JpegR::applyGainMap(jr_uncompressed_ptr yuv420_image_ptr, Color rgb_sdr = srgbInvOetf(rgb_gamma_sdr); #endif float gain; - // TODO: determine map scaling factor based on actual map dims - size_t map_scale_factor = kMapDimensionScaleFactor; // TODO: If map_scale_factor is guaranteed to be an integer, then remove the following. - // Currently map_scale_factor is of type size_t, but it could be changed to a float - // later. if (map_scale_factor != floorf(map_scale_factor)) { gain = sampleMap(gainmap_image_ptr, map_scale_factor, x, y); } else { @@ -1110,7 +1116,7 @@ status_t JpegR::applyGainMap(jr_uncompressed_ptr yuv420_image_ptr, for (int th = 0; th < threads - 1; th++) { workers.push_back(std::thread(applyRecMap)); } - const int rowStep = threads == 1 ? yuv420_image_ptr->height : kJobSzInRows; + const int rowStep = threads == 1 ? yuv420_image_ptr->height : map_scale_factor; for (size_t rowStart = 0; rowStart < yuv420_image_ptr->height;) { int rowEnd = (std::min)(rowStart + rowStep, yuv420_image_ptr->height); jobQueue.enqueueJob(rowStart, rowEnd); |