[ACR-1695] Add Jpeg-XL image support and 'image_util_encode_set_webp_lossless()'... 12/273712/14 accepted/tizen/unified/20220424.221526 accepted/tizen/unified/20220426.021431 submit/tizen/20220422.045752 submit/tizen/20220424.231651
authorjiyong.min <jiyong.min@samsung.com>
Wed, 13 Apr 2022 00:07:09 +0000 (09:07 +0900)
committerjiyong.min <jiyong.min@samsung.com>
Fri, 22 Apr 2022 00:39:18 +0000 (09:39 +0900)
 - Add Jpeg-XL image support
 - 'image_util_encode_set_webp_lossless()' is deprecated.

Change-Id: I7cdb6386c544e8e6494a9a41be2db02073bad367

CMakeLists.txt
doc/image_util_doc.h
include/image_util_decode.h
include/image_util_encode.h
include/image_util_private.h
include/image_util_type.h
packaging/capi-media-image-util.spec
src/image_util_decode.c
src/image_util_encode.c
src/image_util_private.c
test/image_util_testsuite.c

index 242be68e781f5e7d8bf3807e1c8a6aff590e97bb..c9c3de41b6be3b766d0791564c97e93859c61565 100644 (file)
@@ -9,7 +9,7 @@ SET(INC_DIR include)
 INCLUDE_DIRECTORIES(${INC_DIR})
 
 # for package file
-SET(dependents "dlog mmutil-magick mmutil-common mmutil-gif mmutil-jpeg mmutil-imgp mmutil-anim mmutil-heif capi-base-common capi-media-tool glib-2.0")
+SET(dependents "dlog mmutil-magick mmutil-common mmutil-gif mmutil-jpeg mmutil-imgp mmutil-anim mmutil-heif mmutil-jxl capi-base-common capi-media-tool glib-2.0")
 SET(pc_dependents "capi-base-common capi-media-tool")
 INCLUDE(FindPkgConfig)
 pkg_check_modules(${fw_name} REQUIRED ${dependents})
index 438cb88583dda5b81ba6f912eadd7ee333d29b18..84a4f14a6fd73ca19818039442d0514069bc8958 100755 (executable)
  * @section CAPI_MEDIA_IMAGE_UTIL_MODULE_ENCODE_DECODE_OVERVIEW Overview
  *
  * Image Util API provides support for encoding and decoding of images. The API allows :
- *- Encoding of a JPEG/PNG/GIF/BMP and WEBP(Since 6.0) image.
- *- Decoding of a JPEG/PNG/GIF/BMP/WEBP(Since 6.0) and HEIF(Since 6.5) image.
- * Encoding supports gif images including the animated, but decoding gif does not support the animated.
+ * <div><table class="doxtable" >
+ *     <tr>
+ *        <th><b>Formats</b></th>
+ *        <th><b>Encoding</b></th>
+ *        <th><b>Decoding</b></th>
+ *        <th><b>Remarks</b></th>
+ *     </tr>
+ *     <tr>
+ *        <td>JPEG</td>
+ *        <td>O</td>
+ *        <td>O</td>
+ *        <td></td>
+ *     </tr>
+ *     <tr>
+ *        <td>PNG</td>
+ *        <td>O</td>
+ *        <td>O</td>
+ *        <td></td>
+ *     </tr>
+ *     <tr>
+ *        <td>GIF</td>
+ *        <td>O</td>
+ *        <td>O</td>
+ *        <td>Encoding supports gif images including the animated, but decoding gif does not support the animated.</td>
+ *     </tr>
+ *     <tr>
+ *        <td>BMP</td>
+ *        <td>O</td>
+ *        <td>O</td>
+ *        <td></td>
+ *     </tr>
+ *     <tr>
+ *        <td>WEBP</td>
+ *        <td>O</td>
+ *        <td>O</td>
+ *        <td>Since 6.0</td>
+ *     </tr>
+ *     <tr>
+ *        <td>HEIC</td>
+ *        <td></td>
+ *        <td>O</td>
+ *        <td>Since 6.5</td>
+ *     </tr>
+ *     <tr>
+ *        <td>JPEG-XL</td>
+ *        <td>O</td>
+ *        <td>O</td>
+ *        <td>Since 7.0</td>
+ *     </tr>
+ *</table></div>
  *
- * The decoding of a jpeg/png/gif/bmp/webp/heif image located at a given path, to a buffer can be done by calling #image_util_decode_run() function and decoding of a jpeg/png/gif/bmp/webp/heif image on memory
+ * The decoding of a jpeg/png/gif/bmp/webp/heif/jpeg-xl image located at a given path, to a buffer can be done by calling #image_util_decode_run() function and decoding of a jpeg/png/gif/bmp/webp/heif/jpeg-xl image on memory
  * can be done by calling #image_util_decode_set_output_buffer(). Similarly, for encoding #image_util_encode_run() and #image_util_encode_set_output_buffer() functions can be called
- * to encode an image buffer to a jpeg/png/gif/bmp/webp image and a buffer respectively.
+ * to encode an image buffer to a jpeg/png/gif/bmp/webp/jpeg-xl image and a buffer respectively.
  *
  * @subsection CAPI_MEDIA_IMAGE_UTIL_ENCODE_DECODE_FOREACH_OPERATIONS Foreach Operations
  * <div><table class="doxtable" >
