#define __TIZEN_MEDIA_IMAGE_UTIL_H__
#include <image_util_type.h>
+#include <image_util_decode.h>
+#include <image_util_encode.h>
#ifdef __cplusplus
extern "C"
int image_util_foreach_supported_jpeg_colorspace(image_util_supported_jpeg_colorspace_cb callback, void *user_data) TIZEN_DEPRECATED_API;
/**
-* @deprecated Deprecated since 3.0. Use image_util_decode_create() instead.
-* @brief Decodes the JPEG image to the buffer.
-* @since_tizen 2.3
-*
-* @remarks You must release @a image_buffer using free().\n
-* http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.\n
-* http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.\n
-* If you decode the JPEG image which has odd numbered width or height to YUV colorspace, \n
-* the width or height of decoded data will be rounded down to even numbered width or height.
-*
-* @param[in] path The image file path
-* @param[in] colorspace The decoded image colorspace
-* @param[out] image_buffer The image buffer for the decoded image
-* @param[out] width The image width
-* @param[out] height The image height
-* @param[out] size The image buffer size
-*
-* @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_OUT_OF_MEMORY out of memory
-* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
-* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
-* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
-*
-* @see image_util_supported_jpeg_colorspace_cb()
-* @see image_util_decode_jpeg_from_memory()
-* @see image_util_foreach_supported_jpeg_colorspace()
-*/
-int image_util_decode_jpeg(const char *path, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size) TIZEN_DEPRECATED_API;
-
-/**
-* @deprecated Deprecated since 3.0. Use image_util_decode_create() instead.
-* @brief Decodes the JPEG image(in memory) to the buffer.
-* @since_tizen 2.3
-*
-* @remarks You must release @a image_buffer using free().\n
-* If you decode the JPEG image which has odd numbered width or height to YUV colorspace, \n
-* the width or height of decoded data will be rounded down to even numbered width or height.
-*
-* @param[in] jpeg_buffer The JPEG image buffer
-* @param[in] jpeg_size The JPEG image buffer size
-* @param[in] colorspace The decoded image colorspace
-* @param[out] image_buffer The image buffer for the decoded image
-* @param[out] width The image width
-* @param[out] height The image height
-* @param[out] size The image buffer size
-*
-* @return 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_OUT_OF_MEMORY out of memory
-* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
-* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
-* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
-*
-* @see image_util_supported_jpeg_colorspace_cb()
-* @see image_util_decode_jpeg()
-* @see image_util_foreach_supported_jpeg_colorspace()
-*/
-int image_util_decode_jpeg_from_memory(const unsigned char *jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size) TIZEN_DEPRECATED_API;
-
-/**
-* @deprecated Deprecated since 3.0. Use image_util_decode_create() instead.
-* @brief Decodes the JPEG image to the buffer with downscale decoding option.
-* @since_tizen @if WEARABLE @else 2.4 @endif
-*
-* @remarks You must release @a image_buffer using free().\n
-* http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.\n
-* http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.\n
-* If you decode the JPEG image which has odd numbered width or height to YUV colorspace, \n
-* the width or height of decoded data will be rounded down to even numbered width or height.
-*
-* @param[in] path The image file path
-* @param[in] colorspace The decoded image colorspace
-* @param[in] downscale The downscale value
-* @param[out] image_buffer The image buffer for the decoded image
-* @param[out] width The image width
-* @param[out] height The image height
-* @param[out] size The image buffer size
-*
-* @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_OUT_OF_MEMORY out of memory
-* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
-* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
-* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
-*
-* @see image_util_supported_jpeg_colorspace_cb()
-* @see image_util_decode_jpeg_from_memory()
-* @see image_util_foreach_supported_jpeg_colorspace()
-*/
-int image_util_decode_jpeg_with_downscale(const char *path, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char **image_buffer, int *width, int *height, unsigned int *size) TIZEN_DEPRECATED_API;
-
-/**
-* @deprecated Deprecated since 3.0. Use image_util_decode_create() instead.
-* @brief Decodes the JPEG image(in memory) to the buffer with downscale decoding option.
-* @since_tizen @if WEARABLE @else 2.4 @endif
-*
-* @remarks You must release @a image_buffer using free().\n
-* If you decode the JPEG image which has odd numbered width or height to YUV colorspace, \n
-* the width or height of decoded data will be rounded down to even numbered width or height.
-*
-* @param[in] jpeg_buffer The JPEG image buffer
-* @param[in] jpeg_size The JPEG image buffer size
-* @param[in] colorspace The decoded image colorspace
-* @param[in] downscale The downscale value
-* @param[out] image_buffer The image buffer for the decoded image
-* @param[out] width The image width
-* @param[out] height The image height
-* @param[out] size The image buffer size
-*
-* @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_OUT_OF_MEMORY out of memory
-* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
-* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
-* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
-*
-* @see image_util_supported_jpeg_colorspace_cb()
-* @see image_util_decode_jpeg()
-* @see image_util_foreach_supported_jpeg_colorspace()
-*/
-int image_util_decode_jpeg_from_memory_with_downscale(const unsigned char *jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char **image_buffer, int *width, int *height, unsigned int *size) TIZEN_DEPRECATED_API;
-
-/**
-* @deprecated Deprecated since 3.0. Use image_util_encode_create() instead.
-* @brief Encodes the image to the JPEG image.
-* @since_tizen 2.3
-*
-* @remarks http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.\n
-* http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.
-*
-* @param[in] buffer The original image buffer
-* @param[in] width The original image width
-* @param[in] height The original image height
-* @param[in] colorspace The original image colorspace
-* @param[in] quality The quality for JPEG image encoding(1 ~ 100)
-* @param[in] path The file path to be created
-*
-* @return 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_NO_SUCH_FILE No such file
-* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
-* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
-* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
-*
-* @see image_util_supported_jpeg_colorspace_cb()
-* @see image_util_foreach_supported_jpeg_colorspace()
-* @see image_util_encode_jpeg_to_memory()
-*/
-int image_util_encode_jpeg(const unsigned char *buffer, int width, int height, image_util_colorspace_e colorspace, int quality, const char *path) TIZEN_DEPRECATED_API;
-
-/**
-* @deprecated Deprecated since 3.0. Use image_util_encode_create() instead.
-* @brief Encodes the image to the JPEG image
-* @since_tizen 2.3
-*
-* @remarks You must release @a jpeg_buffer using free().
-*
-* @param[in] image_buffer The original image buffer
-* @param[in] width The image width
-* @param[in] height The image height
-* @param[in] colorspace The original image colorspace
-* @param[in] quality The quality for JPEG image encoding(1 ~ 100)
-* @param[out] jpeg_buffer The created JPEG image buffer \n
-* The buffer is created by frameworks
-* @param[out] jpeg_size The created jpeg image buffer size
-*
-* @return 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_OUT_OF_MEMORY out of memory
-* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
-* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
-* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
-*
-* @see image_util_supported_jpeg_colorspace_cb()
-* @see image_util_foreach_supported_jpeg_colorspace()
-* @see image_util_encode_jpeg()
-*/
-int image_util_encode_jpeg_to_memory(const unsigned char *image_buffer, int width, int height, image_util_colorspace_e colorspace, int quality, unsigned char **jpeg_buffer, unsigned int *jpeg_size) TIZEN_DEPRECATED_API;
-
-/**
* @brief Called once for each supported image encode/decode colorspace.
* @since_tizen 3.0
*
int image_util_foreach_supported_colorspace(image_util_type_e image_type, image_util_supported_colorspace_cb callback, void *user_data);
/**
-* @brief Creates a handle to image util decoding.
-* @since_tizen 3.0
-*
-* @details This function creates a handle to image util decoding.
-*
-* @remarks You must release the @a image util handle using image_util_decode_destroy().
-*
-* @param[out] handle A handle to image util decoding
-*
-* @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_OUT_OF_MEMORY Out of memory
-*
-* @see image_util_decode_destroy()
-*
-*/
-int image_util_decode_create(image_util_decode_h *handle);
-
-/**
-* @brief Sets the input file path from which to decode.
-* @since_tizen 3.0
-*
-* @remarks One of image_util_decode_set_input_path() or image_util_decode_set_input_buffer() should be set.\n
-* If both are set then the latest input set, is considered.\n
-* http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.\n
-* 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.
-*
-* @param[in] handle The handle to image util decoding
-* @param[in] path The path to input image
-*
-* @return @c 0 on success,
-* otherwise a negative error value
-*
-* @retval #IMAGE_UTIL_ERROR_NONE Successful
-* @retval #IMAGE_UTIL_ERROR_NO_SUCH_FILE No such file
-* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
-* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
-* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
-* @retval #IMAGE_UTIL_ERROR_OUT_OF_MEMORY Out of memory
-* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
-*
-* @pre image_util_decode_create()
-*
-* @post image_util_decode_run() / image_util_decode_run_async()
-* @post image_util_decode_destroy()
-*
-* @see image_util_decode_create()
-* @see image_util_decode_set_output_buffer()
-* @see image_util_decode_run()
-* @see image_util_decode_run_async()
-* @see image_util_decode_destroy()
-*/
-int image_util_decode_set_input_path(image_util_decode_h handle, const char *path);
-
-/**
-* @brief Sets the input buffer from which to decode.
-* @since_tizen 3.0
-*
-* @remarks One of image_util_decode_set_input_path() or image_util_decode_set_input_buffer() should be set.\n
-* 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.
-*
-* @param[in] handle The handle to image util decoding
-* @param[in] src_buffer The input image buffer
-* @param[in] src_size The input image buffer size
-*
-* @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_OUT_OF_MEMORY Out of memory
-* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
-*
-* @pre image_util_decode_create()
-*
-* @post image_util_decode_run() / image_util_decode_run_async()
-* @post image_util_decode_destroy()
-*
-* @see image_util_decode_create()
-* @see image_util_decode_set_output_buffer()
-* @see image_util_decode_run()
-* @see image_util_decode_run_async()
-* @see image_util_decode_destroy()
-*/
-int image_util_decode_set_input_buffer(image_util_decode_h handle, const unsigned char *src_buffer, unsigned long long src_size);
-
-/**
-* @brief Sets the output buffer to which the decoded buffer will be written to.
-* @since_tizen 3.0
-*
-* @remarks Either image_util_decode_set_input_path() or image_util_decode_set_input_buffer() should be set.\n
-* By default the decoded output buffer colorspace will be IMAGE_UTIL_COLORSPACE_RGBA8888.
-* Use image_util_decode_set_colorspace to change the colorspace.
-* @a dst_buffer should be released after @a image_util_decode_run() or @a image_util_decode_run_async().
-*
-* @param[in] handle The handle to image util decoding
-* @param[in] dst_buffer The decoded output buffer
-*
-* @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
-*
-* @pre image_util_decode_create()
-*
-* @post image_util_decode_run() / image_util_decode_run_async()
-* @post image_util_decode_destroy()
-*
-* @see image_util_decode_create()
-* @see image_util_decode_set_input_path()
-* @see image_util_decode_set_input_buffer()
-* @see image_util_decode_run()
-* @see image_util_decode_run_async()
-* @see image_util_decode_destroy()
-*/
-int image_util_decode_set_output_buffer(image_util_decode_h handle, unsigned char **dst_buffer);
-
-/**
-* @brief Sets the decoded image colorspace format.
-* @since_tizen 3.0
-*
-* @remarks The default colorspace is IMAGE_UTIL_COLORSPACE_RGBA8888.\n
-* Use image_util_foreach_supported_colorspace to get supported colorspaces for each image format.\n
-* Errors would be returned if not supported.
-*
-* @param[in] handle The handle to image util decoding
-* @param[in] colorspace The decoded image colorspace
-*
-* @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_NOT_SUPPORTED_FORMAT Format not supported
-*
-* @pre image_util_decode_create()
-* @pre image_util_decode_set_input_path() / image_util_decode_set_input_buffer()
-*
-* @post image_util_decode_run() / image_util_decode_run_async()
-* @post image_util_decode_destroy()
-*
-* @see image_util_supported_colorspace_cb()
-* @see image_util_foreach_supported_colorspace()
-* @see image_util_decode_create()
-* @see image_util_decode_set_input_path()
-* @see image_util_decode_set_input_buffer()
-* @see image_util_decode_set_output_buffer()
-* @see image_util_decode_run()
-* @see image_util_decode_run_async()
-* @see image_util_decode_destroy()
-*/
-int image_util_decode_set_colorspace(image_util_encode_h handle, image_util_colorspace_e colorspace);
-
-/**
-* @brief Sets the downscale value at which JPEG image should be decoded.
-* @since_tizen 3.0
-*
-* @remarks This is API is supported only for JPEG decoding.
-*
-* @param[in] handle The handle to image util decoding
-* @param[in] down_scale The downscale at which image is to be decoded
-*
-* @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_NOT_SUPPORTED_FORMAT Format not supported
-*
-* @pre image_util_decode_create()
-* @pre image_util_decode_set_input_path() / image_util_decode_set_input_buffer()
-*
-* @post image_util_decode_run() / image_util_decode_run_async()
-* @post image_util_decode_destroy()
-*
-* @see image_util_decode_create()
-* @see image_util_decode_set_input_path()
-* @see image_util_decode_set_input_buffer()
-* @see image_util_decode_set_output_buffer()
-* @see image_util_decode_run()
-* @see image_util_decode_run_async()
-* @see image_util_decode_destroy()
-*/
-int image_util_decode_set_jpeg_downscale(image_util_encode_h handle, image_util_scale_e down_scale);
-
-/**
-* @brief Starts decoding of the image and fills the output buffer set using image_util_decode_set_output_buffer().
-* @since_tizen 3.0
-*
-* @remarks The output will be stored in the pointer set using image_util_decode_set_output_buffer().\n
-* The function executes synchronously.\n
-* When any of the @pre functions are not called, IMAGE_UTIL_ERROR_INVALID_PARAMETER is returned.
-*
-* @param[in] handle The handle to image util decoding
-* @param[out] width Width of the decoded image
-* @param[out] height Height of the decoded image
-* @param[out] size Size of the decoded image
-*
-* @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
-*
-* @pre image_util_decode_create()
-* @pre image_util_decode_set_input_buffer() / image_util_decode_set_input_path().
-* @pre image_util_decode_set_output_buffer()
-*
-* @post image_util_decode_destroy()
-*
-* @see image_util_decode_create()
-* @see image_util_decode_set_input_path()
-* @see image_util_decode_set_input_buffer()
-* @see image_util_decode_set_output_buffer()
-* @see image_util_decode_destroy()
-*/
-int image_util_decode_run(image_util_decode_h handle, unsigned long *width, unsigned long *height, unsigned long long *size);
-
-/**
-* @brief Starts decoding of the image and fills the output buffer set using image_util_decode_set_output_buffer().
-* @since_tizen 3.0
-*
-* @remarks The output will be stored in the pointer set using image_util_decode_set_output_buffer().\n
-* The function executes asynchronously, which contains complete callback.\n
-* When any of the @pre functions are not called, IMAGE_UTIL_ERROR_INVALID_PARAMETER is returned.
-*
-* @param[in] handle The handle to image util decoding
-* @param[in] callback The callback function to be invoked
-* @param[in] user_data The user data to be passed to the callback function
-*
-* @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
-*
-* @pre image_util_decode_create()
-* @pre image_util_decode_set_input_buffer() / image_util_decode_set_input_path().
-* @pre image_util_decode_set_output_buffer()
-*
-* @post image_util_decode_destroy()
-*
-* @see image_util_decode_create()
-* @see image_util_decode_set_input_path()
-* @see image_util_decode_set_input_buffer()
-* @see image_util_decode_set_output_buffer()
-* @see image_util_decode_destroy()
-*/
-int image_util_decode_run_async(image_util_decode_h handle, image_util_decode_completed_cb callback, void *user_data);
-
-/**
-* @brief Destroys the image decoding handle.
-* @since_tizen 3.0
-*
-* @remarks Any image handle created should be destroyed.
-*
-* @param[in] handle The handle to image util decoding
-*
-* @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
-*
-* @pre image_util_decode_create()
-*
-* @see image_util_decode_create()
-*/
-int image_util_decode_destroy(image_util_decode_h handle);
-
-/**
-* @brief Creates a handle to image util encoding.
-* @since_tizen 3.0
-*
-* @details This function creates a handle to image util encoding.
-*
-* @remarks You must release the @a image util handle using image_util_encode_destroy().
-*
-* @param[in] image_type The type of output image for which to create encode handle.
-* @param[out] handle A handle to image util encoding
-*
-* @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_OUT_OF_MEMORY Out of memory
-*
-* @see image_util_encode_destroy()
-*
-*/
-int image_util_encode_create(image_util_type_e image_type, image_util_encode_h *handle);
-
-/**
-* @brief Sets the resolution of the encoded image.
-* @since_tizen 3.0
-*
-* @remarks This should be called before calling image_util_encode_run().\n
-* While encoding animated gif image, resolution should be set for each frame.
-*
-* @param[in] handle The handle to image util encoding
-* @param[in] width Width of the original image
-* @param[in] height Height of the original image
-*
-* @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
-*
-* @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_set_input_buffer()
-* @see image_util_encode_set_output_path()
-* @see image_util_encode_set_output_buffer()
-* @see image_util_encode_run()
-* @see image_util_encode_run_async()
-* @see image_util_encode_destroy()
-*/
-int image_util_encode_set_resolution(image_util_encode_h handle, unsigned long width, unsigned long height);
-
-/**
-* @brief Sets the colorspace format for image encoding.
-* @since_tizen 3.0
-*
-* @remarks The default colorspace is IMAGE_UTIL_COLORSPACE_RGBA8888.\n
-* Use image_util_foreach_supported_colorspace to get supported colorspaces for each image format.\n
-* Errors would be returned if not supported.
-*
-* @param[in] handle The handle to image util encoding
-* @param[in] colorspace The encoded image colorspace
-*
-* @return @c 0 on success,
-* otherwise a negative error value
-*
-* @retval #IMAGE_UTIL_ERROR_NONE Successful
-* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
-* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
-*
-* @pre image_util_encode_create()
-*
-* @post image_util_encode_run() / image_util_encode_run_async()
-* @post image_util_encode_destroy()
-*
-* @see image_util_supported_colorspace_cb()
-* @see image_util_foreach_supported_colorspace()
-* @see image_util_encode_create()
-* @see image_util_encode_set_resolution()
-* @see image_util_encode_set_input_buffer()
-* @see image_util_encode_set_output_path()
-* @see image_util_encode_set_output_buffer()
-* @see image_util_encode_run()
-* @see image_util_encode_run_async()
-* @see image_util_encode_destroy()
-*/
-int image_util_encode_set_colorspace(image_util_encode_h handle, image_util_colorspace_e colorspace);
-
-/**
-* @brief Sets the quality for image encoding.
-* @since_tizen 3.0
-*
-* @remarks If application does not set this, then by default quality of 75 is set.\n
-* Quality is supported for JPEG format. IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT will be returned for other formats.
-*
-* @param[in] handle The handle to image util encoding
-* @param[in] quality Encoding quality from 1~100
-*
-* @return @c 0 on success,
-* otherwise a negative error value
-*
-* @retval #IMAGE_UTIL_ERROR_NONE Successful
-* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
-* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
-*
-* @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_set_resolution()
-* @see image_util_encode_set_input_buffer()
-* @see image_util_encode_set_output_path()
-* @see image_util_encode_set_output_buffer()
-* @see image_util_encode_run()
-* @see image_util_encode_run_async()
-* @see image_util_encode_destroy()
-*/
-int image_util_encode_set_quality(image_util_encode_h handle, int quality);
-
-/**
-* @brief Sets the compression value of png image encoding(0~9).
-* @since_tizen 3.0
-*
-* @remarks If application does not set this, then default compression of 6 is set.
-*
-* @param[in] handle The handle to image util encoding
-* @param[in] compression The compression value valid from 0~9
-*
-* @return @c 0 on success,
-* otherwise a negative error value
-*
-* @retval #IMAGE_UTIL_ERROR_NONE Successful
-* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
-* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
-* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
-*
-* @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_set_resolution()
-* @see image_util_encode_set_input_buffer()
-* @see image_util_encode_set_output_path()
-* @see image_util_encode_set_output_buffer()
-* @see image_util_encode_run()
-* @see image_util_encode_run_async()
-* @see image_util_encode_destroy()
-*/
-int image_util_encode_set_png_compression(image_util_encode_h handle, image_util_png_compression_e compression);
-
-/**
-* @brief Sets the time delay between each frame in the encoded animated gif image.
-* @since_tizen 3.0
-*
-* @remarks In case animated gif image if this is not set then there will be no delay between each frame.\n
-* This should be set for each frame in the animated gif image.\n
-* This can be set a different value for each frame, which results in different delay time between different frames.
-*
-* @param[in] handle The handle to image util encoding
-* @param[in] delay_time Time delay between each frame in the encoded image, in 0.01sec units.
-*
-* @return @c 0 on success,
-* otherwise a negative error value
-*
-* @retval #IMAGE_UTIL_ERROR_NONE Successful
-* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
-* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
-*
-* @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_set_resolution()
-* @see image_util_encode_set_input_buffer()
-* @see image_util_encode_set_output_path()
-* @see image_util_encode_set_output_buffer()
-* @see image_util_encode_run()
-* @see image_util_encode_run_async()
-* @see image_util_encode_destroy()
-*/
-int image_util_encode_set_gif_frame_delay_time(image_util_encode_h handle, unsigned long long delay_time);
-
-/**
-* @brief Sets the input buffer from which to encode.
-* @since_tizen 3.0
-*
-* @remarks Either image_util_encode_set_output_path() or image_util_encode_set_output_buffer() should be set.\n
-* By default the input buffer colorspace will be considered as IMAGE_UTIL_COLORSPACE_RGBA8888.\n
-* Use image_util_encode_set_colorspace to change the colorspace.\n
-* While encoding animated gif image, input buffer should be set for each frame.
-*
-* @param[in] handle The handle to image util decoding
-* @param[in] src_buffer The input image buffer
-*
-* @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
-*
-* @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_set_resolution()
-* @see image_util_encode_set_input_buffer()
-* @see image_util_encode_set_output_path()
-* @see image_util_encode_set_output_buffer()
-* @see image_util_encode_run()
-* @see image_util_encode_run_async()
-* @see image_util_encode_destroy()
-*/
-int image_util_encode_set_input_buffer(image_util_encode_h handle, const unsigned char *src_buffer);
-
-/**
-* @brief Sets the output path to which to encoded buffer will be written to.
-* @since_tizen 3.0
-*
-* @remarks One of image_util_encode_set_output_path() or image_util_encode_set_output_buffer() should be set.\n
-* If both are set then the latest output set is considered.\n
-* http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.\n
-* http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.
-*
-* @param[in] handle The handle to image util encoding
-* @param[in] path The output file path
-*
-* @return @c 0 on success,
-* otherwise a negative error value
-*
-* @retval #IMAGE_UTIL_ERROR_NONE Successful
-* @retval #IMAGE_UTIL_ERROR_NO_SUCH_FILE No such file
-* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
-* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
-* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
-*
-* @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_set_resolution()
-* @see image_util_encode_set_input_buffer()
-* @see image_util_encode_run()
-* @see image_util_encode_run_async()
-* @see image_util_encode_destroy()
-*/
-int image_util_encode_set_output_path(image_util_encode_h handle, const char *path);
-
-/**
-* @brief Sets the output buffer to which to encoded buffer will be written to.
-* @since_tizen 3.0
-*
-* @remarks One of image_util_encode_set_output_path() or image_util_encode_set_output_buffer() should be set.\n
-* If both are set then the latest output set is considered.\n
-* Before 4.0, output buffer setting is not supported for bmp. IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT will be returned for bmp.\n
-* Since 4.0, output buffer setting has been supported for bmp. Applications can set the output buffer to write encoded bmp.\n
-* In case of gif encoding, the output buffer will be completely available only after image_util_encode_destroy().
-* @a dst_buffer should be released after @a image_util_encode_run() or @a image_util_encode_run_async().
-*
-* @param[in] handle The handle to image util encoding
-* @param[in] dst_buffer The output image buffer
-*
-* @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 Format not supported
-*
-* @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_set_resolution()
-* @see image_util_encode_set_input_buffer()
-* @see image_util_encode_run()
-* @see image_util_encode_run_async()
-* @see image_util_encode_destroy()
-*/
-int image_util_encode_set_output_buffer(image_util_encode_h handle, unsigned char **dst_buffer);
-
-/**
-* @brief Starts encoding of the image and fills the output buffer, set using image_util_encode_set_output_buffer() or image_util_encode_set_output_path().
-* @since_tizen 3.0
-*
-* @remarks The output will be stored in the pointer set to image_util_encode_set_output_buffer() or image_util_encode_set_output_path().\n
-* The function executes synchronously.\n
-* When any of the @pre functions are not called, IMAGE_UTIL_ERROR_INVALID_PARAMETER is returned.\n
-* In case of animated gif encoding, image_util_encode_set_resolution(), image_util_encode_set_input_buffer() and\n
-* image_util_encode_set_gif_frame_delay_time() MUST be called for each frame.
-* In case of animated gif encoding, call image_util_encode_run() for each frame to encode progressively.
-*
-* @param[in] handle The handle to image util encoding
-* @param[out] size Size of the encoded image
-*
-* @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
-*
-* @pre image_util_encode_create()
-* @pre image_util_encode_set_resolution()
-* @pre image_util_encode_set_input_buffer()
-* @pre image_util_encode_set_output_buffer() / image_util_encode_set_output_path()
-*
-* @post image_util_encode_destroy()
-*
-* @see image_util_encode_create()
-* @see image_util_encode_set_resolution()
-* @see image_util_encode_set_input_buffer()
-* @see image_util_encode_set_gif_frame_delay_time()
-* @see image_util_encode_set_output_path()
-* @see image_util_encode_set_output_buffer()
-* @see image_util_encode_destroy()
-*/
-int image_util_encode_run(image_util_encode_h handle, unsigned long long *size);
-
-/**
-* @brief Starts encoding of the image and fills the output buffer, set using image_util_encode_set_output_buffer() or image_util_encode_set_output_path().
-* @since_tizen 3.0
-*
-* @remarks The output will be stored in the pointer set to image_util_encode_set_output_buffer() or image_util_encode_set_output_path().\n
-* The function executes asynchronously, which contains complete callback.\n
-* When any of the @pre functions are not called, IMAGE_UTIL_ERROR_INVALID_PARAMETER is returned.\n
-* In case of animated gif encoding, image_util_encode_set_resolution(), image_util_encode_set_input_buffer() and\n
-* image_util_encode_set_gif_frame_delay_time() MUST be called for each frame.
-* In case of animated gif encoding, call image_util_encode_run_async() for each frame to encode progressively.
-*
-* @param[in] handle The handle to image util encoding
-* @param[in] callback The callback function to be invoked
-* @param[in] user_data The user data to be passed to the callback function
-*
-* @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
-*
-* @pre image_util_encode_create()
-* @pre image_util_encode_set_resolution()
-* @pre image_util_encode_set_input_buffer()
-* @pre image_util_encode_set_output_buffer() / image_util_encode_set_output_path()
-*
-* @post image_util_encode_destroy()
-*
-* @see image_util_encode_create()
-* @see image_util_encode_set_resolution()
-* @see image_util_encode_set_input_buffer()
-* @see image_util_encode_set_gif_frame_delay_time()
-* @see image_util_encode_set_output_path()
-* @see image_util_encode_set_output_buffer()
-* @see image_util_encode_destroy()
-*/
-int image_util_encode_run_async(image_util_encode_h handle, image_util_encode_completed_cb callback, void *user_data);
-
-/**
-* @brief Destroys the image encoding handle.
-* @since_tizen 3.0
-*
-* @remarks Any image handle created should be destroyed.
-*
-* @param[in] handle The handle to image util encoding
-*
-* @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
-*
-* @pre image_util_encode_create()
-*
-* @see image_util_encode_create()
-*/
-int image_util_encode_destroy(image_util_encode_h handle);
-
-/**
* @}
*/
--- /dev/null
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef __TIZEN_MEDIA_IMAGE_UTIL_DECODE_H__
+#define __TIZEN_MEDIA_IMAGE_UTIL_DECODE_H__
+
+#include <image_util_type.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+* @addtogroup CAPI_MEDIA_IMAGE_UTIL_ENCODE_DECODE_MODULE
+* @{
+*/
+
+/**
+* @brief Creates a handle to image util decoding.
+* @since_tizen 3.0
+*
+* @details This function creates a handle to image util decoding.
+*
+* @remarks You must release the @a image util handle using image_util_decode_destroy().
+*
+* @param[out] handle A handle to image util decoding
+*
+* @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_OUT_OF_MEMORY Out of memory
+*
+* @see image_util_decode_destroy()
+*
+*/
+int image_util_decode_create(image_util_decode_h *handle);
+
+/**
+* @brief Sets the input file path from which to decode.
+* @since_tizen 3.0
+*
+* @remarks One of image_util_decode_set_input_path() or image_util_decode_set_input_buffer() should be set.\n
+* If both are set then the latest input set, is considered.\n
+* http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.\n
+* 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.
+*
+* @param[in] handle The handle to image util decoding
+* @param[in] path The path to input image
+*
+* @return @c 0 on success,
+* otherwise a negative error value
+*
+* @retval #IMAGE_UTIL_ERROR_NONE Successful
+* @retval #IMAGE_UTIL_ERROR_NO_SUCH_FILE No such file
+* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
+* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
+* @retval #IMAGE_UTIL_ERROR_OUT_OF_MEMORY Out of memory
+* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
+*
+* @pre image_util_decode_create()
+*
+* @post image_util_decode_run() / image_util_decode_run_async()
+* @post image_util_decode_destroy()
+*
+* @see image_util_decode_create()
+* @see image_util_decode_set_output_buffer()
+* @see image_util_decode_run()
+* @see image_util_decode_run_async()
+* @see image_util_decode_destroy()
+*/
+int image_util_decode_set_input_path(image_util_decode_h handle, const char *path);
+
+/**
+* @brief Sets the input buffer from which to decode.
+* @since_tizen 3.0
+*
+* @remarks One of image_util_decode_set_input_path() or image_util_decode_set_input_buffer() should be set.\n
+* 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.
+*
+* @param[in] handle The handle to image util decoding
+* @param[in] src_buffer The input image buffer
+* @param[in] src_size The input image buffer size
+*
+* @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_OUT_OF_MEMORY Out of memory
+* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
+*
+* @pre image_util_decode_create()
+*
+* @post image_util_decode_run() / image_util_decode_run_async()
+* @post image_util_decode_destroy()
+*
+* @see image_util_decode_create()
+* @see image_util_decode_set_output_buffer()
+* @see image_util_decode_run()
+* @see image_util_decode_run_async()
+* @see image_util_decode_destroy()
+*/
+int image_util_decode_set_input_buffer(image_util_decode_h handle, const unsigned char *src_buffer, unsigned long long src_size);
+
+/**
+* @brief Sets the output buffer to which the decoded buffer will be written to.
+* @since_tizen 3.0
+*
+* @remarks Either image_util_decode_set_input_path() or image_util_decode_set_input_buffer() should be set.\n
+* By default the decoded output buffer colorspace will be IMAGE_UTIL_COLORSPACE_RGBA8888.
+* Use image_util_decode_set_colorspace to change the colorspace.
+* @a dst_buffer should be released after @a image_util_decode_run() or @a image_util_decode_run_async().
+*
+* @param[in] handle The handle to image util decoding
+* @param[in] dst_buffer The decoded output buffer
+*
+* @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
+*
+* @pre image_util_decode_create()
+*
+* @post image_util_decode_run() / image_util_decode_run_async()
+* @post image_util_decode_destroy()
+*
+* @see image_util_decode_create()
+* @see image_util_decode_set_input_path()
+* @see image_util_decode_set_input_buffer()
+* @see image_util_decode_run()
+* @see image_util_decode_run_async()
+* @see image_util_decode_destroy()
+*/
+int image_util_decode_set_output_buffer(image_util_decode_h handle, unsigned char **dst_buffer);
+
+/**
+* @brief Sets the decoded image colorspace format.
+* @since_tizen 3.0
+*
+* @remarks The default colorspace is IMAGE_UTIL_COLORSPACE_RGBA8888.\n
+* Use image_util_foreach_supported_colorspace to get supported colorspaces for each image format.\n
+* Errors would be returned if not supported.
+*
+* @param[in] handle The handle to image util decoding
+* @param[in] colorspace The decoded image colorspace
+*
+* @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_NOT_SUPPORTED_FORMAT Format not supported
+*
+* @pre image_util_decode_create()
+* @pre image_util_decode_set_input_path() / image_util_decode_set_input_buffer()
+*
+* @post image_util_decode_run() / image_util_decode_run_async()
+* @post image_util_decode_destroy()
+*
+* @see image_util_supported_colorspace_cb()
+* @see image_util_foreach_supported_colorspace()
+* @see image_util_decode_create()
+* @see image_util_decode_set_input_path()
+* @see image_util_decode_set_input_buffer()
+* @see image_util_decode_set_output_buffer()
+* @see image_util_decode_run()
+* @see image_util_decode_run_async()
+* @see image_util_decode_destroy()
+*/
+int image_util_decode_set_colorspace(image_util_encode_h handle, image_util_colorspace_e colorspace);
+
+/**
+* @brief Sets the downscale value at which JPEG image should be decoded.
+* @since_tizen 3.0
+*
+* @remarks This is API is supported only for JPEG decoding.
+*
+* @param[in] handle The handle to image util decoding
+* @param[in] down_scale The downscale at which image is to be decoded
+*
+* @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_NOT_SUPPORTED_FORMAT Format not supported
+*
+* @pre image_util_decode_create()
+* @pre image_util_decode_set_input_path() / image_util_decode_set_input_buffer()
+*
+* @post image_util_decode_run() / image_util_decode_run_async()
+* @post image_util_decode_destroy()
+*
+* @see image_util_decode_create()
+* @see image_util_decode_set_input_path()
+* @see image_util_decode_set_input_buffer()
+* @see image_util_decode_set_output_buffer()
+* @see image_util_decode_run()
+* @see image_util_decode_run_async()
+* @see image_util_decode_destroy()
+*/
+int image_util_decode_set_jpeg_downscale(image_util_encode_h handle, image_util_scale_e down_scale);
+
+/**
+* @brief Starts decoding of the image and fills the output buffer set using image_util_decode_set_output_buffer().
+* @since_tizen 3.0
+*
+* @remarks The output will be stored in the pointer set using image_util_decode_set_output_buffer().\n
+* The function executes synchronously.\n
+* When any of the @pre functions are not called, IMAGE_UTIL_ERROR_INVALID_PARAMETER is returned.
+*
+* @param[in] handle The handle to image util decoding
+* @param[out] width Width of the decoded image
+* @param[out] height Height of the decoded image
+* @param[out] size Size of the decoded image
+*
+* @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
+*
+* @pre image_util_decode_create()
+* @pre image_util_decode_set_input_buffer() / image_util_decode_set_input_path().
+* @pre image_util_decode_set_output_buffer()
+*
+* @post image_util_decode_destroy()
+*
+* @see image_util_decode_create()
+* @see image_util_decode_set_input_path()
+* @see image_util_decode_set_input_buffer()
+* @see image_util_decode_set_output_buffer()
+* @see image_util_decode_destroy()
+*/
+int image_util_decode_run(image_util_decode_h handle, unsigned long *width, unsigned long *height, unsigned long long *size);
+
+/**
+* @brief Starts decoding of the image and fills the output buffer set using image_util_decode_set_output_buffer().
+* @since_tizen 3.0
+*
+* @remarks The output will be stored in the pointer set using image_util_decode_set_output_buffer().\n
+* The function executes asynchronously, which contains complete callback.\n
+* When any of the @pre functions are not called, IMAGE_UTIL_ERROR_INVALID_PARAMETER is returned.
+*
+* @param[in] handle The handle to image util decoding
+* @param[in] callback The callback function to be invoked
+* @param[in] user_data The user data to be passed to the callback function
+*
+* @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
+*
+* @pre image_util_decode_create()
+* @pre image_util_decode_set_input_buffer() / image_util_decode_set_input_path().
+* @pre image_util_decode_set_output_buffer()
+*
+* @post image_util_decode_destroy()
+*
+* @see image_util_decode_create()
+* @see image_util_decode_set_input_path()
+* @see image_util_decode_set_input_buffer()
+* @see image_util_decode_set_output_buffer()
+* @see image_util_decode_destroy()
+*/
+int image_util_decode_run_async(image_util_decode_h handle, image_util_decode_completed_cb callback, void *user_data);
+
+/**
+* @brief Destroys the image decoding handle.
+* @since_tizen 3.0
+*
+* @remarks Any image handle created should be destroyed.
+*
+* @param[in] handle The handle to image util decoding
+*
+* @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
+*
+* @pre image_util_decode_create()
+*
+* @see image_util_decode_create()
+*/
+int image_util_decode_destroy(image_util_decode_h handle);
+
+/**
+* @deprecated Deprecated since 3.0. Use image_util_decode_create() instead.
+* @brief Decodes the JPEG image to the buffer.
+* @since_tizen 2.3
+*
+* @remarks You must release @a image_buffer using free().\n
+* http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.\n
+* http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.\n
+* If you decode the JPEG image which has odd numbered width or height to YUV colorspace, \n
+* the width or height of decoded data will be rounded down to even numbered width or height.
+*
+* @param[in] path The image file path
+* @param[in] colorspace The decoded image colorspace
+* @param[out] image_buffer The image buffer for the decoded image
+* @param[out] width The image width
+* @param[out] height The image height
+* @param[out] size The image buffer size
+*
+* @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_OUT_OF_MEMORY out of memory
+* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
+* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @see image_util_supported_jpeg_colorspace_cb()
+* @see image_util_decode_jpeg_from_memory()
+* @see image_util_foreach_supported_jpeg_colorspace()
+*/
+int image_util_decode_jpeg(const char *path, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size) TIZEN_DEPRECATED_API;
+
+/**
+* @deprecated Deprecated since 3.0. Use image_util_decode_create() instead.
+* @brief Decodes the JPEG image(in memory) to the buffer.
+* @since_tizen 2.3
+*
+* @remarks You must release @a image_buffer using free().\n
+* If you decode the JPEG image which has odd numbered width or height to YUV colorspace, \n
+* the width or height of decoded data will be rounded down to even numbered width or height.
+*
+* @param[in] jpeg_buffer The JPEG image buffer
+* @param[in] jpeg_size The JPEG image buffer size
+* @param[in] colorspace The decoded image colorspace
+* @param[out] image_buffer The image buffer for the decoded image
+* @param[out] width The image width
+* @param[out] height The image height
+* @param[out] size The image buffer size
+*
+* @return 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_OUT_OF_MEMORY out of memory
+* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
+* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @see image_util_supported_jpeg_colorspace_cb()
+* @see image_util_decode_jpeg()
+* @see image_util_foreach_supported_jpeg_colorspace()
+*/
+int image_util_decode_jpeg_from_memory(const unsigned char *jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size) TIZEN_DEPRECATED_API;
+
+/**
+* @deprecated Deprecated since 3.0. Use image_util_decode_create() instead.
+* @brief Decodes the JPEG image to the buffer with downscale decoding option.
+* @since_tizen @if WEARABLE @else 2.4 @endif
+*
+* @remarks You must release @a image_buffer using free().\n
+* http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.\n
+* http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.\n
+* If you decode the JPEG image which has odd numbered width or height to YUV colorspace, \n
+* the width or height of decoded data will be rounded down to even numbered width or height.
+*
+* @param[in] path The image file path
+* @param[in] colorspace The decoded image colorspace
+* @param[in] downscale The downscale value
+* @param[out] image_buffer The image buffer for the decoded image
+* @param[out] width The image width
+* @param[out] height The image height
+* @param[out] size The image buffer size
+*
+* @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_OUT_OF_MEMORY out of memory
+* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
+* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @see image_util_supported_jpeg_colorspace_cb()
+* @see image_util_decode_jpeg_from_memory()
+* @see image_util_foreach_supported_jpeg_colorspace()
+*/
+int image_util_decode_jpeg_with_downscale(const char *path, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char **image_buffer, int *width, int *height, unsigned int *size) TIZEN_DEPRECATED_API;
+
+/**
+* @deprecated Deprecated since 3.0. Use image_util_decode_create() instead.
+* @brief Decodes the JPEG image(in memory) to the buffer with downscale decoding option.
+* @since_tizen @if WEARABLE @else 2.4 @endif
+*
+* @remarks You must release @a image_buffer using free().\n
+* If you decode the JPEG image which has odd numbered width or height to YUV colorspace, \n
+* the width or height of decoded data will be rounded down to even numbered width or height.
+*
+* @param[in] jpeg_buffer The JPEG image buffer
+* @param[in] jpeg_size The JPEG image buffer size
+* @param[in] colorspace The decoded image colorspace
+* @param[in] downscale The downscale value
+* @param[out] image_buffer The image buffer for the decoded image
+* @param[out] width The image width
+* @param[out] height The image height
+* @param[out] size The image buffer size
+*
+* @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_OUT_OF_MEMORY out of memory
+* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
+* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @see image_util_supported_jpeg_colorspace_cb()
+* @see image_util_decode_jpeg()
+* @see image_util_foreach_supported_jpeg_colorspace()
+*/
+int image_util_decode_jpeg_from_memory_with_downscale(const unsigned char *jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char **image_buffer, int *width, int *height, unsigned int *size) TIZEN_DEPRECATED_API;
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
--- /dev/null
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef __TIZEN_MEDIA_IMAGE_UTIL_ENCODE_H__
+#define __TIZEN_MEDIA_IMAGE_UTIL_ENCODE_H__
+
+#include <image_util_type.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+/**
+* @addtogroup CAPI_MEDIA_IMAGE_UTIL_ENCODE_DECODE_MODULE
+* @{
+*/
+
+/**
+* @brief Creates a handle to image util encoding.
+* @since_tizen 3.0
+*
+* @details This function creates a handle to image util encoding.
+*
+* @remarks You must release the @a image util handle using image_util_encode_destroy().
+*
+* @param[in] image_type The type of output image for which to create encode handle.
+* @param[out] handle A handle to image util encoding
+*
+* @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_OUT_OF_MEMORY Out of memory
+*
+* @see image_util_encode_destroy()
+*
+*/
+int image_util_encode_create(image_util_type_e image_type, image_util_encode_h *handle);
+
+/**
+* @brief Sets the resolution of the encoded image.
+* @since_tizen 3.0
+*
+* @remarks This should be called before calling image_util_encode_run().\n
+* While encoding animated gif image, resolution should be set for each frame.
+*
+* @param[in] handle The handle to image util encoding
+* @param[in] width Width of the original image
+* @param[in] height Height of the original image
+*
+* @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
+*
+* @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_set_input_buffer()
+* @see image_util_encode_set_output_path()
+* @see image_util_encode_set_output_buffer()
+* @see image_util_encode_run()
+* @see image_util_encode_run_async()
+* @see image_util_encode_destroy()
+*/
+int image_util_encode_set_resolution(image_util_encode_h handle, unsigned long width, unsigned long height);
+
+/**
+* @brief Sets the colorspace format for image encoding.
+* @since_tizen 3.0
+*
+* @remarks The default colorspace is IMAGE_UTIL_COLORSPACE_RGBA8888.\n
+* Use image_util_foreach_supported_colorspace to get supported colorspaces for each image format.\n
+* Errors would be returned if not supported.
+*
+* @param[in] handle The handle to image util encoding
+* @param[in] colorspace The encoded image colorspace
+*
+* @return @c 0 on success,
+* otherwise a negative error value
+*
+* @retval #IMAGE_UTIL_ERROR_NONE Successful
+* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
+* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+*
+* @pre image_util_encode_create()
+*
+* @post image_util_encode_run() / image_util_encode_run_async()
+* @post image_util_encode_destroy()
+*
+* @see image_util_supported_colorspace_cb()
+* @see image_util_foreach_supported_colorspace()
+* @see image_util_encode_create()
+* @see image_util_encode_set_resolution()
+* @see image_util_encode_set_input_buffer()
+* @see image_util_encode_set_output_path()
+* @see image_util_encode_set_output_buffer()
+* @see image_util_encode_run()
+* @see image_util_encode_run_async()
+* @see image_util_encode_destroy()
+*/
+int image_util_encode_set_colorspace(image_util_encode_h handle, image_util_colorspace_e colorspace);
+
+/**
+* @brief Sets the quality for image encoding.
+* @since_tizen 3.0
+*
+* @remarks If application does not set this, then by default quality of 75 is set.\n
+* Quality is supported for JPEG format. IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT will be returned for other formats.
+*
+* @param[in] handle The handle to image util encoding
+* @param[in] quality Encoding quality from 1~100
+*
+* @return @c 0 on success,
+* otherwise a negative error value
+*
+* @retval #IMAGE_UTIL_ERROR_NONE Successful
+* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
+* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+*
+* @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_set_resolution()
+* @see image_util_encode_set_input_buffer()
+* @see image_util_encode_set_output_path()
+* @see image_util_encode_set_output_buffer()
+* @see image_util_encode_run()
+* @see image_util_encode_run_async()
+* @see image_util_encode_destroy()
+*/
+int image_util_encode_set_quality(image_util_encode_h handle, int quality);
+
+/**
+* @brief Sets the compression value of png image encoding(0~9).
+* @since_tizen 3.0
+*
+* @remarks If application does not set this, then default compression of 6 is set.
+*
+* @param[in] handle The handle to image util encoding
+* @param[in] compression The compression value valid from 0~9
+*
+* @return @c 0 on success,
+* otherwise a negative error value
+*
+* @retval #IMAGE_UTIL_ERROR_NONE Successful
+* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
+* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
+*
+* @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_set_resolution()
+* @see image_util_encode_set_input_buffer()
+* @see image_util_encode_set_output_path()
+* @see image_util_encode_set_output_buffer()
+* @see image_util_encode_run()
+* @see image_util_encode_run_async()
+* @see image_util_encode_destroy()
+*/
+int image_util_encode_set_png_compression(image_util_encode_h handle, image_util_png_compression_e compression);
+
+/**
+* @brief Sets the time delay between each frame in the encoded animated gif image.
+* @since_tizen 3.0
+*
+* @remarks In case animated gif image if this is not set then there will be no delay between each frame.\n
+* This should be set for each frame in the animated gif image.\n
+* This can be set a different value for each frame, which results in different delay time between different frames.
+*
+* @param[in] handle The handle to image util encoding
+* @param[in] delay_time Time delay between each frame in the encoded image, in 0.01sec units.
+*
+* @return @c 0 on success,
+* otherwise a negative error value
+*
+* @retval #IMAGE_UTIL_ERROR_NONE Successful
+* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
+* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+*
+* @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_set_resolution()
+* @see image_util_encode_set_input_buffer()
+* @see image_util_encode_set_output_path()
+* @see image_util_encode_set_output_buffer()
+* @see image_util_encode_run()
+* @see image_util_encode_run_async()
+* @see image_util_encode_destroy()
+*/
+int image_util_encode_set_gif_frame_delay_time(image_util_encode_h handle, unsigned long long delay_time);
+
+/**
+* @brief Sets the input buffer from which to encode.
+* @since_tizen 3.0
+*
+* @remarks Either image_util_encode_set_output_path() or image_util_encode_set_output_buffer() should be set.\n
+* By default the input buffer colorspace will be considered as IMAGE_UTIL_COLORSPACE_RGBA8888.\n
+* Use image_util_encode_set_colorspace to change the colorspace.\n
+* While encoding animated gif image, input buffer should be set for each frame.
+*
+* @param[in] handle The handle to image util decoding
+* @param[in] src_buffer The input image buffer
+*
+* @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
+*
+* @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_set_resolution()
+* @see image_util_encode_set_input_buffer()
+* @see image_util_encode_set_output_path()
+* @see image_util_encode_set_output_buffer()
+* @see image_util_encode_run()
+* @see image_util_encode_run_async()
+* @see image_util_encode_destroy()
+*/
+int image_util_encode_set_input_buffer(image_util_encode_h handle, const unsigned char *src_buffer);
+
+/**
+* @brief Sets the output path to which to encoded buffer will be written to.
+* @since_tizen 3.0
+*
+* @remarks One of image_util_encode_set_output_path() or image_util_encode_set_output_buffer() should be set.\n
+* If both are set then the latest output set is considered.\n
+* http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.\n
+* http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.
+*
+* @param[in] handle The handle to image util encoding
+* @param[in] path The output file path
+*
+* @return @c 0 on success,
+* otherwise a negative error value
+*
+* @retval #IMAGE_UTIL_ERROR_NONE Successful
+* @retval #IMAGE_UTIL_ERROR_NO_SUCH_FILE No such file
+* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
+* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @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_set_resolution()
+* @see image_util_encode_set_input_buffer()
+* @see image_util_encode_run()
+* @see image_util_encode_run_async()
+* @see image_util_encode_destroy()
+*/
+int image_util_encode_set_output_path(image_util_encode_h handle, const char *path);
+
+/**
+* @brief Sets the output buffer to which to encoded buffer will be written to.
+* @since_tizen 3.0
+*
+* @remarks One of image_util_encode_set_output_path() or image_util_encode_set_output_buffer() should be set.\n
+* If both are set then the latest output set is considered.\n
+* Before 4.0, output buffer setting is not supported for bmp. IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT will be returned for bmp.\n
+* Since 4.0, output buffer setting has been supported for bmp. Applications can set the output buffer to write encoded bmp.\n
+* In case of gif encoding, the output buffer will be completely available only after image_util_encode_destroy().
+* @a dst_buffer should be released after @a image_util_encode_run() or @a image_util_encode_run_async().
+*
+* @param[in] handle The handle to image util encoding
+* @param[in] dst_buffer The output image buffer
+*
+* @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 Format not supported
+*
+* @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_set_resolution()
+* @see image_util_encode_set_input_buffer()
+* @see image_util_encode_run()
+* @see image_util_encode_run_async()
+* @see image_util_encode_destroy()
+*/
+int image_util_encode_set_output_buffer(image_util_encode_h handle, unsigned char **dst_buffer);
+
+/**
+* @brief Starts encoding of the image and fills the output buffer, set using image_util_encode_set_output_buffer() or image_util_encode_set_output_path().
+* @since_tizen 3.0
+*
+* @remarks The output will be stored in the pointer set to image_util_encode_set_output_buffer() or image_util_encode_set_output_path().\n
+* The function executes synchronously.\n
+* When any of the @pre functions are not called, IMAGE_UTIL_ERROR_INVALID_PARAMETER is returned.\n
+* In case of animated gif encoding, image_util_encode_set_resolution(), image_util_encode_set_input_buffer() and\n
+* image_util_encode_set_gif_frame_delay_time() MUST be called for each frame.
+* In case of animated gif encoding, call image_util_encode_run() for each frame to encode progressively.
+*
+* @param[in] handle The handle to image util encoding
+* @param[out] size Size of the encoded image
+*
+* @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
+*
+* @pre image_util_encode_create()
+* @pre image_util_encode_set_resolution()
+* @pre image_util_encode_set_input_buffer()
+* @pre image_util_encode_set_output_buffer() / image_util_encode_set_output_path()
+*
+* @post image_util_encode_destroy()
+*
+* @see image_util_encode_create()
+* @see image_util_encode_set_resolution()
+* @see image_util_encode_set_input_buffer()
+* @see image_util_encode_set_gif_frame_delay_time()
+* @see image_util_encode_set_output_path()
+* @see image_util_encode_set_output_buffer()
+* @see image_util_encode_destroy()
+*/
+int image_util_encode_run(image_util_encode_h handle, unsigned long long *size);
+
+/**
+* @brief Starts encoding of the image and fills the output buffer, set using image_util_encode_set_output_buffer() or image_util_encode_set_output_path().
+* @since_tizen 3.0
+*
+* @remarks The output will be stored in the pointer set to image_util_encode_set_output_buffer() or image_util_encode_set_output_path().\n
+* The function executes asynchronously, which contains complete callback.\n
+* When any of the @pre functions are not called, IMAGE_UTIL_ERROR_INVALID_PARAMETER is returned.\n
+* In case of animated gif encoding, image_util_encode_set_resolution(), image_util_encode_set_input_buffer() and\n
+* image_util_encode_set_gif_frame_delay_time() MUST be called for each frame.
+* In case of animated gif encoding, call image_util_encode_run_async() for each frame to encode progressively.
+*
+* @param[in] handle The handle to image util encoding
+* @param[in] callback The callback function to be invoked
+* @param[in] user_data The user data to be passed to the callback function
+*
+* @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
+*
+* @pre image_util_encode_create()
+* @pre image_util_encode_set_resolution()
+* @pre image_util_encode_set_input_buffer()
+* @pre image_util_encode_set_output_buffer() / image_util_encode_set_output_path()
+*
+* @post image_util_encode_destroy()
+*
+* @see image_util_encode_create()
+* @see image_util_encode_set_resolution()
+* @see image_util_encode_set_input_buffer()
+* @see image_util_encode_set_gif_frame_delay_time()
+* @see image_util_encode_set_output_path()
+* @see image_util_encode_set_output_buffer()
+* @see image_util_encode_destroy()
+*/
+int image_util_encode_run_async(image_util_encode_h handle, image_util_encode_completed_cb callback, void *user_data);
+
+/**
+* @brief Destroys the image encoding handle.
+* @since_tizen 3.0
+*
+* @remarks Any image handle created should be destroyed.
+*
+* @param[in] handle The handle to image util encoding
+*
+* @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
+*
+* @pre image_util_encode_create()
+*
+* @see image_util_encode_create()
+*/
+int image_util_encode_destroy(image_util_encode_h handle);
+
+/**
+* @deprecated Deprecated since 3.0. Use image_util_encode_create() instead.
+* @brief Encodes the image to the JPEG image.
+* @since_tizen 2.3
+*
+* @remarks http://tizen.org/privilege/mediastorage is needed if input or output path are relevant to media storage.\n
+* http://tizen.org/privilege/externalstorage is needed if input or output path are relevant to external storage.
+*
+* @param[in] buffer The original image buffer
+* @param[in] width The original image width
+* @param[in] height The original image height
+* @param[in] colorspace The original image colorspace
+* @param[in] quality The quality for JPEG image encoding(1 ~ 100)
+* @param[in] path The file path to be created
+*
+* @return 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_NO_SUCH_FILE No such file
+* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
+* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @see image_util_supported_jpeg_colorspace_cb()
+* @see image_util_foreach_supported_jpeg_colorspace()
+* @see image_util_encode_jpeg_to_memory()
+*/
+int image_util_encode_jpeg(const unsigned char *buffer, int width, int height, image_util_colorspace_e colorspace, int quality, const char *path) TIZEN_DEPRECATED_API;
+
+/**
+* @deprecated Deprecated since 3.0. Use image_util_encode_create() instead.
+* @brief Encodes the image to the JPEG image
+* @since_tizen 2.3
+*
+* @remarks You must release @a jpeg_buffer using free().
+*
+* @param[in] image_buffer The original image buffer
+* @param[in] width The image width
+* @param[in] height The image height
+* @param[in] colorspace The original image colorspace
+* @param[in] quality The quality for JPEG image encoding(1 ~ 100)
+* @param[out] jpeg_buffer The created JPEG image buffer \n
+* The buffer is created by frameworks
+* @param[out] jpeg_size The created jpeg image buffer size
+*
+* @return 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_OUT_OF_MEMORY out of memory
+* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Format not supported
+* @retval #IMAGE_UTIL_ERROR_INVALID_OPERATION Invalid operation
+* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @see image_util_supported_jpeg_colorspace_cb()
+* @see image_util_foreach_supported_jpeg_colorspace()
+* @see image_util_encode_jpeg()
+*/
+int image_util_encode_jpeg_to_memory(const unsigned char *image_buffer, int width, int height, image_util_colorspace_e colorspace, int quality, unsigned char **jpeg_buffer, unsigned int *jpeg_size) TIZEN_DEPRECATED_API;
+
+/**
+ * @}
+ */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
* limitations under the License.
*/
-#include <dlog.h>
-
#include <mm_util_imgp.h>
-#include <mm_util_jpeg.h>
-#include <mm_util_png.h>
-#include <mm_util_gif.h>
-#include <mm_util_bmp.h>
+
#include <image_util.h>
#include <image_util_private.h>
-#include <stdio.h>
-#include <stdlib.h>
-
-static int _convert_decode_scale_tbl[] = {
- MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1,
- MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2,
- MM_UTIL_JPEG_DECODE_DOWNSCALE_1_4,
- MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8,
-};
-
-#define _NUM_OF_SCALE (sizeof(_convert_decode_scale_tbl)/sizeof(int))
static void _image_util_transform_completed_cb(media_packet_h * dst, int error, void *user_data)
{
return _convert_image_util_error_code(__func__, err);
}
-int image_util_decode_jpeg(const char *path, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- DEPRECATION_LOGW("image_util_decode_jpeg()", "image_util_decode_create()");
-
- image_util_retvm_if((path == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "path is null");
- image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
- image_util_retvm_if((size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "size is null");
- image_util_retvm_if((strlen(path) == 0), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path");
- image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
- image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
-
- mm_util_jpeg_yuv_data decoded;
- memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
-
- err = mm_util_decode_from_jpeg_file(&decoded, path, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG));
- if (err == MM_UTIL_ERROR_NONE) {
- *image_buffer = decoded.data;
- if (width)
- *width = decoded.width;
- if (height)
- *height = decoded.height;
- if (size)
- *size = decoded.size;
- }
- return _convert_image_util_error_code(__func__, err);
-}
-
-int image_util_decode_jpeg_from_memory(const unsigned char *jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- DEPRECATION_LOGW("image_util_decode_jpeg_from_memory()", "image_util_decode_create()");
-
- image_util_retvm_if((jpeg_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "jpeg_buffer is null");
- image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
- image_util_retvm_if((size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "size is null");
- image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
- image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
-
- mm_util_jpeg_yuv_data decoded;
- memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
-
- err = mm_util_decode_from_jpeg_memory(&decoded, (void *)jpeg_buffer, (unsigned int)jpeg_size, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG));
-
- if (err == MM_UTIL_ERROR_NONE) {
- *image_buffer = decoded.data;
- if (width)
- *width = decoded.width;
- if (height)
- *height = decoded.height;
- if (size)
- *size = decoded.size;
- }
-
- return _convert_image_util_error_code(__func__, err);
-}
-
-int image_util_decode_jpeg_with_downscale(const char *path, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char **image_buffer, int *width, int *height, unsigned int *size)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- DEPRECATION_LOGW("image_util_decode_jpeg_with_downscale()", "image_util_decode_create()");
-
- image_util_retvm_if((path == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "path is null");
- image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
- image_util_retvm_if((size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "size is null");
- image_util_retvm_if((strlen(path) == 0), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path");
- image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
- image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
- image_util_retvm_if((downscale < 0 || downscale >= _NUM_OF_SCALE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "downsacle is invalid");
-
- mm_util_jpeg_yuv_data decoded;
- memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
-
- err = mm_util_decode_from_jpeg_file_with_downscale(&decoded, path, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[downscale]);
- if (err == MM_UTIL_ERROR_NONE) {
- *image_buffer = decoded.data;
- if (width)
- *width = decoded.width;
- if (height)
- *height = decoded.height;
- if (size)
- *size = decoded.size;
- }
- return _convert_image_util_error_code(__func__, err);
-}
-
-int image_util_decode_jpeg_from_memory_with_downscale(const unsigned char *jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char **image_buffer, int *width, int *height, unsigned int *size)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- DEPRECATION_LOGW("image_util_decode_jpeg_from_memory_with_downscale()", "image_util_decode_create()");
-
- image_util_retvm_if((jpeg_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "jpeg_buffer is null");
- image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
- image_util_retvm_if((size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "size is null");
- image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
- image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
- image_util_retvm_if((downscale < 0 || downscale >= _NUM_OF_SCALE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "downsacle is invalid");
-
- mm_util_jpeg_yuv_data decoded;
- memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
-
- err = mm_util_decode_from_jpeg_memory_with_downscale(&decoded, (void *)jpeg_buffer, (unsigned int)jpeg_size, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[downscale]);
-
- if (err == MM_UTIL_ERROR_NONE) {
- *image_buffer = decoded.data;
- if (width)
- *width = decoded.width;
- if (height)
- *height = decoded.height;
- if (size)
- *size = decoded.size;
- }
-
- return _convert_image_util_error_code(__func__, err);
-}
-
-int image_util_encode_jpeg(const unsigned char *buffer, int width, int height, image_util_colorspace_e colorspace, int quality, const char *path)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- DEPRECATION_LOGW("image_util_encode_jpeg()", "image_util_encode_create()");
-
- image_util_retvm_if((path == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "path is null");
- image_util_retvm_if((buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "buffer is null");
- image_util_retvm_if((strlen(path) == 0), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path");
- image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
- image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
-
- err = mm_util_jpeg_encode_to_file(path, (void *)buffer, width, height, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), quality);
- return _convert_image_util_error_code(__func__, err);
-}
-
-int image_util_encode_jpeg_to_memory(const unsigned char *image_buffer, int width, int height, image_util_colorspace_e colorspace, int quality, unsigned char **jpeg_buffer, unsigned int *jpeg_size)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- DEPRECATION_LOGW("image_util_encode_jpeg_to_memory()", "image_util_encode_create()");
-
- image_util_retvm_if((jpeg_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "jpeg_buffer is null");
- image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
- image_util_retvm_if((jpeg_size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "jpeg_size is null");
- image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
- image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
-
- err = mm_util_jpeg_encode_to_memory((void **)jpeg_buffer, jpeg_size, (void *)image_buffer, width, height, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), quality);
- return _convert_image_util_error_code(__func__, err);
-}
-
int image_util_extract_color_from_memory(const unsigned char *image_buffer, int width, int height, unsigned char *rgb_r, unsigned char *rgb_g, unsigned char *rgb_b)
{
int ret = MM_UTIL_ERROR_NONE;
return IMAGE_UTIL_ERROR_NONE;
}
-
-static void _image_util_decode_destroy_image_handle(decode_encode_s * handle)
-{
- image_util_retm_if((handle == NULL), "Invalid Handle");
- void *image_handle = (void *)(handle->image_h);
- image_util_retm_if((image_handle == NULL), "Invalid image handle");
-
- IMAGE_UTIL_SAFE_FREE(image_handle);
-}
-
-static int _image_util_decode_create_jpeg_handle(decode_encode_s * handle)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
- /* It is needed to reuse decode handle for C#, so it shoud be reallocated */
- _image_util_decode_destroy_image_handle(handle);
-
- mm_util_jpeg_yuv_data *_handle = (mm_util_jpeg_yuv_data *) calloc(1, sizeof(mm_util_jpeg_yuv_data));
- image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY);
-
- handle->image_h = (mm_util_imgp_h) _handle;
- handle->colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888;
- handle->down_scale = sizeof(image_util_scale_e);
-
- return err;
-}
-
-static int _image_util_decode_create_png_handle(decode_encode_s * handle)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
- /* It is needed to reuse decode handle for C#, so it shoud be reallocated */
- _image_util_decode_destroy_image_handle(handle);
-
- mm_util_png_data *_handle = (mm_util_png_data *) calloc(1, sizeof(mm_util_png_data));
- image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY);
-
- mm_util_init_decode_png(_handle);
-
- handle->image_h = (mm_util_imgp_h) _handle;
-
- return err;
-}
-
-static int _image_util_decode_create_gif_handle(decode_encode_s * handle)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
- /* It is needed to reuse decode handle for C#, so it shoud be reallocated */
- _image_util_decode_destroy_image_handle(handle);
-
- mm_util_gif_data *_handle = (mm_util_gif_data *) calloc(1, sizeof(mm_util_gif_data));
- image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY);
-
- handle->image_h = (mm_util_imgp_h) _handle;
-
- return err;
-}
-
-static int _image_util_decode_create_bmp_handle(decode_encode_s * handle)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
- /* It is needed to reuse decode handle for C#, so it shoud be reallocated */
- _image_util_decode_destroy_image_handle(handle);
-
- mm_util_bmp_data *_handle = (mm_util_bmp_data *) calloc(1, sizeof(mm_util_bmp_data));
- image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY);
-
- handle->image_h = (mm_util_imgp_h) _handle;
-
- return err;
-}
-
-int image_util_decode_create(image_util_decode_h * handle)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- image_util_debug("image_util_decode_create");
-
- image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
- decode_encode_s *_handle = (decode_encode_s *) calloc(1, sizeof(decode_encode_s));
- image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", IMAGE_UTIL_ERROR_OUT_OF_MEMORY);
-
- _handle->src_buffer = NULL;
- _handle->dst_buffer = NULL;
- _handle->path = NULL;
- _handle->image_h = 0;
- _handle->is_decode = TRUE;
- _handle->image_type = -1;
-
- *handle = (image_util_decode_h) _handle;
-
- return _convert_image_util_error_code(__func__, err);
-}
-
-static char _JPEG_HEADER[] = { 0xFF, 0xD8 };
-static char _PNG_HEADER[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
-static char _GIF_HEADER[] = { 'G', 'I', 'F' };
-static char _BMP_HEADER[] = { 'B', 'M' };
-
-static int _image_util_decode_create_image_handle(image_util_decode_h handle, const unsigned char *src_buffer)
-{
- image_util_type_e image_type = -1;
- static struct {
- char *header;
- int size;
- image_util_type_e image_type;
- } image_header[] = {
- {
- _JPEG_HEADER, sizeof(_JPEG_HEADER), IMAGE_UTIL_JPEG}
- , {
- _PNG_HEADER, sizeof(_PNG_HEADER), IMAGE_UTIL_PNG}
- , {
- _GIF_HEADER, sizeof(_GIF_HEADER), IMAGE_UTIL_GIF}
- , {
- _BMP_HEADER, sizeof(_BMP_HEADER), IMAGE_UTIL_BMP}
- ,};
- unsigned int i = 0;
- int err = MM_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == FALSE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if (src_buffer == NULL) {
- image_util_error("Invalid input buffer");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- for (i = 0; i < sizeof(image_header) / sizeof(image_header[0]); i++) {
- if (strncmp((const char *)src_buffer, image_header[i].header, image_header[i].size) == 0) {
- image_type = image_header[i].image_type;
- break;
- }
- }
-
- _handle->image_type = image_type;
-
- switch (image_type) {
- case IMAGE_UTIL_JPEG:
- err = _image_util_decode_create_jpeg_handle(_handle);
- break;
- case IMAGE_UTIL_PNG:
- err = _image_util_decode_create_png_handle(_handle);
- break;
- case IMAGE_UTIL_GIF:
- err = _image_util_decode_create_gif_handle(_handle);
- break;
- case IMAGE_UTIL_BMP:
- err = _image_util_decode_create_bmp_handle(_handle);
- break;
- default:
- err = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
- break;
- }
-
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("Error - create image handle");
- return _convert_image_util_error_code(__func__, err);
- }
-
- return _convert_image_util_error_code(__func__, err);
-}
-
-int image_util_decode_set_input_path(image_util_decode_h handle, const char *path)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
- FILE *fp = NULL;
- unsigned char *src_buffer = NULL;
-
- if (_handle == NULL || _handle->is_decode == FALSE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- image_util_retvm_if((path == NULL || strlen(path) == 0), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path");
-
- if (_handle->src_buffer)
- _handle->src_buffer = NULL;
-
- fp = fopen(path, "r");
- if (fp == NULL) {
- image_util_error("File open failed %s", path);
- return IMAGE_UTIL_ERROR_NO_SUCH_FILE;
- }
- src_buffer = (void *)malloc(sizeof(_PNG_HEADER));
- if (src_buffer == NULL) {
- image_util_error("malloc fail");
- fclose(fp);
- fp = NULL;
- return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
- }
-
- if (!fread(src_buffer, 1, sizeof(_PNG_HEADER), fp)) {
- image_util_error("File read failed");
- fclose(fp);
- fp = NULL;
- IMAGE_UTIL_SAFE_FREE(src_buffer);
- return IMAGE_UTIL_ERROR_INVALID_OPERATION;
- }
-
- err = _image_util_decode_create_image_handle(_handle, src_buffer);
- if (err != IMAGE_UTIL_ERROR_NONE) {
- image_util_error("_image_util_decode_create_image_handle failed");
- fclose(fp);
- fp = NULL;
- IMAGE_UTIL_SAFE_FREE(src_buffer);
- return err;
- }
-
- fclose(fp);
- fp = NULL;
- IMAGE_UTIL_SAFE_FREE(src_buffer);
-
- _handle->path = g_strndup(path, strlen(path));
-
- return err;
-}
-
-int image_util_decode_set_input_buffer(image_util_decode_h handle, const unsigned char *src_buffer, unsigned long long src_size)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == FALSE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if (src_buffer == NULL || src_size == 0) {
- image_util_error("Invalid input buffer");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- IMAGE_UTIL_SAFE_FREE(_handle->path);
-
- err = _image_util_decode_create_image_handle(_handle, src_buffer);
- if (err != IMAGE_UTIL_ERROR_NONE) {
- image_util_error("_image_util_decode_create_image_handle failed");
- return err;
- }
-
- IMAGE_UTIL_SAFE_FREE(_handle->src_buffer);
-
- _handle->src_buffer = (void *)calloc(1, sizeof(void *));
- if (_handle->src_buffer == NULL) {
- image_util_error("The memory of input buffer was not allocated");
- _image_util_decode_destroy_image_handle(_handle);
- return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
- }
-
- _handle->src_buffer[0] = (void *)src_buffer;
- _handle->src_size = src_size;
-
- return err;
-}
-
-int image_util_decode_set_output_buffer(image_util_decode_h handle, unsigned char **dst_buffer)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == FALSE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if (dst_buffer == NULL) {
- image_util_error("Invalid output buffer");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- _handle->dst_buffer = (void **)dst_buffer;
-
- return err;
-}
-
-int image_util_decode_set_colorspace(image_util_encode_h handle, image_util_colorspace_e colorspace)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == FALSE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
- if ((_handle->image_type == IMAGE_UTIL_JPEG) || (_handle->image_type == IMAGE_UTIL_PNG)
- || (_handle->image_type == IMAGE_UTIL_GIF) || (_handle->image_type == IMAGE_UTIL_BMP)) {
- image_util_retvm_if((is_supported_colorspace(colorspace, _handle->image_type) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
- } else {
- image_util_error("Invalid image type");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- _handle->colorspace = colorspace;
-
- return err;
-}
-
-int image_util_decode_set_jpeg_downscale(image_util_encode_h handle, image_util_scale_e down_scale)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == FALSE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if (_handle->image_type != IMAGE_UTIL_JPEG) {
- image_util_error("Wrong image format");
- return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
- }
- image_util_retvm_if((down_scale < 0 || down_scale >= _NUM_OF_SCALE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "downscale is invalid");
-
- _handle->down_scale = down_scale;
-
- return err;
-}
-
-static int _image_util_decode_internal(decode_encode_s * _handle)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- switch (_handle->image_type) {
- case IMAGE_UTIL_JPEG:
- {
- mm_util_jpeg_yuv_data *jpeg_data;
-
- jpeg_data = (mm_util_jpeg_yuv_data *) _handle->image_h;
- if (jpeg_data == NULL) {
- image_util_error("Invalid jpeg data");
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- if (_handle->path) {
- if (_handle->down_scale < sizeof(image_util_scale_e))
- err = mm_util_decode_from_jpeg_file_with_downscale(jpeg_data, _handle->path, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[_handle->down_scale]);
- else
- err = mm_util_decode_from_jpeg_file(jpeg_data, _handle->path, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG));
- } else {
- if (_handle->down_scale < sizeof(image_util_scale_e))
- err = mm_util_decode_from_jpeg_memory_with_downscale(jpeg_data, _handle->src_buffer[0], (unsigned int)_handle->src_size, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[_handle->down_scale]);
- else
- err = mm_util_decode_from_jpeg_memory(jpeg_data, _handle->src_buffer[0], (unsigned int)_handle->src_size, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG));
- }
-
- if (err == MM_UTIL_ERROR_NONE) {
- *(_handle->dst_buffer) = jpeg_data->data;
- _handle->dst_size = (unsigned long long)jpeg_data->size;
- _handle->width = jpeg_data->width;
- _handle->height = jpeg_data->height;
- }
- }
- break;
- case IMAGE_UTIL_PNG:
- {
- mm_util_png_data *png_data;
-
- png_data = (mm_util_png_data *) _handle->image_h;
- if (png_data == NULL) {
- image_util_error("Invalid png data");
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- if (_handle->path)
- err = mm_util_decode_from_png_file(png_data, _handle->path);
- else
- err = mm_util_decode_from_png_memory(png_data, &_handle->src_buffer[0], _handle->src_size);
-
- if (err == MM_UTIL_ERROR_NONE) {
- *(_handle->dst_buffer) = png_data->data;
- _handle->dst_size = png_data->size;
- _handle->width = png_data->width;
- _handle->height = png_data->height;
- }
- }
- break;
- case IMAGE_UTIL_GIF:
- {
- mm_util_gif_data *gif_data;
-
- gif_data = (mm_util_gif_data *) _handle->image_h;
- if (gif_data == NULL) {
- image_util_error("Invalid gif data");
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- if (_handle->path)
- err = mm_util_decode_from_gif_file(gif_data, _handle->path);
- else
- err = mm_util_decode_from_gif_memory(gif_data, &_handle->src_buffer[0]);
-
- if (err == MM_UTIL_ERROR_NONE) {
- *(_handle->dst_buffer) = gif_data->frames[0]->data;
- _handle->dst_size = gif_data->size;
- _handle->width = gif_data->width;
- _handle->height = gif_data->height;
- }
- }
- break;
- case IMAGE_UTIL_BMP:
- {
- mm_util_bmp_data *bmp_data;
-
- bmp_data = (mm_util_bmp_data *) _handle->image_h;
- if (bmp_data == NULL) {
- image_util_error("Invalid bmp data");
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- if (_handle->path)
- err = mm_util_decode_from_bmp_file(bmp_data, _handle->path);
- else
- err = mm_util_decode_from_bmp_memory(bmp_data, &_handle->src_buffer[0], _handle->src_size);
-
- if (err == MM_UTIL_ERROR_NONE) {
- *(_handle->dst_buffer) = bmp_data->data;
- _handle->dst_size = bmp_data->size;
- _handle->width = bmp_data->width;
- _handle->height = bmp_data->height;
- }
- }
- break;
- default:
- err = MM_UTIL_ERROR_INVALID_PARAMETER;
- break;
- }
-
- return err;
-}
-
-int image_util_decode_run(image_util_decode_h handle, unsigned long *width, unsigned long *height, unsigned long long *size)
-{
- int err = MM_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == FALSE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if ((_handle->path == NULL && _handle->src_buffer == NULL) || _handle->dst_buffer == NULL) {
- image_util_error("Invalid input/output");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- err = _image_util_decode_internal(_handle);
-
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("Error - decode run");
- return _convert_image_util_error_code(__func__, err);
- }
-
- if (width)
- *width = _handle->width;
- if (height)
- *height = _handle->height;
- if (size)
- *size = _handle->dst_size;
-
- return _convert_image_util_error_code(__func__, err);
-}
-
-gpointer _image_util_decode_thread(gpointer data)
-{
- decode_encode_s *_handle = (decode_encode_s *) data;
- int err = MM_UTIL_ERROR_NONE;
-
- if (!_handle) {
- image_util_error("[ERROR] - handle");
- return NULL;
- }
-
- err = _image_util_decode_internal(_handle);
- if (err == MM_UTIL_ERROR_NONE)
- image_util_debug("Success - decode_internal");
- else
- image_util_error("Error - decode_internal");
-
- if (_handle->_decode_cb) {
- image_util_debug("completed_cb");
- _handle->_decode_cb->image_decode_completed_cb(_convert_image_util_error_code(__func__, err), _handle->_decode_cb->user_data, _handle->width, _handle->height, _handle->dst_size);
- }
-
- image_util_debug("exit thread");
-
- return NULL;
-}
-
-static int _image_util_decode_create_thread(decode_encode_s * handle)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
- image_util_retvm_if((handle->thread != NULL), MM_UTIL_ERROR_INVALID_OPERATION, "A thread is alread running");
-
- /*create threads */
- handle->thread = g_thread_new("decode_thread", (GThreadFunc) _image_util_decode_thread, (gpointer) handle);
- if (!handle->thread) {
- image_util_error("ERROR - create thread");
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- return err;
-}
-
-int image_util_decode_run_async(image_util_decode_h handle, image_util_decode_completed_cb completed_cb, void *user_data)
-{
- int err = MM_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == FALSE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if ((_handle->path == NULL && _handle->src_buffer == NULL) || _handle->dst_buffer == NULL) {
- image_util_error("Invalid input/output");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- image_util_retvm_if((completed_cb == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid callback");
- image_util_retvm_if((_handle->thread != NULL), MM_UTIL_ERROR_INVALID_OPERATION, "A thread is alread running");
-
- if (_handle->_decode_cb != NULL) {
- IMAGE_UTIL_SAFE_FREE(_handle->_decode_cb);
- _handle->_decode_cb = NULL;
- }
-
- _handle->_decode_cb = (decode_cb_s *) calloc(1, sizeof(decode_cb_s));
- image_util_retvm_if((_handle->_decode_cb == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "Out of memory");
-
- _handle->_decode_cb->user_data = user_data;
- _handle->_decode_cb->image_decode_completed_cb = completed_cb;
-
- err = _image_util_decode_create_thread(_handle);
- if (err != MM_UTIL_ERROR_NONE) {
- IMAGE_UTIL_SAFE_FREE(_handle->_decode_cb);
- _handle->_decode_cb = NULL;
- }
-
- return _convert_image_util_error_code(__func__, err);
-}
-
-int image_util_decode_destroy(image_util_decode_h handle)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- image_util_debug("image_util_decode_destroy");
-
- if (_handle == NULL || _handle->is_decode == FALSE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- _image_util_decode_destroy_image_handle(_handle);
-
- /* g_thread_exit(handle->thread); */
- if (_handle->thread) {
- g_thread_join(_handle->thread);
- IMAGE_UTIL_SAFE_FREE(_handle->_decode_cb);
- }
- IMAGE_UTIL_SAFE_FREE(_handle->src_buffer);
- IMAGE_UTIL_SAFE_FREE(_handle);
-
- return err;
-}
-
-static int _image_util_encode_get_gif_frame(mm_gif_file_h gif_data, unsigned int index, mm_gif_image_h *frame)
-{
- int err = MM_UTIL_ERROR_NONE;
- image_util_retvm_if((gif_data == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
- image_util_retvm_if((frame == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
- err = mm_util_gif_enocde_get_image_handle(gif_data, (int)index, frame);
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("mm_util_gif_enocde_get_image_handle is failed %d", err);
- return _convert_image_util_error_code(__func__, err);
- }
- if (*frame == NULL) {
- err = mm_util_gif_image_create(gif_data, frame);
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("mm_util_gif_image_create is failed %d", err);
- return _convert_image_util_error_code(__func__, err);
- }
- err = mm_util_gif_enocde_set_image_handle(gif_data, *frame);
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("mm_util_gif_enocde_set_image_handle is failed %d", err);
- mm_util_gif_image_destory(*frame);
- return _convert_image_util_error_code(__func__, err);
- }
- }
- return err;
-}
-
-static void _image_util_encode_destroy_image_handle(decode_encode_s * handle)
-{
- image_util_retm_if((handle == NULL), "Invalid Handle");
- void *image_handle = (void *)(handle->image_h);
- image_util_retm_if((image_handle == NULL), "Invalid image handle");
-
- if (handle->image_type == IMAGE_UTIL_GIF)
- mm_util_gif_encode_destroy(image_handle);
-
- IMAGE_UTIL_SAFE_FREE(image_handle);
-}
-
-static int _image_util_encode_create_jpeg_handle(decode_encode_s * handle)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
- mm_util_jpeg_yuv_data *_handle = (mm_util_jpeg_yuv_data *) calloc(1, sizeof(mm_util_jpeg_yuv_data));
- image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY);
-
- handle->image_h = (mm_util_imgp_h) _handle;
- handle->colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888;
- handle->quality = 75;
-
- return err;
-}
-
-static int _image_util_encode_create_png_handle(decode_encode_s * handle)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
- mm_util_png_data *_handle = (mm_util_png_data *) calloc(1, sizeof(mm_util_png_data));
- image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY);
-
- mm_util_init_encode_png(_handle);
-
- handle->image_h = (mm_util_imgp_h) _handle;
-
- return err;
-}
-
-static int _image_util_encode_create_gif_handle(decode_encode_s * handle)
-{
- int err = MM_UTIL_ERROR_NONE;
- mm_gif_file_h _handle = NULL;
-
- image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
- err = mm_util_gif_encode_create(&_handle);
- image_util_retvm_if((err != MM_UTIL_ERROR_NONE), _convert_image_util_error_code(__func__, err), "Error - mm_util_gif_encode_create is failed (%d)", err);
-
- handle->image_h = (mm_util_imgp_h) _handle;
-
- return err;
-}
-
-static int _image_util_encode_create_bmp_handle(decode_encode_s * handle)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
- mm_util_bmp_data *_handle = (mm_util_bmp_data *) calloc(1, sizeof(mm_util_bmp_data));
- image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY);
-
- handle->image_h = (mm_util_imgp_h) _handle;
-
- return err;
-}
-
-int image_util_encode_create(image_util_type_e image_type, image_util_encode_h * handle)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- image_util_debug("image_util_encode_create");
-
- image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
-
- decode_encode_s *_handle = (decode_encode_s *) calloc(1, sizeof(decode_encode_s));
- image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", IMAGE_UTIL_ERROR_OUT_OF_MEMORY);
-
- _handle->image_type = image_type;
- _handle->src_buffer = NULL;
- _handle->dst_buffer = NULL;
- _handle->path = NULL;
- _handle->image_h = 0;
- _handle->is_decode = FALSE;
- _handle->is_encoded = FALSE;
- _handle->current_buffer_count = 0;
- _handle->current_resolution_count = 0;
- _handle->current_delay_count = 0;
-
- switch (image_type) {
- case IMAGE_UTIL_JPEG:
- err = _image_util_encode_create_jpeg_handle(_handle);
- break;
- case IMAGE_UTIL_PNG:
- err = _image_util_encode_create_png_handle(_handle);
- break;
- case IMAGE_UTIL_GIF:
- err = _image_util_encode_create_gif_handle(_handle);
- break;
- case IMAGE_UTIL_BMP:
- err = _image_util_encode_create_bmp_handle(_handle);
- break;
- default:
- err = MM_UTIL_ERROR_INVALID_PARAMETER;
- break;
- }
-
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("Error - create image handle");
- IMAGE_UTIL_SAFE_FREE(_handle);
- return _convert_image_util_error_code(__func__, err);
- }
-
- *handle = (image_util_encode_h) _handle;
-
- return _convert_image_util_error_code(__func__, err);
-}
-
-int image_util_encode_set_resolution(image_util_encode_h handle, unsigned long width, unsigned long height)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == TRUE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- image_util_retvm_if((_image_util_check_resolution(width, height) == false), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution");
-
- switch (_handle->image_type) {
- case IMAGE_UTIL_JPEG:
- {
- mm_util_jpeg_yuv_data *jpeg_data;
-
- jpeg_data = (mm_util_jpeg_yuv_data *) _handle->image_h;
- if (jpeg_data == NULL) {
- image_util_error("Invalid jpeg data");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- jpeg_data->width = width;
- jpeg_data->height = height;
- }
- break;
- case IMAGE_UTIL_PNG:
- {
- mm_util_png_data *png_data;
-
- png_data = (mm_util_png_data *) _handle->image_h;
- if (png_data == NULL) {
- image_util_error("Invalid png data");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- mm_util_png_encode_set_width(png_data, width);
- mm_util_png_encode_set_height(png_data, height);
- }
- break;
- case IMAGE_UTIL_GIF:
- {
- mm_gif_file_h gif_data = (mm_gif_file_h)_handle->image_h;
- if (gif_data == NULL) {
- image_util_error("Invalid gif data");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- image_util_retvm_if((width > INT_MAX) || (height > INT_MAX), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution");
-
- if (_handle->current_resolution_count == 0) {
- _handle->width = width;
- _handle->height = height;
- mm_util_gif_encode_set_resolution(gif_data, width, height);
- }
- mm_gif_image_h frame = NULL;
- err = _image_util_encode_get_gif_frame(gif_data, _handle->current_resolution_count, &frame);
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("_image_util_encode_get_gif_frame is failed %d", err);
- return _convert_image_util_error_code(__func__, err);
- }
- err = mm_util_gif_image_set_position(frame, 0, 0, (int)width, (int)height);
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("mm_util_gif_image_set_position is failed %d", err);
- return _convert_image_util_error_code(__func__, err);
- }
- _handle->current_resolution_count++;
-
- return err;
- }
- break;
- case IMAGE_UTIL_BMP:
- {
- mm_util_bmp_data *bmp_data;
-
- bmp_data = (mm_util_bmp_data *) _handle->image_h;
- if (bmp_data == NULL) {
- image_util_error("Invalid bmp data");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- mm_util_bmp_encode_set_width(bmp_data, width);
- mm_util_bmp_encode_set_height(bmp_data, height);
- }
- break;
- default:
- err = IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- break;
- }
-
- _handle->width = width;
- _handle->height = height;
-
- return err;
-}
-
-int image_util_encode_set_colorspace(image_util_encode_h handle, image_util_colorspace_e colorspace)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == TRUE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
-
- if ((_handle->image_type == IMAGE_UTIL_JPEG) || (_handle->image_type == IMAGE_UTIL_PNG)
- || (_handle->image_type == IMAGE_UTIL_GIF) || (_handle->image_type == IMAGE_UTIL_BMP)) {
- image_util_retvm_if((is_supported_colorspace(colorspace, _handle->image_type) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
- } else {
- image_util_error("Invalid image type");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- _handle->colorspace = colorspace;
-
- return err;
-}
-
-int image_util_encode_set_quality(image_util_encode_h handle, int quality)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == TRUE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if (_handle->image_type != IMAGE_UTIL_JPEG) {
- image_util_error("Wrong image format");
- return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
- }
- image_util_retvm_if((quality <= 0 || quality > 100), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid quality");
-
- _handle->quality = quality;
-
- return err;
-}
-
-int image_util_encode_set_png_compression(image_util_encode_h handle, image_util_png_compression_e compression)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
- mm_util_png_data *png_data;
-
- if (_handle == NULL || _handle->is_decode == TRUE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if (_handle->image_type != IMAGE_UTIL_PNG) {
- image_util_error("Wrong image format");
- return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
- }
- image_util_retvm_if((compression < IMAGE_UTIL_PNG_COMPRESSION_0 || compression > IMAGE_UTIL_PNG_COMPRESSION_9), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid compression value");
-
- png_data = (mm_util_png_data *) _handle->image_h;
- if (png_data == NULL) {
- image_util_error("Invalid png data");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- mm_util_png_encode_set_compression_level(png_data, compression);
-
- return err;
-}
-
-int image_util_encode_set_gif_frame_delay_time(image_util_encode_h handle, unsigned long long delay_time)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
- mm_gif_file_h gif_data = NULL;
-
- if (_handle == NULL || _handle->is_decode == TRUE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if (_handle->image_type != IMAGE_UTIL_GIF) {
- image_util_error("Wrong image format");
- return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
- }
-
- gif_data = (mm_gif_file_h) _handle->image_h;
- if (gif_data == NULL) {
- image_util_error("Invalid gif data");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- image_util_retvm_if((delay_time > INT_MAX), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid delay time");
-
- mm_gif_image_h frame = NULL;
- err = _image_util_encode_get_gif_frame(gif_data, _handle->current_delay_count, &frame);
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("_image_util_encode_get_gif_frame is failed %d", err);
- return _convert_image_util_error_code(__func__, err);
- }
- err = mm_util_gif_image_set_delay_time(frame, (int)delay_time);
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("mm_util_gif_image_set_delay_time is failed %d", err);
- return _convert_image_util_error_code(__func__, err);
- }
- _handle->current_delay_count++;
-
- return err;
-}
-
-int image_util_encode_set_input_buffer(image_util_encode_h handle, const unsigned char *src_buffer)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == TRUE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if (src_buffer == NULL) {
- image_util_error("Invalid input buffer");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- /* initialize buffer and value for source buffer */
- if (_handle->image_type == IMAGE_UTIL_GIF) {
- mm_gif_file_h gif_data = (mm_gif_file_h) _handle->image_h;
- mm_gif_image_h frame = NULL;
- if (gif_data == NULL) {
- image_util_error("Invalid gif data");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- err = _image_util_encode_get_gif_frame(gif_data, _handle->current_buffer_count, &frame);
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("_image_util_encode_get_gif_frame is failed %d", err);
- return _convert_image_util_error_code(__func__, err);
- }
- err = mm_util_gif_image_set_image(frame, src_buffer);
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("mm_util_gif_image_set_delay_time is failed %d", err);
- return _convert_image_util_error_code(__func__, err);
- }
- _handle->current_buffer_count++;
- } else {
- if (_handle->src_buffer == NULL)
- _handle->src_buffer = (void *)calloc(1, sizeof(void *));
- image_util_retvm_if(_handle->src_buffer == NULL, IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "calloc fail");
-
- _handle->src_buffer[_handle->current_buffer_count] = (void *)src_buffer;
- }
-
- return err;
-}
-
-int image_util_encode_set_output_path(image_util_encode_h handle, const char *path)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == TRUE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- image_util_retvm_if((path == NULL || strlen(path) == 0), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path");
-
- if (_handle->dst_buffer)
- _handle->dst_buffer = NULL;
-
- IMAGE_UTIL_SAFE_FREE(_handle->path);
-
- _handle->path = g_strndup(path, strlen(path));
-
- return err;
-}
-
-int image_util_encode_set_output_buffer(image_util_encode_h handle, unsigned char **dst_buffer)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == TRUE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if (dst_buffer == NULL) {
- image_util_error("Invalid output buffer");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- IMAGE_UTIL_SAFE_FREE(_handle->path);
-
- _handle->dst_buffer = (void **)dst_buffer;
-
- return err;
-}
-
-static int _image_util_encode_internal(decode_encode_s * _handle)
-{
- int err = MM_UTIL_ERROR_NONE;
-
- switch (_handle->image_type) {
- case IMAGE_UTIL_JPEG:
- {
- if (_handle->path)
- err = mm_util_jpeg_encode_to_file(_handle->path, _handle->src_buffer[0], _handle->width, _handle->height, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _handle->quality);
- else
- err = mm_util_jpeg_encode_to_memory(_handle->dst_buffer, (unsigned int *)&(_handle->dst_size), _handle->src_buffer[0], _handle->width, _handle->height, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _handle->quality);
- }
- break;
- case IMAGE_UTIL_PNG:
- {
- mm_util_png_data *png_data;
-
- png_data = (mm_util_png_data *) _handle->image_h;
- if (png_data == NULL) {
- image_util_error("Invalid png data");
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- if (_handle->path)
- err = mm_util_encode_to_png_file(&(_handle->src_buffer[0]), png_data, _handle->path);
- else
- err = mm_util_encode_to_png_memory(&(_handle->src_buffer[0]), png_data);
-
- if (err == MM_UTIL_ERROR_NONE) {
- if (_handle->dst_buffer)
- *(_handle->dst_buffer) = png_data->data;
- _handle->dst_size = png_data->size;
- _handle->width = png_data->width;
- _handle->height = png_data->height;
- }
- }
- break;
- case IMAGE_UTIL_GIF:
- {
- mm_gif_file_h gif_data = (mm_gif_file_h)_handle->image_h;
- unsigned long encoded_buffer_size = 0;
- if (gif_data == NULL) {
- image_util_error("Invalid gif data");
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
- image_util_debug("[Count] buffer:%d, resolution:%d, delay:%d", _handle->current_buffer_count, _handle->current_resolution_count, _handle->current_delay_count);
- if ((_handle->current_buffer_count > 1) && ((_handle->current_buffer_count != _handle->current_resolution_count) || (_handle->current_buffer_count != _handle->current_delay_count))) {
- image_util_error("Total frame count does not match with the data set, for animated gif encoding");
- return MM_UTIL_ERROR_INVALID_OPERATION;
- } else if ((_handle->current_buffer_count > 0) && ((_handle->current_buffer_count != _handle->current_resolution_count))) {
- image_util_error("Total frame count does not match with the data set, for gif encoding");
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
- if (_handle->path)
- err = mm_util_gif_encode_set_file(gif_data, _handle->path);
- else
- err = mm_util_gif_encode_set_mem(gif_data, _handle->dst_buffer, &encoded_buffer_size);
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("mm_util_gif_encode_set_file | mm_util_gif_encode_set_mem is failed(%d)", err);
- return _convert_image_util_error_code(__func__, err);
- }
- err = mm_util_gif_encode(gif_data);
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("mm_util_gif_encode is failed(%d)", err);
- return _convert_image_util_error_code(__func__, err);
- }
- if (encoded_buffer_size != 0)
- _handle->dst_size = (unsigned long long)encoded_buffer_size;
- }
- break;
- case IMAGE_UTIL_BMP:
- {
- mm_util_bmp_data *bmp_data;
-
- bmp_data = (mm_util_bmp_data *) _handle->image_h;
- if (bmp_data == NULL) {
- image_util_error("Invalid bmp data");
- return MM_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- bmp_data->data = _handle->src_buffer[0];
- if (_handle->path) {
- err = mm_util_encode_bmp_to_file(bmp_data, _handle->path);
- } else {
- size_t size = 0;
- err = mm_util_encode_bmp_to_memory(bmp_data, &(bmp_data->data), &size);
- if (err == MM_UTIL_ERROR_NONE)
- bmp_data->size = (unsigned long long)size;
- else
- bmp_data->size = 0;
- }
- if (err == MM_UTIL_ERROR_NONE) {
- if (_handle->dst_buffer)
- *(_handle->dst_buffer) = bmp_data->data;
- _handle->dst_size = bmp_data->size;
- _handle->width = bmp_data->width;
- _handle->height = bmp_data->height;
- }
- }
- break;
- default:
- err = MM_UTIL_ERROR_INVALID_PARAMETER;
- break;
- }
-
- return err;
-}
-
-int image_util_encode_run(image_util_encode_h handle, unsigned long long *size)
-{
- int err = MM_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == TRUE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if (_handle->path == NULL && _handle->dst_buffer == NULL) {
- image_util_error("Invalid output");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if (_handle->image_type != IMAGE_UTIL_GIF && _handle->src_buffer == NULL) {
- image_util_error("Invalid input");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- image_util_retvm_if((_image_util_check_resolution(_handle->width, _handle->height) == false), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution");
-
- err = _image_util_encode_internal(_handle);
- _handle->is_encoded = TRUE;
-
- if (err != MM_UTIL_ERROR_NONE) {
- image_util_error("Error - encode run");
- return _convert_image_util_error_code(__func__, err);
- }
-
- if (size)
- *size = _handle->dst_size;
-
- return _convert_image_util_error_code(__func__, err);
-}
-
-gpointer _image_util_encode_thread(gpointer data)
-{
- decode_encode_s *_handle = (decode_encode_s *) data;
- int err = MM_UTIL_ERROR_NONE;
-
- if (!_handle) {
- image_util_error("[ERROR] - handle");
- return NULL;
- }
-
- err = _image_util_encode_internal(_handle);
- if (err == MM_UTIL_ERROR_NONE)
- image_util_debug("Success - encode_internal");
- else
- image_util_error("Error - encode_internal");
-
- if (_handle->_encode_cb) {
- image_util_debug("completed_cb");
- _handle->_encode_cb->image_encode_completed_cb(_convert_image_util_error_code(__func__, err), _handle->_encode_cb->user_data, _handle->dst_size);
- }
-
- IMAGE_UTIL_SAFE_FREE(_handle->_encode_cb);
- _handle->thread = NULL;
- _handle->is_encoded = TRUE;
- image_util_debug("exit thread");
-
- return NULL;
-}
-
-static int _image_util_encode_create_thread(decode_encode_s * handle)
-{
- int ret = MM_UTIL_ERROR_NONE;
-
- image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
- image_util_retvm_if((handle->thread != NULL), MM_UTIL_ERROR_INVALID_OPERATION, "The thread is alread running");
-
- /*create threads */
- handle->thread = g_thread_new("encode_thread", (GThreadFunc) _image_util_encode_thread, (gpointer) handle);
- if (!handle->thread) {
- image_util_error("ERROR - create thread");
-
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- return ret;
-}
-
-int image_util_encode_run_async(image_util_encode_h handle, image_util_encode_completed_cb completed_cb, void *user_data)
-{
- int err = MM_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- if (_handle == NULL || _handle->is_decode == TRUE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if (_handle->path == NULL && _handle->dst_buffer == NULL) {
- image_util_error("Invalid output");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- if (_handle->image_type != IMAGE_UTIL_GIF && _handle->src_buffer == NULL) {
- image_util_error("Invalid input");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
- image_util_retvm_if((_image_util_check_resolution(_handle->width, _handle->height) == false), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution");
- image_util_retvm_if((completed_cb == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid callback");
- image_util_retvm_if((_handle->thread != NULL), MM_UTIL_ERROR_INVALID_OPERATION, "The thread is alread running");
-
- if (_handle->_encode_cb != NULL) {
- IMAGE_UTIL_SAFE_FREE(_handle->_encode_cb);
- _handle->_encode_cb = NULL;
- }
- _handle->_encode_cb = (encode_cb_s *) calloc(1, sizeof(encode_cb_s));
- image_util_retvm_if((_handle->_encode_cb == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "Out of memory");
-
- _handle->_encode_cb->user_data = user_data;
- _handle->_encode_cb->image_encode_completed_cb = completed_cb;
-
- err = _image_util_encode_create_thread(_handle);
- if (err != MM_UTIL_ERROR_NONE) {
- IMAGE_UTIL_SAFE_FREE(_handle->_encode_cb);
- _handle->_encode_cb = NULL;
- }
-
- return _convert_image_util_error_code(__func__, err);
-}
-
-int image_util_encode_destroy(image_util_encode_h handle)
-{
- int err = IMAGE_UTIL_ERROR_NONE;
- decode_encode_s *_handle = (decode_encode_s *) handle;
-
- image_util_debug("image_util_encode_destroy");
-
- if (_handle == NULL || _handle->is_decode == TRUE) {
- image_util_error("Invalid Handle");
- return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
- }
-
- _image_util_encode_destroy_image_handle(_handle);
-
- /* g_thread_exit(handle->thread); */
- if (_handle->thread) {
- g_thread_join(_handle->thread);
- IMAGE_UTIL_SAFE_FREE(_handle->_encode_cb);
- }
-
- IMAGE_UTIL_SAFE_FREE(_handle->path);
- IMAGE_UTIL_SAFE_FREE(_handle->src_buffer);
- IMAGE_UTIL_SAFE_FREE(_handle);
-
- return err;
-}
--- /dev/null
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <mm_util_imgp.h>
+#include <mm_util_jpeg.h>
+#include <mm_util_png.h>
+#include <mm_util_gif.h>
+#include <mm_util_bmp.h>
+
+#include <image_util.h>
+#include <image_util_private.h>
+
+static int _convert_decode_scale_tbl[] = {
+ MM_UTIL_JPEG_DECODE_DOWNSCALE_1_1,
+ MM_UTIL_JPEG_DECODE_DOWNSCALE_1_2,
+ MM_UTIL_JPEG_DECODE_DOWNSCALE_1_4,
+ MM_UTIL_JPEG_DECODE_DOWNSCALE_1_8,
+};
+
+#define _NUM_OF_SCALE (sizeof(_convert_decode_scale_tbl)/sizeof(int))
+
+static void _image_util_decode_destroy_image_handle(decode_encode_s * handle)
+{
+ image_util_retm_if((handle == NULL), "Invalid Handle");
+ void *image_handle = (void *)(handle->image_h);
+ image_util_retm_if((image_handle == NULL), "Invalid image handle");
+
+ IMAGE_UTIL_SAFE_FREE(image_handle);
+}
+
+static int _image_util_decode_create_jpeg_handle(decode_encode_s * handle)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+
+ /* It is needed to reuse decode handle for C#, so it shoud be reallocated */
+ _image_util_decode_destroy_image_handle(handle);
+
+ mm_util_jpeg_yuv_data *_handle = (mm_util_jpeg_yuv_data *) calloc(1, sizeof(mm_util_jpeg_yuv_data));
+ image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY);
+
+ handle->image_h = (mm_util_imgp_h) _handle;
+ handle->colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888;
+ handle->down_scale = sizeof(image_util_scale_e);
+
+ return err;
+}
+
+static int _image_util_decode_create_png_handle(decode_encode_s * handle)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+
+ /* It is needed to reuse decode handle for C#, so it shoud be reallocated */
+ _image_util_decode_destroy_image_handle(handle);
+
+ mm_util_png_data *_handle = (mm_util_png_data *) calloc(1, sizeof(mm_util_png_data));
+ image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY);
+
+ mm_util_init_decode_png(_handle);
+
+ handle->image_h = (mm_util_imgp_h) _handle;
+
+ return err;
+}
+
+static int _image_util_decode_create_gif_handle(decode_encode_s * handle)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+
+ /* It is needed to reuse decode handle for C#, so it shoud be reallocated */
+ _image_util_decode_destroy_image_handle(handle);
+
+ mm_util_gif_data *_handle = (mm_util_gif_data *) calloc(1, sizeof(mm_util_gif_data));
+ image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY);
+
+ handle->image_h = (mm_util_imgp_h) _handle;
+
+ return err;
+}
+
+static int _image_util_decode_create_bmp_handle(decode_encode_s * handle)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+
+ /* It is needed to reuse decode handle for C#, so it shoud be reallocated */
+ _image_util_decode_destroy_image_handle(handle);
+
+ mm_util_bmp_data *_handle = (mm_util_bmp_data *) calloc(1, sizeof(mm_util_bmp_data));
+ image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY);
+
+ handle->image_h = (mm_util_imgp_h) _handle;
+
+ return err;
+}
+
+int image_util_decode_create(image_util_decode_h * handle)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ image_util_debug("image_util_decode_create");
+
+ image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+
+ decode_encode_s *_handle = (decode_encode_s *) calloc(1, sizeof(decode_encode_s));
+ image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", IMAGE_UTIL_ERROR_OUT_OF_MEMORY);
+
+ _handle->src_buffer = NULL;
+ _handle->dst_buffer = NULL;
+ _handle->path = NULL;
+ _handle->image_h = 0;
+ _handle->is_decode = TRUE;
+ _handle->image_type = -1;
+
+ *handle = (image_util_decode_h) _handle;
+
+ return _convert_image_util_error_code(__func__, err);
+}
+
+static char _JPEG_HEADER[] = { 0xFF, 0xD8 };
+static char _PNG_HEADER[] = { 0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a };
+static char _GIF_HEADER[] = { 'G', 'I', 'F' };
+static char _BMP_HEADER[] = { 'B', 'M' };
+
+static int _image_util_decode_create_image_handle(image_util_decode_h handle, const unsigned char *src_buffer)
+{
+ image_util_type_e image_type = -1;
+ static struct {
+ char *header;
+ int size;
+ image_util_type_e image_type;
+ } image_header[] = {
+ {
+ _JPEG_HEADER, sizeof(_JPEG_HEADER), IMAGE_UTIL_JPEG}
+ , {
+ _PNG_HEADER, sizeof(_PNG_HEADER), IMAGE_UTIL_PNG}
+ , {
+ _GIF_HEADER, sizeof(_GIF_HEADER), IMAGE_UTIL_GIF}
+ , {
+ _BMP_HEADER, sizeof(_BMP_HEADER), IMAGE_UTIL_BMP}
+ ,};
+ unsigned int i = 0;
+ int err = MM_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == FALSE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if (src_buffer == NULL) {
+ image_util_error("Invalid input buffer");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ for (i = 0; i < sizeof(image_header) / sizeof(image_header[0]); i++) {
+ if (strncmp((const char *)src_buffer, image_header[i].header, image_header[i].size) == 0) {
+ image_type = image_header[i].image_type;
+ break;
+ }
+ }
+
+ _handle->image_type = image_type;
+
+ switch (image_type) {
+ case IMAGE_UTIL_JPEG:
+ err = _image_util_decode_create_jpeg_handle(_handle);
+ break;
+ case IMAGE_UTIL_PNG:
+ err = _image_util_decode_create_png_handle(_handle);
+ break;
+ case IMAGE_UTIL_GIF:
+ err = _image_util_decode_create_gif_handle(_handle);
+ break;
+ case IMAGE_UTIL_BMP:
+ err = _image_util_decode_create_bmp_handle(_handle);
+ break;
+ default:
+ err = MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
+ break;
+ }
+
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("Error - create image handle");
+ return _convert_image_util_error_code(__func__, err);
+ }
+
+ return _convert_image_util_error_code(__func__, err);
+}
+
+int image_util_decode_set_input_path(image_util_decode_h handle, const char *path)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+ FILE *fp = NULL;
+ unsigned char *src_buffer = NULL;
+
+ if (_handle == NULL || _handle->is_decode == FALSE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ image_util_retvm_if((path == NULL || strlen(path) == 0), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path");
+
+ if (_handle->src_buffer)
+ _handle->src_buffer = NULL;
+
+ fp = fopen(path, "r");
+ if (fp == NULL) {
+ image_util_error("File open failed %s", path);
+ return IMAGE_UTIL_ERROR_NO_SUCH_FILE;
+ }
+ src_buffer = (void *)malloc(sizeof(_PNG_HEADER));
+ if (src_buffer == NULL) {
+ image_util_error("malloc fail");
+ fclose(fp);
+ fp = NULL;
+ return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
+ }
+
+ if (!fread(src_buffer, 1, sizeof(_PNG_HEADER), fp)) {
+ image_util_error("File read failed");
+ fclose(fp);
+ fp = NULL;
+ IMAGE_UTIL_SAFE_FREE(src_buffer);
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ err = _image_util_decode_create_image_handle(_handle, src_buffer);
+ if (err != IMAGE_UTIL_ERROR_NONE) {
+ image_util_error("_image_util_decode_create_image_handle failed");
+ fclose(fp);
+ fp = NULL;
+ IMAGE_UTIL_SAFE_FREE(src_buffer);
+ return err;
+ }
+
+ fclose(fp);
+ fp = NULL;
+ IMAGE_UTIL_SAFE_FREE(src_buffer);
+
+ _handle->path = g_strndup(path, strlen(path));
+
+ return err;
+}
+
+int image_util_decode_set_input_buffer(image_util_decode_h handle, const unsigned char *src_buffer, unsigned long long src_size)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == FALSE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if (src_buffer == NULL || src_size == 0) {
+ image_util_error("Invalid input buffer");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ IMAGE_UTIL_SAFE_FREE(_handle->path);
+
+ err = _image_util_decode_create_image_handle(_handle, src_buffer);
+ if (err != IMAGE_UTIL_ERROR_NONE) {
+ image_util_error("_image_util_decode_create_image_handle failed");
+ return err;
+ }
+
+ IMAGE_UTIL_SAFE_FREE(_handle->src_buffer);
+
+ _handle->src_buffer = (void *)calloc(1, sizeof(void *));
+ if (_handle->src_buffer == NULL) {
+ image_util_error("The memory of input buffer was not allocated");
+ _image_util_decode_destroy_image_handle(_handle);
+ return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
+ }
+
+ _handle->src_buffer[0] = (void *)src_buffer;
+ _handle->src_size = src_size;
+
+ return err;
+}
+
+int image_util_decode_set_output_buffer(image_util_decode_h handle, unsigned char **dst_buffer)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == FALSE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if (dst_buffer == NULL) {
+ image_util_error("Invalid output buffer");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ _handle->dst_buffer = (void **)dst_buffer;
+
+ return err;
+}
+
+int image_util_decode_set_colorspace(image_util_encode_h handle, image_util_colorspace_e colorspace)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == FALSE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+ if ((_handle->image_type == IMAGE_UTIL_JPEG) || (_handle->image_type == IMAGE_UTIL_PNG)
+ || (_handle->image_type == IMAGE_UTIL_GIF) || (_handle->image_type == IMAGE_UTIL_BMP)) {
+ image_util_retvm_if((is_supported_colorspace(colorspace, _handle->image_type) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+ } else {
+ image_util_error("Invalid image type");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ _handle->colorspace = colorspace;
+
+ return err;
+}
+
+int image_util_decode_set_jpeg_downscale(image_util_encode_h handle, image_util_scale_e down_scale)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == FALSE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if (_handle->image_type != IMAGE_UTIL_JPEG) {
+ image_util_error("Wrong image format");
+ return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
+ }
+ image_util_retvm_if((down_scale < 0 || down_scale >= _NUM_OF_SCALE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "downscale is invalid");
+
+ _handle->down_scale = down_scale;
+
+ return err;
+}
+
+static int _image_util_decode_internal(decode_encode_s * _handle)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ switch (_handle->image_type) {
+ case IMAGE_UTIL_JPEG:
+ {
+ mm_util_jpeg_yuv_data *jpeg_data;
+
+ jpeg_data = (mm_util_jpeg_yuv_data *) _handle->image_h;
+ if (jpeg_data == NULL) {
+ image_util_error("Invalid jpeg data");
+ return MM_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (_handle->path) {
+ if (_handle->down_scale < sizeof(image_util_scale_e))
+ err = mm_util_decode_from_jpeg_file_with_downscale(jpeg_data, _handle->path, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[_handle->down_scale]);
+ else
+ err = mm_util_decode_from_jpeg_file(jpeg_data, _handle->path, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG));
+ } else {
+ if (_handle->down_scale < sizeof(image_util_scale_e))
+ err = mm_util_decode_from_jpeg_memory_with_downscale(jpeg_data, _handle->src_buffer[0], (unsigned int)_handle->src_size, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[_handle->down_scale]);
+ else
+ err = mm_util_decode_from_jpeg_memory(jpeg_data, _handle->src_buffer[0], (unsigned int)_handle->src_size, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG));
+ }
+
+ if (err == MM_UTIL_ERROR_NONE) {
+ *(_handle->dst_buffer) = jpeg_data->data;
+ _handle->dst_size = (unsigned long long)jpeg_data->size;
+ _handle->width = jpeg_data->width;
+ _handle->height = jpeg_data->height;
+ }
+ }
+ break;
+ case IMAGE_UTIL_PNG:
+ {
+ mm_util_png_data *png_data;
+
+ png_data = (mm_util_png_data *) _handle->image_h;
+ if (png_data == NULL) {
+ image_util_error("Invalid png data");
+ return MM_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (_handle->path)
+ err = mm_util_decode_from_png_file(png_data, _handle->path);
+ else
+ err = mm_util_decode_from_png_memory(png_data, &_handle->src_buffer[0], _handle->src_size);
+
+ if (err == MM_UTIL_ERROR_NONE) {
+ *(_handle->dst_buffer) = png_data->data;
+ _handle->dst_size = png_data->size;
+ _handle->width = png_data->width;
+ _handle->height = png_data->height;
+ }
+ }
+ break;
+ case IMAGE_UTIL_GIF:
+ {
+ mm_util_gif_data *gif_data;
+
+ gif_data = (mm_util_gif_data *) _handle->image_h;
+ if (gif_data == NULL) {
+ image_util_error("Invalid gif data");
+ return MM_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (_handle->path)
+ err = mm_util_decode_from_gif_file(gif_data, _handle->path);
+ else
+ err = mm_util_decode_from_gif_memory(gif_data, &_handle->src_buffer[0]);
+
+ if (err == MM_UTIL_ERROR_NONE) {
+ *(_handle->dst_buffer) = gif_data->frames[0]->data;
+ _handle->dst_size = gif_data->size;
+ _handle->width = gif_data->width;
+ _handle->height = gif_data->height;
+ }
+ }
+ break;
+ case IMAGE_UTIL_BMP:
+ {
+ mm_util_bmp_data *bmp_data;
+
+ bmp_data = (mm_util_bmp_data *) _handle->image_h;
+ if (bmp_data == NULL) {
+ image_util_error("Invalid bmp data");
+ return MM_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (_handle->path)
+ err = mm_util_decode_from_bmp_file(bmp_data, _handle->path);
+ else
+ err = mm_util_decode_from_bmp_memory(bmp_data, &_handle->src_buffer[0], _handle->src_size);
+
+ if (err == MM_UTIL_ERROR_NONE) {
+ *(_handle->dst_buffer) = bmp_data->data;
+ _handle->dst_size = bmp_data->size;
+ _handle->width = bmp_data->width;
+ _handle->height = bmp_data->height;
+ }
+ }
+ break;
+ default:
+ err = MM_UTIL_ERROR_INVALID_PARAMETER;
+ break;
+ }
+
+ return err;
+}
+
+int image_util_decode_run(image_util_decode_h handle, unsigned long *width, unsigned long *height, unsigned long long *size)
+{
+ int err = MM_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == FALSE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if ((_handle->path == NULL && _handle->src_buffer == NULL) || _handle->dst_buffer == NULL) {
+ image_util_error("Invalid input/output");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ err = _image_util_decode_internal(_handle);
+
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("Error - decode run");
+ return _convert_image_util_error_code(__func__, err);
+ }
+
+ if (width)
+ *width = _handle->width;
+ if (height)
+ *height = _handle->height;
+ if (size)
+ *size = _handle->dst_size;
+
+ return _convert_image_util_error_code(__func__, err);
+}
+
+gpointer _image_util_decode_thread(gpointer data)
+{
+ decode_encode_s *_handle = (decode_encode_s *) data;
+ int err = MM_UTIL_ERROR_NONE;
+
+ if (!_handle) {
+ image_util_error("[ERROR] - handle");
+ return NULL;
+ }
+
+ err = _image_util_decode_internal(_handle);
+ if (err == MM_UTIL_ERROR_NONE)
+ image_util_debug("Success - decode_internal");
+ else
+ image_util_error("Error - decode_internal");
+
+ if (_handle->_decode_cb) {
+ image_util_debug("completed_cb");
+ _handle->_decode_cb->image_decode_completed_cb(_convert_image_util_error_code(__func__, err), _handle->_decode_cb->user_data, _handle->width, _handle->height, _handle->dst_size);
+ }
+
+ image_util_debug("exit thread");
+
+ return NULL;
+}
+
+static int _image_util_decode_create_thread(decode_encode_s * handle)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+ image_util_retvm_if((handle->thread != NULL), MM_UTIL_ERROR_INVALID_OPERATION, "A thread is alread running");
+
+ /*create threads */
+ handle->thread = g_thread_new("decode_thread", (GThreadFunc) _image_util_decode_thread, (gpointer) handle);
+ if (!handle->thread) {
+ image_util_error("ERROR - create thread");
+ return MM_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ return err;
+}
+
+int image_util_decode_run_async(image_util_decode_h handle, image_util_decode_completed_cb completed_cb, void *user_data)
+{
+ int err = MM_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == FALSE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if ((_handle->path == NULL && _handle->src_buffer == NULL) || _handle->dst_buffer == NULL) {
+ image_util_error("Invalid input/output");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ image_util_retvm_if((completed_cb == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid callback");
+ image_util_retvm_if((_handle->thread != NULL), MM_UTIL_ERROR_INVALID_OPERATION, "A thread is alread running");
+
+ if (_handle->_decode_cb != NULL) {
+ IMAGE_UTIL_SAFE_FREE(_handle->_decode_cb);
+ _handle->_decode_cb = NULL;
+ }
+
+ _handle->_decode_cb = (decode_cb_s *) calloc(1, sizeof(decode_cb_s));
+ image_util_retvm_if((_handle->_decode_cb == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "Out of memory");
+
+ _handle->_decode_cb->user_data = user_data;
+ _handle->_decode_cb->image_decode_completed_cb = completed_cb;
+
+ err = _image_util_decode_create_thread(_handle);
+ if (err != MM_UTIL_ERROR_NONE) {
+ IMAGE_UTIL_SAFE_FREE(_handle->_decode_cb);
+ _handle->_decode_cb = NULL;
+ }
+
+ return _convert_image_util_error_code(__func__, err);
+}
+
+int image_util_decode_destroy(image_util_decode_h handle)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ image_util_debug("image_util_decode_destroy");
+
+ if (_handle == NULL || _handle->is_decode == FALSE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ _image_util_decode_destroy_image_handle(_handle);
+
+ /* g_thread_exit(handle->thread); */
+ if (_handle->thread) {
+ g_thread_join(_handle->thread);
+ IMAGE_UTIL_SAFE_FREE(_handle->_decode_cb);
+ }
+ IMAGE_UTIL_SAFE_FREE(_handle->src_buffer);
+ IMAGE_UTIL_SAFE_FREE(_handle);
+
+ return err;
+}
+int image_util_decode_jpeg(const char *path, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ DEPRECATION_LOGW("image_util_decode_jpeg()", "image_util_decode_create()");
+
+ image_util_retvm_if((path == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "path is null");
+ image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
+ image_util_retvm_if((size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "size is null");
+ image_util_retvm_if((strlen(path) == 0), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path");
+ image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+ image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+
+ mm_util_jpeg_yuv_data decoded;
+ memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
+
+ err = mm_util_decode_from_jpeg_file(&decoded, path, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG));
+ if (err == MM_UTIL_ERROR_NONE) {
+ *image_buffer = decoded.data;
+ if (width)
+ *width = decoded.width;
+ if (height)
+ *height = decoded.height;
+ if (size)
+ *size = decoded.size;
+ }
+ return _convert_image_util_error_code(__func__, err);
+}
+
+int image_util_decode_jpeg_from_memory(const unsigned char *jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ DEPRECATION_LOGW("image_util_decode_jpeg_from_memory()", "image_util_decode_create()");
+
+ image_util_retvm_if((jpeg_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "jpeg_buffer is null");
+ image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
+ image_util_retvm_if((size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "size is null");
+ image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+ image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+
+ mm_util_jpeg_yuv_data decoded;
+ memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
+
+ err = mm_util_decode_from_jpeg_memory(&decoded, (void *)jpeg_buffer, (unsigned int)jpeg_size, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG));
+
+ if (err == MM_UTIL_ERROR_NONE) {
+ *image_buffer = decoded.data;
+ if (width)
+ *width = decoded.width;
+ if (height)
+ *height = decoded.height;
+ if (size)
+ *size = decoded.size;
+ }
+
+ return _convert_image_util_error_code(__func__, err);
+}
+
+int image_util_decode_jpeg_with_downscale(const char *path, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char **image_buffer, int *width, int *height, unsigned int *size)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ DEPRECATION_LOGW("image_util_decode_jpeg_with_downscale()", "image_util_decode_create()");
+
+ image_util_retvm_if((path == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "path is null");
+ image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
+ image_util_retvm_if((size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "size is null");
+ image_util_retvm_if((strlen(path) == 0), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path");
+ image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+ image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+ image_util_retvm_if((downscale < 0 || downscale >= _NUM_OF_SCALE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "downsacle is invalid");
+
+ mm_util_jpeg_yuv_data decoded;
+ memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
+
+ err = mm_util_decode_from_jpeg_file_with_downscale(&decoded, path, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[downscale]);
+ if (err == MM_UTIL_ERROR_NONE) {
+ *image_buffer = decoded.data;
+ if (width)
+ *width = decoded.width;
+ if (height)
+ *height = decoded.height;
+ if (size)
+ *size = decoded.size;
+ }
+ return _convert_image_util_error_code(__func__, err);
+}
+
+int image_util_decode_jpeg_from_memory_with_downscale(const unsigned char *jpeg_buffer, int jpeg_size, image_util_colorspace_e colorspace, image_util_scale_e downscale, unsigned char **image_buffer, int *width, int *height, unsigned int *size)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ DEPRECATION_LOGW("image_util_decode_jpeg_from_memory_with_downscale()", "image_util_decode_create()");
+
+ image_util_retvm_if((jpeg_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "jpeg_buffer is null");
+ image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
+ image_util_retvm_if((size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "size is null");
+ image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+ image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+ image_util_retvm_if((downscale < 0 || downscale >= _NUM_OF_SCALE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "downsacle is invalid");
+
+ mm_util_jpeg_yuv_data decoded;
+ memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data));
+
+ err = mm_util_decode_from_jpeg_memory_with_downscale(&decoded, (void *)jpeg_buffer, (unsigned int)jpeg_size, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), _convert_decode_scale_tbl[downscale]);
+
+ if (err == MM_UTIL_ERROR_NONE) {
+ *image_buffer = decoded.data;
+ if (width)
+ *width = decoded.width;
+ if (height)
+ *height = decoded.height;
+ if (size)
+ *size = decoded.size;
+ }
+
+ return _convert_image_util_error_code(__func__, err);
+}
--- /dev/null
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <mm_util_imgp.h>
+#include <mm_util_jpeg.h>
+#include <mm_util_png.h>
+#include <mm_util_gif.h>
+#include <mm_util_bmp.h>
+
+#include <image_util.h>
+#include <image_util_private.h>
+
+static int _image_util_encode_get_gif_frame(mm_gif_file_h gif_data, unsigned int index, mm_gif_image_h *frame)
+{
+ int err = MM_UTIL_ERROR_NONE;
+ image_util_retvm_if((gif_data == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+ image_util_retvm_if((frame == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+
+ err = mm_util_gif_enocde_get_image_handle(gif_data, (int)index, frame);
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("mm_util_gif_enocde_get_image_handle is failed %d", err);
+ return _convert_image_util_error_code(__func__, err);
+ }
+ if (*frame == NULL) {
+ err = mm_util_gif_image_create(gif_data, frame);
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("mm_util_gif_image_create is failed %d", err);
+ return _convert_image_util_error_code(__func__, err);
+ }
+ err = mm_util_gif_enocde_set_image_handle(gif_data, *frame);
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("mm_util_gif_enocde_set_image_handle is failed %d", err);
+ mm_util_gif_image_destory(*frame);
+ return _convert_image_util_error_code(__func__, err);
+ }
+ }
+ return err;
+}
+
+static void _image_util_encode_destroy_image_handle(decode_encode_s * handle)
+{
+ image_util_retm_if((handle == NULL), "Invalid Handle");
+ void *image_handle = (void *)(handle->image_h);
+ image_util_retm_if((image_handle == NULL), "Invalid image handle");
+
+ if (handle->image_type == IMAGE_UTIL_GIF)
+ mm_util_gif_encode_destroy(image_handle);
+
+ IMAGE_UTIL_SAFE_FREE(image_handle);
+}
+
+static int _image_util_encode_create_jpeg_handle(decode_encode_s * handle)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+
+ mm_util_jpeg_yuv_data *_handle = (mm_util_jpeg_yuv_data *) calloc(1, sizeof(mm_util_jpeg_yuv_data));
+ image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY);
+
+ handle->image_h = (mm_util_imgp_h) _handle;
+ handle->colorspace = IMAGE_UTIL_COLORSPACE_RGBA8888;
+ handle->quality = 75;
+
+ return err;
+}
+
+static int _image_util_encode_create_png_handle(decode_encode_s * handle)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+
+ mm_util_png_data *_handle = (mm_util_png_data *) calloc(1, sizeof(mm_util_png_data));
+ image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY);
+
+ mm_util_init_encode_png(_handle);
+
+ handle->image_h = (mm_util_imgp_h) _handle;
+
+ return err;
+}
+
+static int _image_util_encode_create_gif_handle(decode_encode_s * handle)
+{
+ int err = MM_UTIL_ERROR_NONE;
+ mm_gif_file_h _handle = NULL;
+
+ image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+
+ err = mm_util_gif_encode_create(&_handle);
+ image_util_retvm_if((err != MM_UTIL_ERROR_NONE), _convert_image_util_error_code(__func__, err), "Error - mm_util_gif_encode_create is failed (%d)", err);
+
+ handle->image_h = (mm_util_imgp_h) _handle;
+
+ return err;
+}
+
+static int _image_util_encode_create_bmp_handle(decode_encode_s * handle)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+
+ mm_util_bmp_data *_handle = (mm_util_bmp_data *) calloc(1, sizeof(mm_util_bmp_data));
+ image_util_retvm_if((_handle == NULL), MM_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", MM_UTIL_ERROR_OUT_OF_MEMORY);
+
+ handle->image_h = (mm_util_imgp_h) _handle;
+
+ return err;
+}
+
+int image_util_encode_create(image_util_type_e image_type, image_util_encode_h * handle)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ image_util_debug("image_util_encode_create");
+
+ image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+
+ decode_encode_s *_handle = (decode_encode_s *) calloc(1, sizeof(decode_encode_s));
+ image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "OUT_OF_MEMORY(0x%08x)", IMAGE_UTIL_ERROR_OUT_OF_MEMORY);
+
+ _handle->image_type = image_type;
+ _handle->src_buffer = NULL;
+ _handle->dst_buffer = NULL;
+ _handle->path = NULL;
+ _handle->image_h = 0;
+ _handle->is_decode = FALSE;
+ _handle->is_encoded = FALSE;
+ _handle->current_buffer_count = 0;
+ _handle->current_resolution_count = 0;
+ _handle->current_delay_count = 0;
+
+ switch (image_type) {
+ case IMAGE_UTIL_JPEG:
+ err = _image_util_encode_create_jpeg_handle(_handle);
+ break;
+ case IMAGE_UTIL_PNG:
+ err = _image_util_encode_create_png_handle(_handle);
+ break;
+ case IMAGE_UTIL_GIF:
+ err = _image_util_encode_create_gif_handle(_handle);
+ break;
+ case IMAGE_UTIL_BMP:
+ err = _image_util_encode_create_bmp_handle(_handle);
+ break;
+ default:
+ err = MM_UTIL_ERROR_INVALID_PARAMETER;
+ break;
+ }
+
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("Error - create image handle");
+ IMAGE_UTIL_SAFE_FREE(_handle);
+ return _convert_image_util_error_code(__func__, err);
+ }
+
+ *handle = (image_util_encode_h) _handle;
+
+ return _convert_image_util_error_code(__func__, err);
+}
+
+int image_util_encode_set_resolution(image_util_encode_h handle, unsigned long width, unsigned long height)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == TRUE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ image_util_retvm_if((_image_util_check_resolution(width, height) == false), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution");
+
+ switch (_handle->image_type) {
+ case IMAGE_UTIL_JPEG:
+ {
+ mm_util_jpeg_yuv_data *jpeg_data;
+
+ jpeg_data = (mm_util_jpeg_yuv_data *) _handle->image_h;
+ if (jpeg_data == NULL) {
+ image_util_error("Invalid jpeg data");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ jpeg_data->width = width;
+ jpeg_data->height = height;
+ }
+ break;
+ case IMAGE_UTIL_PNG:
+ {
+ mm_util_png_data *png_data;
+
+ png_data = (mm_util_png_data *) _handle->image_h;
+ if (png_data == NULL) {
+ image_util_error("Invalid png data");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ mm_util_png_encode_set_width(png_data, width);
+ mm_util_png_encode_set_height(png_data, height);
+ }
+ break;
+ case IMAGE_UTIL_GIF:
+ {
+ mm_gif_file_h gif_data = (mm_gif_file_h)_handle->image_h;
+ if (gif_data == NULL) {
+ image_util_error("Invalid gif data");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ image_util_retvm_if((width > INT_MAX) || (height > INT_MAX), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution");
+
+ if (_handle->current_resolution_count == 0) {
+ _handle->width = width;
+ _handle->height = height;
+ mm_util_gif_encode_set_resolution(gif_data, width, height);
+ }
+ mm_gif_image_h frame = NULL;
+ err = _image_util_encode_get_gif_frame(gif_data, _handle->current_resolution_count, &frame);
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("_image_util_encode_get_gif_frame is failed %d", err);
+ return _convert_image_util_error_code(__func__, err);
+ }
+ err = mm_util_gif_image_set_position(frame, 0, 0, (int)width, (int)height);
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("mm_util_gif_image_set_position is failed %d", err);
+ return _convert_image_util_error_code(__func__, err);
+ }
+ _handle->current_resolution_count++;
+
+ return err;
+ }
+ break;
+ case IMAGE_UTIL_BMP:
+ {
+ mm_util_bmp_data *bmp_data;
+
+ bmp_data = (mm_util_bmp_data *) _handle->image_h;
+ if (bmp_data == NULL) {
+ image_util_error("Invalid bmp data");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ mm_util_bmp_encode_set_width(bmp_data, width);
+ mm_util_bmp_encode_set_height(bmp_data, height);
+ }
+ break;
+ default:
+ err = IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ break;
+ }
+
+ _handle->width = width;
+ _handle->height = height;
+
+ return err;
+}
+
+int image_util_encode_set_colorspace(image_util_encode_h handle, image_util_colorspace_e colorspace)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == TRUE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+
+ if ((_handle->image_type == IMAGE_UTIL_JPEG) || (_handle->image_type == IMAGE_UTIL_PNG)
+ || (_handle->image_type == IMAGE_UTIL_GIF) || (_handle->image_type == IMAGE_UTIL_BMP)) {
+ image_util_retvm_if((is_supported_colorspace(colorspace, _handle->image_type) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+ } else {
+ image_util_error("Invalid image type");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ _handle->colorspace = colorspace;
+
+ return err;
+}
+
+int image_util_encode_set_quality(image_util_encode_h handle, int quality)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == TRUE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if (_handle->image_type != IMAGE_UTIL_JPEG) {
+ image_util_error("Wrong image format");
+ return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
+ }
+ image_util_retvm_if((quality <= 0 || quality > 100), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid quality");
+
+ _handle->quality = quality;
+
+ return err;
+}
+
+int image_util_encode_set_png_compression(image_util_encode_h handle, image_util_png_compression_e compression)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+ mm_util_png_data *png_data;
+
+ if (_handle == NULL || _handle->is_decode == TRUE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if (_handle->image_type != IMAGE_UTIL_PNG) {
+ image_util_error("Wrong image format");
+ return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
+ }
+ image_util_retvm_if((compression < IMAGE_UTIL_PNG_COMPRESSION_0 || compression > IMAGE_UTIL_PNG_COMPRESSION_9), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid compression value");
+
+ png_data = (mm_util_png_data *) _handle->image_h;
+ if (png_data == NULL) {
+ image_util_error("Invalid png data");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ mm_util_png_encode_set_compression_level(png_data, compression);
+
+ return err;
+}
+
+int image_util_encode_set_gif_frame_delay_time(image_util_encode_h handle, unsigned long long delay_time)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+ mm_gif_file_h gif_data = NULL;
+
+ if (_handle == NULL || _handle->is_decode == TRUE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if (_handle->image_type != IMAGE_UTIL_GIF) {
+ image_util_error("Wrong image format");
+ return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT;
+ }
+
+ gif_data = (mm_gif_file_h) _handle->image_h;
+ if (gif_data == NULL) {
+ image_util_error("Invalid gif data");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ image_util_retvm_if((delay_time > INT_MAX), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid delay time");
+
+ mm_gif_image_h frame = NULL;
+ err = _image_util_encode_get_gif_frame(gif_data, _handle->current_delay_count, &frame);
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("_image_util_encode_get_gif_frame is failed %d", err);
+ return _convert_image_util_error_code(__func__, err);
+ }
+ err = mm_util_gif_image_set_delay_time(frame, (int)delay_time);
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("mm_util_gif_image_set_delay_time is failed %d", err);
+ return _convert_image_util_error_code(__func__, err);
+ }
+ _handle->current_delay_count++;
+
+ return err;
+}
+
+int image_util_encode_set_input_buffer(image_util_encode_h handle, const unsigned char *src_buffer)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == TRUE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if (src_buffer == NULL) {
+ image_util_error("Invalid input buffer");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ /* initialize buffer and value for source buffer */
+ if (_handle->image_type == IMAGE_UTIL_GIF) {
+ mm_gif_file_h gif_data = (mm_gif_file_h) _handle->image_h;
+ mm_gif_image_h frame = NULL;
+ if (gif_data == NULL) {
+ image_util_error("Invalid gif data");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ err = _image_util_encode_get_gif_frame(gif_data, _handle->current_buffer_count, &frame);
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("_image_util_encode_get_gif_frame is failed %d", err);
+ return _convert_image_util_error_code(__func__, err);
+ }
+ err = mm_util_gif_image_set_image(frame, src_buffer);
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("mm_util_gif_image_set_delay_time is failed %d", err);
+ return _convert_image_util_error_code(__func__, err);
+ }
+ _handle->current_buffer_count++;
+ } else {
+ if (_handle->src_buffer == NULL)
+ _handle->src_buffer = (void *)calloc(1, sizeof(void *));
+ image_util_retvm_if(_handle->src_buffer == NULL, IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "calloc fail");
+
+ _handle->src_buffer[_handle->current_buffer_count] = (void *)src_buffer;
+ }
+
+ return err;
+}
+
+int image_util_encode_set_output_path(image_util_encode_h handle, const char *path)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == TRUE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ image_util_retvm_if((path == NULL || strlen(path) == 0), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path");
+
+ if (_handle->dst_buffer)
+ _handle->dst_buffer = NULL;
+
+ IMAGE_UTIL_SAFE_FREE(_handle->path);
+
+ _handle->path = g_strndup(path, strlen(path));
+
+ return err;
+}
+
+int image_util_encode_set_output_buffer(image_util_encode_h handle, unsigned char **dst_buffer)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == TRUE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if (dst_buffer == NULL) {
+ image_util_error("Invalid output buffer");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ IMAGE_UTIL_SAFE_FREE(_handle->path);
+
+ _handle->dst_buffer = (void **)dst_buffer;
+
+ return err;
+}
+
+static int _image_util_encode_internal(decode_encode_s * _handle)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ switch (_handle->image_type) {
+ case IMAGE_UTIL_JPEG:
+ {
+ if (_handle->path)
+ err = mm_util_jpeg_encode_to_file(_handle->path, _handle->src_buffer[0], _handle->width, _handle->height, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _handle->quality);
+ else
+ err = mm_util_jpeg_encode_to_memory(_handle->dst_buffer, (unsigned int *)&(_handle->dst_size), _handle->src_buffer[0], _handle->width, _handle->height, TYPECAST_COLOR_BY_TYPE(_handle->colorspace, IMAGE_UTIL_JPEG), _handle->quality);
+ }
+ break;
+ case IMAGE_UTIL_PNG:
+ {
+ mm_util_png_data *png_data;
+
+ png_data = (mm_util_png_data *) _handle->image_h;
+ if (png_data == NULL) {
+ image_util_error("Invalid png data");
+ return MM_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (_handle->path)
+ err = mm_util_encode_to_png_file(&(_handle->src_buffer[0]), png_data, _handle->path);
+ else
+ err = mm_util_encode_to_png_memory(&(_handle->src_buffer[0]), png_data);
+
+ if (err == MM_UTIL_ERROR_NONE) {
+ if (_handle->dst_buffer)
+ *(_handle->dst_buffer) = png_data->data;
+ _handle->dst_size = png_data->size;
+ _handle->width = png_data->width;
+ _handle->height = png_data->height;
+ }
+ }
+ break;
+ case IMAGE_UTIL_GIF:
+ {
+ mm_gif_file_h gif_data = (mm_gif_file_h)_handle->image_h;
+ unsigned long encoded_buffer_size = 0;
+ if (gif_data == NULL) {
+ image_util_error("Invalid gif data");
+ return MM_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ image_util_debug("[Count] buffer:%d, resolution:%d, delay:%d", _handle->current_buffer_count, _handle->current_resolution_count, _handle->current_delay_count);
+ if ((_handle->current_buffer_count > 1) && ((_handle->current_buffer_count != _handle->current_resolution_count) || (_handle->current_buffer_count != _handle->current_delay_count))) {
+ image_util_error("Total frame count does not match with the data set, for animated gif encoding");
+ return MM_UTIL_ERROR_INVALID_OPERATION;
+ } else if ((_handle->current_buffer_count > 0) && ((_handle->current_buffer_count != _handle->current_resolution_count))) {
+ image_util_error("Total frame count does not match with the data set, for gif encoding");
+ return MM_UTIL_ERROR_INVALID_OPERATION;
+ }
+ if (_handle->path)
+ err = mm_util_gif_encode_set_file(gif_data, _handle->path);
+ else
+ err = mm_util_gif_encode_set_mem(gif_data, _handle->dst_buffer, &encoded_buffer_size);
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("mm_util_gif_encode_set_file | mm_util_gif_encode_set_mem is failed(%d)", err);
+ return _convert_image_util_error_code(__func__, err);
+ }
+ err = mm_util_gif_encode(gif_data);
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("mm_util_gif_encode is failed(%d)", err);
+ return _convert_image_util_error_code(__func__, err);
+ }
+ if (encoded_buffer_size != 0)
+ _handle->dst_size = (unsigned long long)encoded_buffer_size;
+ }
+ break;
+ case IMAGE_UTIL_BMP:
+ {
+ mm_util_bmp_data *bmp_data;
+
+ bmp_data = (mm_util_bmp_data *) _handle->image_h;
+ if (bmp_data == NULL) {
+ image_util_error("Invalid bmp data");
+ return MM_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ bmp_data->data = _handle->src_buffer[0];
+ if (_handle->path) {
+ err = mm_util_encode_bmp_to_file(bmp_data, _handle->path);
+ } else {
+ size_t size = 0;
+ err = mm_util_encode_bmp_to_memory(bmp_data, &(bmp_data->data), &size);
+ if (err == MM_UTIL_ERROR_NONE)
+ bmp_data->size = (unsigned long long)size;
+ else
+ bmp_data->size = 0;
+ }
+ if (err == MM_UTIL_ERROR_NONE) {
+ if (_handle->dst_buffer)
+ *(_handle->dst_buffer) = bmp_data->data;
+ _handle->dst_size = bmp_data->size;
+ _handle->width = bmp_data->width;
+ _handle->height = bmp_data->height;
+ }
+ }
+ break;
+ default:
+ err = MM_UTIL_ERROR_INVALID_PARAMETER;
+ break;
+ }
+
+ return err;
+}
+
+int image_util_encode_run(image_util_encode_h handle, unsigned long long *size)
+{
+ int err = MM_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == TRUE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if (_handle->path == NULL && _handle->dst_buffer == NULL) {
+ image_util_error("Invalid output");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if (_handle->image_type != IMAGE_UTIL_GIF && _handle->src_buffer == NULL) {
+ image_util_error("Invalid input");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ image_util_retvm_if((_image_util_check_resolution(_handle->width, _handle->height) == false), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution");
+
+ err = _image_util_encode_internal(_handle);
+ _handle->is_encoded = TRUE;
+
+ if (err != MM_UTIL_ERROR_NONE) {
+ image_util_error("Error - encode run");
+ return _convert_image_util_error_code(__func__, err);
+ }
+
+ if (size)
+ *size = _handle->dst_size;
+
+ return _convert_image_util_error_code(__func__, err);
+}
+
+gpointer _image_util_encode_thread(gpointer data)
+{
+ decode_encode_s *_handle = (decode_encode_s *) data;
+ int err = MM_UTIL_ERROR_NONE;
+
+ if (!_handle) {
+ image_util_error("[ERROR] - handle");
+ return NULL;
+ }
+
+ err = _image_util_encode_internal(_handle);
+ if (err == MM_UTIL_ERROR_NONE)
+ image_util_debug("Success - encode_internal");
+ else
+ image_util_error("Error - encode_internal");
+
+ if (_handle->_encode_cb) {
+ image_util_debug("completed_cb");
+ _handle->_encode_cb->image_encode_completed_cb(_convert_image_util_error_code(__func__, err), _handle->_encode_cb->user_data, _handle->dst_size);
+ }
+
+ IMAGE_UTIL_SAFE_FREE(_handle->_encode_cb);
+ _handle->thread = NULL;
+ _handle->is_encoded = TRUE;
+ image_util_debug("exit thread");
+
+ return NULL;
+}
+
+static int _image_util_encode_create_thread(decode_encode_s * handle)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+
+ image_util_retvm_if((handle == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle");
+ image_util_retvm_if((handle->thread != NULL), MM_UTIL_ERROR_INVALID_OPERATION, "The thread is alread running");
+
+ /*create threads */
+ handle->thread = g_thread_new("encode_thread", (GThreadFunc) _image_util_encode_thread, (gpointer) handle);
+ if (!handle->thread) {
+ image_util_error("ERROR - create thread");
+
+ return MM_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ return ret;
+}
+
+int image_util_encode_run_async(image_util_encode_h handle, image_util_encode_completed_cb completed_cb, void *user_data)
+{
+ int err = MM_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ if (_handle == NULL || _handle->is_decode == TRUE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if (_handle->path == NULL && _handle->dst_buffer == NULL) {
+ image_util_error("Invalid output");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ if (_handle->image_type != IMAGE_UTIL_GIF && _handle->src_buffer == NULL) {
+ image_util_error("Invalid input");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ image_util_retvm_if((_image_util_check_resolution(_handle->width, _handle->height) == false), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid resolution");
+ image_util_retvm_if((completed_cb == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid callback");
+ image_util_retvm_if((_handle->thread != NULL), MM_UTIL_ERROR_INVALID_OPERATION, "The thread is alread running");
+
+ if (_handle->_encode_cb != NULL) {
+ IMAGE_UTIL_SAFE_FREE(_handle->_encode_cb);
+ _handle->_encode_cb = NULL;
+ }
+ _handle->_encode_cb = (encode_cb_s *) calloc(1, sizeof(encode_cb_s));
+ image_util_retvm_if((_handle->_encode_cb == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "Out of memory");
+
+ _handle->_encode_cb->user_data = user_data;
+ _handle->_encode_cb->image_encode_completed_cb = completed_cb;
+
+ err = _image_util_encode_create_thread(_handle);
+ if (err != MM_UTIL_ERROR_NONE) {
+ IMAGE_UTIL_SAFE_FREE(_handle->_encode_cb);
+ _handle->_encode_cb = NULL;
+ }
+
+ return _convert_image_util_error_code(__func__, err);
+}
+
+int image_util_encode_destroy(image_util_encode_h handle)
+{
+ int err = IMAGE_UTIL_ERROR_NONE;
+ decode_encode_s *_handle = (decode_encode_s *) handle;
+
+ image_util_debug("image_util_encode_destroy");
+
+ if (_handle == NULL || _handle->is_decode == TRUE) {
+ image_util_error("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ _image_util_encode_destroy_image_handle(_handle);
+
+ /* g_thread_exit(handle->thread); */
+ if (_handle->thread) {
+ g_thread_join(_handle->thread);
+ IMAGE_UTIL_SAFE_FREE(_handle->_encode_cb);
+ }
+
+ IMAGE_UTIL_SAFE_FREE(_handle->path);
+ IMAGE_UTIL_SAFE_FREE(_handle->src_buffer);
+ IMAGE_UTIL_SAFE_FREE(_handle);
+
+ return err;
+}
+
+int image_util_encode_jpeg(const unsigned char *buffer, int width, int height, image_util_colorspace_e colorspace, int quality, const char *path)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ DEPRECATION_LOGW("image_util_encode_jpeg()", "image_util_encode_create()");
+
+ image_util_retvm_if((path == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "path is null");
+ image_util_retvm_if((buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "buffer is null");
+ image_util_retvm_if((strlen(path) == 0), IMAGE_UTIL_ERROR_NO_SUCH_FILE, "Invalid path");
+ image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+ image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+
+ err = mm_util_jpeg_encode_to_file(path, (void *)buffer, width, height, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), quality);
+ return _convert_image_util_error_code(__func__, err);
+}
+
+int image_util_encode_jpeg_to_memory(const unsigned char *image_buffer, int width, int height, image_util_colorspace_e colorspace, int quality, unsigned char **jpeg_buffer, unsigned int *jpeg_size)
+{
+ int err = MM_UTIL_ERROR_NONE;
+
+ DEPRECATION_LOGW("image_util_encode_jpeg_to_memory()", "image_util_encode_create()");
+
+ image_util_retvm_if((jpeg_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "jpeg_buffer is null");
+ image_util_retvm_if((image_buffer == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "image_buffer is null");
+ image_util_retvm_if((jpeg_size == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "jpeg_size is null");
+ image_util_retvm_if((is_valid_colorspace(colorspace) == FALSE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid colorspace");
+ image_util_retvm_if((is_supported_colorspace(colorspace, IMAGE_UTIL_JPEG) == FALSE), IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported format");
+
+ err = mm_util_jpeg_encode_to_memory((void **)jpeg_buffer, jpeg_size, (void *)image_buffer, width, height, TYPECAST_COLOR_BY_TYPE(colorspace, IMAGE_UTIL_JPEG), quality);
+ return _convert_image_util_error_code(__func__, err);
+}
+