From: Ji Yong Min Date: Mon, 1 Jun 2015 08:07:36 +0000 (+0900) Subject: [Image-Util] Add new API X-Git-Tag: submit/tizen/20150601.103851^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fheads%2Ftizen_3.0.2015.q2_common;p=platform%2Fcore%2Fapi%2Fimage-util.git [Image-Util] Add new API - Add to encode/decode API with downscale option - Fix some bugs - Fix memroy leak & stack overflow issue Change-Id: Ibb21ee09f0e8c16f8627231a4ae7ec283a5a7667 Signed-off-by: Jiyong Min --- diff --git a/include/image_util.h b/include/image_util.h old mode 100644 new mode 100755 index 8c4567b..323ad6c --- a/include/image_util.h +++ b/include/image_util.h @@ -17,8 +17,7 @@ #ifndef __TIZEN_MEDIA_IMAGE_UTIL_H__ #define __TIZEN_MEDIA_IMAGE_UTIL_H__ -#include -#include +#include #ifdef __cplusplus extern "C" @@ -32,89 +31,6 @@ extern "C" * @brief This file contains the image util API. */ -/** - * @addtogroup CAPI_MEDIA_IMAGE_UTIL_MODULE - * @{ - */ - -/** - * @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; - -/** - * @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; - -/** - * @brief Enumerations of rotation - */ -typedef enum -{ - IMAGE_UTIL_ROTATION_NONE = 0, /**< None */ - IMAGE_UTIL_ROTATION_90 = 1, /**< 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 -* -* @param[in] error_code The error code of image util transfrom -* @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); - - - /** * @addtogroup CAPI_MEDIA_IMAGE_UTIL_MODULE * @{ @@ -612,7 +528,9 @@ int image_util_crop(unsigned char * dest, int x , int y, int* width, int *height * * @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 @@ -641,7 +559,9 @@ int image_util_decode_jpeg( const char *path , image_util_colorspace_e colorspac * @brief Decodes the JPEG image(in memory) to the buffer. * @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 @@ -667,6 +587,73 @@ int image_util_decode_jpeg( const char *path , image_util_colorspace_e colorspac */ 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 2.3 diff --git a/include/image_util_private.h b/include/image_util_private.h index b18ee19..63f2a02 100755 --- a/include/image_util_private.h +++ b/include/image_util_private.h @@ -17,6 +17,7 @@ #ifndef __TIZEN_MEDIA_IMAGE_UTIL_PRIVATE_H__ #define __TIZEN_MEDIA_IMAGE_UTIL_PRIVATE_H__ +#include #ifdef __cplusplus extern "C" diff --git a/include/image_util_type.h b/include/image_util_type.h new file mode 100755 index 0000000..e3db8ad --- /dev/null +++ b/include/image_util_type.h @@ -0,0 +1,137 @@ +/* +* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef __TIZEN_MEDIA_IMAGE_UTIL_TYPE_H__ +#define __TIZEN_MEDIA_IMAGE_UTIL_TYPE_H__ + +#include +#include + +#ifdef __cplusplus +extern "C" +{ +#endif + +#define IMAGE_UTIL_ERROR_CLASS TIZEN_ERROR_IMAGE_UTIL + +/** + * @file image_util_type.h + * @brief This file contains the image util API + */ + +/** + * @addtogroup CAPI_MEDIA_IMAGE_UTIL_MODULE + * @{ + */ + +/** + * @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; + +/** + * @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; + +/** + * @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 */ +} 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] 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); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __TIZEN_MEDIA_IMAGE_UTIL_TYPE_H__ */ diff --git a/packaging/capi-media-image-util.spec b/packaging/capi-media-image-util.spec old mode 100644 new mode 100755 index c980ca7..961ef66 --- a/packaging/capi-media-image-util.spec +++ b/packaging/capi-media-image-util.spec @@ -1,6 +1,6 @@ Name: capi-media-image-util Summary: A Image Utility library in Tizen Native API -Version: 0.1.1 +Version: 0.1.2 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/image_util.c b/src/image_util.c old mode 100644 new mode 100755 index d07469f..fb71ece --- a/src/image_util.c +++ b/src/image_util.c @@ -53,21 +53,27 @@ static int _convert_encode_colorspace_tbl[] = { MM_UTIL_JPEG_FMT_YUV420 , /* IMAGE_UTIL_COLORSPACE_YUV420 */ -1 , /* IMAGE_UTIL_COLORSPACE_YUV422 */ MM_UTIL_JPEG_FMT_YUV420 , /* IMAGE_UTIL_COLORSPACE_I420 */ - MM_UTIL_JPEG_FMT_NV12 , /* IMAGE_UTIL_COLORSPACE_NV12 */ + -1 , /* 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){ int ret = IMAGE_UTIL_ERROR_INVALID_OPERATION; @@ -189,7 +195,7 @@ int _image_util_check_transcode_is_completed(transformation_s * handle, bool *is if(handle && handle->image_h) { - ret = mm_transform_is_completed(handle->image_h, is_completed); + ret = mm_util_transform_is_completed(handle->image_h, is_completed); } else { @@ -436,6 +442,12 @@ int image_util_transform_get_colorspace(transformation_h handle, image_util_colo return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } + if(!_handle->set_convert) + { + LOGE("Did not set colorspace before"); + return IMAGE_UTIL_ERROR_INVALID_OPERATION; + } + if(!colorspace) { LOGE("colorspace area parameter error"); @@ -459,6 +471,12 @@ int image_util_transform_get_resolution(transformation_h handle, unsigned int *w return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } + if(!_handle->set_resize) + { + LOGE("Did not set resolution before"); + return IMAGE_UTIL_ERROR_INVALID_OPERATION; + } + if(!width || !height) { LOGE("resolution area parameter error"); @@ -484,6 +502,12 @@ int image_util_transform_get_rotation(transformation_h handle, image_util_rotati return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } + if(!_handle->set_rotate) + { + LOGE("Did not set rotation before"); + return IMAGE_UTIL_ERROR_INVALID_OPERATION; + } + if(!rotation) { LOGE("rotation area parameter error"); @@ -506,9 +530,9 @@ int image_util_transform_get_crop_area(transformation_h handle, unsigned int *st return IMAGE_UTIL_ERROR_INVALID_PARAMETER; } - if(_handle->set_resize) + if(!_handle->set_crop) { - LOGE("Crop and Resize can't do at the same time"); + LOGE("Did not set crop area before"); return IMAGE_UTIL_ERROR_INVALID_OPERATION; } @@ -747,6 +771,66 @@ int image_util_decode_jpeg_from_memory( const unsigned char * jpeg_buffer , int 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) + 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); + 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}; + + ret = mm_util_decode_from_jpeg_file_with_downscale(&decoded, (char*)path, _convert_encode_colorspace_tbl[colorspace], _convert_decode_scale_tbl[downscale]); + 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_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) + 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); + 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; + + ret = mm_util_decode_from_jpeg_memory_with_downscale(&decoded, jpeg_buffer, jpeg_size, _convert_encode_colorspace_tbl[colorspace], _convert_decode_scale_tbl[downscale]); + + 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_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; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt old mode 100644 new mode 100755 index 6dd749c..d2f30d9 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -7,7 +7,7 @@ FOREACH(flag ${${fw_test}_CFLAGS}) MESSAGE(${flag}) ENDFOREACH() -SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall") +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})