index 3c34f4590227c4efb33ffbc64884f79ace829eb1..0742ac0ee744933aadca0502dcd372858b17038f 100644 (file)
@@ -60,7 +60,8 @@ int image_util_decode_create(image_util_decode_h *handle);
 *             %http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.\n
 *             Finds out image type by reading the header of the image provided in input path.\n
 *             Since 6.0, this module supports WEBP image format.\n
-*             Since 6.5, this module supports HEIF image format.
+*             Since 6.5, this module supports HEIF image format.\n
+*             Since 7.0, this module supports JPEG-XL image format.
 *
 * @param[in] handle The handle of image util decoding
 * @param[in] path The path to input image
@@ -96,7 +97,8 @@ int image_util_decode_set_input_path(image_util_decode_h handle, const char *pat
 *              If both are set then the latest input set, is considered.\n
 *              Finds out image type by reading the header of the image provided in input buffer.\n
 *              Since 6.0, this module supports WEBP image format.\n
-*              Since 6.5, this module supports HEIF image format.
+*              Since 6.5, this module supports HEIF image format.\n
+*              Since 7.0, this module supports JPEG-XL image format.
 *
 * @param[in] handle The handle of image util decoding
 * @param[in] src_buffer The input image buffer
index d18308a9e3f1153eeb755e2bb3d8f48badea7b26..9aefb998ad65816f16f5a4749d30efab10d3f77d 100644 (file)
@@ -195,13 +195,45 @@ int image_util_encode_set_quality(image_util_encode_h handle, int quality);
 int image_util_encode_set_png_compression(image_util_encode_h handle, image_util_png_compression_e compression);
 
 /**
+* @deprecated Deprecated since 7.0. Use image_util_encode_set_lossless() instead.
 * @brief Sets lossless compression of WEBP images.
 * @since_tizen 6.0
 *
-* @remarks If application does not set this, then the default value is false.
+* @remarks If application does not set this, then the default value is @c false.
 *
 * @param[in] handle The handle of image util encoding
-* @param[in] lossless The flag determining whether the compression is lossless or lossy: true for lossless, false for lossy
+* @param[in] lossless The flag determining whether the compression is lossless or lossy: @c true for lossless, @c false for lossy
+*
+* @return @c 0 on success,
+*                 otherwise a negative error value
+*
+* @retval #IMAGE_UTIL_ERROR_NONE Successful
+* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
+* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Not supported format
+*
+* @pre image_util_encode_create()
+*
+* @post image_util_encode_run() / image_util_encode_run_async()
+* @post image_util_encode_destroy()
+*
+* @see image_util_encode_create()
+* @see image_util_encode_run_to_file()
+* @see image_util_encode_run_to_buffer()
+* @see image_util_encode_run_async_to_file()
+* @see image_util_encode_run_async_to_buffer()
+* @see image_util_encode_destroy()
+*/
+int image_util_encode_set_webp_lossless(image_util_encode_h handle, bool lossless) TIZEN_DEPRECATED_API;
+
+/**
+* @brief Sets lossless compression of WEBP and JPEG-XL images.
+* @since_tizen 7.0
+*
+* @remarks If application does not set this, then the default value is @c false.
+*
+* @param[in] handle The handle of image util encoding
+* @param[in] lossless The flag determining whether the compression is lossless or lossy: @c true for lossless, @c false for lossy
 *
 * @return @c 0 on success,
 *                 otherwise a negative error value
@@ -223,7 +255,7 @@ int image_util_encode_set_png_compression(image_util_encode_h handle, image_util
 * @see image_util_encode_run_async_to_buffer()
 * @see image_util_encode_destroy()
 */
-int image_util_encode_set_webp_lossless(image_util_encode_h handle, bool lossless);
+int image_util_encode_set_lossless(image_util_encode_h handle, bool lossless);
 
 /**
 * @deprecated Deprecated since 5.5. Use image_util_agif_encode_add_frame() instead.
@@ -460,6 +492,7 @@ int image_util_encode_run_async(image_util_encode_h handle, image_util_encode_co
 *          Before 6.0, #IMAGE_UTIL_COLORSPACE_RGBA8888 was the only supported colorspace for PNG. But since 6.0, this module supports more colorspaces for PNG.
 *          To get supported colorspaces for PNG, you can use image_util_foreach_supported_colorspace().\n
 *          Since 6.0, this module supports WEBP, you can use image_util_foreach_supported_colorspace() to get supported colorspaces for WEBP.\n
+*          Since 7.0, this module supports JPEG-XL, you can use image_util_foreach_supported_colorspace() to get supported colorspaces for JPEG-XL.
 *
 * @param[in] handle The handle of image util encoding
 * @param[in] image The image handle for encoding
@@ -496,6 +529,7 @@ int image_util_encode_run_to_file(image_util_encode_h handle, image_util_image_h
 *          Before 6.0, #IMAGE_UTIL_COLORSPACE_RGBA8888 was the only supported colorspace for PNG. But since 6.0, this module supports more colorspaces for PNG.
 *          To get supported colorspaces for PNG, you can use image_util_foreach_supported_colorspace().\n
 *          Since 6.0, this module supports WEBP, you can use image_util_foreach_supported_colorspace() to get supported colorspaces for WEBP.\n
+*          Since 7.0, this module supports JPEG-XL, you can use image_util_foreach_supported_colorspace() to get supported colorspaces for JPEG-XL.
 *
 * @param[in] handle The handle of image util encoding
 * @param[in] image The image handle for encoding
@@ -533,6 +567,7 @@ int image_util_encode_run_to_buffer(image_util_encode_h handle, image_util_image
 *          Before 6.0, #IMAGE_UTIL_COLORSPACE_RGBA8888 was the only supported colorspace for PNG. But since 6.0, this module supports more colorspaces for PNG.
 *          To get supported colorspaces for PNG, you can use image_util_foreach_supported_colorspace().\n
 *          Since 6.0, this module supports WEBP, you can use image_util_foreach_supported_colorspace() to get supported colorspaces for WEBP.\n
+*          Since 7.0, this module supports JPEG-XL, you can use image_util_foreach_supported_colorspace() to get supported colorspaces for JPEG-XL.
 *
 * @param[in] handle The handle of image util encoding
 * @param[in] image The image handle for encoding
@@ -569,6 +604,7 @@ int image_util_encode_run_async_to_file(image_util_encode_h handle, image_util_i
 *          Before 6.0, #IMAGE_UTIL_COLORSPACE_RGBA8888 was the only supported colorspace for PNG. But since 6.0, this module supports more colorspaces for PNG.
 *          To get supported colorspaces for PNG, you can use image_util_foreach_supported_colorspace().\n
 *          Since 6.0, this module supports WEBP, you can use image_util_foreach_supported_colorspace() to get supported colorspaces for WEBP.\n
+*          Since 7.0, this module supports JPEG-XL, you can use image_util_foreach_supported_colorspace() to get supported colorspaces for JPEG-XL.
 *
 * @param[in] handle The handle of image util encoding
 * @param[in] image The image handle for encoding
index dae430bf24fbd265d4203ca04ff83828532b4bd6..82cd29060014d8b8c04813a0344d6986655bf41b 100644 (file)
@@ -116,7 +116,7 @@ typedef struct {
 } transformation_s;
 
 #define IMAGE_UTIL_TYPE_CHECK(type) \
-       image_util_retvm_if((type < IMAGE_UTIL_JPEG || type > IMAGE_UTIL_HEIF), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid image type [%d]", type)
+       image_util_retvm_if((type < IMAGE_UTIL_JPEG || type > IMAGE_UTIL_JPEG_XL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid image type [%d]", type)
 
 #define IMAGE_UTIL_SUPPORT_TYPE_CHECK(value, support) \
        image_util_retvm_if((value != support), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "Not supported format")
index b62321cf0cd9e6c9155fb45e7827cfe415ab5b32..1632afcf2d3a54a3d2bb1b57b4a4c10ef0e56fc6 100644 (file)
@@ -167,12 +167,13 @@ typedef void(*image_util_transform_completed2_cb)(image_util_image_h dst, int er
  * @since_tizen 3.0
  */
 typedef enum {
-       IMAGE_UTIL_JPEG,         /**< Image format JPEG */
-       IMAGE_UTIL_PNG,          /**< Image format PNG */
-       IMAGE_UTIL_GIF,          /**< Image format GIF */
-       IMAGE_UTIL_BMP,          /**< Image format BMP */
-       IMAGE_UTIL_WEBP,         /**< Image format WEBP (Since 6.0) */
-       IMAGE_UTIL_HEIF,         /**< Image format HEIF (Since 6.5) */
+       IMAGE_UTIL_JPEG,    /**< Image format JPEG */
+       IMAGE_UTIL_PNG,     /**< Image format PNG */
+       IMAGE_UTIL_GIF,     /**< Image format GIF */
+       IMAGE_UTIL_BMP,     /**< Image format BMP */
+       IMAGE_UTIL_WEBP,    /**< Image format WEBP (Since 6.0) */
+       IMAGE_UTIL_HEIF,    /**< Image format HEIF (Since 6.5) */
+       IMAGE_UTIL_JPEG_XL, /**< Image format JPEG-XL (Since 7.0) */
 } image_util_type_e;
 
 /**
index ca86103e7c1a761654902035c9c8c530c802c317..436ba51bea8e78fb502d3b48d532f661bcc72f1e 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-image-util
 Summary:    A Image Utility library in Tizen Native API
-Version:    0.3.3
+Version:    0.4.0
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
@@ -14,6 +14,7 @@ BuildRequires:  pkgconfig(mmutil-gif)
 BuildRequires:  pkgconfig(mmutil-magick)
 BuildRequires:  pkgconfig(mmutil-anim)
 BuildRequires:  pkgconfig(mmutil-heif)
+BuildRequires:  pkgconfig(mmutil-jxl)
 BuildRequires:  pkgconfig(capi-base-common)
 BuildRequires:  pkgconfig(capi-media-tool)
 BuildRequires:  pkgconfig(glib-2.0)
index b591eaeffca11f54cd6e97942c684deec0d54aa8..2844c5750047e4be3a26790badbb50701b865612 100644 (file)
@@ -22,6 +22,7 @@
 #include <mm_util_magick.h>
 #include <mm_util_image.h>
 #include <mm_util_heif.h>
+#include <mm_util_jxl.h>
 
 #include <image_util.h>
 #include <image_util_private.h>
@@ -105,6 +106,8 @@ static int __image_util_decode_check_image_type(const unsigned char *image_buffe
        static unsigned char _BMP_HEADER[] = { 'B', 'M' };
        static unsigned char _WEBP_HEADER[] = { 0x57, 0x45, 0x42, 0x50 };
        static unsigned char _HEIF_HEADER[] = { 'f', 't', 'y', 'p' };
+       static unsigned char _JXL_HEADER[] = { 'J', 'X', 'L'};
+       static unsigned char _JXL_CODESTREAM_HEADER[] = { 0xFF, 0x0A }; // if image start with codestream without JXL container
 
        static struct {
                image_util_type_e image_type;
@@ -118,6 +121,8 @@ static int __image_util_decode_check_image_type(const unsigned char *image_buffe
                { IMAGE_UTIL_BMP, _BMP_HEADER, sizeof(_BMP_HEADER), 0 },
                { IMAGE_UTIL_WEBP, _WEBP_HEADER, sizeof(_WEBP_HEADER), 8 },
                { IMAGE_UTIL_HEIF, _HEIF_HEADER, sizeof(_HEIF_HEADER), 4 },
+               { IMAGE_UTIL_JPEG_XL, _JXL_HEADER, sizeof(_JXL_HEADER), 4 },
+               { IMAGE_UTIL_JPEG_XL, _JXL_CODESTREAM_HEADER, sizeof(_JXL_CODESTREAM_HEADER), 0 },
        };
        unsigned int i = 0;
 
@@ -304,6 +309,15 @@ static int __image_util_decode_internal(decode_s *_handle, mm_util_image_h *imag
                }
                break;
 
+       case IMAGE_UTIL_JPEG_XL:
+               {
+                       if (_handle->path)
+                               err = mm_util_decode_jxl_from_file(_handle->path, colorspace, image_info);
+                       else
+                               err = mm_util_decode_jxl_from_buffer(_handle->src_buffer, _handle->src_size, colorspace, image_info);
+               }
+               break;
+
        default:
                image_util_error("Not supported format [%d]", _handle->image_type);
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
@@ -398,6 +412,10 @@ static int __image_util_decode_run_from_file(image_util_decode_h handle, const c
                ret = mm_util_decode_heif_from_file(file_path, colorspace, image);
                break;
 
+       case IMAGE_UTIL_JPEG_XL:
+               ret = mm_util_decode_jxl_from_file(file_path, colorspace, image);
+               break;
+
        default:
                image_util_error("Not supported format [%d]", image_type);
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
@@ -454,6 +472,10 @@ static int __image_util_decode_run_from_buffer(image_util_decode_h handle, const
                ret = mm_util_decode_heif_from_buffer((void *)buffer, buffer_size, colorspace, image);
                break;
 
+       case IMAGE_UTIL_JPEG_XL:
+               ret = mm_util_decode_jxl_from_buffer((void *)buffer, buffer_size, colorspace, image);
+               break;
+
        default:
                image_util_error("Not supported format [%d]", image_type);
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
index c443187cf5c9dc8065c9135703ace18cf8023adb..3eaaec266d9ec66cb21896ddf7c29fb0c4705911 100644 (file)
@@ -20,6 +20,7 @@
 #include <mm_util_magick.h>
 #include <mm_util_image.h>
 #include <mm_util_anim.h>
+#include <mm_util_jxl.h>
 
 #include <image_util.h>
 #include <image_util_private.h>
@@ -245,9 +246,21 @@ int image_util_encode_set_webp_lossless(image_util_encode_h handle, bool lossles
 {
        encode_s *_handle = (encode_s *) handle;
 
+       image_util_warning("DEPRECATION WARNING: image_util_encode_set_webp_lossless() is deprecated and will be removed from next release. Use image_util_encode_set_lossless() instead.");
+
+       image_util_retvm_if(!_handle, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+       IMAGE_UTIL_SUPPORT_TYPE_CHECK(_handle->image_type, IMAGE_UTIL_WEBP);
+
+       return _image_error_capi(mm_util_enc_opt_set_lossless(_handle->enc_opt, lossless));
+}
+
+int image_util_encode_set_lossless(image_util_encode_h handle, bool lossless)
+{
+       encode_s *_handle = (encode_s *) handle;
+
        image_util_retvm_if(!_handle, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
 
-       return _image_error_capi(mm_util_enc_opt_set_webp_lossless(_handle->enc_opt, lossless));
+       return _image_error_capi(mm_util_enc_opt_set_lossless(_handle->enc_opt, lossless));
 }
 
 int image_util_encode_set_gif_frame_delay_time(image_util_encode_h handle, unsigned long long delay_time)
@@ -381,6 +394,12 @@ static int __image_util_encode_internal(encode_s * _handle)
                else
                        err = mm_util_encode_image_to_buffer(_src, _handle->enc_opt, _handle->dst_buffer, &_handle->dst_size);
                break;
+       case IMAGE_UTIL_JPEG_XL:
+               if (_handle->path)
+                       err = mm_util_encode_jxl_to_file(_src, _handle->enc_opt, _handle->path);
+               else
+                       err = mm_util_encode_jxl_to_buffer(_src, _handle->enc_opt, _handle->dst_buffer, &_handle->dst_size);
+               break;
        default:
                image_util_error("Invalid image_type %d", _handle->image_type);
                mm_image_destroy_image(_src);
@@ -430,6 +449,10 @@ static int __image_util_encode_run_to_file(image_util_encode_h handle, image_uti
                ret = mm_util_encode_image_to_file(image, _handle->enc_opt, file_path);
                break;
 
+       case IMAGE_UTIL_JPEG_XL:
+               ret = mm_util_encode_jxl_to_file(image, _handle->enc_opt, file_path);
+               break;
+
        default:
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
                break;
@@ -472,6 +495,11 @@ static int __image_util_encode_run_to_buffer(image_util_encode_h handle, image_u
        case IMAGE_UTIL_WEBP:
                ret = mm_util_encode_image_to_buffer(image, _handle->enc_opt, (void **)buffer, buffer_size);
                break;
+
+       case IMAGE_UTIL_JPEG_XL:
+               ret = mm_util_encode_jxl_to_buffer(image, _handle->enc_opt, (void **)buffer, buffer_size);
+               break;
+
        default:
                return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
                break;
index 106c7828a45a5a1391b25d57c47492881b36b392..1758f523b1a3796a0738f782df6b5820b58e114c 100644 (file)
@@ -168,6 +168,24 @@ static int _convert_heif_colorspace_tbl[] = {
        [IMAGE_UTIL_COLORSPACE_NV61] = _NOT_SUPPORTED_COLORSPACE,
 };
 
+static int _convert_jxl_colorspace_tbl[] = {
+       [IMAGE_UTIL_COLORSPACE_YV12] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_YUV422] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_I420] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_NV12] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_UYVY] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_YUYV] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_RGB565] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_RGB888] = MM_UTIL_COLOR_RGB24,
+       [IMAGE_UTIL_COLORSPACE_ARGB8888] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_BGRA8888] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_RGBA8888] = MM_UTIL_COLOR_RGBA,
+       [IMAGE_UTIL_COLORSPACE_BGRX8888] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_NV21] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_NV16] = _NOT_SUPPORTED_COLORSPACE,
+       [IMAGE_UTIL_COLORSPACE_NV61] = _NOT_SUPPORTED_COLORSPACE,
+};
+
 unsigned int _get_number_of_colorspace(void)
 {
        return G_N_ELEMENTS(_convert_colorspace_tbl);
@@ -202,6 +220,9 @@ gboolean _is_supported_colorspace(image_util_colorspace_e colorspace, image_util
        case IMAGE_UTIL_HEIF:
                image_util_retvm_if((_convert_heif_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[heif] %d not supported format", colorspace);
                break;
+       case IMAGE_UTIL_JPEG_XL:
+               image_util_retvm_if((_convert_jxl_colorspace_tbl[colorspace] == _NOT_SUPPORTED_COLORSPACE), FALSE, "[jpeg-xl] %d not supported format", colorspace);
+               break;
        default:
                image_util_retvm_if(TRUE, FALSE, "Invalid image type");
        }
@@ -245,6 +266,9 @@ int _convert_type_of_colorspace_with_image_type(const image_util_colorspace_e co
        case IMAGE_UTIL_HEIF:
                new_colorspace = _convert_heif_colorspace_tbl[colorspace];
                break;
+       case IMAGE_UTIL_JPEG_XL:
+               new_colorspace = _convert_jxl_colorspace_tbl[colorspace];
+               break;
        default:
                image_util_error("Invalid image type");
        }
index 01a8a4ef53fc8726770654b34c2fd8a092ba8613..c37d17d73bf888e9ea3787b7362461dd87561fff 100644 (file)
@@ -24,7 +24,7 @@
 #include <image_util_private.h>
 
 /* logs for testsuite */
-#define VERSION                                "0.1.1 of 16 Aug 2019"
+#define VERSION                                "0.1.2 of 13 Apr 2022"
 /* prints log of menu-queue for testsuite */
 #define DEBUG_QUEUE                    0       /* 0:disable, 1:enable */
 /* saves the intermediate image to process name("transform" or "decode"), Not supported for encoding */
@@ -225,18 +225,18 @@ static void __display_set(const char *text, const char *ex)
                g_print("*** input %s: ", text);
 }
 
