diff options
author | jk7744.park <jk7744.park@samsung.com> | 2015-10-24 16:23:27 +0900 |
---|---|---|
committer | jk7744.park <jk7744.park@samsung.com> | 2015-10-24 16:23:27 +0900 |
commit | 2141bab43e5a9d97273d68fb1429fdf041a0afe2 (patch) | |
tree | c10d4b9ca9847a3d4392313ed46f8190429e768d | |
parent | 6804b5c218d269c58c53dae3c4771d1869dc3e9b (diff) | |
download | image-util-accepted/tizen_2.4_mobile.tar.gz image-util-accepted/tizen_2.4_mobile.tar.bz2 image-util-accepted/tizen_2.4_mobile.zip |
tizen 2.4 releasetizen_2.4_mobile_releasesubmit/tizen_2.4/20151028.063549accepted/tizen/2.4/mobile/20151029.034758tizen_2.4accepted/tizen_2.4_mobile
-rwxr-xr-x | CMakeLists.txt | 2 | ||||
-rwxr-xr-x | doc/image_util_doc.h | 4 | ||||
-rwxr-xr-x | include/image_util.h | 168 | ||||
-rwxr-xr-x[-rw-r--r--] | include/image_util_internal.h | 28 | ||||
-rwxr-xr-x | include/image_util_private.h | 39 | ||||
-rwxr-xr-x | include/image_util_type.h | 97 | ||||
-rwxr-xr-x | packaging/capi-media-image-util.spec | 9 | ||||
-rwxr-xr-x | src/image_util.c | 597 | ||||
-rwxr-xr-x | test/CMakeLists.txt | 12 | ||||
-rwxr-xr-x | test/image_util_test.c | 631 | ||||
-rwxr-xr-x | test/multimeida_image_util_test.c | 208 |
11 files changed, 1164 insertions, 631 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 5655afb..1616b7f 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -44,7 +44,7 @@ FOREACH(flag ${${fw_name}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") ENDFOREACH(flag) -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall") +SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror") SET(CMAKE_C_FLAGS_DEBUG "-O0 -g") IF("${ARCH}" MATCHES "^arm.*") diff --git a/doc/image_util_doc.h b/doc/image_util_doc.h index ac63a44..d2d4797 100755 --- a/doc/image_util_doc.h +++ b/doc/image_util_doc.h @@ -40,7 +40,7 @@ * * The decoding of a jpeg image located at a given path, to a buffer can be done by calling #image_util_decode_jpeg() function and decoding of a jpeg image on memory * can be done by calling #image_util_decode_jpeg_from_memory(). Similarly, for encoding #image_util_encode_jpeg() and #image_util_encode_jpeg_to_memory() functions can be called - * to encode an image buffer to a jpeg image and a jpeg buffer respectively. The API also allows to transform including convert the colorspace (#image_util_colorspace_e) of an image by calling + * to encode an image buffer to a jpeg image and a jpeg buffer respectively. The API also allows to transform including convert the colorspace(#image_util_colorspace_e) of an image by calling * #image_util_transform_run() function. * * @subsection CAPI_MEDIA_IMAGE_UTIL_FOREACH_OPERATIONS Foreach Operations @@ -58,4 +58,4 @@ *</table></div> */ -#endif // __TIZEN_MEDIA_IMAGE_UTIL_DOC_H__ +#endif /* __TIZEN_MEDIA_IMAGE_UTIL_DOC_H__ */ diff --git a/include/image_util.h b/include/image_util.h index 77e350e..d0bda67 100755 --- a/include/image_util.h +++ b/include/image_util.h @@ -36,7 +36,7 @@ extern "C" /** * @brief Creates a handle to image util transform. -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @details This function creates a handle to image util transform. * @@ -59,7 +59,7 @@ int image_util_transform_create(transformation_h *handle); /** * @brief Sets the image util's accurate mode. -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @details This function set if you use hardware accerlation or not. * @@ -74,6 +74,7 @@ int image_util_transform_create(transformation_h *handle); * * @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_PERMISSION_DENIED The application does not have the privilege to call this funtion * @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED The application does not have the hardware acceleration * @@ -86,7 +87,7 @@ int image_util_transform_set_hardware_acceleration(transformation_h handle, bool /** * @brief Sets the information of the converting -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @param[in] handle The handle to image util transform * @param[in] colorspace The colorspace of the image buffer @@ -96,6 +97,7 @@ int image_util_transform_set_hardware_acceleration(transformation_h handle, bool * * @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_PERMISSION_DENIED The application does not have the privilege to call this funtion * @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Not supported format * @@ -109,7 +111,9 @@ int image_util_transform_set_colorspace(transformation_h handle, image_util_colo /** * @brief Sets the information of the resizing -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 +* +* @remarks image_util_transform_set_resolution and image_util_transform_set_crop_area can't do that at the same time. * * @param[in] handle The handle to image util transform * @param[in] width The width of image buffer @@ -120,6 +124,7 @@ int image_util_transform_set_colorspace(transformation_h handle, image_util_colo * * @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_PERMISSION_DENIED The application does not have the privilege to call this funtion * * @pre image_util_transform_create(). @@ -132,7 +137,7 @@ int image_util_transform_set_resolution(transformation_h handle, unsigned int wi /** * @brief Sets the information of the rotating -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @param[in] handle The handle to image util transform * @param[in] rotation The rotation value of image buffer @@ -142,6 +147,7 @@ int image_util_transform_set_resolution(transformation_h handle, unsigned int wi * * @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_PERMISSION_DENIED The application does not have the privilege to call this funtion * * @pre image_util_transform_create(). @@ -154,7 +160,9 @@ int image_util_transform_set_rotation(transformation_h handle, image_util_rotati /** * @brief Sets the information of the cropping -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 +* +* @remarks image_util_transform_set_resolution and image_util_transform_set_crop_area can't do that at the same time. * * @param[in] handle The handle to image util transform * @param[in] start_x The start x position of cropped image buffer @@ -167,6 +175,7 @@ int image_util_transform_set_rotation(transformation_h handle, image_util_rotati * * @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_PERMISSION_DENIED The application does not have the privilege to call this funtion * * @pre image_util_transform_create(). @@ -179,16 +188,17 @@ int image_util_transform_set_crop_area(transformation_h handle, unsigned int sta /** * @brief Gets the colorspace of the image buffer -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @param[in] handle The handle to image util transform -* @param[in,out] colorspace The colorspace of the image buffer +* @param[in, out] colorspace The colorspace of the 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 Not supported format * * @pre image_util_transform_create().\n @@ -201,17 +211,18 @@ int image_util_transform_get_colorspace(transformation_h handle, image_util_colo /** * @brief Gets the resolution of the image buffer -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @param[in] handle The handle to image util transform -* @param[in,out] width The width of source image buffer -* @param[in,out] height The height of source image buffer +* @param[in, out] width The width of source image buffer +* @param[in, out] height The height of source 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_PERMISSION_DENIED The application does not have the privilege to call this funtion * * @pre image_util_transform_create().\n @@ -220,20 +231,21 @@ int image_util_transform_get_colorspace(transformation_h handle, image_util_colo * @see image_util_transform_create() * @see image_util_transform_destroy() */ -int image_util_transform_get_resolution(transformation_h handle, unsigned int *width , unsigned int *height); +int image_util_transform_get_resolution(transformation_h handle, unsigned int *width, unsigned int *height); /** * @brief Gets the information of the rotating -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @param[in] handle The handle to image util transform -* @param[in,out] rotation The rotation value of image buffer +* @param[in, out] rotation The rotation value of 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_PERMISSION_DENIED The application does not have the privilege to call this funtion * * @pre image_util_transform_create().\n @@ -246,19 +258,20 @@ int image_util_transform_get_rotation(transformation_h handle, image_util_rotati /** * @brief Gets the information of the cropping -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @param[in] handle The handle to image util transform -* @param[in,out] start_x The start x position of cropped source image buffer -* @param[in,out] start_y The start y position of cropped source image buffer -* @param[in,out] end_x The end x position of cropped source image buffer -* @param[in,out] end_y The end y position of cropped source image buffer +* @param[in, out] start_x The start x position of cropped source image buffer +* @param[in, out] start_y The start y position of cropped source image buffer +* @param[in, out] end_x The end x position of cropped source image buffer +* @param[in, out] end_y The end y position of cropped source 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_PERMISSION_DENIED The application does not have the privilege to call this funtion * * @pre image_util_transform_create().\n @@ -271,11 +284,12 @@ int image_util_transform_get_crop_area(transformation_h handle, unsigned int *st /** * @brief Transform the image for given image util handle. -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * -*@remarks If H/W acceleration is not set, transformation is done via S/W acceleration. +* @remarks If H/W acceleration is not set, transformation is done via S/W acceleration. * -* @details The function execute asynchronously, which contains complete callback +* @details The function execute asynchronously, which contains complete callback \n +* If you set more than two transforming, the order of running is crop or resolution, colorspace converting, rotaion. \n * * @param[in] handle The handle of transform * @param[in] src The handle to image util transform @@ -287,6 +301,7 @@ int image_util_transform_get_crop_area(transformation_h handle, unsigned int *st * * @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_PERMISSION_DENIED The application does not have the privilege to call this funtion * * @see image_util_transform_create() @@ -297,7 +312,7 @@ int image_util_transform_run(transformation_h handle, media_packet_h src, image_ /** * @brief Destroys a handle to image util. -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @details The function frees all resources related to the image util handle. The image util * handle no longer can be used to perform any operation. A new image util handle @@ -319,7 +334,7 @@ int image_util_transform_destroy(transformation_h handle); /** * @brief Called once for each supported JPEG encode/decode colorspace. -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @param[in] colorspace The colorspace * @param[in] user_data The user data passed from the foreach function @@ -335,11 +350,11 @@ int image_util_transform_destroy(transformation_h handle); * @see image_util_decode_jpeg() * @see image_util_decode_jpeg_from_memory() */ -typedef bool (*image_util_supported_jpeg_colorspace_cb)( image_util_colorspace_e colorspace , void * user_data); +typedef bool(*image_util_supported_jpeg_colorspace_cb)(image_util_colorspace_e colorspace, void *user_data); /** * @brief Retrieves all supported JPEG encoding/decoding colorspace by invoking a callback function once for each one. -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @param[in] callback The callback function to invoke * @param[in] user_data The user data to be passed to the callback function @@ -357,11 +372,11 @@ typedef bool (*image_util_supported_jpeg_colorspace_cb)( image_util_colorspace_e * @see image_util_decode_jpeg() * @see image_util_decode_jpeg_from_memory() */ -int image_util_foreach_supported_jpeg_colorspace(image_util_supported_jpeg_colorspace_cb callback, void * user_data); +int image_util_foreach_supported_jpeg_colorspace(image_util_supported_jpeg_colorspace_cb callback, void *user_data); /** * @brief Calculates the size of the image buffer for the specified resolution and colorspace. -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @param[in] width The image width * @param[in] height The image height @@ -381,15 +396,17 @@ int image_util_foreach_supported_jpeg_colorspace(image_util_supported_jpeg_color * @see image_util_encode_jpeg() * @see image_util_encode_jpeg_to_memory() */ -int image_util_calculate_buffer_size(int width , int height, image_util_colorspace_e colorspace , unsigned int *size); +int image_util_calculate_buffer_size(int width, int height, image_util_colorspace_e colorspace , unsigned int *size); /** * @brief Decodes the JPEG image to the buffer. -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @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. +* 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 @@ -412,13 +429,15 @@ int image_util_calculate_buffer_size(int width , int height, image_util_colorspa * @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); +int image_util_decode_jpeg(const char *path, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size); /** * @brief Decodes the JPEG image(in memory) to the buffer. -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * -* @remarks You must release @a image_buffer using free(). +* @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 @@ -442,11 +461,78 @@ int image_util_decode_jpeg( const char *path , image_util_colorspace_e colorspac * @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); +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); + +/** +* @brief Decodes the JPEG image to the buffer with downscale decoding option. +* @since_tizen 2.4 +* +* @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); + +/** +* @brief Decodes the JPEG image(in memory) to the buffer with downscale decoding option. +* @since_tizen 2.4 +* +* @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); /** * @brief Encodes the image to the JPEG image. -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @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. @@ -455,7 +541,7 @@ int image_util_decode_jpeg_from_memory( const unsigned char * jpeg_buffer , int * @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] quality The quality for JPEG image encoding(1 ~ 100) * @param[in] path The file path to be created * * @return 0 on success, @@ -472,11 +558,11 @@ int image_util_decode_jpeg_from_memory( const unsigned char * jpeg_buffer , int * @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); +int image_util_encode_jpeg(const unsigned char *buffer, int width, int height, image_util_colorspace_e colorspace, int quality, const char *path); /** * @brief Encodes the image to the JPEG image -* @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @remarks You must release @a jpeg_buffer using free(). * @@ -484,7 +570,7 @@ int image_util_encode_jpeg( const unsigned char *buffer, int width, int height, * @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[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 @@ -503,7 +589,7 @@ int image_util_encode_jpeg( const unsigned char *buffer, int width, int height, * @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); +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); diff --git a/include/image_util_internal.h b/include/image_util_internal.h index afb8984..f8ad80b 100644..100755 --- a/include/image_util_internal.h +++ b/include/image_util_internal.h @@ -32,11 +32,11 @@ extern "C" /** * @internal * @brief Converts the image's colorspace. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @remarks You must get the @a dest buffer size using image_util_transform_calculate_buffer_size(). * -* @param[in,out] dest The image buffer for result \n +* @param[in, out] dest The image buffer for result \n * Must be allocated by the user * @param[in] dest_colorspace The colorspace to be converted * @param[in] src The source image buffer @@ -56,19 +56,19 @@ extern "C" * @see image_util_transform_create() * @see image_util_transform_destroy() */ -int image_util_convert_colorspace( unsigned char * dest , image_util_colorspace_e dest_colorspace , const unsigned char * src , int width, int height, image_util_colorspace_e src_colorspace); +int image_util_convert_colorspace(unsigned char *dest, image_util_colorspace_e dest_colorspace, const unsigned char *src, int width, int height, image_util_colorspace_e src_colorspace); /** * @internal * @brief Resizes the image to the specified destination width and height. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @remarks Because of YUV format padding, the destination image size can be adjusted. * -* @param[in,out] dest The image buffer for result \n +* @param[in, out] dest The image buffer for result \n * Must be allocated by the user. -* @param[in,out] dest_width The image width to resize, and resized width -* @param[in,out] dest_height The image height to resize, and resized height +* @param[in, out] dest_width The image width to resize, and resized width +* @param[in, out] dest_height The image height to resize, and resized height * @param[in] src The image buffer for the original image * @param[in] src_width The original image width * @param[in] src_height The original image height @@ -85,12 +85,12 @@ int image_util_convert_colorspace( unsigned char * dest , image_util_colorspace_ * * @see image_util_transform_calculate_buffer_size() */ -int image_util_resize(unsigned char * dest, int *dest_width , int *dest_height, const unsigned char * src, int src_width, int src_height , image_util_colorspace_e colorspace); +int image_util_resize(unsigned char *dest, int *dest_width, int *dest_height, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace); /** * @internal * @brief Rotates the image to the specified angle given in degrees. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @remarks Because of YUV format padding, the destination image size can be adjusted. * Rotations are supported only in these color spaces\n @@ -104,7 +104,7 @@ int image_util_resize(unsigned char * dest, int *dest_width , int *dest_height, * #IMAGE_UTIL_COLORSPACE_RGBA8888\n * #IMAGE_UTIL_COLORSPACE_BGRX8888\n. * -* @param[in,out] dest The image buffer for result \n +* @param[in, out] dest The image buffer for result \n * Must be allocated by the user. * @param[out] dest_width The rotated image width * @param[out] dest_height The rotated image height @@ -124,12 +124,12 @@ int image_util_resize(unsigned char * dest, int *dest_width , int *dest_height, * * @see image_util_transform_calculate_buffer_size() */ -int image_util_rotate(unsigned char * dest, int *dest_width, int *dest_height, image_util_rotation_e dest_rotation, const unsigned char * src, int src_width, int src_height, image_util_colorspace_e colorspace); +int image_util_rotate(unsigned char *dest, int *dest_width, int *dest_height, image_util_rotation_e dest_rotation, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace); /** * @internal * @brief Crops the image to the specified point and dimension. - * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif +* @since_tizen 2.3 * * @remarks Because of YUV format padding, the destination image size can be adjusted. * Crop is supported only in these colorspaces\n @@ -142,7 +142,7 @@ int image_util_rotate(unsigned char * dest, int *dest_width, int *dest_height, i * #IMAGE_UTIL_COLORSPACE_RGBA8888\n * #IMAGE_UTIL_COLORSPACE_BGRX8888\n. * -* @param[in,out] dest The image buffer for result. Must be allocated by you +* @param[in, out] dest The image buffer for result. Must be allocated by you * @param[in] x The starting x-axis of crop * @param[in] y The starting y-axis of crop * @param[in/out] width The image width to crop, and cropped width @@ -162,7 +162,7 @@ int image_util_rotate(unsigned char * dest, int *dest_width, int *dest_height, i * * @see image_util_transform_calculate_buffer_size() */ -int image_util_crop(unsigned char * dest, int x , int y, int* width, int *height, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace); +int image_util_crop(unsigned char *dest, int x, int y, int *width, int *height, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace); diff --git a/include/image_util_private.h b/include/image_util_private.h index 63f2a02..0722826 100755 --- a/include/image_util_private.h +++ b/include/image_util_private.h @@ -18,21 +18,52 @@ #define __TIZEN_MEDIA_IMAGE_UTIL_PRIVATE_H__ #include <image_util_type.h> +#include <dlog.h> +#include <stdlib.h> #ifdef __cplusplus extern "C" { #endif -typedef struct -{ +#ifdef LOG_TAG +#undef LOG_TAG +#endif + +#define LOG_TAG "CAPI_MEDIA_IMAGE_UTIL" + +#define FONT_COLOR_RESET "\033[0m" +#define FONT_COLOR_RED "\033[31m" + +#define image_util_debug(fmt, arg...) do { \ + LOGD(FONT_COLOR_RESET""fmt"", ##arg); \ + } while (0) + +#define image_util_error(fmt, arg...) do { \ + LOGE(FONT_COLOR_RED""fmt"", ##arg); \ + } while (0) + +#define image_util_retm_if(expr, fmt, arg...) do { \ + if(expr) { \ + LOGE(FONT_COLOR_RED""fmt"", ##arg); \ + return; \ + } \ + } while (0) + +#define image_util_retvm_if(expr, val, fmt, arg...) do { \ + if(expr) { \ + LOGE(FONT_COLOR_RED""fmt"", ##arg); \ + return (val); \ + } \ + } while (0) + +typedef struct { void *user_data; media_packet_h dst; image_util_transform_completed_cb image_processing_completed_cb; } image_util_cb_s; -typedef struct -{ +typedef struct { media_packet_h src; media_packet_h dst; image_util_colorspace_e colorspace; diff --git a/include/image_util_type.h b/include/image_util_type.h index 738d8c0..1d81fba 100755 --- a/include/image_util_type.h +++ b/include/image_util_type.h @@ -39,73 +39,90 @@ extern "C" /** * @brief Enumeration for error. + * @since_tizen 2.3 */ typedef enum { - IMAGE_UTIL_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ - IMAGE_UTIL_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ - IMAGE_UTIL_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ - IMAGE_UTIL_ERROR_NO_SUCH_FILE = TIZEN_ERROR_NO_SUCH_FILE, /**< No such file */ - IMAGE_UTIL_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Internal error */ - IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT = TIZEN_ERROR_IMAGE_UTIL | 0x01, /**< Not supported format */ - IMAGE_UTIL_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ - IMAGE_UTIL_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED /**< Not supported */ -} image_util_error_e; + IMAGE_UTIL_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */ + IMAGE_UTIL_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + IMAGE_UTIL_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + IMAGE_UTIL_ERROR_NO_SUCH_FILE = TIZEN_ERROR_NO_SUCH_FILE, /**< No such file */ + IMAGE_UTIL_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Internal error */ + IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT = TIZEN_ERROR_IMAGE_UTIL | 0x01, /**< Not supported format */ + IMAGE_UTIL_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */ + IMAGE_UTIL_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED /**< Not supported */ +} +image_util_error_e; /** * @brief Enumeration for colorspace. + * @since_tizen 2.3 */ -typedef enum -{ - IMAGE_UTIL_COLORSPACE_YV12, /**< YV12 - YCrCb planar format */ - IMAGE_UTIL_COLORSPACE_YUV422, /**< YUV422 - planar */ - IMAGE_UTIL_COLORSPACE_I420, /**< YUV420 - planar */ - IMAGE_UTIL_COLORSPACE_NV12, /**< NV12- planar */ - - IMAGE_UTIL_COLORSPACE_UYVY, /**< UYVY - packed */ - IMAGE_UTIL_COLORSPACE_YUYV, /**< YUYV - packed */ - - IMAGE_UTIL_COLORSPACE_RGB565, /**< RGB565, high-byte is Blue */ - IMAGE_UTIL_COLORSPACE_RGB888, /**< RGB888, high-byte is Blue */ - IMAGE_UTIL_COLORSPACE_ARGB8888, /**< ARGB8888, high-byte is Blue */ - - IMAGE_UTIL_COLORSPACE_BGRA8888, /**< BGRA8888, high-byte is Alpha */ - IMAGE_UTIL_COLORSPACE_RGBA8888, /**< RGBA8888, high-byte is Alpha */ - IMAGE_UTIL_COLORSPACE_BGRX8888, /**< BGRX8888, high-byte is X */ - IMAGE_UTIL_COLORSPACE_NV21, /**< NV12- planar */ - IMAGE_UTIL_COLORSPACE_NV16, /**< NV16- planar */ - IMAGE_UTIL_COLORSPACE_NV61, /**< NV61- planar */ -}image_util_colorspace_e; +typedef enum { + IMAGE_UTIL_COLORSPACE_YV12, /**< YV12 - YCrCb planar format */ + IMAGE_UTIL_COLORSPACE_YUV422, /**< YUV422 - planar */ + IMAGE_UTIL_COLORSPACE_I420, /**< YUV420 - planar */ + IMAGE_UTIL_COLORSPACE_NV12, /**< NV12- planar */ + + IMAGE_UTIL_COLORSPACE_UYVY, /**< UYVY - packed */ + IMAGE_UTIL_COLORSPACE_YUYV, /**< YUYV - packed */ + + IMAGE_UTIL_COLORSPACE_RGB565, /**< RGB565, high-byte is Blue */ + IMAGE_UTIL_COLORSPACE_RGB888, /**< RGB888, high-byte is Blue */ + IMAGE_UTIL_COLORSPACE_ARGB8888, /**< ARGB8888, high-byte is Blue */ + + IMAGE_UTIL_COLORSPACE_BGRA8888, /**< BGRA8888, high-byte is Alpha */ + IMAGE_UTIL_COLORSPACE_RGBA8888, /**< RGBA8888, high-byte is Alpha */ + IMAGE_UTIL_COLORSPACE_BGRX8888, /**< BGRX8888, high-byte is X */ + IMAGE_UTIL_COLORSPACE_NV21, /**< NV12- planar */ + IMAGE_UTIL_COLORSPACE_NV16, /**< NV16- planar */ + IMAGE_UTIL_COLORSPACE_NV61, /**< NV61- planar */ +} image_util_colorspace_e; + +/** + * @brief Enumeration for scale decoding. + * @since_tizen 2.4 + */ +typedef enum { + IMAGE_UTIL_DOWNSCALE_1_1, /** 1/1 downscale */ + IMAGE_UTIL_DOWNSCALE_1_2, /** 1/2 downscale */ + IMAGE_UTIL_DOWNSCALE_1_4, /** 1/4 downscale */ + IMAGE_UTIL_DOWNSCALE_1_8, /** 1/8 downscale */ +} image_util_scale_e; /** * @brief Enumeration for rotation. + * @since_tizen 2.3 */ -typedef enum -{ - IMAGE_UTIL_ROTATION_NONE = 0, /**< None */ - IMAGE_UTIL_ROTATION_90, /**< Rotation 90 degree */ - IMAGE_UTIL_ROTATION_180, /**< Rotation 180 degree */ - IMAGE_UTIL_ROTATION_270, /**< Rotation 270 degree */ - IMAGE_UTIL_ROTATION_FLIP_HORZ, /**< Flip horizontal */ - IMAGE_UTIL_ROTATION_FLIP_VERT, /**< Flip vertical */ +typedef enum { + IMAGE_UTIL_ROTATION_NONE = 0, /**< None */ + IMAGE_UTIL_ROTATION_90, /**< Rotation 90 degree */ + IMAGE_UTIL_ROTATION_180, /**< Rotation 180 degree */ + IMAGE_UTIL_ROTATION_270, /**< Rotation 270 degree */ + IMAGE_UTIL_ROTATION_FLIP_HORZ, /**< Flip horizontal */ + IMAGE_UTIL_ROTATION_FLIP_VERT, /**< Flip vertical */ } image_util_rotation_e; /** * @ingroup CAPI_MEDIA_IMAGE_UTIL_MODULE * @brief Image util handle. +* @since_tizen 2.3 */ typedef struct transformation_s *transformation_h; /** * @ingroup CAPI_MEDIA_IMAGE_UTIL_MODULE * @brief Called when transform is finished just before returning the output. +* @since_tizen 2.3 +* +* @remarks You must release the @a dst result using media_packet_destroy(). * * @param[in] error_code The error code of image util transfrom -* @param[in,out] dst The result buffer of image util transform +* @param[in, out] dst The result buffer of image util transform * @param[in] user_data The user data passed from the callback registration function * @pre image_util_transform_run() will invoke this function. */ -typedef void (*image_util_transform_completed_cb)(media_packet_h *dst, int error_code, void *user_data); +typedef void(*image_util_transform_completed_cb)(media_packet_h *dst, int error_code, void *user_data); /** * @} diff --git a/packaging/capi-media-image-util.spec b/packaging/capi-media-image-util.spec index d58b67e..a7331e5 100755 --- a/packaging/capi-media-image-util.spec +++ b/packaging/capi-media-image-util.spec @@ -1,7 +1,7 @@ Name: capi-media-image-util Summary: A Image Utility library in Tizen Native API -Version: 0.1.3 -Release: 28 +Version: 0.1.10 +Release: 31 Group: System/Libraries License: Apache-2.0 Source0: %{name}-%{version}.tar.gz @@ -12,8 +12,6 @@ BuildRequires: pkgconfig(mmutil-imgp) BuildRequires: pkgconfig(capi-base-common) BuildRequires: pkgconfig(capi-media-tool) BuildRequires: cmake -BuildRequires: gettext-devel -BuildRequires: model-build-features %description A Image Utility library in Tizen Native API @@ -36,6 +34,9 @@ A Image Utility library in Tizen Native API (Developement) %setup -q %build +export CFLAGS+=" -Wextra -Wno-array-bounds" +export CFLAGS+=" -Wno-ignored-qualifiers -Wno-unused-parameter -Wshadow" +export CFLAGS+=" -Wwrite-strings -Wswitch-default" MAJORVER=`echo %{version} | awk 'BEGIN {FS="."}{print $1}'` cmake . -DCMAKE_INSTALL_PREFIX=/usr -DFULLVER=%{version} -DMAJORVER=${MAJORVER} \ %if 0%{?model_build_feature_multimedia_image_hw_acceleration} diff --git a/src/image_util.c b/src/image_util.c index 3b47854..0c2b962 100755 --- a/src/image_util.c +++ b/src/image_util.c @@ -14,7 +14,6 @@ * limitations under the License. */ -#define LOG_TAG "CAPI_MEDIA_IMAGE_UTIL" #include <dlog.h> #include <mm_util_imgp.h> @@ -32,8 +31,8 @@ #define IMAGE_UTIL_SAFE_FREE(src) { if(src) {free(src); src = NULL;}} static int _convert_colorspace_tbl[] = { - MM_UTIL_IMG_FMT_YUV420 , /* IMAGE_UTIL_COLORSPACE_YUV420 */ - MM_UTIL_IMG_FMT_YUV422 , /* IMAGE_UTIL_COLORSPACE_YUV422 */ + MM_UTIL_IMG_FMT_YUV420, /* IMAGE_UTIL_COLORSPACE_YUV420 */ + MM_UTIL_IMG_FMT_YUV422, /* IMAGE_UTIL_COLORSPACE_YUV422 */ MM_UTIL_IMG_FMT_I420, /* IMAGE_UTIL_COLORSPACE_I420 */ MM_UTIL_IMG_FMT_NV12, /* IMAGE_UTIL_COLORSPACE_NV12 */ MM_UTIL_IMG_FMT_UYVY, /* IMAGE_UTIL_COLORSPACE_UYVY */ @@ -56,82 +55,88 @@ static int _convert_encode_colorspace_tbl[] = { MM_UTIL_JPEG_FMT_YUV420 , /* IMAGE_UTIL_COLORSPACE_I420 */ MM_UTIL_JPEG_FMT_NV12 , /* IMAGE_UTIL_COLORSPACE_NV12 */ -1 , /* IMAGE_UTIL_COLORSPACE_UYVY */ - MM_UTIL_JPEG_FMT_YUYV , /* IMAGE_UTIL_COLORSPACE_YUYV */ + -1 , /* IMAGE_UTIL_COLORSPACE_YUYV */ -1 , /* IMAGE_UTIL_COLORSPACE_RGB565 */ MM_UTIL_JPEG_FMT_RGB888 , /* IMAGE_UTIL_COLORSPACE_RGB888 */ MM_UTIL_JPEG_FMT_ARGB8888 , /* IMAGE_UTIL_COLORSPACE_ARGB8888 */ MM_UTIL_JPEG_FMT_BGRA8888 , /* IMAGE_UTIL_COLORSPACE_BGRA8888 */ MM_UTIL_JPEG_FMT_RGBA8888 , /* IMAGE_UTIL_COLORSPACE_RGBA8888 */ -1 , /* IMAGE_UTIL_COLORSPACE_BGRX8888 */ - MM_UTIL_JPEG_FMT_NV21 , /* IMAGE_UTIL_COLORSPACE_NV21 */ - MM_UTIL_JPEG_FMT_NV16 , /* IMAGE_UTIL_COLORSPACE_NV16 */ - MM_UTIL_JPEG_FMT_NV61 , /* IMAGE_UTIL_COLORSPACE_NV61 */ + -1 , /* IMAGE_UTIL_COLORSPACE_NV21 */ + -1 , /* IMAGE_UTIL_COLORSPACE_NV16 */ + -1 , /* IMAGE_UTIL_COLORSPACE_NV61 */ }; +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, +}; -static int _convert_image_util_error_code(const char *func, int code){ +static int _convert_image_util_error_code(const char *func, int code) +{ int ret = IMAGE_UTIL_ERROR_INVALID_OPERATION; char *errorstr = NULL; - switch(code) - { + switch (code) { case MM_ERROR_NONE: ret = IMAGE_UTIL_ERROR_NONE; - errorstr = "ERROR_NONE"; + errorstr = strdup("ERROR_NONE"); break; - case MM_ERROR_IMAGE_FILEOPEN : - case IMAGE_UTIL_ERROR_NO_SUCH_FILE : + case MM_ERROR_IMAGE_FILEOPEN: + case IMAGE_UTIL_ERROR_NO_SUCH_FILE: ret = IMAGE_UTIL_ERROR_NO_SUCH_FILE; - errorstr = "NO_SUCH_FILE"; + errorstr = strdup("NO_SUCH_FILE"); break; - case MM_ERROR_IMAGE_INTERNAL : + case MM_ERROR_IMAGE_INTERNAL: ret = IMAGE_UTIL_ERROR_INVALID_OPERATION; - errorstr = "INVALID_OPERATION"; + errorstr = strdup("INVALID_OPERATION"); break; case IMAGE_UTIL_ERROR_INVALID_PARAMETER: + case MM_ERROR_IMAGEHANDLE_NOT_INITIALIZED: case MM_ERROR_NO_DECODED_DATA: case MM_ERROR_IMAGE_INVALID_VALUE: ret = IMAGE_UTIL_ERROR_INVALID_PARAMETER; - errorstr = "INVALID_PARAMETER"; + errorstr = strdup("INVALID_PARAMETER"); break; case MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT: case MM_ERROR_IMAGE_DEVICE_NOT_SUPPORT: ret = IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT; - errorstr = "NOT_SUPPORTED_FORMAT"; + errorstr = strdup("NOT_SUPPORTED_FORMAT"); + break; + case MM_ERROR_IMAGE_NO_FREE_SPACE: + ret = IMAGE_UTIL_ERROR_OUT_OF_MEMORY; + errorstr = strdup("OUT_OF_MEMORY"); break; - - default: ret = IMAGE_UTIL_ERROR_INVALID_OPERATION; - errorstr = "INVALID_OPERATION"; + errorstr = strdup("INVALID_OPERATION"); } - LOGD( "[%s] %s(0x%08x)",func, errorstr, ret); + image_util_debug("[%s] %s(0x%08x)", func, errorstr, ret); + IMAGE_UTIL_SAFE_FREE(errorstr); return ret; } static image_util_error_e _image_util_error_convert(int error) { - if(error == MM_ERROR_NONE) - { - LOGD("Error None"); - return IMAGE_UTIL_ERROR_NONE; - } - else if(error == MM_ERROR_IMAGE_INVALID_VALUE) - { - LOGE("INVALID_PARAMETER(0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER); - return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - } - else if(error == MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT) - { - LOGE("NOT_SUPPORTED_FORMAT(0x%08x)", IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT); - return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + switch (error) { + case MM_ERROR_NONE: + image_util_debug("Error None"); + return IMAGE_UTIL_ERROR_NONE; + case MM_ERROR_IMAGE_INVALID_VALUE: + image_util_error("INVALID_PARAMETER(0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER); + return IMAGE_UTIL_ERROR_INVALID_PARAMETER; + case MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT: + image_util_error("NOT_SUPPORTED_FORMAT(0x%08x)", IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT); + return IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT; + default: + image_util_error("INVALID_OPERATION(0x%08x)", error); + return IMAGE_UTIL_ERROR_INVALID_OPERATION; } - - LOGE("INVALID_OPERATION(0x%08x)", error); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; } static void _image_util_transform_completed_cb(media_packet_h *dst, int error, void *user_data) @@ -139,8 +144,7 @@ static void _image_util_transform_completed_cb(media_packet_h *dst, int error, v int error_value = IMAGE_UTIL_ERROR_NONE; image_util_cb_s *_util_cb = (image_util_cb_s *)user_data; - if((_util_cb != NULL) && (_util_cb->image_processing_completed_cb != NULL)) - { + if ((_util_cb != NULL) && (_util_cb->image_processing_completed_cb != NULL)) { error_value = _image_util_error_convert(error); _util_cb->image_processing_completed_cb(dst, error_value, _util_cb->user_data); } @@ -155,63 +159,38 @@ static int _image_util_create_transform_handle(transformation_s *handle) ret = mm_util_create(&image_h); - if(ret == MM_ERROR_NONE) - { - handle->image_h = image_h; - } - else - { - LOGE("Error in mm_util_create"); - } + image_util_retvm_if((ret != MM_ERROR_NONE), ret, "Error in mm_util_create"); + + handle->image_h = image_h; return ret; } static bool _image_util_check_resolution(int width, int height) { - if(width <= 0) - { - LOGE("invalid width [%d]", width); + if (width <= 0) { + image_util_error("invalid width [%d]", width); return false; } - if(height <= 0) - { - LOGE("invalid height [%d]", height); + if (height <= 0) { + image_util_error("invalid height [%d]", height); return false; } return true; } -int _image_util_check_transcode_is_completed(transformation_s * handle, bool *is_completed) -{ - int ret = IMAGE_UTIL_ERROR_NONE; - - if(handle && handle->image_h) - { - ret = mm_transform_is_completed(handle->image_h, is_completed); - } - else - { - LOGE("Invalid Handle"); - return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - } - - ret = _convert_image_util_error_code(__func__, ret); - - return ret; -} - -int image_util_foreach_supported_jpeg_colorspace(image_util_supported_jpeg_colorspace_cb callback, void * user_data) +int image_util_foreach_supported_jpeg_colorspace(image_util_supported_jpeg_colorspace_cb callback, void *user_data) { int i = 0; - if( callback == NULL ) + if (callback == NULL) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - for( i = sizeof(_convert_encode_colorspace_tbl)/sizeof(int) -1; i >= 0; i--) { /* RGB has higher precedence than YUV */ - if ( _convert_encode_colorspace_tbl[i] != -1) - if( false == callback(i , user_data) ) + /* RGB has higher precedence than YUV */ + for (i = sizeof(_convert_encode_colorspace_tbl) / sizeof(int) - 1; i >= 0; i--) { + if (_convert_encode_colorspace_tbl[i] != -1) + if (false == callback(i, user_data)) return IMAGE_UTIL_ERROR_NONE; } @@ -223,20 +202,12 @@ int image_util_transform_create(transformation_h *handle) { int ret = IMAGE_UTIL_ERROR_NONE; - LOGD("image_util_create"); + image_util_debug("image_util_create"); - if(handle == NULL) - { - LOGE("Invalid Handle"); - return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - } + image_util_retvm_if((handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); - transformation_s *_handle = (transformation_s*)calloc(1,sizeof(transformation_s)); - if(_handle == NULL) - { - LOGE("OUT_OF_MEMORY(0x%08x)", IMAGE_UTIL_ERROR_OUT_OF_MEMORY); - return IMAGE_UTIL_ERROR_OUT_OF_MEMORY; - } + transformation_s *_handle = (transformation_s *)calloc(1, sizeof(transformation_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->colorspace = -1; _handle->_util_cb = NULL; @@ -248,45 +219,34 @@ int image_util_transform_create(transformation_h *handle) _handle->set_crop = false; ret = _image_util_create_transform_handle(_handle); - if(ret != MM_ERROR_NONE) - { - LOGE("INVALID_OPERATION"); + if (ret != MM_ERROR_NONE) { + image_util_error("INVALID_OPERATION"); IMAGE_UTIL_SAFE_FREE(_handle); return IMAGE_UTIL_ERROR_INVALID_OPERATION; } *handle = (transformation_h)_handle; - return ret; + return _convert_image_util_error_code(__func__, ret); } int image_util_transform_set_hardware_acceleration(transformation_h handle, bool mode) { - transformation_s *_handle = (transformation_s*)handle; - - LOGD("Set hardware_acceleration %d", mode); + int ret = IMAGE_UTIL_ERROR_NONE; + transformation_s *_handle = (transformation_s *)handle; - if(_handle == NULL) - { - LOGE("Invalid Handle"); - return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - } + image_util_debug("Set hardware_acceleration %d", mode); + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); #ifndef ENABLE_HW_ACCELERATION - if(mode == true) { - LOGE("hardware acceleration is not supported"); - return IMAGE_UTIL_ERROR_NOT_SUPPORTED; - } + image_util_retvm_if((mode == true), IMAGE_UTIL_ERROR_NOT_SUPPORTED, "hardware acceleration is not supported"); #endif - if(mm_util_set_hardware_acceleration(_handle->image_h, mode) == MM_ERROR_NONE) - { - LOGD("Set hardware_acceleration %d", mode); - _handle->hardware_acceleration = mode; - } else { - LOGE("Error - Set hardware_acceleration"); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } + ret = mm_util_set_hardware_acceleration(_handle->image_h, mode); + image_util_retvm_if((ret != MM_ERROR_NONE), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Error - Set hardware_acceleration"); + + image_util_debug("Set hardware_acceleration %d", mode); + _handle->hardware_acceleration = mode; return IMAGE_UTIL_ERROR_NONE; } @@ -294,154 +254,112 @@ int image_util_transform_set_hardware_acceleration(transformation_h handle, boo int image_util_transform_set_colorspace(transformation_h handle, image_util_colorspace_e colorspace) { int ret = IMAGE_UTIL_ERROR_NONE; - transformation_s *_handle = (transformation_s*)handle; + transformation_s *_handle = (transformation_s *)handle; - LOGD("Set colorspace_convert_info [%d]", colorspace); + image_util_debug("Set colorspace_convert_info [%d]", colorspace); - if(_handle == NULL) - { - LOGE("Invalid Handle"); - return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - } + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); ret = mm_util_set_colorspace_convert(_handle->image_h, colorspace); - if(ret != MM_ERROR_NONE) - { - LOGE("IMAGE_UTIL_ERROR_INVALID_OPERATION(0x%08x)", IMAGE_UTIL_ERROR_INVALID_OPERATION); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } + image_util_retvm_if((ret != MM_ERROR_NONE), IMAGE_UTIL_ERROR_INVALID_OPERATION, "IMAGE_UTIL_ERROR_INVALID_OPERATION(0x%08x)", IMAGE_UTIL_ERROR_INVALID_OPERATION); _handle->colorspace = colorspace; _handle->set_convert = true; - return ret; + return _convert_image_util_error_code(__func__, ret); } int image_util_transform_set_resolution(transformation_h handle, unsigned int width, unsigned int height) { int ret = IMAGE_UTIL_ERROR_NONE; - transformation_s *_handle = (transformation_s*)handle; + transformation_s *_handle = (transformation_s *)handle; - LOGD("Set resize_info w[%d] h[%d]", width, height); + image_util_debug("Set resize_info w[%d] h[%d]", width, height); - if(_handle == NULL) - { - LOGE("Invalid Handle"); - return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - } + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((_handle->set_crop), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Crop and Resize can't do at the same time"); - if(_handle->set_crop) - { - LOGE("Crop and Resize can't do at the same time"); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } - - if(_image_util_check_resolution(width, height)) { + if (_image_util_check_resolution(width, height)) { ret = mm_util_set_resolution(_handle->image_h, width, height); - if(ret != MM_ERROR_NONE) { - LOGE("IMAGE_UTIL_ERROR_INVALID_OPERATION(0x%08x)", IMAGE_UTIL_ERROR_INVALID_OPERATION); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } + image_util_retvm_if((ret != MM_ERROR_NONE), IMAGE_UTIL_ERROR_INVALID_OPERATION, "IMAGE_UTIL_ERROR_INVALID_OPERATION(0x%08x)", IMAGE_UTIL_ERROR_INVALID_OPERATION); _handle->width = width; _handle->height = height; _handle->set_resize = true; - } - else - { - LOGE("INVALID_PARAMETER"); + } else { + image_util_error("INVALID_PARAMETER"); return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } - return ret; + return _convert_image_util_error_code(__func__, ret); } int image_util_transform_set_rotation(transformation_h handle, image_util_rotation_e rotation) { int ret = IMAGE_UTIL_ERROR_NONE; - transformation_s *_handle = (transformation_s*)handle; + transformation_s *_handle = (transformation_s *)handle; - LOGD("Set rotate_info [%d]", rotation); + image_util_debug("Set rotate_info [%d]", rotation); - if(_handle == NULL) - { - LOGE("Invalid Handle"); - return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - } + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); ret = mm_util_set_rotation(_handle->image_h, rotation); - if(ret != MM_ERROR_NONE) - { - LOGE("IMAGE_UTIL_ERROR_INVALID_OPERATION(0x%08x)", IMAGE_UTIL_ERROR_INVALID_OPERATION); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } + image_util_retvm_if((ret != MM_ERROR_NONE), IMAGE_UTIL_ERROR_INVALID_OPERATION, "IMAGE_UTIL_ERROR_INVALID_OPERATION(0x%08x)", IMAGE_UTIL_ERROR_INVALID_OPERATION); _handle->rotation = rotation; _handle->set_rotate = true; - return ret; + return _convert_image_util_error_code(__func__, ret); } int image_util_transform_set_crop_area(transformation_h handle, unsigned int start_x, unsigned int start_y, unsigned int end_x, unsigned int end_y) { int ret = IMAGE_UTIL_ERROR_NONE; - transformation_s *_handle = (transformation_s*)handle; + transformation_s *_handle = (transformation_s *)handle; int dest_width; int dest_height; - if(_handle == NULL) - { - LOGE("Invalid Handle"); - return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - } - - if(_handle->set_resize) - { - LOGE("Crop and Resize can't do at the same time"); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); + image_util_retvm_if((_handle->set_resize), IMAGE_UTIL_ERROR_INVALID_OPERATION, "Crop and Resize can't do at the same time"); dest_width = end_x - start_x; dest_height = end_y - start_y; - LOGD("Set crop_info x[%d] y[%d] w[%d] h[%d]", start_x, start_y, dest_width, dest_height); + image_util_debug("Set crop_info x[%d] y[%d] w[%d] h[%d]", start_x, start_y, dest_width, dest_height); - if(_image_util_check_resolution(dest_width, dest_height)) - { + if (_image_util_check_resolution(dest_width, dest_height)) { ret = mm_util_set_crop_area(_handle->image_h, start_x, start_y, end_x, end_y); - if(ret != MM_ERROR_NONE) { - LOGE("IMAGE_UTIL_ERROR_INVALID_OPERATION(0x%08x)", IMAGE_UTIL_ERROR_INVALID_OPERATION); - return IMAGE_UTIL_ERROR_INVALID_OPERATION; - } + image_util_retvm_if((ret != MM_ERROR_NONE), IMAGE_UTIL_ERROR_INVALID_OPERATION, "IMAGE_UTIL_ERROR_INVALID_OPERATION(0x%08x)", IMAGE_UTIL_ERROR_INVALID_OPERATION); _handle->start_x = start_x; _handle->start_y = start_y; _handle->end_x = end_x; _handle->end_y = end_y; _handle->set_crop = true; - } - else - { - LOGE("INVALID_PARAMETER"); + } else { + image_util_error("INVALID_PARAMETER"); return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } - return ret; + return _convert_image_util_error_code(__func__, ret); } int image_util_transform_get_colorspace(transformation_h handle, image_util_colorspace_e *colorspace) { int ret = IMAGE_UTIL_ERROR_NONE; - transformation_s *_handle = (transformation_s*)handle; + transformation_s *_handle = (transformation_s *)handle; - LOGD("Get colorspace_convert_info [%d]", colorspace); + image_util_debug("Get colorspace_convert_info [%d]", colorspace); - if(_handle == NULL) - { - LOGE("Invalid Handle"); + if (_handle == NULL) { + image_util_error("Invalid Handle"); return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } - if(!colorspace) - { - LOGE("colorspace area parameter error"); + if (!colorspace) { + image_util_error("colorspace area parameter error"); + return IMAGE_UTIL_ERROR_INVALID_OPERATION; + } + + if (!_handle->set_convert) { + image_util_error("Did not set colorspace before"); return IMAGE_UTIL_ERROR_INVALID_OPERATION; } @@ -452,19 +370,22 @@ int image_util_transform_get_colorspace(transformation_h handle, image_util_colo int image_util_transform_get_resolution(transformation_h handle, unsigned int *width, unsigned int *height) { int ret = IMAGE_UTIL_ERROR_NONE; - transformation_s *_handle = (transformation_s*)handle; + transformation_s *_handle = (transformation_s *)handle; - LOGD("Set resize_info w[%d] h[%d]", width, height); + image_util_debug("Set resize_info w[%d] h[%d]", width, height); - if(_handle == NULL) - { - LOGE("Invalid Handle"); + if (_handle == NULL) { + image_util_error("Invalid Handle"); return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } - if(!width || !height) - { - LOGE("resolution area parameter error"); + if (!width || !height) { + image_util_error("resolution area parameter error"); + return IMAGE_UTIL_ERROR_INVALID_OPERATION; + } + + if (!_handle->set_resize) { + image_util_error("Did not set resolution before"); return IMAGE_UTIL_ERROR_INVALID_OPERATION; } @@ -477,19 +398,22 @@ int image_util_transform_get_resolution(transformation_h handle, unsigned int *w int image_util_transform_get_rotation(transformation_h handle, image_util_rotation_e *rotation) { int ret = IMAGE_UTIL_ERROR_NONE; - transformation_s *_handle = (transformation_s*)handle; + transformation_s *_handle = (transformation_s *)handle; - LOGD("Set rotate_info [%d]", rotation); + image_util_debug("Set rotate_info [%d]", rotation); - if(_handle == NULL) - { - LOGE("Invalid Handle"); + if (_handle == NULL) { + image_util_error("Invalid Handle"); return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } - if(!rotation) - { - LOGE("rotation area parameter error"); + if (!rotation) { + image_util_error("rotation area parameter error"); + return IMAGE_UTIL_ERROR_INVALID_OPERATION; + } + + if (!_handle->set_rotate) { + image_util_error("Did not set rotation before"); return IMAGE_UTIL_ERROR_INVALID_OPERATION; } @@ -501,23 +425,20 @@ int image_util_transform_get_rotation(transformation_h handle, image_util_rotati int image_util_transform_get_crop_area(transformation_h handle, unsigned int *start_x, unsigned int *start_y, unsigned int *end_x, unsigned int *end_y) { int ret = IMAGE_UTIL_ERROR_NONE; - transformation_s *_handle = (transformation_s*)handle; + transformation_s *_handle = (transformation_s *)handle; - if(_handle == NULL) - { - LOGE("Invalid Handle"); + if (_handle == NULL) { + image_util_error("Invalid Handle"); return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } - if(_handle->set_resize) - { - LOGE("Crop and Resize can't do at the same time"); + if (!start_x || !start_y || !end_x || !end_y) { + image_util_error("crop area parameter error"); return IMAGE_UTIL_ERROR_INVALID_OPERATION; } - if(!start_x || !start_y || !end_x ||!end_y) - { - LOGE("crop area parameter error"); + if (!_handle->set_crop) { + image_util_error("Did not set crop area before"); return IMAGE_UTIL_ERROR_INVALID_OPERATION; } @@ -532,40 +453,31 @@ int image_util_transform_get_crop_area(transformation_h handle, unsigned int *st int image_util_transform_run(transformation_h handle, media_packet_h src, image_util_transform_completed_cb completed_cb, void *user_data) { int ret = IMAGE_UTIL_ERROR_NONE; - transformation_s *_handle = (transformation_s*)handle; + transformation_s *_handle = (transformation_s *)handle; - LOGD("image_util_transform"); + image_util_debug("image_util_transform"); - if(_handle == NULL) - { - LOGE("Invalid Handle"); - return IMAGE_UTIL_ERROR_INVALID_PARAMETER; - } + image_util_retvm_if((_handle == NULL), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid Handle"); - if(completed_cb) - { - _handle->_util_cb = (image_util_cb_s*)calloc(1, sizeof(image_util_cb_s)); - if(!_handle->_util_cb) { - LOGE("Out of memory"); - return IMAGE_UTIL_ERROR_OUT_OF_MEMORY; + if (completed_cb) { + if (_handle->_util_cb != NULL) { + IMAGE_UTIL_SAFE_FREE(_handle->_util_cb); + _handle->_util_cb = NULL; } + _handle->_util_cb = (image_util_cb_s *)calloc(1, sizeof(image_util_cb_s)); + image_util_retvm_if((_handle->_util_cb == NULL), IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "Out of memory"); _handle->_util_cb->user_data = user_data; _handle->_util_cb->image_processing_completed_cb = completed_cb; - } - else - { - LOGE("INVALID_PARAMETER[completed_cb] (0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER); + } else { + image_util_error("INVALID_PARAMETER[completed_cb](0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER); return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } - if(_handle->_util_cb && src && (_handle->set_convert || _handle->set_resize || _handle->set_rotate || _handle->set_crop)) - { + if (_handle->_util_cb && src && (_handle->set_convert || _handle->set_resize || _handle->set_rotate || _handle->set_crop)) { ret = mm_util_transform(_handle->image_h, src, (mm_util_completed_callback)_image_util_transform_completed_cb, (void *)_handle->_util_cb); - } - else - { - LOGE("INVALID_PARAMETER[transform] (0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER); + } else { + image_util_error("INVALID_PARAMETER[transform] (0x%08x)", IMAGE_UTIL_ERROR_INVALID_PARAMETER); return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } return _convert_image_util_error_code(__func__, ret); @@ -574,13 +486,12 @@ int image_util_transform_run(transformation_h handle, media_packet_h src, image_ int image_util_transform_destroy(transformation_h handle) { int ret = IMAGE_UTIL_ERROR_NONE; - transformation_s *_handle = (transformation_s*)handle; + transformation_s *_handle = (transformation_s *)handle; - LOGD("image_util_destroy"); + image_util_debug("image_util_destroy"); - if(_handle == NULL) - { - LOGE("Invalid Handle"); + if (_handle == NULL) { + image_util_error("Invalid Handle"); return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } @@ -589,57 +500,57 @@ int image_util_transform_destroy(transformation_h handle) IMAGE_UTIL_SAFE_FREE(_handle->_util_cb); IMAGE_UTIL_SAFE_FREE(_handle); - return ret; + return _convert_image_util_error_code(__func__, ret); } -int image_util_convert_colorspace( unsigned char * dest , image_util_colorspace_e dest_colorspace , const unsigned char * src , int width, int height, image_util_colorspace_e src_colorspace) +int image_util_convert_colorspace(unsigned char *dest, image_util_colorspace_e dest_colorspace, const unsigned char *src, int width, int height, image_util_colorspace_e src_colorspace) { int ret = IMAGE_UTIL_ERROR_NONE; - if( dest == NULL || src == NULL ) + if (dest == NULL || src == NULL) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( dest_colorspace < 0 || dest_colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int)) + if (dest_colorspace < 0 || dest_colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int)) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( src_colorspace < 0 || src_colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int)) + if (src_colorspace < 0 || src_colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int)) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - ret = mm_util_convert_colorspace(src, width, height, _convert_colorspace_tbl[src_colorspace] , dest, _convert_colorspace_tbl[dest_colorspace]); + ret = mm_util_convert_colorspace(src, width, height, _convert_colorspace_tbl[src_colorspace], dest, _convert_colorspace_tbl[dest_colorspace]); return _convert_image_util_error_code(__func__, ret); } -int image_util_calculate_buffer_size(int width , int height, image_util_colorspace_e colorspace ,unsigned int *size) +int image_util_calculate_buffer_size(int width, int height, image_util_colorspace_e colorspace , unsigned int *size) { int ret = IMAGE_UTIL_ERROR_NONE; - if( colorspace < 0 || width <= 0 || height <= 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int) || size == NULL) + if (colorspace < 0 || width <= 0 || height <= 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int) || size == NULL) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); ret = mm_util_get_image_size(_convert_colorspace_tbl[colorspace], width, height, size); return _convert_image_util_error_code(__func__, ret); } -int image_util_resize(unsigned char * dest, int *dest_width , int *dest_height, const unsigned char * src, int src_width, int src_height , image_util_colorspace_e colorspace) +int image_util_resize(unsigned char *dest, int *dest_width, int *dest_height, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace) { int ret = IMAGE_UTIL_ERROR_NONE; - if( dest == NULL || src == NULL ) + if (dest == NULL || src == NULL) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int)) + if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int)) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( dest_width == NULL || dest_height == NULL) + if (dest_width == NULL || dest_height == NULL) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( *dest_width <= 0 || *dest_height <= 0 ) + if (*dest_width <= 0 || *dest_height <= 0) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); unsigned int dest_w, dest_h; dest_w = *dest_width; dest_h = *dest_height; - ret = mm_util_resize_image(src, src_width, src_height, _convert_colorspace_tbl[colorspace], dest,&dest_w, &dest_h); - if( ret == 0){ + ret = mm_util_resize_image(src, src_width, src_height, _convert_colorspace_tbl[colorspace], dest, &dest_w, &dest_h); + if (ret == 0) { *dest_width = dest_w; *dest_height = dest_h; } @@ -647,46 +558,46 @@ int image_util_resize(unsigned char * dest, int *dest_width , int *dest_height, return _convert_image_util_error_code(__func__, ret); } -int image_util_rotate(unsigned char * dest, int *dest_width, int *dest_height, image_util_rotation_e dest_rotation, const unsigned char * src, int src_width, int src_height, image_util_colorspace_e colorspace) +int image_util_rotate(unsigned char *dest, int *dest_width, int *dest_height, image_util_rotation_e dest_rotation, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace) { int ret = IMAGE_UTIL_ERROR_NONE; - if( dest == NULL || src == NULL ) + if (dest == NULL || src == NULL) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int)) + if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int)) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( dest_rotation < 0 || dest_rotation > IMAGE_UTIL_ROTATION_FLIP_VERT ) + if (dest_rotation < 0 || dest_rotation > IMAGE_UTIL_ROTATION_FLIP_VERT) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( dest_width == NULL || dest_height == NULL) + if (dest_width == NULL || dest_height == NULL) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); unsigned int dest_w, dest_h; - ret = mm_util_rotate_image(src, src_width, src_height, _convert_colorspace_tbl[colorspace], dest,&dest_w, &dest_h, dest_rotation); - if( ret == 0){ + ret = mm_util_rotate_image(src, src_width, src_height, _convert_colorspace_tbl[colorspace], dest, &dest_w, &dest_h, dest_rotation); + if (ret == 0) { *dest_width = dest_w; *dest_height = dest_h; } return _convert_image_util_error_code(__func__, ret); } -int image_util_crop(unsigned char * dest, int x , int y, int* width, int* height, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace) +int image_util_crop(unsigned char *dest, int x, int y, int *width, int *height, const unsigned char *src, int src_width, int src_height, image_util_colorspace_e colorspace) { int ret = IMAGE_UTIL_ERROR_NONE; - if( dest == NULL || src == NULL ) + if (dest == NULL || src == NULL) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int)) + if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int)) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( width == NULL ) + if (width == NULL) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( src_width <= x || src_height <= y || src_width < x+*width || src_height< y+*height) + if (src_width <= x || src_height <= y || src_width < x + *width || src_height < y + *height) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); unsigned int dest_w, dest_h; dest_w = *width; dest_h = *height; - ret = mm_util_crop_image( src, src_width, src_height, _convert_colorspace_tbl[colorspace], x, y, &dest_w, &dest_h, dest); - if( ret == 0){ + ret = mm_util_crop_image(src, src_width, src_height, _convert_colorspace_tbl[colorspace], x, y, &dest_w, &dest_h, dest); + if (ret == 0) { *width = dest_w; *height = dest_h; } @@ -694,93 +605,157 @@ int image_util_crop(unsigned char * dest, int x , int y, int* width, int* height return _convert_image_util_error_code(__func__, ret); } -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 image_util_decode_jpeg(const char *path, image_util_colorspace_e colorspace, unsigned char **image_buffer, int *width, int *height, unsigned int *size) +{ + int ret = IMAGE_UTIL_ERROR_NONE; + + if (path == NULL || image_buffer == NULL || size == NULL) + return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); + if (strlen(path) == 0) + return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_NO_SUCH_FILE); + if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int)) + return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); + if (_convert_encode_colorspace_tbl[colorspace] == -1) + return _convert_image_util_error_code(__func__, MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT); + + mm_util_jpeg_yuv_data decoded; + memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data)); + + ret = mm_util_decode_from_jpeg_file(&decoded, path, _convert_encode_colorspace_tbl[colorspace]); + if (ret == 0) { + *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__, ret); +} + +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 ret = IMAGE_UTIL_ERROR_NONE; + + if (jpeg_buffer == NULL || image_buffer == NULL || size == NULL) + return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); + if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int)) + return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); + if (_convert_encode_colorspace_tbl[colorspace] == -1) + return _convert_image_util_error_code(__func__, MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT); + + mm_util_jpeg_yuv_data decoded; + memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data)); + + ret = mm_util_decode_from_jpeg_memory(&decoded, (void *)jpeg_buffer, jpeg_size, _convert_encode_colorspace_tbl[colorspace]); + + if (ret == 0) { + *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__, ret); +} + +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 ret = IMAGE_UTIL_ERROR_NONE; - if( path == NULL || image_buffer == NULL || size == NULL) + if (path == NULL || image_buffer == NULL || size == NULL) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if(strlen (path) == 0) + if (strlen(path) == 0) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_NO_SUCH_FILE); - if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int)) + if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int)) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( _convert_encode_colorspace_tbl[colorspace] == -1 ) + if (_convert_encode_colorspace_tbl[colorspace] == -1) return _convert_image_util_error_code(__func__, MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT); + if (downscale < 0 || downscale >= sizeof(_convert_decode_scale_tbl) / sizeof(int)) + return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - mm_util_jpeg_yuv_data decoded = { 0, 0, 0, NULL}; + mm_util_jpeg_yuv_data decoded; + memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data)); - ret = mm_util_decode_from_jpeg_file(&decoded, (char*)path, _convert_encode_colorspace_tbl[colorspace]); - if( ret == 0 ){ + ret = mm_util_decode_from_jpeg_file_with_downscale(&decoded, path, _convert_encode_colorspace_tbl[colorspace], _convert_decode_scale_tbl[downscale]); + if (ret == 0) { *image_buffer = decoded.data; - if(width) + if (width) *width = decoded.width; - if(height) + if (height) *height = decoded.height; - if(size) + if (size) *size = decoded.size; } return _convert_image_util_error_code(__func__, ret); } -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 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 ret = IMAGE_UTIL_ERROR_NONE; - if( jpeg_buffer == NULL || image_buffer == NULL || size == NULL) + if (jpeg_buffer == NULL || image_buffer == NULL || size == NULL) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int)) + if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int)) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( _convert_encode_colorspace_tbl[colorspace] == -1 ) + if (_convert_encode_colorspace_tbl[colorspace] == -1) return _convert_image_util_error_code(__func__, MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT); + if (downscale < 0 || downscale >= sizeof(_convert_decode_scale_tbl) / sizeof(int)) + return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); mm_util_jpeg_yuv_data decoded; + memset(&decoded, 0, sizeof(mm_util_jpeg_yuv_data)); - ret = mm_util_decode_from_jpeg_memory(&decoded , jpeg_buffer, jpeg_size, _convert_encode_colorspace_tbl[colorspace] ); + ret = mm_util_decode_from_jpeg_memory_with_downscale(&decoded, (void *)jpeg_buffer, jpeg_size, _convert_encode_colorspace_tbl[colorspace], _convert_decode_scale_tbl[downscale]); - if( ret == 0 ){ + if (ret == 0) { *image_buffer = decoded.data; - if(width) + if (width) *width = decoded.width; - if(height) + if (height) *height = decoded.height; - if(size) + if (size) *size = decoded.size; } return _convert_image_util_error_code(__func__, ret); } -int image_util_encode_jpeg( const unsigned char *buffer, int width, int height, image_util_colorspace_e colorspace, int quality, const char *path) +int image_util_encode_jpeg(const unsigned char *buffer, int width, int height, image_util_colorspace_e colorspace, int quality, const char *path) { int ret = IMAGE_UTIL_ERROR_NONE; - if( path == NULL || buffer == NULL ) + if (path == NULL || buffer == NULL) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if(strlen (path) == 0) + if (strlen(path) == 0) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_NO_SUCH_FILE); - if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int)) + if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int)) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( _convert_encode_colorspace_tbl[colorspace] == -1 ) + if (_convert_encode_colorspace_tbl[colorspace] == -1) return _convert_image_util_error_code(__func__, MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT); - ret = mm_util_jpeg_encode_to_file(path, buffer, width, height, _convert_encode_colorspace_tbl[colorspace], quality); + ret = mm_util_jpeg_encode_to_file(path, (void *)buffer, width, height, _convert_encode_colorspace_tbl[colorspace], quality); return _convert_image_util_error_code(__func__, ret); } -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 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 ret = IMAGE_UTIL_ERROR_NONE; int isize; - if( jpeg_buffer == NULL || image_buffer == NULL || jpeg_size == NULL ) + if (jpeg_buffer == NULL || image_buffer == NULL || jpeg_size == NULL) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl)/sizeof(int)) + if (colorspace < 0 || colorspace >= sizeof(_convert_colorspace_tbl) / sizeof(int)) return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER); - if( _convert_encode_colorspace_tbl[colorspace] == -1 ) + if (_convert_encode_colorspace_tbl[colorspace] == -1) return _convert_image_util_error_code(__func__, MM_ERROR_IMAGE_NOT_SUPPORT_FORMAT); - ret = mm_util_jpeg_encode_to_memory( (void**)jpeg_buffer, &isize, image_buffer, width, height, _convert_encode_colorspace_tbl[colorspace] , quality ); - if( ret == 0 ) + ret = mm_util_jpeg_encode_to_memory((void **)jpeg_buffer, &isize, (void *)image_buffer, width, height, _convert_encode_colorspace_tbl[colorspace], quality); + if (ret == 0) *jpeg_size = isize; return _convert_image_util_error_code(__func__, ret); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index d2f30d9..7c57a1d 100755 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,7 +1,8 @@ SET(fw_test "${fw_name}-test") INCLUDE(FindPkgConfig) -pkg_check_modules(${fw_test} REQUIRED glib-2.0 elementary evas ecore edje ecore-x ) +pkg_check_modules(${fw_test} REQUIRED glib-2.0) + FOREACH(flag ${${fw_test}_CFLAGS}) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}") MESSAGE(${flag}) @@ -9,13 +10,12 @@ ENDFOREACH() SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -pie -Wall") -#ADD_EXECUTABLE("system-sensor" system-sensor.c) -#TARGET_LINK_LIBRARIES("system-sensor" ${fw_name} ${${fw_test}_LDFLAGS}) - aux_source_directory(. sources) FOREACH(src ${sources}) GET_FILENAME_COMPONENT(src_name ${src} NAME_WE) MESSAGE("${src_name}") - ADD_EXECUTABLE(${src_name} ${src}) - TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS}) + ADD_EXECUTABLE(${fw_test} ${src}) + TARGET_LINK_LIBRARIES(${fw_test} ${fw_name} ${${fw_test}_LDFLAGS}) ENDFOREACH() + +#INSTALL(TARGETS ${fw_test} DESTINATION bin) diff --git a/test/image_util_test.c b/test/image_util_test.c new file mode 100755 index 0000000..1fa1614 --- /dev/null +++ b/test/image_util_test.c @@ -0,0 +1,631 @@ +/* +* 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 <glib.h> +#include <stdio.h> +#include <stdlib.h> +#include <image_util.h> +#include <image_util_type.h> +#include <mm_error.h> + +#define MAX_STRING_LEN 128 +#define IMAGE_FORMAT_LABEL_BUFFER_SIZE 4 + +#define IMAGE_UTIL_SAFE_FREE(src) { if(src) {free(src); src = NULL;}} + + +GMainLoop *g_loop = NULL; +transformation_h g_handle = NULL; +media_packet_h g_src = NULL; +media_packet_h g_result = NULL; +char *g_path = NULL; +unsigned int g_width = 0; +unsigned int g_height = 0; +int g_format = -1; + +GCond *g_thread_cond = NULL; +GMutex *g_thread_mutex = NULL; + +enum { + CURRENT_STATE_MAIN_MENU, + CURRENT_STATE_SET_IMAGE_MENU, +}; + +enum { + CURRENT_STATE_SET_IMAGE_NONE, + CURRENT_STATE_SET_IMAGE_PATH, + CURRENT_STATE_SET_IMAGE_WIDTH, + CURRENT_STATE_SET_IMAGE_HEIGHT, + CURRENT_STATE_SET_IMAGE_FORMAT, +}; + +int g_menu_state = CURRENT_STATE_MAIN_MENU; +int g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE; + +void _wait() +{ + g_mutex_lock(g_thread_mutex); + g_printf("waiting... untill finishing transform \n"); + g_cond_wait(g_thread_cond, g_thread_mutex); + g_printf("<=== get signal from callback \n"); + g_mutex_unlock(g_thread_mutex); +} + +void _signal() +{ + g_mutex_lock(g_thread_mutex); + g_cond_signal(g_thread_cond); + g_printf("===> send signal to test proc \n"); + g_mutex_unlock(g_thread_mutex); +} + +media_format_mimetype_e +_image_util_mapping_imgp_format_to_mime(image_util_colorspace_e colorspace) +{ + media_format_mimetype_e mimetype = -1; + + switch (colorspace) { + case IMAGE_UTIL_COLORSPACE_NV12: + mimetype = MEDIA_FORMAT_NV12; + break; + case IMAGE_UTIL_COLORSPACE_NV16: + mimetype = MEDIA_FORMAT_NV16; + break; + case IMAGE_UTIL_COLORSPACE_YUYV: + mimetype = MEDIA_FORMAT_YUYV; + break; + case IMAGE_UTIL_COLORSPACE_UYVY: + mimetype = MEDIA_FORMAT_UYVY; + break; + case IMAGE_UTIL_COLORSPACE_YUV422: + mimetype = MEDIA_FORMAT_422P; + break; + case IMAGE_UTIL_COLORSPACE_I420: + mimetype = MEDIA_FORMAT_I420; + break; + case IMAGE_UTIL_COLORSPACE_NV21: + mimetype = MEDIA_FORMAT_YV12; + break; + case IMAGE_UTIL_COLORSPACE_RGB565: + mimetype = MEDIA_FORMAT_RGB565; + break; + case IMAGE_UTIL_COLORSPACE_RGB888: + mimetype = MEDIA_FORMAT_RGB888; + break; + case IMAGE_UTIL_COLORSPACE_RGBA8888: + mimetype = MEDIA_FORMAT_RGBA; + break; + case IMAGE_UTIL_COLORSPACE_ARGB8888: + mimetype = MEDIA_FORMAT_ARGB; + break; + case IMAGE_UTIL_COLORSPACE_BGRA8888: + case IMAGE_UTIL_COLORSPACE_BGRX8888: + case IMAGE_UTIL_COLORSPACE_NV61: + default: + mimetype = -1; + g_printf("Not Supported Format"); + break; + } + + g_printf("imgp fmt: %d mimetype fmt: %d", colorspace, mimetype); + return mimetype; +} + +bool test_transform_completed_cb(media_packet_h *packet, image_util_error_e error, void *user_data) +{ + uint64_t size = 0; + char output_file[25] = {}; + + media_format_h dst_fmt; + media_format_mimetype_e dst_mimetype; + int dst_width, dst_height, dst_avg_bps, dst_max_bps; + char *output_fmt = NULL; + + g_printf("test_transform_completed_cb============= [%d] \n", error); + if (error == MM_ERROR_NONE) { + g_printf("completed"); + output_fmt = (char *)malloc(sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE); + if (output_fmt) { + if (media_packet_get_format(*packet, &dst_fmt) != MM_ERROR_NONE) { + g_printf("Imedia_packet_get_format"); + _signal(); + return FALSE; + } + + if (g_result != NULL) { + media_packet_destroy(g_result); + } + media_packet_create_alloc(dst_fmt, NULL, NULL, &g_result); + if (media_packet_get_buffer_size(g_result, &size) != MM_ERROR_NONE) { + g_printf("Imedia_packet_get_format)"); + media_format_unref(dst_fmt); + _signal(); + return FALSE; + } + g_printf("g_result: %p [%d] \n", g_result, size); + + if (media_format_get_video_info(dst_fmt, &dst_mimetype, &dst_width, &dst_height, &dst_avg_bps, &dst_max_bps) == MEDIA_FORMAT_ERROR_NONE) { + memset(output_fmt, 0, IMAGE_FORMAT_LABEL_BUFFER_SIZE); + if (dst_mimetype == MEDIA_FORMAT_YV12 || dst_mimetype == MEDIA_FORMAT_422P || dst_mimetype == MEDIA_FORMAT_I420 + || dst_mimetype == MEDIA_FORMAT_NV12 || dst_mimetype == MEDIA_FORMAT_UYVY || dst_mimetype == MEDIA_FORMAT_YUYV) { + strncpy(output_fmt, "yuv", strlen("yuv")); + } else { + strncpy(output_fmt, "rgb", strlen("rgb")); + } + g_printf("[mimetype: %d] W x H : %d x %d \n", dst_mimetype, dst_width, dst_height); + snprintf(output_file, 25, "result_%dx%d.%s", dst_width, dst_height, output_fmt); + } + } + + FILE *fpout = fopen(output_file, "w"); + if (fpout) { + media_packet_get_buffer_size(*packet, &size); + void *dst = NULL; + if (media_packet_get_buffer_data_ptr(*packet, &dst) != MM_ERROR_NONE) { + IMAGE_UTIL_SAFE_FREE(dst); + IMAGE_UTIL_SAFE_FREE(output_fmt); + fclose(fpout); + g_printf("[dst] media_packet_get_extra \n"); + _signal(); + return FALSE; + } + g_printf("dst: %p [%d] \n", dst, size); + fwrite(dst, 1, size, fpout); + g_printf("FREE \n"); + fclose(fpout); + } + + g_printf("write result \n"); + g_printf("Free (output_fmt) \n"); + IMAGE_UTIL_SAFE_FREE(output_fmt); + } else { + g_printf("[ERROR] complete cb"); + _signal(); + return FALSE; + } + + media_packet_destroy(*packet); + + _signal(); + + return TRUE; +} + +static int +create_media_packet() +{ + int ret = 0; + media_format_h fmt; + void *src; + void *ptr; + if (media_format_create(&fmt) == MEDIA_FORMAT_ERROR_NONE) { + if (media_format_set_video_mime(fmt, _image_util_mapping_imgp_format_to_mime(g_format)) != MEDIA_FORMAT_ERROR_NONE) { + media_format_unref(fmt); + g_printf("[Error] Set - video mime\n"); + return MM_ERROR_IMAGE_INVALID_VALUE; + } + + if (media_format_set_video_width(fmt, g_width) != MEDIA_FORMAT_ERROR_NONE) { + media_format_unref(fmt); + g_printf("[Error] Set - video width\n"); + return MM_ERROR_IMAGE_INVALID_VALUE; + } + + if (media_format_set_video_height(fmt, g_height) != MEDIA_FORMAT_ERROR_NONE) { + media_format_unref(fmt); + g_printf("[Error] Set - video heigh\nt"); + return MM_ERROR_IMAGE_INVALID_VALUE; + } + + if (media_format_set_video_avg_bps(fmt, 2000000) != MEDIA_FORMAT_ERROR_NONE) { + media_format_unref(fmt); + g_printf("[Error] Set - video avg bps\n"); + return MM_ERROR_IMAGE_INVALID_VALUE; + } + + if (media_format_set_video_max_bps(fmt, 15000000) != MEDIA_FORMAT_ERROR_NONE) { + media_format_unref(fmt); + g_printf("[Error] Set - video max bps\n"); + return MM_ERROR_IMAGE_INVALID_VALUE; + } + + g_printf("media_format_set_video_info success! file:%s, w:%d, h:%d, %d\n", g_path, g_width, g_height, _image_util_mapping_imgp_format_to_mime(g_format)); + } else { + g_printf("media_format_create failed..."); + } + + ret = media_packet_create_alloc(fmt, NULL, NULL, &g_src); + if (ret == MM_ERROR_NONE) { + g_printf("Success - media_packet_create_alloc\n"); + uint64_t size = 0; + if (media_packet_get_buffer_size(g_src, &size) == MEDIA_PACKET_ERROR_NONE) { + ptr = malloc(size); + if (ptr == NULL) { + g_printf("\tmemory allocation failed\n"); + return MM_ERROR_IMAGE_INTERNAL; + } + if (media_packet_get_buffer_data_ptr(g_src, &ptr) == MEDIA_PACKET_ERROR_NONE) { + FILE *fp = fopen(g_path, "r"); + if (fp == NULL) { + g_printf("\tfile open failed %d\n", errno); + return MM_ERROR_IMAGE_INTERNAL; + } + src = malloc(size); + if (src == NULL) { + g_printf("\tmemory allocation failed\n"); + return MM_ERROR_IMAGE_INTERNAL; + } + if (fread(src, 1, (int)size, fp)) { + g_printf("#Success# fread\n"); + memcpy(ptr, src, (int)size); + g_printf("memcpy\n"); + } else { + g_printf("#Error# fread\n"); + } + } + } + } else { + media_format_unref(fmt); + g_printf("ERROR - media_packet_create_alloc"); + return ret; + } + media_format_unref(fmt); + return ret; +} + +static void _create() +{ + int ret = 0; + if (g_handle != NULL) { + ret = image_util_transform_destroy(g_handle); + if (ret != IMAGE_UTIL_ERROR_NONE) { + g_printf("[%d]Error image_util_transform_destroy [%d]\n", __LINE__, ret); + } else { + g_printf("[%d]Success image_util_transform_destroy [%d]\n", __LINE__, ret); + } + } + ret = image_util_transform_create(&g_handle); + if (ret != IMAGE_UTIL_ERROR_NONE) { + g_printf("[%d]Error image_util_transform_create [%d]\n", __LINE__, ret); + } else { + g_printf("[%d]Success image_util_transform_create [%d]\n", __LINE__, ret); + } +} + +static void _set_image() +{ + int ret = 0; + if (g_src) { + media_packet_destroy(g_src); + g_printf("[%d]Success source packet is destroyed \n", __LINE__); + } + ret = create_media_packet(); + if (ret == MM_ERROR_NONE) { + g_printf("Success - Create_media_packet\n"); + } else { + g_printf("Error - Create_media_packet\n"); + } +} + +static void _destroy() +{ + int ret = 0; + + if (g_handle) { + ret = image_util_transform_destroy(g_handle); + if (ret != IMAGE_UTIL_ERROR_NONE) { + g_printf("[%d]Error image_util_transform_destroy [%d]\n", __LINE__, ret); + } else { + g_printf("[%d]Success image_util_transform_destroy [%d]\n", __LINE__, ret); + } + } else { + g_printf("[%d]Error handle was already destroyed \n", __LINE__); + } + g_handle = NULL; +} + +static void _transform(char *cmd) +{ + int ret = 0; + unsigned int width = 0; + unsigned int height = 0; + image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_RGB888; + image_util_rotation_e angle; + int start_x; + int start_y; + int end_x; + int end_y; + + if (!strcmp("convert", cmd)) { + colorspace = IMAGE_UTIL_COLORSPACE_RGB888; + + ret = image_util_transform_set_colorspace(g_handle, colorspace); + if (ret != IMAGE_UTIL_ERROR_NONE) { + g_printf("[%d]error image_util_set colorspace [%d]\n", __LINE__, ret); + return; + } + } + + if (!strcmp("resize", cmd)) { + width = 480; + height = 360; + + ret = image_util_transform_set_resolution(g_handle, width, height); + if (ret != IMAGE_UTIL_ERROR_NONE) { + g_printf("[%d]Error image_util_set resolution [%d]\n", __LINE__, ret); + return; + } + } + + if (!strcmp("rotate", cmd)) { + angle = 1; + + ret = image_util_transform_set_rotation(g_handle, angle); + if (ret != IMAGE_UTIL_ERROR_NONE) { + g_printf("[%d]Error image_util_set colorspace [%d]\n", __LINE__, ret); + return; + } + } + + if (!strcmp("crop", cmd)) { + start_x = 500; + start_y = 500; + end_x = 700; + end_y = 700; + + ret = image_util_transform_set_crop_area(g_handle, start_x, start_y, end_x, end_y); + if (ret != IMAGE_UTIL_ERROR_NONE) { + g_printf("[%d]Error image_util_set colorspace [%d]\n", __LINE__, ret); + return; + } + } + + if (!strcmp("run", cmd)) { + ret = image_util_transform_run(g_handle, g_src, test_transform_completed_cb, NULL); + if (ret != IMAGE_UTIL_ERROR_NONE) { + g_printf("[%d]Error image_util_transform [%d]\n", __LINE__, ret); + return; + } + _wait(); + } + +} + +void quit(void) +{ + if (g_loop) + g_main_loop_quit(g_loop); +} + +void reset_current_menu_state() +{ + g_menu_state = CURRENT_STATE_MAIN_MENU; + return; +} + +static void display_set_image_menu(void) +{ + g_print("\n"); + g_print("====================================================\n"); + g_print(" image-util Core-API test: Main menu v0.2\n"); + g_print("----------------------------------------------------\n"); + g_print("1. set image path \n"); + g_print("2. set image width \n"); + g_print("3. set image height \n"); + g_print("4. set image format \n"); + g_print("0. back \n"); + g_print("----------------------------------------------------\n"); + g_print("====================================================\n"); + +} + +static void display_menu(void) +{ + g_print("\n"); + g_print("====================================================\n"); + g_print(" image-util Core-API test: Main menu v0.2\n"); + g_print("----------------------------------------------------\n"); + g_print("1. create handle \n"); + g_print("2. set image \n"); + g_print("3. set convert \n"); + g_print("4. set crop \n"); + g_print("5. set resize \n"); + g_print("6. set rotate \n"); + g_print("7. run \n"); + g_print("8. run with result \n"); + g_print("9. destroy handle \n"); + g_print("0. quit \n"); + g_print("----------------------------------------------------\n"); + g_print("====================================================\n"); + +} + +static void interpret_set_image_cmd(char *cmd) +{ + int len = strlen(cmd); + if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_NONE) { + if (len == 1) { + if (!strncmp(cmd, "1", len)) { + g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_PATH; + g_print("Path: "); + } else if (!strncmp(cmd, "2", len)) { + g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_WIDTH; + g_print("Width: "); + } else if (!strncmp(cmd, "3", len)) { + g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_HEIGHT; + g_print("height: "); + } else if (!strncmp(cmd, "4", len)) { + g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_FORMAT; + g_print("Format: "); + } else if (!strncmp(cmd, "0", len)) { + _set_image(); + reset_current_menu_state(); + display_menu(); + } + } else { + g_print("wrong command\n"); + display_set_image_menu(); + } + } else if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_PATH) { + IMAGE_UTIL_SAFE_FREE(g_path); + g_path = (char *)g_malloc(MAX_STRING_LEN * sizeof(char *)); + memset(g_path, 0x00, MAX_STRING_LEN); + snprintf(g_path, MAX_STRING_LEN, "%s", cmd); + g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE; + display_set_image_menu(); + } else if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_WIDTH) { + g_width = atoi(cmd); + g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE; + display_set_image_menu(); + } else if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_HEIGHT) { + g_height = atoi(cmd); + g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE; + display_set_image_menu(); + } else if (g_menu_set_image_state == CURRENT_STATE_SET_IMAGE_FORMAT) { + g_format = atoi(cmd); + g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE; + display_set_image_menu(); + } +} + +static void interpret_cmd(char *cmd) +{ + int len = strlen(cmd); + if (g_menu_state == CURRENT_STATE_MAIN_MENU) { + if (len == 1) { + if (!strncmp(cmd, "1", len)) { + _create(); + } else if (!strncmp(cmd, "2", len)) { + g_menu_state = CURRENT_STATE_SET_IMAGE_MENU; + g_menu_set_image_state = CURRENT_STATE_SET_IMAGE_NONE; + display_set_image_menu(); + return; + } else if (!strncmp(cmd, "3", len)) { + _transform("convert"); + } else if (!strncmp(cmd, "4", len)) { + _transform("crop"); + } else if (!strncmp(cmd, "5", len)) { + _transform("resize"); + } else if (!strncmp(cmd, "6", len)) { + _transform("rotate"); + } else if (!strncmp(cmd, "7", len)) { + _transform("run"); + } else if (!strncmp(cmd, "9", len)) { + _destroy(); + } else if (!strncmp(cmd, "0", len)) { + quit(); + } + } else { + g_print("wrong command\n"); + } + + display_menu(); + } else if (g_menu_state == CURRENT_STATE_SET_IMAGE_MENU) { + interpret_set_image_cmd(cmd); + } else { + g_print("wrong menu state\n"); + } +} + +gboolean input(GIOChannel *channel) +{ + gchar buf[MAX_STRING_LEN]; + gsize read; + GError *error = NULL; + + g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error); + + buf[read] = '\0'; + g_strstrip(buf); + interpret_cmd(buf); + + return TRUE; +} + +int main(int argc, char **argv) +{ + int ret = IMAGE_UTIL_ERROR_NONE; + + GIOChannel *stdin_channel = NULL; + stdin_channel = g_io_channel_unix_new(0); + g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL); + g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL); + + if (argc < 4) { + g_printf("Usage: image_utl_test filename width height format \n"); + return ret; + } + + g_handle = NULL; + g_src = NULL; + g_path = (char *)g_malloc(MAX_STRING_LEN * sizeof(char *)); + memset(g_path, 0x00, MAX_STRING_LEN); + snprintf(g_path, MAX_STRING_LEN, "%s", argv[1]); + g_width = atoi(argv[2]); + g_height = atoi(argv[3]); + g_format = atoi(argv[4]); + + g_thread_mutex = g_mutex_new(); + g_thread_cond = g_cond_new(); + + ret = image_util_transform_create(&g_handle); + if (ret != IMAGE_UTIL_ERROR_NONE) { + g_printf("[%d]Error image_util_transform_create [%d]\n", __LINE__, ret); + goto Exit; + } + + bool hardware_acceleration = FALSE; + + ret = create_media_packet(); + if (ret == MM_ERROR_NONE) { + g_printf("Success - Create_media_packet\n"); + } else { + g_printf("Error - Create_media_packet\n"); + goto Exit; + } + + ret = image_util_transform_set_hardware_acceleration(g_handle, hardware_acceleration); + if (ret != IMAGE_UTIL_ERROR_NONE) { + g_printf("[%d]Error image_util_transform_set_hardware_acceleration condition [%d]\n", __LINE__, ret); + goto Exit; + } + + display_menu(); + + g_loop = g_main_loop_new(NULL, FALSE); + + g_main_loop_run(g_loop); + g_main_loop_unref(g_loop); + +Exit: + g_mutex_free(g_thread_mutex); + g_cond_free(g_thread_cond); + if (g_path) { + IMAGE_UTIL_SAFE_FREE(g_path); + g_printf("[%d]Success file path is destroyed \n", __LINE__); + } else { + g_printf("[%d]Error file path was already destroyed \n", __LINE__); + } + if (g_src) { + media_packet_destroy(g_src); + g_printf("[%d]Success source packet is destroyed \n", __LINE__); + } else { + g_printf("[%d]Error source packet was already destroyed \n", __LINE__); + } + _destroy(); + + return 0; +} diff --git a/test/multimeida_image_util_test.c b/test/multimeida_image_util_test.c deleted file mode 100755 index 43e6be0..0000000 --- a/test/multimeida_image_util_test.c +++ /dev/null @@ -1,208 +0,0 @@ -/* -* 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 <image_util.h> - -GMainLoop *g_loop = NULL; - -bool test_transform_completed_cb(media_packet_h *dst, image_util_error_e error, void *user_data) -{ - transformation_s *transform = (transformation_s *)user_data; - printf("test_transform_completed_cb============= [%d]\n", error); - - if(error == MM_ERROR_NONE) { - printf("completed"); - *dst = transform->dst; - if(g_loop) - g_main_loop_quit(g_loop); - } else { - printf("[ERROR] complete cb"); - GThread * destroy_thread = g_thread_new(NULL, image_util_destroy, transform); - g_thread_unref(destroy_thread); - } - - return TRUE; -} - -static int -create_media_packet(media_format_h *packet) -{ - int ret = 0; - media_format_h fmt; - if(media_format_create(&fmt) == MEDIA_FORMAT_ERROR_NONE) { - if(media_format_set_video_mime(fmt, MEDIA_FORMAT_I420) != MEDIA_FORMAT_ERROR_NONE) { - media_format_unref(fmt); - printf("[Error] Set - video mime"); - return MM_ERROR_IMAGE_INVALID_VALUE; - } - - if(media_format_set_video_width(fmt, 320) != MEDIA_FORMAT_ERROR_NONE) { - media_format_unref(fmt); - printf("[Error] Set - video width"); - return MM_ERROR_IMAGE_INVALID_VALUE; - } - - if(media_format_set_video_height(fmt, 240) != MEDIA_FORMAT_ERROR_NONE) { - media_format_unref(fmt); - printf("[Error] Set - video height"); - return MM_ERROR_IMAGE_INVALID_VALUE; - } - - if(media_format_set_video_avg_bps(fmt, 2000000) != MEDIA_FORMAT_ERROR_NONE) { - media_format_unref(fmt); - printf("[Error] Set - video avg bps"); - return MM_ERROR_IMAGE_INVALID_VALUE; - } - - if(media_format_set_video_max_bps(fmt, 15000000) != MEDIA_FORMAT_ERROR_NONE) { - media_format_unref(fmt); - printf("[Error] Set - video max bps"); - return MM_ERROR_IMAGE_INVALID_VALUE; - } - - printf("media_format_set_video_info success! w:320, h:240, MEDIA_FORMAT_I420\n"); - } - else { - printf("media_format_create failed..."); - } - - ret = media_packet_create_alloc(fmt, (media_packet_finalize_cb)transform_completed_cb, NULL, packet); - if(ret == MM_ERROR_NONE) { - printf("Success - media_packet_create_alloc"); - } else { - media_format_unref(fmt); - printf("ERROR - media_packet_create_alloc"); - return ret; - } - media_format_unref(fmt); - return ret; -} - -int main(int argc, char ** argv) -{ - transformation_h handle = NULL; - media_packet_h src; - int ret = IMAGE_UTIL_ERROR_NONE; - - ret = image_util_create(&handle); - if(ret != IMAGE_UTIL_ERROR_NONE) - { - printf("[%d]error image_util_create [%d]\n", __LINE__, ret); - } - - unsigned int width = 0; - unsigned int height = 0; - int colorspace = 0; - mm_util_img_rotate_type angle; - int start_x; - int start_y; - int end_x; - int end_y; - bool hardware_acceleration = FALSE; - - ret = create_media_packet(&src); - if(ret == MM_ERROR_NONE) { - printf("Success - Create_media_packet"); - } else { - printf("ERROR - Create_media_packet"); - return ret; - } - - ret = image_util_transform_set_hardware_acceleration(handle, hardware_acceleration); - if(ret != IMAGE_UTIL_ERROR_NONE) - { - printf("[%d]error image_util_set condition [%d]\n", __LINE__, ret); - return 0; - } - - if (!strcmp("convert", argv[1])) { - colorspace = atoi(argv[2]); - - ret = image_util_transform_set_colorspace(handle, colorspace); - if(ret != IMAGE_UTIL_ERROR_NONE) - { - printf("[%d]error image_util_set colorspace [%d]\n", __LINE__, ret); - return 0; - } - } - - if (!strcmp("resize", argv[1])) { - width = atoi(argv[2]); - height = atoi(argv[3]); - - ret = image_util_transform_set_resolution(handle, width, height); - if(ret != IMAGE_UTIL_ERROR_NONE) - { - printf("[%d]error image_util_set resolution [%d]\n", __LINE__, ret); - return 0; - } - } - - if (!strcmp("rotate", argv[1])) { - angle = atoi(argv[2]); - - ret = image_util_transform_set_rotation(handle, angle); - if(ret != IMAGE_UTIL_ERROR_NONE) - { - printf("[%d]error image_util_set colorspace [%d]\n", __LINE__, ret); - return 0; - } - } - - if (!strcmp("crop", argv[1])) { - start_x = atoi(argv[2]); - start_y = atoi(argv[3]); - end_x atoi(argv[4]); - end_y atoi(argv[5]); - - ret = image_util_transform_set_crop_area(handle, start_x, start_y, end_x, end_y); - if(ret != IMAGE_UTIL_ERROR_NONE) - { - printf("[%d]error image_util_set colorspace [%d]\n", __LINE__, ret); - return 0; - } - } - - ret = image_util_transform_run(handle, src, test_transform_completed_cb, handle); - if(ret != IMAGE_UTIL_ERROR_NONE) - { - printf("[%d]error image_util_transform [%d]\n", __LINE__, ret); - } - - if(ret != IMAGE_UTIL_ERROR_NONE) - goto Exit; - - g_loop = g_main_loop_new(NULL, FALSE); - - g_main_loop_run(g_loop); - g_main_loop_unref(g_loop); - -Exit: - ret = image_util_destroy(handle); - if(ret != IMAGE_UTIL_ERROR_NONE) - { - printf("[%d]error image_util_destroy [%d]\n", __LINE__, ret); - } - else - { - printf("[%d]Success image_util_destroy [%d]\n", __LINE__, ret); - } - - if(_util_s != NULL) - free(_util_s); - - return 0; -} |