SET(submodule "image-util")
# for package file
-SET(dependents "dlog mmutil-jpeg mmutil-imgp capi-base-common")
-SET(pc_dependents "capi-base-common")
+SET(dependents "dlog mmutil-jpeg mmutil-imgp capi-base-common capi-media-tool mm-common")
+SET(pc_dependents "dlog capi-base-common capi-media-tool mm-common")
SET(fw_name "${project_prefix}-${service}-${submodule}")
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
See the License for the specific language governing permissions and\r
limitations under the License.\r
-\r
-\r
-\r
Name: @PC_NAME@
Description: @PACKAGE_DESCRIPTION@
Version: @VERSION@
-Requires: @PC_REQUIRED@
+Requires: @PC_REQUIRED@ capi-media-tool mm-common
Libs: -L${libdir} @PC_LDFLAGS@
Cflags: -I${includedir}
* 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.
+* limitations under the License.
*/
#define __TIZEN_MEDIA_IMAGE_UTIL_H__
#include <tizen.h>
+#include <media_packet.h>
#ifdef __cplusplus
extern "C"
* @{
*/
-
+/**
+ * @brief Enumeration for error.
+ */
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_NOT_SUPPORT_API /**< Not supported format */
+ 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 Enumerations of colorspace
+ * @brief Enumeration for colorspace.
*/
typedef enum
{
- IMAGE_UTIL_COLORSPACE_YV12, /**< YV12 - YCrCb planar format */
- IMAGE_UTIL_COLORSPACE_YUV422, /**< YUV422 - planer */
- IMAGE_UTIL_COLORSPACE_I420, /**< I420 - planer */
- IMAGE_UTIL_COLORSPACE_NV12, /**< NV12- planer */
-
- 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_e;
-
+ 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_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.
+*/
+typedef struct transformation_s *transformation_h;
+
+
+/**
+* @ingroup CAPI_MEDIA_IMAGE_UTIL_MODULE
+* @brief Called when transform is finished just before returning the output.
+*
+* @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
+ * @{
+ */
+
+/**
+* @brief Creates a handle to image util transform.
+* @since_tizen 2.3
+*
+* @details This function creates a handle to image util transform.
+*
+* @remarks You must release the @a image util handle using image_util_transform_destroy().
+*
+* @param[out] handle A handle to image util transform
+*
+* @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_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @see image_util_transform_destroy()
+*
+*/
+int image_util_transform_create(transformation_h *handle);
+
+/**
+* @brief Sets the image util's accurate mode.
+*
+* @details This function set if you use hardware accerlation or not.
+*
+* @remarks The value returned will be IMAGE_UTIL_ERROR_NOT_SUPPORTED, if H/W acceleration doesn't support on the device.
+*
+* @param[in] handle The handle to image util
+* @param [in] mode Set @c true, user can use the hardware acceleration\n
+* otherwise set @c false if user can only software image processing
+*
+* @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_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
+*
+* @pre image_util_transform_create().
+*
+* @see image_util_transform_create()
+* @see image_util_transform_destroy()
+*/
+int image_util_transform_set_hardware_acceleration(transformation_h handle, bool mode);
+
+/**
+* @brief Sets the information of the converting
+* @since_tizen 2.3
+*
+* @param[in] handle The handle to image util transform
+* @param[in] 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_PERMISSION_DENIED The application does not have the privilege to call this funtion
+* @retval #IMAGE_UTIL_ERROR_NOT_SUPPORTED_FORMAT Not supported format
+*
+* @pre image_util_transform_create().
+*
+* @see image_util_transform_create()
+* @see image_util_transform_run()
+* @see image_util_transform_destroy()
+*/
+int image_util_transform_set_colorspace(transformation_h handle, image_util_colorspace_e colorspace);
+/**
+* @brief Sets the information of the resizing
+* @since_tizen 2.3
+*
+* @param[in] handle The handle to image util transform
+* @param[in] width The width of image buffer
+* @param[in] height The height 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_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @pre image_util_transform_create().
+*
+* @see image_util_transform_create()
+* @see image_util_transform_run()
+* @see image_util_transform_destroy()
+*/
+int image_util_transform_set_resolution(transformation_h handle, unsigned int width, unsigned int height);
/**
+* @brief Sets the information of the rotating
+* @since_tizen 2.3
+*
+* @param[in] handle The handle to image util transform
+* @param[in] 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_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @pre image_util_transform_create().
+*
+* @see image_util_transform_create()
+* @see image_util_transform_run()
+* @see image_util_transform_destroy()
+*/
+int image_util_transform_set_rotation(transformation_h handle, image_util_rotation_e rotation);
+
+/**
+* @brief Sets the information of the cropping
+* @since_tizen 2.3
+*
+* @param[in] handle The handle to image util transform
+* @param[in] start_x The start x position of cropped image buffer
+* @param[in] start_y The start y position of cropped image buffer
+* @param[in] end_x The end x position of cropped image buffer
+* @param[in] end_y The end y position of cropped 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_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @pre image_util_transform_create().
+*
+* @see image_util_transform_create()
+* @see image_util_transform_run()
+* @see image_util_transform_destroy()
+*/
+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);
+
+/**
+* @brief Gets the colorspace of the image buffer
+* @since_tizen 2.3
+*
+* @param[in] handle The handle to image util transform
+* @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_NOT_SUPPORTED_FORMAT Not supported format
+*
+* @pre image_util_transform_create().\n
+ image_util_transform_set_crop_area().
+*
+* @see image_util_transform_create()
+* @see image_util_transform_destroy()
+*/
+int image_util_transform_get_colorspace(transformation_h handle, image_util_colorspace_e *colorspace);
+
+/**
+* @brief Gets the resolution of the image buffer
+* @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
+*
+* @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_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @pre image_util_transform_create().\n
+ image_util_transform_set_resolution().
+*
+* @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);
+
+/**
+* @brief Gets the information of the rotating
+* @since_tizen 2.3
+*
+* @param[in] handle The handle to image util transform
+* @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_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @pre image_util_transform_create().\n
+ image_util_transform_set_rotation().
+*
+* @see image_util_transform_create()
+* @see image_util_transform_destroy()
+*/
+int image_util_transform_get_rotation(transformation_h handle, image_util_rotation_e *rotation);
+
+/**
+* @brief Gets the information of the cropping
+* @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
+*
+* @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_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @pre image_util_transform_create().\n
+ image_util_transform_set_crop_area().
+*
+* @see image_util_transform_create()
+* @see image_util_transform_destroy()
+*/
+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);
+
+/**
+* @brief Transform the image for given image util handle.
+* @since_tizen 2.3
+*
+*@remarks If H/W acceleration is not set, transformation is done via S/W acceleration.
+*
+* @details The function execute asynchronously, which contains complete callback
+*
+* @param[in] handle The handle of transform
+* @param[in] src The handle to image util transform
+* @param[in] callback The callback function to be invoked
+* @param[in] user_data The user data to be passed to the callback function
+*
+* @return @c 0 on success,
+* otherwise a negative error value
+*
+* @retval #IMAGE_UTIL_ERROR_NONE Successful
+* @retval #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
+* @retval #IMAGE_UTIL_ERROR_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @see image_util_transform_create()
+* @see image_util_transform_set_hardware_acceleration
+* @see image_util_transform_destroy()
+*/
+int image_util_transform_run(transformation_h handle, media_packet_h src, image_util_transform_completed_cb callback, void *user_data);
+
+/**
+* @brief Destroys a handle to image util.
+* @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
+* has to be created before the next usage.
+*
+* @param[in] handle The handle to image util transform
+*
+* @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_PERMISSION_DENIED The application does not have the privilege to call this funtion
+*
+* @see image_util_transform_create()
+*
+*/
+int image_util_transform_destroy(transformation_h handle);
+/**
* @brief Called once for each supported JPEG encode/decode colorspace.
*
* @param[in] colorspace The colorspace
--- /dev/null
+/*
+* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#ifndef __TIZEN_MEDIA_IMAGE_UTIL_PRIVATE_H__
+#define __TIZEN_MEDIA_IMAGE_UTIL_PRIVATE_H__
+
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef struct
+{
+ void *user_data;
+ media_packet_h dst;
+ image_util_transform_completed_cb image_processing_completed_cb;
+} image_util_cb_s;
+
+typedef struct
+{
+ media_packet_h src;
+ media_packet_h dst;
+ image_util_colorspace_e colorspace;
+ image_util_rotation_e dest_rotation;
+ bool hardware_acceleration;
+ MMHandleType image_h;
+ image_util_cb_s *_util_cb;
+ unsigned int width;
+ unsigned int height;
+ image_util_rotation_e rotation;
+ unsigned int start_x;
+ unsigned int start_y;
+ unsigned int end_x;
+ unsigned int end_y;
+ bool set_convert;
+ bool set_resize;
+ bool set_rotate;
+ bool set_crop;
+} transformation_s;
+
+
+/**
+* @}
+*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __TIZEN_MEDIA_IMAGE_UTIL_PRIVATE_H__ */
BuildRequires: pkgconfig(mmutil-jpeg)
BuildRequires: pkgconfig(mmutil-imgp)
BuildRequires: pkgconfig(capi-base-common)
-
+BuildRequires: pkgconfig(capi-media-tool)
BuildRequires: cmake
BuildRequires: gettext-devel
* 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.
+* limitations under the License.
*/
#define LOG_TAG "CAPI_MEDIA_IMAGE_UTIL"
#include <mm_util_imgp.h>
#include <mm_util_jpeg.h>
#include <image_util.h>
-#include <mm.h>
+#include <image_util_private.h>
#include <stdio.h>
+#include <stdlib.h>
+#include <mm_error.h>
+
+#define IMAGE_UTIL_STRING_VALID(str) \
+ ((str != NULL && strlen(str) > 0) ? true : false)
+
+#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_BGRA8888, /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
MM_UTIL_IMG_FMT_RGBA8888, /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
MM_UTIL_IMG_FMT_BGRX8888, /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
+ MM_UTIL_JPEG_FMT_NV21, /* IMAGE_UTIL_COLORSPACE_NV12 */
+ MM_UTIL_JPEG_FMT_NV16, /* IMAGE_UTIL_COLORSPACE_NV16 */
+ MM_UTIL_JPEG_FMT_NV61, /* IMAGE_UTIL_COLORSPACE_NV61 */
};
static int _convert_encode_colorspace_tbl[] = {
- MM_UTIL_JPEG_FMT_YUV420 , /* IMAGE_UTIL_COLORSPACE_YUV420 */
- -1 , /* IMAGE_UTIL_COLORSPACE_YUV422 */
- -1 , /* IMAGE_UTIL_COLORSPACE_I420 */
- -1 , /* IMAGE_UTIL_COLORSPACE_NV12 */
- -1 , /* IMAGE_UTIL_COLORSPACE_UYVY */
- -1 , /* IMAGE_UTIL_COLORSPACE_YUYV */
- -1 , /* IMAGE_UTIL_COLORSPACE_RGB565 */
- MM_UTIL_JPEG_FMT_RGB888 , /* IMAGE_UTIL_COLORSPACE_RGB888 */
- -1 , /* IMAGE_UTIL_COLORSPACE_ARGB8888 */
- -1 , /* IMAGE_UTIL_COLORSPACE_BGRA8888 */
- -1 , /* IMAGE_UTIL_COLORSPACE_RGBA8888 */
- -1 , /* IMAGE_UTIL_COLORSPACE_BGRX8888 */
+ 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_UYVY */
+ MM_UTIL_JPEG_FMT_YUYV , /* 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 */
};
default:
ret = IMAGE_UTIL_ERROR_INVALID_OPERATION;
errorstr = "INVALID_OPERATION";
-
+
}
-
- LOGE( "[%s] %s(0x%08x)",func, errorstr, ret);
+
+ LOGD( "[%s] %s(0x%08x)",func, errorstr, ret);
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;
+ }
+
+ 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)
+{
+ 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))
+ {
+ error_value = _image_util_error_convert(error);
+ _util_cb->image_processing_completed_cb(dst, error_value, _util_cb->user_data);
+ }
+
+ return;
+}
+
+static int _image_util_create_transform_handle(transformation_s *handle)
+{
+ int ret = MM_ERROR_NONE;
+ MMHandleType image_h;
+
+ ret = mm_util_create(&image_h);
+
+ if(ret == MM_ERROR_NONE)
+ {
+ handle->image_h = image_h;
+ }
+ else
+ {
+ LOGE("Error in mm_util_create");
+ }
+
+ return ret;
+}
+
+static bool _image_util_check_resolution(int width, int height)
+{
+ if(width <= 0)
+ {
+ LOGE("invalid width [%d]", width);
+ return false;
+ }
+
+ if(height <= 0)
+ {
+ LOGE("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 i = 0;
-int image_util_foreach_supported_jpeg_colorspace(image_util_supported_jpeg_colorspace_cb callback, void * user_data){
if( callback == NULL )
return _convert_image_util_error_code(__func__, IMAGE_UTIL_ERROR_INVALID_PARAMETER);
- int i;
- for( i = 0 ; i < sizeof(_convert_encode_colorspace_tbl)/sizeof(int) ; i++){
+ 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) )
return IMAGE_UTIL_ERROR_NONE;
-
+
}
+
return IMAGE_UTIL_ERROR_NONE;
}
-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_transform_create(transformation_h *handle)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+
+ LOGD("image_util_create");
+
+ if(handle == NULL)
+ {
+ LOGE("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ 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;
+ }
+
+ _handle->colorspace = -1;
+ _handle->_util_cb = NULL;
+ _handle->image_h = 0;
+ _handle->hardware_acceleration = false;
+ _handle->set_convert = false;
+ _handle->set_resize = false;
+ _handle->set_rotate = false;
+ _handle->set_crop = false;
+
+ ret = _image_util_create_transform_handle(_handle);
+ if(ret != MM_ERROR_NONE)
+ {
+ LOGE("INVALID_OPERATION");
+ IMAGE_UTIL_SAFE_FREE(_handle);
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ *handle = (transformation_h)_handle;
+
+ return 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);
+
+ if(_handle == NULL)
+ {
+ LOGE("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if(mode == true) {
+ LOGE("hardware acceleration is not supported");
+ return IMAGE_UTIL_ERROR_NOT_SUPPORTED;
+ }
+
+ 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;
+ }
+
+ return IMAGE_UTIL_ERROR_NONE;
+}
+
+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;
+
+ LOGD("Set colorspace_convert_info [%d]", colorspace);
+
+ if(_handle == NULL)
+ {
+ LOGE("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ 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;
+ }
+
+ _handle->colorspace = colorspace;
+ _handle->set_convert = true;
+
+ return 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;
+
+ LOGD("Set resize_info w[%d] h[%d]", width, height);
+
+ if(_handle == NULL)
+ {
+ LOGE("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ 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)) {
+ 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;
+ }
+ _handle->width = width;
+ _handle->height = height;
+ _handle->set_resize = true;
+ }
+ else
+ {
+ LOGE("INVALID_PARAMETER");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ return 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;
+
+ LOGD("Set rotate_info [%d]", rotation);
+
+ if(_handle == NULL)
+ {
+ LOGE("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ 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;
+ }
+ _handle->rotation = rotation;
+ _handle->set_rotate = true;
+
+ return 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;
+ 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;
+ }
+
+ 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);
+
+ 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;
+ }
+ _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");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ return 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;
+
+ LOGD("Get colorspace_convert_info [%d]", colorspace);
+
+ if(_handle == NULL)
+ {
+ LOGE("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if(!colorspace)
+ {
+ LOGE("colorspace area parameter error");
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ *colorspace = _handle->colorspace;
+ return ret;
+}
+
+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;
+
+ LOGD("Set resize_info w[%d] h[%d]", width, height);
+
+ if(_handle == NULL)
+ {
+ LOGE("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if(!width || !height)
+ {
+ LOGE("resolution area parameter error");
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ *width = _handle->width;
+ *height = _handle->height;
+
+ return ret;
+}
+
+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;
+
+ LOGD("Set rotate_info [%d]", rotation);
+
+ if(_handle == NULL)
+ {
+ LOGE("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if(!rotation)
+ {
+ LOGE("rotation area parameter error");
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ *rotation = _handle->rotation;
+
+ return ret;
+}
+
+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;
+
+ 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;
+ }
+
+ if(!start_x || !start_y || !end_x ||!end_y)
+ {
+ LOGE("crop area parameter error");
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ *start_x = _handle->start_x;
+ *start_y = _handle->start_y;
+ *end_x = _handle->end_x;
+ *end_y = _handle->end_y;
+
+ return ret;
+}
+
+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;
+
+ LOGD("image_util_transform");
+
+ if(_handle == NULL)
+ {
+ LOGE("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ 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;
+ }
+
+ _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);
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ 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);
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ return _convert_image_util_error_code(__func__, ret);
+}
+
+int image_util_transform_destroy(transformation_h handle)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ transformation_s *_handle = (transformation_s*)handle;
+
+ LOGD("image_util_destroy");
+
+ if(_handle == NULL)
+ {
+ LOGE("Invalid Handle");
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = mm_util_destroy(_handle->image_h);
+
+ IMAGE_UTIL_SAFE_FREE(_handle->_util_cb);
+ IMAGE_UTIL_SAFE_FREE(_handle);
+
+ return 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 ret = IMAGE_UTIL_ERROR_NONE;
- int ret;
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))
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 ret;
+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)
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 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 ret = IMAGE_UTIL_ERROR_NONE;
+
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))
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 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 ret = IMAGE_UTIL_ERROR_NONE;
+
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))
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 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 ret = IMAGE_UTIL_ERROR_NONE;
+
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))
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 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 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);
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;
+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__, 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;
+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 )
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);
ret = mm_util_jpeg_encode_to_file(path, buffer, width, height, _convert_encode_colorspace_tbl[colorspace], quality);
- return _convert_image_util_error_code(__func__, ret);
+ 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 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 ret = IMAGE_UTIL_ERROR_NONE;
int isize;
+
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))
ret = mm_util_jpeg_encode_to_memory( (void**)jpeg_buffer, &isize, image_buffer, width, height, _convert_encode_colorspace_tbl[colorspace] , quality );
if( ret == 0 )
*jpeg_size = isize;
-
+
return _convert_image_util_error_code(__func__, ret);
}
* limitations under the License.
*/
-#include <Elementary.h>
-#include <glib.h>
-#include <Ecore.h>
-#include <Ecore_X.h>
-#include <stdbool.h>
-#include <stdio.h>
#include <image_util.h>
-/*
- * Function displaying image on canva
- */
-static void _display_buffer_as_efl_image(Evas_Object *img, unsigned char *buf, int w, int h, image_util_colorspace_e colorspace)
+GMainLoop *g_loop = NULL;
+
+bool test_transform_completed_cb(media_packet_h *dst, image_util_error_e error, void *user_data)
{
- unsigned int sizeBGRA8888;
- int err;
-
- /*
- * Calculates the size of image buffer for the specified resolution and colorspace
- */
- err = image_util_calculate_buffer_size(w, h, IMAGE_UTIL_COLORSPACE_BGRA8888, &sizeBGRA8888);
- if ( IMAGE_UTIL_ERROR_NONE != err)
- return;
- static unsigned char *new_buff;
- free(new_buff);
- new_buff = malloc(sizeBGRA8888);
-
- /*
- * Convert the image's colorspace
- */
- err = image_util_convert_colorspace(new_buff, IMAGE_UTIL_COLORSPACE_BGRA8888, buf, w, h, colorspace);
- if ( IMAGE_UTIL_ERROR_NONE != err) {
- free(new_buff);
- return;
+ 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);
}
- evas_object_hide(img);
- evas_object_image_size_set(img, w, h);
- evas_object_image_colorspace_set(img, EVAS_COLORSPACE_ARGB8888);
- evas_object_image_data_copy_set(img, (void*)new_buff);
- evas_object_image_reload(img);
-
- evas_object_image_data_update_add(img,0,0, w, h);
- evas_object_show(img);
-}
-
-struct raw_image{
- unsigned char *buffer;
- int size;
- int w;
- int h;
-};
-
-Evas_Object* img;
-
-char *colorspace_str_tbl[] = {
- "IMAGE_UTIL_COLORSPACE_YV12", /**< YV12 */
- "IMAGE_UTIL_COLORSPACE_YUV422", /**< YUV422 */
- "IMAGE_UTIL_COLORSPACE_I420", /**< I420 */
- "IMAGE_UTIL_COLORSPACE_NV12", /**< NV12 */
-
- "IMAGE_UTIL_COLORSPACE_UYVY", /**< UYVY */
- "IMAGE_UTIL_COLORSPACE_YUYV", /**< YUYV */
-
- "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 */
-};
-
-
-
-bool decode_jpeg_cb( image_util_colorspace_e colorspace , void * user_data){
- int ret;
- unsigned char * buffer = NULL;
- int w, h;
- unsigned int size;
-
- const char *path = (const char*)user_data;
-
- printf("jpeg(%s) decode to [%s]\n", path, colorspace_str_tbl[colorspace] );
-
-
- w = h = 0;
- ret = image_util_decode_jpeg( path ,colorspace, &buffer, &w, &h , &size );
- printf("image (%dx%d) - %dbyte , ret = %d(%x)\n", w,h, size, ret, ret);
- if( ret != 0 )
- return true;
-
- _display_buffer_as_efl_image( img, buffer, w, h, colorspace);
- sleep(2);
- return true;
-
-}
-void jpeg_decode_test( const char *path ){
-
- printf("****************\n");
- printf("JPEG DECODE TEST - start\n");
- printf("****************\n");
- image_util_foreach_supported_jpeg_colorspace( decode_jpeg_cb , (void*)path);
- printf("****************\n");
- printf("JPEG DECODE TEST - end\n");
- printf("****************\n");
-
+ return TRUE;
}
-bool encode_jpeg_cb( image_util_colorspace_e colorspace , void * user_data){
- struct raw_image *img_data = (struct raw_image *)user_data;
- unsigned char *buffer;
- unsigned int size;
- int ret;
- char filename[255];
-
- printf("jpeg encode from [%s]\n", colorspace_str_tbl[colorspace] );
-
- image_util_calculate_buffer_size(img_data->w,img_data->h, colorspace, &size);
- buffer = malloc(size);
- ret = image_util_convert_colorspace(buffer, colorspace , img_data->buffer , img_data->w, img_data->h , IMAGE_UTIL_COLORSPACE_BGRA8888);
-
- snprintf(filename, 255, "test_%s.jpg", colorspace_str_tbl[colorspace]);
- ret = image_util_encode_jpeg(buffer, img_data->w , img_data->h , colorspace, 100, filename);
- printf("%s encode jpg %d\n", colorspace_str_tbl[colorspace] , ret);
-
- return true;
-
-}
-
-void jpeg_encode_test( const char *path ){
- printf("****************\n");
- printf("JPEG ENCODE TEST - start\n");
- printf("****************\n");
-
- int w,h;
- struct raw_image img_data;
- evas_object_image_file_set(img, path , NULL);
- unsigned char* origin_buffer = evas_object_image_data_get(img, true);
- evas_object_image_size_get(img, &w, &h);
- evas_object_resize(img, w,h);
- img_data.buffer = origin_buffer;
- img_data.h = h;
- img_data.w = w;
- image_util_foreach_supported_jpeg_colorspace( encode_jpeg_cb , (void*)&img_data);
- evas_object_image_data_set(img, origin_buffer);
-
- printf("****************\n");
- printf("JPEG ENCODE TEST - end\n");
- printf("****************\n");
-
-}
-
-void colorspace_convert_test( const char *path ){
- printf("****************\n");
- printf("colorspace_convert_test TEST - start\n");
- printf("****************\n");
-
-
- int w,h;
- evas_object_image_file_set(img, path, NULL);
- unsigned char* origin_buffer = evas_object_image_data_get(img, true);
- evas_object_image_size_get(img, &w, &h);
- evas_object_resize(img, w,h);
-
- int i;
- int j;
- int ret;
-
- for( i = IMAGE_UTIL_COLORSPACE_YV12 ; i <= IMAGE_UTIL_COLORSPACE_BGRX8888 ; i++ ){
- unsigned char *buffer;
- unsigned int size;
-
- if( i == IMAGE_UTIL_COLORSPACE_BGRA8888 )
- continue;
-
- image_util_calculate_buffer_size(w, h, i,&size);
- buffer = malloc(size);
- ret = image_util_convert_colorspace(buffer, i , origin_buffer, w, h, IMAGE_UTIL_COLORSPACE_BGRA8888);
- printf("[%d] convert %s -> %s\n", ret , colorspace_str_tbl[IMAGE_UTIL_COLORSPACE_BGRA8888], colorspace_str_tbl[i]);
-
- for( j = IMAGE_UTIL_COLORSPACE_YV12 ; j <= IMAGE_UTIL_COLORSPACE_BGRX8888 ; j++){
- if( i == j )
- continue;
- unsigned char *buffer2;
- unsigned int size2;
- image_util_calculate_buffer_size(w, h, j,&size2);
- buffer2 = malloc(size2);
- ret = image_util_convert_colorspace(buffer2, j , buffer, w, h, i);
- printf("[%d] convert %s -> %s\n", ret , colorspace_str_tbl[i], colorspace_str_tbl[j]);
- free(buffer2);
+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;
}
-
- free(buffer);
-
- }
-
+ 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;
+ }
- evas_object_image_data_set(img, origin_buffer);
+ 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;
+ }
-
- printf("****************\n");
- printf("colorspace_convert_test - end\n");
- printf("****************\n");
+ 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...");
+ }
-void rotate_test( const char *path ){
- printf("****************\n");
- printf("rotate_test TEST - start\n");
- printf("****************\n");
- int w,h,dw,dh;
- int ret;
- unsigned char *origin_buffer;
- unsigned int size;
- int i;
-
-
- w = h = 0;
- ret = image_util_decode_jpeg( path ,IMAGE_UTIL_COLORSPACE_RGB888, &origin_buffer, &w, &h , &size );
- printf("image (%dx%d) - %dbyte , ret = %d(%x)\n", w,h, size, ret, ret);
-
- _display_buffer_as_efl_image(img, origin_buffer, w,h, IMAGE_UTIL_COLORSPACE_RGB888);
- sleep(2);
-
- unsigned char *dest_buffer = NULL;
- unsigned int nsize;
- dw = h;
- dh = w;
- image_util_calculate_buffer_size( dw,dh, IMAGE_UTIL_COLORSPACE_RGB888 , &nsize);
- dest_buffer = malloc(nsize);
-
- for( i = 0 ; i < 10 ; i ++ ){
- ret = image_util_rotate(dest_buffer, &dw,&dh, IMAGE_UTIL_ROTATION_90, origin_buffer, w,h, IMAGE_UTIL_COLORSPACE_RGB888);
- printf("image_util_rotate ret = %d\n", ret);
- printf("%x%x%x\n", dest_buffer[0], dest_buffer[20], dest_buffer[44]);
- _display_buffer_as_efl_image(img, dest_buffer, dw,dh, IMAGE_UTIL_COLORSPACE_RGB888);
- sleep(2);
- int tw, th;
- unsigned char *tmp_buffer;
- tmp_buffer = dest_buffer;
- dest_buffer = origin_buffer;
- origin_buffer = tmp_buffer;
- tw = dw;
- th = dh;
- dw = w;
- dh = h;
- w = tw;
- h = th;
+ 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;
}
-
- printf("****************\n");
- printf("transform_test TEST - end\n");
- printf("****************\n");
-
+ media_format_unref(fmt);
+ return ret;
}
-void* test_main(void *arg){
- jpeg_decode_test("sample.jpg");
- //jpeg_encode_test("sample.jpg");
- //colorspace_convert_test("sample.jpg");
- rotate_test("sample.jpg");
-
-
- return NULL;
-}
+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;
+ }
- Eina_Bool _window_update(void *data){
- return 1;
-}
+ 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;
+ }
+ }
-int main(int argc, char ** argv)
-{
- int w,h;
- elm_init(argc, argv);
- Evas_Object* win;
+ 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;
+ }
+ }
- win = elm_win_add(NULL, "VIDEO OVERLAY", ELM_WIN_BASIC);
- elm_win_title_set(win, "video overlay window");
- elm_win_borderless_set(win, EINA_TRUE);
- ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h);
- evas_object_resize(win, w, h);
- elm_win_indicator_state_set(win, EINA_TRUE);
+ if (!strcmp("rotate", argv[1])) {
+ angle = atoi(argv[2]);
- evas_object_show(win);
+ 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;
+ }
+ }
- img = evas_object_image_add(evas_object_evas_get(win));
- printf("%d,%d\n", w,h);
+ 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);
+ }
-
- evas_object_resize(img, w,h);
- evas_object_image_fill_set(img, 0, 0, w, h);
- evas_object_show(img);
+ if(ret != IMAGE_UTIL_ERROR_NONE)
+ goto Exit;
+ g_loop = g_main_loop_new(NULL, FALSE);
- ecore_timer_add(0.1, _window_update, NULL);
-
+ g_main_loop_run(g_loop);
+ g_main_loop_unref(g_loop);
-
- pthread_t gloop_thread;
- pthread_create(&gloop_thread, NULL, test_main, NULL);
+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);
+ }
- elm_run();
- elm_shutdown();
-
+ if(_util_s != NULL)
+ free(_util_s);
return 0;
}
-
-