+typedef struct {
+       unsigned int e;
+       const char *t;
+} test_menu_s;
+
 typedef enum {
        RAW_IMG_SET_COLOR,
        RAW_IMG_SET_SIZE,
        RAW_IMG_MENU_MAX,
 } test_raw_img_menu_e;
 
-typedef struct {
-       test_raw_img_menu_e e;
-       const char *t;
-} test_raw_img_menu_s;
-
-static const test_raw_img_menu_s g_disp_raw_img_menu[RAW_IMG_MENU_MAX] = {
+static const test_menu_s g_disp_raw_img_menu[RAW_IMG_MENU_MAX] = {
        { RAW_IMG_SET_COLOR,            "set colorspace (opt. default=IMAGE_UTIL_COLORSPACE_RGBA8888)" },
        { RAW_IMG_SET_SIZE,                     "set width & height" },
 };
@@ -248,7 +248,7 @@ static void __display_set_raw_menu(void)
        g_print("====================================================\n");
        g_print("   image-util Core-API test: Set raw data menu v%s\n", VERSION);
        g_print("----------------------------------------------------\n");
-       for (idx = 0; idx < RAW_IMG_MENU_MAX; idx++)
+       for (idx = 0; idx < G_N_ELEMENTS(g_disp_raw_img_menu); idx++)
                g_print("%u. %s\n", g_disp_raw_img_menu[idx].e, g_disp_raw_img_menu[idx].t);
        g_print("b. back\n");
        g_print("q. quit\n");
@@ -268,12 +268,7 @@ typedef enum {
        DECODE_MENU_MAX,
 } test_decode_menu_e;
 
-typedef struct {
-       test_decode_menu_e e;
-       const char *t;
-} test_decode_menu_s;
-
-static const test_decode_menu_s g_disp_decode_menu[DECODE_MENU_MAX] = {
+static const test_menu_s g_disp_decode_menu[DECODE_MENU_MAX] = {
        { DECODE_SET_BUFFER,            "set input buffer" },
        { DECODE_SET_COLOR,                     "set color (mand. default=IMAGE_UTIL_COLORSPACE_RGBA8888)" },
        { DECODE_SET_DOWNSCALE,         "set downscale (opt. for jpeg only)" },
@@ -291,7 +286,7 @@ static void __display_decode_menu(void)
        g_print("====================================================\n");
        g_print("   image-util Core-API test: Decode menu v%s\n", VERSION);
        g_print("----------------------------------------------------\n");
-       for (idx = 0; idx < DECODE_MENU_MAX; idx++)
+       for (idx = 0; idx < G_N_ELEMENTS(g_disp_decode_menu); idx++)
                g_print("%u. %s\n", g_disp_decode_menu[idx].e, g_disp_decode_menu[idx].t);
        g_print("b. back\n");
        g_print("q. quit\n");
@@ -314,16 +309,11 @@ typedef enum {
        ENCODE_MENU_MAX,
 } test_encode_menu_e;
 
-typedef struct {
-       test_encode_menu_e e;
-       const char *t;
-} test_encode_menu_s;
-
-static const test_encode_menu_s g_disp_encode_menu[ENCODE_MENU_MAX] = {
+static const test_menu_s g_disp_encode_menu[ENCODE_MENU_MAX] = {
        { ENCODE_SET_TYPE,                              "set image_type (mand. default=IMAGE_UTIL_JPEG)" },
        { ENCODE_SET_QUALITY,                   "set quality (opt. for jpeg only)" },
        { ENCODE_SET_COMPRESIION,               "set compression (opt. for png only)" },
-       { ENCODE_SET_LOSSLESS,                  "set lossless (opt. for webp only)" },
+       { ENCODE_SET_LOSSLESS,                  "set lossless (opt. for webp & jpeg-xl)" },
        { ENCODE_SET_TO_BUFFER,                 "set output buffer (opt. deprecated)" },
        { ENCODE_RUN,                                   "encode run (will be deprecated)" },
        { ENCODE_RUN_ASYNC,                             "encode run async (will be deprecated)" },
@@ -340,7 +330,7 @@ static void __display_encode_menu(void)
        g_print("====================================================\n");
        g_print("   image-util Core-API test: Encode menu v%s\n", VERSION);
        g_print("----------------------------------------------------\n");
-       for (idx = 0; idx < ENCODE_MENU_MAX; idx++)
+       for (idx = 0; idx < G_N_ELEMENTS(g_disp_encode_menu); idx++)
                g_print("%u. %s\n", g_disp_encode_menu[idx].e, g_disp_encode_menu[idx].t);
        g_print("b. back\n");
        g_print("q. quit\n");
@@ -359,12 +349,7 @@ typedef enum {
        ENCODE_AGIF_MENU_MAX,
 } test_encode_agif_menu_e;
 
-typedef struct {
-       test_encode_agif_menu_e e;
-       const char *t;
-} test_encode_agif_menu_s;
-
-static const test_encode_agif_menu_s g_disp_encode_agif_menu[ENCODE_AGIF_MENU_MAX] = {
+static const test_menu_s g_disp_encode_agif_menu[ENCODE_AGIF_MENU_MAX] = {
        { ENCODE_AGIF_SET_DIR,                  "set directory" },
        { ENCODE_AGIF_SET_DELAY,                "set delay time (mand. default = 100)" },
        { ENCODE_AGIF_SET_TO_BUFFER,    "set output buffer (opt. will be deprecated)" },
@@ -381,7 +366,7 @@ static void __display_encode_agif_menu(void)
        g_print("====================================================\n");
        g_print("   image-util Core-API test: Encode A-GIF menu v%s\n", VERSION);
        g_print("----------------------------------------------------\n");
-       for (idx = 0; idx < ENCODE_AGIF_MENU_MAX; idx++)
+       for (idx = 0; idx < G_N_ELEMENTS(g_disp_encode_agif_menu); idx++)
                g_print("%u. %s\n", g_disp_encode_agif_menu[idx].e, g_disp_encode_agif_menu[idx].t);
        g_print("b. back\n");
        g_print("q. quit\n");
@@ -400,12 +385,7 @@ typedef enum {
        ENCODE_ANIM_MENU_MAX,
 } test_encode_anim_menu_e;
 
-typedef struct {
-       test_encode_anim_menu_e e;
-       const char *t;
-} test_encode_anim_menu_s;
-
-static const test_encode_anim_menu_s g_disp_encode_anim_menu[ENCODE_ANIM_MENU_MAX] = {
+static const test_menu_s g_disp_encode_anim_menu[ENCODE_ANIM_MENU_MAX] = {
        { ENCODE_ANIM_SET_DIR,                  "set directory" },
        { ENCODE_ANIM_SET_TYPE,                 "set animation type (mand. default = webp)" },
        { ENCODE_ANIM_SET_DELAY,                "set delay time (mand. default = 100)" },
@@ -422,7 +402,7 @@ static void __display_encode_anim_menu(void)
        g_print("====================================================\n");
        g_print("   image-util Core-API test: Encode ANIMATION menu v%s\n", VERSION);
        g_print("----------------------------------------------------\n");
-       for (idx = 0; idx < ENCODE_ANIM_MENU_MAX; idx++)
+       for (idx = 0; idx < G_N_ELEMENTS(g_disp_encode_anim_menu); idx++)
                g_print("%u. %s\n", g_disp_encode_anim_menu[idx].e, g_disp_encode_anim_menu[idx].t);
        g_print("b. back\n");
        g_print("q. quit\n");
@@ -441,12 +421,7 @@ typedef enum {
        TRANSFORM_MENU_MAX,
 } test_transform_menu_e;
 
-typedef struct {
-       test_transform_menu_e e;
-       const char *t;
-} test_transform_menu_s;
-
-static const test_transform_menu_s g_disp_transform_menu[TRANSFORM_MENU_MAX] = {
+static const test_menu_s g_disp_transform_menu[TRANSFORM_MENU_MAX] = {
        { TRANSFORM_SET_CONVERT,        "set convert" },
        { TRANSFORM_SET_CROP,           "set crop" },
        { TRANSFORM_SET_RESIZE,         "set resize" },
@@ -463,7 +438,7 @@ static void __display_transform_menu(void)
        g_print("====================================================\n");
        g_print("   image-util Core-API test: Transform menu v%s\n", VERSION);
        g_print("----------------------------------------------------\n");
-       for (idx = 0; idx < TRANSFORM_MENU_MAX; idx++)
+       for (idx = 0; idx < G_N_ELEMENTS(g_disp_transform_menu); idx++)
                g_print("%u. %s\n", g_disp_transform_menu[idx].e, g_disp_transform_menu[idx].t);
        g_print("b. back\n");
        g_print("q. quit\n");
@@ -482,12 +457,7 @@ typedef enum {
        MAIN_MENU_MAX,
 } test_main_menu_e;
 
-typedef struct {
-       test_main_menu_e e;
-       const char *t;
-} test_main_menu_s;
-
-static const test_main_menu_s g_disp_main_menu[MAIN_MENU_MAX] = {
+static const test_menu_s g_disp_main_menu[MAIN_MENU_MAX] = {
        { TEST_AUTO,                    "test auto" },
        { TEST_DECODE,                  "test decode" },
        { TEST_ENCODE,                  "test encode" },
@@ -504,7 +474,7 @@ static void __display_main_menu(void)
        g_print("====================================================\n");
        g_print("   image-util Core-API test: Main menu v%s\n", VERSION);
        g_print("----------------------------------------------------\n");
-       for (idx = 0; idx < MAIN_MENU_MAX; idx++)
+       for (idx = 0; idx < G_N_ELEMENTS(g_disp_main_menu); idx++)
                g_print("%u. %s\n", g_disp_main_menu[idx].e, g_disp_main_menu[idx].t);
        g_print("q. quit\n");
        g_print("----------------------------------------------------\n");
@@ -578,7 +548,7 @@ static void __display_menu(test_menu_state_e menu_state)
                __display_set("rotation", "0:none, 1:90, 2:180, 3:270");
                break;
        case SET_TYPE_MENU:
-               __display_set("image_type", "0:jpeg, 1:png, 2:gif, 3:bmp, 4:webp");
+               __display_set("image_type", "0:jpeg, 1:png, 2:gif, 3:bmp, 4:webp, 6:jpeg-xl");
                break;
        case SET_ANIM_TYPE_MENU:
                __display_set("image_anim_type", "0:gif, 1:webp");
@@ -660,8 +630,7 @@ static gboolean __write_file(const char *path, void *data, size_t length)
        return TRUE;
 }
 
-#if DUMP_RAW_IMAGE
-static int __write_jpeg(const char *name, image_util_image_h image)
+static void __write_jpeg(const char *name, image_util_image_h image)
 {
        int ret = IMAGE_UTIL_ERROR_NONE;
        image_util_encode_h handle = NULL;
@@ -672,7 +641,7 @@ static int __write_jpeg(const char *name, image_util_image_h image)
        ret = image_util_encode_create(IMAGE_UTIL_JPEG, &handle);
        if (ret != IMAGE_UTIL_ERROR_NONE) {
                g_print("image_util_decode_create failed %d", ret);
-               return ret;
+               goto ERROR;
        }
 
        ret = image_util_encode_run_to_file(handle, image, path);
@@ -683,10 +652,10 @@ static int __write_jpeg(const char *name, image_util_image_h image)
 
 ERROR:
        image_util_encode_destroy(handle);
+       g_free(path);
 
-       return ret;
+       g_print("\t[__write_jpeg] %s write %s\n", name, (ret == IMAGE_UTIL_ERROR_NONE) ? "DONE" : "FAIL");
 }
-#endif
 
 static gboolean __safe_atoui(char *buffer, unsigned int *ui)
 {
@@ -976,25 +945,15 @@ static const char *g_image_exts[] = {
        "gif",
        "bmp",
        "webp",
+       "",     // not supported HEIF
+       "jxl",
 };
 static void __get_auto_path(image_util_type_e image_type, char **path)
 {
        char *_path = NULL;
 
-       switch (image_type) {
-       case IMAGE_UTIL_JPEG:
-               /* fall through */
-       case IMAGE_UTIL_PNG:
-               /* fall through */
-       case IMAGE_UTIL_GIF:
-               /* fall through */
-       case IMAGE_UTIL_BMP:
-               /* fall through */
-       case IMAGE_UTIL_WEBP:
-               // do noting...
-               break;
-       default:
-               g_print("Not supported encode format!\n");
+       if (!g_image_exts[image_type] || (strlen(g_image_exts[image_type]) == 0)) {
+               g_print("Not supported image_type[%d]!\n", image_type);
                return;
        }
 
@@ -1003,27 +962,15 @@ static void __get_auto_path(image_util_type_e image_type, char **path)
        g_free(*path);
        *path = _path;
 
-       g_print("\t__get_auto_path: %s!\n", *path);
+       g_print("\t__get_auto_path: %s\n", *path);
 }
 
 static void __get_encode_path(image_util_type_e image_type, const char *base, char **path)
 {
        char *_path = NULL;
 
-       switch (image_type) {
-       case IMAGE_UTIL_JPEG:
-               /* fall through */
-       case IMAGE_UTIL_PNG:
-               /* fall through */
-       case IMAGE_UTIL_GIF:
-               /* fall through */
-       case IMAGE_UTIL_BMP:
-               /* fall through */
-       case IMAGE_UTIL_WEBP:
-               // do noting...
-               break;
-       default:
-               g_print("Not supported encode format!\n");
+       if (!g_image_exts[image_type] || (strlen(g_image_exts[image_type]) == 0)) {
+               g_print("Not supported image_type[%d]!\n", image_type);
                return;
        }
 
@@ -1032,7 +979,7 @@ static void __get_encode_path(image_util_type_e image_type, const char *base, ch
        g_free(*path);
        *path = _path;
 
-       g_print("\t__get_encode_path: %s!\n", *path);
+       g_print("\t__get_encode_path: %s\n", *path);
 }
 
 static const char *g_anim_image_exts[] = {
@@ -1043,14 +990,8 @@ static void __get_encode_anim_path(image_util_anim_type_e anim_type, const char
 {
        char *_path = NULL;
 
-       switch (anim_type) {
-       case IMAGE_UTIL_ANIM_GIF:
-               /* fall through */
-       case IMAGE_UTIL_ANIM_WEBP:
-               // do noting...
-               break;
-       default:
-               g_print("Not supported encode animation format!\n");
+       if (!g_anim_image_exts[anim_type] || (strlen(g_anim_image_exts[anim_type]) == 0)) {
+               g_print("Not supported anim_type[%d]!\n", anim_type);
                return;
        }
 
@@ -1059,7 +1000,7 @@ static void __get_encode_anim_path(image_util_anim_type_e anim_type, const char
        g_free(*path);
        *path = _path;
 
-       g_print("\t__get_encode_path: %s!\n", *path);
+       g_print("\t__get_encode_anim_path: %s\n", *path);
 }
 /* internal functions for testsuite */
 
@@ -1356,9 +1297,10 @@ static int __run_encode(test_encode_menu_e menu, test_complex_data_s *input,
                }
                break;
        case IMAGE_UTIL_WEBP:
-               ret = image_util_encode_set_webp_lossless(handle, params->lossless);
+       case IMAGE_UTIL_JPEG_XL:
+               ret = image_util_encode_set_lossless(handle, params->lossless);
                if (ret != IMAGE_UTIL_ERROR_NONE) {
-                       g_print("image_util_encode_set_webp_lossless failed %d\n", ret);
+                       g_print("image_util_encode_set_lossless failed %d\n", ret);
                        goto ERROR;
                }
                break;
@@ -2153,6 +2095,11 @@ static void __interpret_decode(const char *cmd, unsigned int index)
                        __data_push(input_data);
                }
                break;
+
+       case DECODE_SAVE_TO_JPEG:
+               __write_jpeg("decode", g_decode_result.image);
+               break;
+
        default:
                g_print("wrong command! %s\n\n", cmd);
                break;