From f2a83867f53c21f7c1c65d594b23d8a23880937a Mon Sep 17 00:00:00 2001 From: "jiyong.min" Date: Fri, 9 Dec 2022 07:07:23 +0900 Subject: [PATCH] Change 'JxlEncoderOptions' to 'JxlEncoderFrameSettings' Below functions have been deprecated since libjxl 0.7.0. - Use struct JxlEncoderFrameSettings instead of struct JxlEncoderOptions - Use JxlEncoderFrameSettingsCreate() instead of JxlEncoderOptionsCreate() - Use JxlEncoderSetFrameLossless() instead of JxlEncoderOptionsSetLossless() Added JxlBasicInfo values due to reinforced error detections - Add __set_basic_info_from_pixel_format() - Calculate the buffer size because TEMP_DATA_SIZE occur error Change-Id: Id725f0a69084d8d212f31ec53c5c5d439a891a05 --- jxl/mm_util_jxl.c | 86 +++++++++++++++++++++++++++++++------------- packaging/libmm-utility.spec | 2 +- 2 files changed, 62 insertions(+), 26 deletions(-) diff --git a/jxl/mm_util_jxl.c b/jxl/mm_util_jxl.c index 5b7c2e1..14bd64d 100644 --- a/jxl/mm_util_jxl.c +++ b/jxl/mm_util_jxl.c @@ -111,20 +111,53 @@ static size_t __get_encoding_threads_configuration(void) return (size_t)(num_of_encoding_threads = mm_util_ini_get_int(INI_CATEGORY_JPEG_XL, INI_ITEM_NUM_OF_ENCODING_TRHEADS, DEFAULT_THREAD)); } -static int __get_decoded_data(mm_util_image_h decoded, uint32_t *width, uint32_t *height, JxlPixelFormat *format, uint8_t **pixels, size_t *pixels_size) +static int __set_basic_info_from_pixel_format(JxlBasicInfo *basic_info, const JxlPixelFormat *pixel_format) { - mm_image_info_s *_image = (mm_image_info_s *)decoded; + mm_util_retvm_if(!basic_info, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid basic_info"); + mm_util_retvm_if(!pixel_format, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid pixel_format"); + + switch (pixel_format->data_type) { + case JXL_TYPE_UINT8: + basic_info->bits_per_sample = 8; + basic_info->exponent_bits_per_sample = 0; + break; + default: + mm_util_error("not supported data_type(%d)", pixel_format->data_type); + return MM_UTIL_ERROR_INVALID_PARAMETER; + } + + basic_info->num_color_channels = (pixel_format->num_channels < 3) ? 1 : 3; + if (pixel_format->num_channels == 2 || pixel_format->num_channels == 4) { + basic_info->alpha_exponent_bits = basic_info->exponent_bits_per_sample; + basic_info->alpha_bits = basic_info->bits_per_sample; + basic_info->num_extra_channels = 1; + } else { + basic_info->alpha_exponent_bits = 0; + basic_info->alpha_bits = 0; + } + + mm_util_info("bits_per_sample = %u, exponent_bits_per_sample = %u, num_color_channels = %u, alpha_exponent_bits = %u, alpha_bits = %u, num_extra_channels = %u", + basic_info->bits_per_sample, basic_info->exponent_bits_per_sample, basic_info->num_color_channels, + basic_info->alpha_exponent_bits, basic_info->alpha_bits, basic_info->num_extra_channels); + + return MM_UTIL_ERROR_NONE; +} + +static int __set_basic_info_from_image(mm_util_image_h decoded, JxlBasicInfo *basic_info, JxlPixelFormat *format, uint8_t **pixels, size_t *pixels_size) +{ + mm_image_info_s *mm_image = (mm_image_info_s *)decoded; mm_util_retvm_if(!mm_image_is_valid_image(decoded), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid decoded"); - mm_util_retvm_if((_image->color != MM_UTIL_COLOR_RGB24) && (_image->color != MM_UTIL_COLOR_RGBA), - MM_UTIL_ERROR_INVALID_PARAMETER, "invalid format %d", _image->color); + mm_util_retvm_if((mm_image->color != MM_UTIL_COLOR_RGB24) && (mm_image->color != MM_UTIL_COLOR_RGBA), + MM_UTIL_ERROR_INVALID_PARAMETER, "invalid format %d", mm_image->color); + mm_util_retvm_if(!format, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid format"); mm_image_debug_image(decoded, "SOURCE"); - *width = (uint32_t)_image->width; - *height = (uint32_t)_image->height; - *format = jxl_formats[_image->color]; - *pixels = _image->data; - *pixels_size = _image->size; + basic_info->xsize = (uint32_t)mm_image->width; + basic_info->ysize = (uint32_t)mm_image->height; + *format = jxl_formats[mm_image->color]; + *pixels = mm_image->data; + *pixels_size = (mm_image->size == TEMP_DATA_SIZE) ? (size_t)(mm_image->width * mm_image->height * format->num_channels) : mm_image->size; return MM_UTIL_ERROR_NONE; } @@ -264,7 +297,7 @@ static int __mm_util_encode_jpegxl(mm_util_image_h decoded_image, mm_util_enc_op JxlPixelFormat jxl_format; JxlBasicInfo basic_info; JxlColorEncoding color_encoding; - JxlEncoderOptions* options = NULL; + JxlEncoderFrameSettings *frame_settings = NULL; uint8_t *pixels = NULL; size_t pixels_size = 0; size_t compressed_size = 64; @@ -279,20 +312,20 @@ static int __mm_util_encode_jpegxl(mm_util_image_h decoded_image, mm_util_enc_op JxlEncoderInitBasicInfo(&basic_info); - ret = __get_decoded_data(decoded_image, &basic_info.xsize, &basic_info.ysize, + ret = __set_basic_info_from_image(decoded_image, &basic_info, &jxl_format, &pixels, &pixels_size); if (ret != MM_UTIL_ERROR_NONE) { - mm_util_error("failed to __get_decoded_data"); + mm_util_error("failed to __set_basic_info_from_image"); return ret; } - basic_info.uses_original_profile = (enc_opt && enc_opt->lossless) ? JXL_TRUE : JXL_FALSE; - basic_info.num_color_channels = jxl_format.num_channels; - if (jxl_format.num_channels == 4) - basic_info.alpha_bits = basic_info.bits_per_sample; + ret = __set_basic_info_from_pixel_format(&basic_info, &jxl_format); + if (ret != MM_UTIL_ERROR_NONE) { + mm_util_error("failed to __set_basic_info_from_pixel_format"); + return ret; + } - mm_util_info("num_color_channels = %u, alpha_bits = %u", - basic_info.num_color_channels, basic_info.alpha_bits); + basic_info.uses_original_profile = (enc_opt && enc_opt->lossless) ? JXL_TRUE : JXL_FALSE; jxl_enc = JxlEncoderCreate(NULL); if (!jxl_enc) { @@ -331,18 +364,18 @@ static int __mm_util_encode_jpegxl(mm_util_image_h decoded_image, mm_util_enc_op goto Exit; } - // set default options - // 'options' will be destroyed when 'JxlEncoderDestroy' is called - options = JxlEncoderOptionsCreate(jxl_enc, NULL); + // set default frame_settings + // 'frame_settings' will be destroyed when 'JxlEncoderDestroy' is called + frame_settings = JxlEncoderFrameSettingsCreate(jxl_enc, NULL); - // set lossless into options - status = JxlEncoderOptionsSetLossless(options, (enc_opt && enc_opt->lossless) ? JXL_TRUE : JXL_FALSE); + // set lossless + status = JxlEncoderSetFrameLossless(frame_settings, basic_info.uses_original_profile); if (status != JXL_ENC_SUCCESS) { - mm_util_error("failed to JxlEncoderOptionsSetLossless(%d)", status); + mm_util_error("failed to JxlEncoderSetFrameLossless(%d)", status); goto Exit; } - status = JxlEncoderAddImageFrame(options, &jxl_format, pixels, pixels_size); + status = JxlEncoderAddImageFrame(frame_settings, &jxl_format, pixels, pixels_size); if (status != JXL_ENC_SUCCESS) { mm_util_error("failed to JxlEncoderAddImageFrame(%d)", status); goto Exit; @@ -382,6 +415,9 @@ static int __mm_util_encode_jpegxl(mm_util_image_h decoded_image, mm_util_enc_op Exit: + if (status != JXL_ENC_SUCCESS) + mm_util_error("JxlEncoderGetError: %d", JxlEncoderGetError(jxl_enc)); + g_free(compressed); JxlThreadParallelRunnerDestroy(jxl_thread); JxlEncoderDestroy(jxl_enc); diff --git a/packaging/libmm-utility.spec b/packaging/libmm-utility.spec index 3f2620b..2959e63 100644 --- a/packaging/libmm-utility.spec +++ b/packaging/libmm-utility.spec @@ -1,6 +1,6 @@ Name: libmm-utility Summary: Multimedia Framework Utility Library -Version: 0.4.10 +Version: 0.4.11 Release: 0 Group: System/Libraries License: Apache-2.0 -- 2.7.4