#include <mm_util_private.h>
#include <tzplatform_config.h>
-#define TEST_STRING_VALID(str) ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
#define WEBP_ENCODE_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "anim_test_enc_file.webp")
#define WEBP_ENCODE_MEM_PATH tzplatform_mkpath(TZ_USER_CONTENT, "anim_test_enc_mem.webp")
char *path = (char *)data;
mm_util_image_h image = NULL;
- if (!TEST_STRING_VALID(path)) {
+ if (!MMUTIL_STRING_VALID(path)) {
g_print("\t[ANIM_testsuite] invalid path %s\n", path);
return;
}
{
g_path = g_strdup(argv[1]);
- if (!TEST_STRING_VALID(g_path)) {
+ if (!MMUTIL_STRING_VALID(g_path)) {
fprintf(stderr, "\t[ANIM_testsuite] invalid path %s\n", argv[1]);
return FALSE;
}
fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_add_image failed : %d\n", ret);
}
-static gboolean __test_encode_to_file(mm_util_img_codec_type type, const char *path)
+static int __anim_encode_setup(mm_util_img_codec_type type, mm_util_anim_enc_h *anim_encode)
{
- int ret = 0;
+ int ret = MM_UTIL_ERROR_NONE;
mm_util_anim_enc_h anim_enc = NULL;
- fprintf(stderr, "[ANIM_testsuite] The test begins: %d, %s\n", type, path);
+ mm_util_retvm_if(!anim_encode, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid anim_encode");
ret = mm_util_anim_enc_create(type, &anim_enc);
if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_create failed : %d\n", ret);
- return FALSE;
+ fprintf(stderr, "\t[ANIM_testsuite] mm_util_anim_enc_create failed : %d\n", ret);
+ return ret;
}
ret = mm_util_anim_enc_set_bgcolor(anim_enc, g_bgcolor[0], g_bgcolor[1], g_bgcolor[2], g_bgcolor[3]);
if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_set_bgcolor failed : %d\n", ret);
+ fprintf(stderr, "\t[ANIM_testsuite] mm_util_anim_enc_set_bgcolor failed : %d\n", ret);
if (ret != MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT)
- goto END;
+ goto ERROR;
}
ret = mm_util_anim_enc_set_loop_count(anim_enc, TEST_LOOP_COUNT);
if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_set_loop_count failed : %d\n", ret);
+ fprintf(stderr, "\t[ANIM_testsuite] mm_util_anim_enc_set_loop_count failed : %d\n", ret);
if (ret != MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT)
- goto END;
+ goto ERROR;
}
ret = mm_util_anim_enc_set_lossless(anim_enc, TRUE);
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\t[ANIM_testsuite] mm_util_anim_enc_set_lossless failed : %d\n", ret);
if (ret != MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT)
- goto END;
+ goto ERROR;
+ }
+
+ *anim_encode = anim_enc;
+ fprintf(stderr, "[ANIM_testsuite] The handle setup\n");
+ return MM_UTIL_ERROR_NONE;
+ERROR:
+ mm_util_anim_enc_destroy(anim_enc);
+
+ return ret;
+}
+
+static gboolean __test_encode_to_file(mm_util_img_codec_type type, const char *path)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_util_anim_enc_h anim_enc = NULL;
+
+ fprintf(stderr, "[ANIM_testsuite] The test begins: %d, %s\n", type, path);
+
+ ret = __anim_encode_setup(type, &anim_enc);
+ if (ret != MM_UTIL_ERROR_NONE) {
+ fprintf(stderr, "\t[ANIM_testsuite] __anim_enc_setup failed : %d\n", ret);
+ return ret;
}
g_queue_foreach(g_queue_images, __add_image, anim_enc);
if (ret != MM_UTIL_ERROR_NONE)
fprintf(stderr, "\t[ANIM_testsuite] mm_util_encode_webp_to_file failed : %d\n", ret);
-END:
mm_util_anim_enc_destroy(anim_enc);
- fprintf(stderr, "[ANIM_testsuite] The test ended\n");
+ fprintf(stderr, "[ANIM_testsuite] The test finished.\n");
- if (ret != MM_UTIL_ERROR_NONE)
- return FALSE;
-
- return TRUE;
+ return (ret == MM_UTIL_ERROR_NONE);
}
static gboolean __test_encode_to_buffer(mm_util_img_codec_type type, const char *path)
{
- int ret = 0;
+ int ret = MM_UTIL_ERROR_NONE;
mm_util_anim_enc_h anim_enc = NULL;
/* for encoding webp to memory */
unsigned char *encoded_data = NULL;
fprintf(stderr, "[ANIM_testsuite] The test begins: %d, %s\n", type, path);
- ret = mm_util_anim_enc_create(type, &anim_enc);
+ ret = __anim_encode_setup(type, &anim_enc);
if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_create failed : %d\n", ret);
- return FALSE;
- }
-
- ret = mm_util_anim_enc_set_bgcolor(anim_enc, g_bgcolor[0], g_bgcolor[1], g_bgcolor[2], g_bgcolor[3]);
- if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_set_bgcolor failed : %d\n", ret);
- if (ret != MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT)
- goto END;
+ fprintf(stderr, "\t[ANIM_testsuite] __anim_enc_setup failed : %d\n", ret);
+ return ret;
}
-
- ret = mm_util_anim_enc_set_loop_count(anim_enc, TEST_LOOP_COUNT);
- if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_set_loop_count failed : %d\n", ret);
- if (ret != MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT)
- goto END;
- }
-
- ret = mm_util_anim_enc_set_lossless(anim_enc, true);
- if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[ANIM_testsuite] mm_util_anim_enc_set_lossless failed : %d\n", ret);
- if (ret != MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT)
- goto END;
- }
-
g_queue_foreach(g_queue_images, __add_image, anim_enc);
ret = mm_util_anim_enc_save_to_buffer(anim_enc, &encoded_data, &encoded_size);
- if (ret != MM_UTIL_ERROR_NONE) {
+ if (ret == MM_UTIL_ERROR_NONE) {
+ ret = mm_util_file_write(path, encoded_data, encoded_size);
+ if (ret != MM_UTIL_ERROR_NONE)
+ printf("Fail mm_util_file_write [%d]\n", ret);
+ } else {
fprintf(stderr, "\t[ANIM_testsuite] mm_util_webp_anim_enc_save_to_buffer failed : %d\n", ret);
- goto END;
}
- ret = mm_util_file_write(path, encoded_data, encoded_size);
- if (ret != MM_UTIL_ERROR_NONE)
- printf("Fail mm_util_file_write [%d]\n", ret);
-
-END:
mm_util_anim_enc_destroy(anim_enc);
- g_free(encoded_data);
-
- fprintf(stderr, "[ANIM_testsuite] The test ended\n");
+ MMUTIL_SAFE_FREE(encoded_data);
- if (ret != MM_UTIL_ERROR_NONE)
- return FALSE;
+ fprintf(stderr, "[ANIM_testsuite] The test finished.\n");
- return TRUE;
+ return (ret == MM_UTIL_ERROR_NONE);
}
int main(int argc, char *argv[])
return 0;
}
- if (FALSE == __get_arguments(argc, argv)) {
+ if (!__get_arguments(argc, argv)) {
fprintf(stderr, "\t[ANIM_testsuite] _get_arguments failed\n");
goto out;
}
/* test encoding webp animation to file */
- if (FALSE == __test_encode_to_file(ANIM_CODEC_WEBP, WEBP_ENCODE_FILE_PATH)) {
- fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_file failed\n");
+ if (!__test_encode_to_file(ANIM_CODEC_WEBP, WEBP_ENCODE_FILE_PATH)) {
+ fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_file(webp) failed\n");
goto out;
}
/* test encoding webp animation to buffer */
- if (FALSE == __test_encode_to_buffer(ANIM_CODEC_WEBP, WEBP_ENCODE_MEM_PATH)) {
- fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_buffer failed\n");
+ if (!__test_encode_to_buffer(ANIM_CODEC_WEBP, WEBP_ENCODE_MEM_PATH)) {
+ fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_buffer(webp) failed\n");
goto out;
}
/* test encoding agif animation to file */
- if (FALSE == __test_encode_to_file(ANIM_CODEC_GIF, GIF_ENCODE_FILE_PATH)) {
- fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_file failed\n");
+ if (!__test_encode_to_file(ANIM_CODEC_GIF, GIF_ENCODE_FILE_PATH)) {
+ fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_file(gif) failed\n");
goto out;
}
/* test encoding agif animation to buffer */
- if (FALSE == __test_encode_to_buffer(ANIM_CODEC_GIF, GIF_ENCODE_MEM_PATH)) {
- fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_buffer failed\n");
+ if (!__test_encode_to_buffer(ANIM_CODEC_GIF, GIF_ENCODE_MEM_PATH)) {
+ fprintf(stderr, "\t[ANIM_testsuite] __test_encode_to_buffer(gif) failed\n");
goto out;
}
out:
- g_free(g_path);
+ MMUTIL_SAFE_FREE(g_path);
g_queue_free_full(g_queue_images, mm_image_destroy_image);
g_queue_free_full(g_queue_files, g_free);
extern "C" {
#endif
+
/* for memory management */
-#define MMUTIL_SAFE_FREE(x) { if (x) { free(x); x = NULL; } }
-#define MMUTIL_SAFE_STRCPY(dst, src, n) g_strlcpy(dst, src, n)
-#define MMUTIL_STRING_VALID(str) ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
+#define MMUTIL_SAFE_FREE(x) do { \
+ g_free(x); \
+ x = NULL; \
+ } while(0)
+#define MMUTIL_SAFE_IMAGE_FREE(x) do { \
+ mm_image_destroy_image(x); \
+ x = NULL; \
+ } while(0)
+#define MMUTIL_SAFE_STRCPY(dst, src, n) g_strlcpy(dst, src, n)
+#define MMUTIL_STRING_VALID(str) (str != NULL && strlen(str) > 0)
#define SAFE_STRLCPY(dst, src, n) g_strlcpy(dst, src, n);
--- /dev/null
+/*
+* Copyright (c) 2022 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 __MM_UTIL_TEST_INTERNAL_H__
+#define __MM_UTIL_TEST_INTERNAL_H__
+
+#include <glib.h>
+#include <mm_util_image.h>
+
+typedef enum {
+ TEST_AUTO,
+ TEST_DECODE_FILE,
+ TEST_DECODE_BUFFER,
+ TEST_ENCODE_FILE,
+ TEST_ENCODE_BUFFER,
+ TEST_NUM,
+} mm_util_test_mode_e;
+
+#endif /*__MM_UTIL_TEST_INTERNAL_H__*/
#include <mm_util_gif.h>
#include <mm_util_image.h>
#include <mm_util_private.h>
+#include <mm_util_test_internal.h>
#include <tzplatform_config.h>
-#define SAFE_FREE(x) { if (x != NULL) { free(x); x = NULL; } }
-#define SAFE_G_FREE(x) { if (x != NULL) { g_free(x); x = NULL; } }
-#define SAFE_IMAGE_FREE(x) { if (x != NULL) { mm_image_destroy_image(x); x = NULL; } }
-
#define DECODE_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "gif_test_dec_file.raw")
#define DECODE_MEM_PATH tzplatform_mkpath(TZ_USER_CONTENT, "gif_test_dec_mem.raw")
#define ENCODE_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "gif_test_enc_file.gif")
#define ENCODE_MEM_PATH tzplatform_mkpath(TZ_USER_CONTENT, "gif_test_enc_mem.gif")
-typedef enum {
- TEST_AUTO,
- TEST_DECODE_FILE,
- TEST_DECODE_MEMORY,
- TEST_ENCODE_FILE,
- TEST_ENCODE_MEMORY,
- TEST_NUM,
-} test_mode_e;
-
static char *MODE_TO_STR[] = {
"AUTO",
"DECODE_FILE",
g_path = g_strdup(argv[2]);
- if ((g_test_mode == TEST_AUTO) || (g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_MEMORY)) {
+ if ((g_test_mode == TEST_AUTO) || (g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_BUFFER)) {
/* do nothing */
- } else if (g_test_mode == TEST_ENCODE_FILE || g_test_mode == TEST_ENCODE_MEMORY) {
+ } else if (g_test_mode == TEST_ENCODE_FILE || g_test_mode == TEST_ENCODE_BUFFER) {
if (argc < 4) {
fprintf(stderr, "\t[GIF_testsuite] not enough args\n");
_print_help(argv[0]);
return TRUE;
}
-gboolean _test_decode(const test_mode_e mode)
+gboolean _test_decode(const mm_util_test_mode_e mode)
{
int ret = 0;
unsigned char *data = NULL;
ret = mm_util_file_write(DECODE_FILE_PATH, data, size);
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\t[GIF_testsuite] mm_util_file_write failed %d\n", ret);
- SAFE_FREE(data);
+ MMUTIL_SAFE_FREE(data);
return FALSE;
}
- SAFE_FREE(data);
- } else if (mode == TEST_DECODE_MEMORY) {
+ MMUTIL_SAFE_FREE(data);
+ } else if (mode == TEST_DECODE_BUFFER) {
ret = mm_util_file_read(g_path, &g_read_data, &g_read_size);
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\t[GIF_testsuite] mm_util_file_read failed %d\n", ret);
ret = mm_util_file_write(DECODE_MEM_PATH, data, size);
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\t[GIF_testsuite] mm_util_file_write failed %d\n", ret);
- SAFE_FREE(data);
+ MMUTIL_SAFE_FREE(data);
return FALSE;
}
- SAFE_FREE(data);
+ MMUTIL_SAFE_FREE(data);
}
return TRUE;
}
-gboolean _test_encode(const test_mode_e mode)
+gboolean _test_encode(const mm_util_test_mode_e mode)
{
int ret = 0;
/* for encoding gif to memory */
void *encoded_data = NULL;
size_t encoded_size = 0;
- if ((mode != TEST_ENCODE_FILE) && (mode != TEST_ENCODE_MEMORY))
+ if ((mode != TEST_ENCODE_FILE) && (mode != TEST_ENCODE_BUFFER))
return TRUE;
ret = mm_util_file_read(g_path, &g_read_data, &g_read_size);
fprintf(stderr, "\t[GIF_testsuite] mm_util_encode_gif_to_file failed : %d\n", ret);
return FALSE;
}
- } else if (mode == TEST_ENCODE_MEMORY) {
+ } else if (mode == TEST_ENCODE_BUFFER) {
ret = mm_util_encode_to_gif_memory(&g_decoded_data, 1, &encoded_data, &encoded_size);
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\t[GIF_testsuite] mm_util_encode_gif_to_memory failed : %d\n", ret);
- SAFE_FREE(encoded_data);
+ MMUTIL_SAFE_FREE(encoded_data);
return FALSE;
}
ret = mm_util_file_write(ENCODE_MEM_PATH, encoded_data, encoded_size);
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\t[GIF_testsuite] mm_util_file_write failed %d\n", ret);
- SAFE_FREE(encoded_data);
+ MMUTIL_SAFE_FREE(encoded_data);
return FALSE;
}
}
- SAFE_FREE(encoded_data);
+ MMUTIL_SAFE_FREE(encoded_data);
return TRUE;
}
gboolean _test_auto()
{
- test_mode_e test_mode = TEST_DECODE_FILE;
+ mm_util_test_mode_e test_mode = TEST_DECODE_FILE;
while (test_mode < TEST_NUM) {
fprintf(stderr, "\t[GIF_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST START\n", MODE_TO_STR[test_mode]);
g_path = g_strdup(DECODE_FILE_PATH);
}
/* test decoding gif */
- if ((test_mode == TEST_DECODE_FILE) || (test_mode == TEST_DECODE_MEMORY)) {
+ if ((test_mode == TEST_DECODE_FILE) || (test_mode == TEST_DECODE_BUFFER)) {
if (FALSE == _test_decode(test_mode)) {
fprintf(stderr, "\t[GIF_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]);
return FALSE;
}
/* test encoding gif */
- if ((test_mode == TEST_ENCODE_FILE) || (test_mode == TEST_ENCODE_MEMORY)) {
+ if ((test_mode == TEST_ENCODE_FILE) || (test_mode == TEST_ENCODE_BUFFER)) {
if (FALSE == _test_encode(test_mode)) {
fprintf(stderr, "\t[GIF_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]);
return FALSE;
fprintf(stderr, "\t[GIF_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST SUCCESS\n", MODE_TO_STR[test_mode]);
- g_free(g_read_data);
- g_read_data = NULL;
- SAFE_IMAGE_FREE(g_decoded_data);
+ MMUTIL_SAFE_FREE(g_read_data);
+ MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
test_mode++;
}
}
/* test decoding gif */
- if ((g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_MEMORY)) {
+ if ((g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_BUFFER)) {
if (FALSE == _test_decode(g_test_mode)) {
fprintf(stderr, "\t[GIF_testsuite] _test_decode(%s) failed\n", MODE_TO_STR[g_test_mode]);
goto out;
}
/* test encoding gif */
- if ((g_test_mode == TEST_ENCODE_FILE) || (g_test_mode == TEST_ENCODE_MEMORY)) {
+ if ((g_test_mode == TEST_ENCODE_FILE) || (g_test_mode == TEST_ENCODE_BUFFER)) {
if (FALSE == _test_encode(g_test_mode)) {
fprintf(stderr, "\t[GIF_testsuite] _test_encode(%s) failed\n", MODE_TO_STR[g_test_mode]);
goto out;
}
out:
- g_free(g_path);
- g_free(g_read_data);
- SAFE_IMAGE_FREE(g_decoded_data);
+ MMUTIL_SAFE_FREE(g_path);
+ MMUTIL_SAFE_FREE(g_read_data);
+ MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
return 0;
}
#include <mm_util_image.h>
#include <mm_util_jpeg.h>
#include <mm_util_private.h>
-
-#define SAFE_FREE(x) { g_free(x); x = NULL; }
-#define SAFE_IMAGE_FREE(x) { if (x != NULL) { mm_image_destroy_image(x); x = NULL; } }
-
-typedef enum {
- TEST_AUTO,
- TEST_DECODE_FILE,
- TEST_DECODE_BUFFER,
- TEST_NUM,
-} heif_test_mode_e;
+#include <mm_util_test_internal.h>
static char *MODE_TO_STR[] = {
"AUTO",
return TRUE;
}
-static gboolean __test_decode(const heif_test_mode_e mode, mm_util_color_format_e color, const char *path)
+static gboolean __test_decode(const mm_util_test_mode_e mode, mm_util_color_format_e color, const char *path)
{
int ret = 0;
static gboolean __test_auto()
{
- heif_test_mode_e test_mode = TEST_DECODE_FILE;
+ mm_util_test_mode_e test_mode = TEST_DECODE_FILE;
mm_util_color_format_e color = MM_UTIL_COLOR_YUV420;
gboolean result = FALSE;
- while (test_mode < TEST_NUM) {
+ while (test_mode <= TEST_DECODE_BUFFER) {
g_print("\t[HEIF_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST START\n", MODE_TO_STR[test_mode]);
/* test decoding heif */
if ((test_mode == TEST_DECODE_FILE) || (test_mode == TEST_DECODE_BUFFER)) {
for (color = MM_UTIL_COLOR_YUV420; color < MM_UTIL_COLOR_NUM; color++) {
result |= __test_decode(test_mode, color, g_test_filename[test_mode][color]);
- SAFE_FREE(g_read_data);
- SAFE_IMAGE_FREE(g_decoded_data);
+ MMUTIL_SAFE_FREE(g_read_data);
+ MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
}
}
out:
g_free(g_path);
- SAFE_FREE(g_read_data);
- SAFE_IMAGE_FREE(g_decoded_data);
+ MMUTIL_SAFE_FREE(g_read_data);
+ MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
return 0;
}
#include <mm_util_imgp.h>
#include <mm_util_image.h>
#include <mm_util_private.h>
+#include <mm_util_test_internal.h>
#include <limits.h>
#include <tzplatform_config.h>
-#define IMGP_FREE(src) { if (src != NULL) {g_free(src); src = NULL; } }
-#define SAFE_IMAGE_FREE(x) { if (x != NULL) { mm_image_destroy_image(x); x = NULL; } }
-
typedef struct {
/* for source image */
char *path;
}
TEST_FAIL:
- SAFE_IMAGE_FREE(_src);
- SAFE_IMAGE_FREE(_dst);
- IMGP_FREE(g_transformed.data);
- IMGP_FREE(g_args.data);
- g_free(g_args.cmd);
- g_free(g_args.path);
+ MMUTIL_SAFE_IMAGE_FREE(_src);
+ MMUTIL_SAFE_IMAGE_FREE(_dst);
+ MMUTIL_SAFE_FREE(g_transformed.data);
+ MMUTIL_SAFE_FREE(g_args.data);
+ MMUTIL_SAFE_FREE(g_args.cmd);
+ MMUTIL_SAFE_FREE(g_args.path);
return 0;
}
#include <mm_util_jpeg.h>
#include <mm_util_image.h>
#include <mm_util_private.h>
+#include <mm_util_test_internal.h>
#include <tzplatform_config.h>
-#define SAFE_FREE(x) { if (x != NULL) { free(x); x = NULL; } }
-#define SAFE_IMAGE_FREE(x) { if (x != NULL) { mm_image_destroy_image(x); x = NULL; } }
-
#define DECODE_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "jpeg_test_dec_file.raw")
#define DECODE_MEM_PATH tzplatform_mkpath(TZ_USER_CONTENT, "jpeg_test_dec_mem.raw")
#define ENCODE_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "jpeg_test_enc_file.jpg")
#define ENCODE_MEM_PATH tzplatform_mkpath(TZ_USER_CONTENT, "jpeg_test_enc_mem.jpg")
-typedef enum {
- TEST_AUTO,
- TEST_DECODE_FILE,
- TEST_DECODE_MEMORY,
- TEST_ENCODE_FILE,
- TEST_ENCODE_MEMORY,
- TEST_NUM,
-} jpeg_test_mode_e;
-
static char *MODE_TO_STR[] = {
"AUTO",
"DECODE_FILE",
} else if (g_test_mode == TEST_DECODE_FILE) {
if (FALSE == mm_util_safe_str_to_valid_uint(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
fprintf(stderr, "\t[JPEG_testsuite] color is default(%d)\n", g_color);
- } else if (g_test_mode == TEST_DECODE_MEMORY) {
+ } else if (g_test_mode == TEST_DECODE_BUFFER) {
if (FALSE == mm_util_safe_str_to_valid_uint(argv[3], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &g_color))
fprintf(stderr, "\t[JPEG_testsuite] color is default(%d)\n", g_color);
- } else if (g_test_mode == TEST_ENCODE_FILE || g_test_mode == TEST_ENCODE_MEMORY) {
+ } else if (g_test_mode == TEST_ENCODE_FILE || g_test_mode == TEST_ENCODE_BUFFER) {
if (argc < 5) {
fprintf(stderr, "\t[JPEG_testsuite] not enough args\n");
_print_help(argv[0]);
return TRUE;
}
-gboolean _test_decode(const jpeg_test_mode_e mode)
+gboolean _test_decode(const mm_util_test_mode_e mode)
{
int ret = 0;
unsigned char *data = NULL;
ret = mm_util_file_write(DECODE_FILE_PATH, data, size);
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\t[JPEG_testsuite] mm_util_file_write failed %d\n", ret);
- SAFE_FREE(data);
+ MMUTIL_SAFE_FREE(data);
return FALSE;
}
- SAFE_FREE(data);
- } else if (mode == TEST_DECODE_MEMORY) {
+ MMUTIL_SAFE_FREE(data);
+ } else if (mode == TEST_DECODE_BUFFER) {
ret = mm_util_file_read(g_path, &g_read_data, &g_read_size);
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\t[JPEG_testsuite] mm_util_file_read failed %d\n", ret);
ret = mm_util_file_write(DECODE_MEM_PATH, data, size);
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\t[JPEG_testsuite] mm_util_file_write failed %d\n", ret);
- SAFE_FREE(data);
+ MMUTIL_SAFE_FREE(data);
return FALSE;
}
- SAFE_FREE(data);
+ MMUTIL_SAFE_FREE(data);
}
return TRUE;
}
-gboolean _test_encode(const jpeg_test_mode_e mode)
+gboolean _test_encode(const mm_util_test_mode_e mode)
{
int ret = 0;
/* for encoding jpeg to memory */
void *encoded_data = NULL;
size_t encoded_size = 0;
- if ((mode != TEST_ENCODE_FILE) && (mode != TEST_ENCODE_MEMORY))
+ if ((mode != TEST_ENCODE_FILE) && (mode != TEST_ENCODE_BUFFER))
return TRUE;
ret = mm_util_file_read(g_path, &g_read_data, &g_read_size);
fprintf(stderr, "\t[JPEG_testsuite] mm_util_jpeg_encode_to_file failed : %d\n", ret);
return FALSE;
}
- } else if (mode == TEST_ENCODE_MEMORY) {
+ } else if (mode == TEST_ENCODE_BUFFER) {
ret = mm_util_encode_to_jpeg_memory(g_decoded_data, (int)g_quality, &encoded_data, &encoded_size);
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\t[JPEG_testsuite] mm_util_jpeg_encode_to_file failed : %d\n", ret);
- SAFE_FREE(encoded_data);
+ MMUTIL_SAFE_FREE(encoded_data);
return FALSE;
}
ret = mm_util_file_write(ENCODE_MEM_PATH, encoded_data, encoded_size);
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\t[JPEG_testsuite] mm_util_file_write failed %d\n", ret);
- SAFE_FREE(encoded_data);
+ MMUTIL_SAFE_FREE(encoded_data);
return FALSE;
}
}
- SAFE_FREE(encoded_data);
+ MMUTIL_SAFE_FREE(encoded_data);
return TRUE;
}
gboolean _test_auto()
{
- jpeg_test_mode_e test_mode = TEST_DECODE_FILE;
+ mm_util_test_mode_e test_mode = TEST_DECODE_FILE;
while (test_mode < TEST_NUM) {
fprintf(stderr, "\t[JPEG_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST START\n", MODE_TO_STR[test_mode]);
g_path = g_strdup(DECODE_FILE_PATH);
}
/* test decoding jpeg */
- if ((test_mode == TEST_DECODE_FILE) || (test_mode == TEST_DECODE_MEMORY)) {
+ if ((test_mode == TEST_DECODE_FILE) || (test_mode == TEST_DECODE_BUFFER)) {
if (FALSE == _test_decode(test_mode)) {
fprintf(stderr, "\t[JPEG_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]);
return FALSE;
}
/* test encoding jpeg */
- if ((test_mode == TEST_ENCODE_FILE) || (test_mode == TEST_ENCODE_MEMORY)) {
+ if ((test_mode == TEST_ENCODE_FILE) || (test_mode == TEST_ENCODE_BUFFER)) {
if (FALSE == _test_encode(test_mode)) {
fprintf(stderr, "\t[JPEG_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]);
return FALSE;
fprintf(stderr, "\t[JPEG_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST SUCCESS\n", MODE_TO_STR[test_mode]);
- SAFE_FREE(g_read_data);
- SAFE_IMAGE_FREE(g_decoded_data);
+ MMUTIL_SAFE_FREE(g_read_data);
+ MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
test_mode++;
}
}
/* test decoding jpeg */
- if ((g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_MEMORY)) {
+ if ((g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_BUFFER)) {
if (FALSE == _test_decode(g_test_mode)) {
fprintf(stderr, "\t[JPEG_testsuite] _test_decode(%s) failed\n", MODE_TO_STR[g_test_mode]);
goto out;
}
/* test encoding jpeg */
- if ((g_test_mode == TEST_ENCODE_FILE) || (g_test_mode == TEST_ENCODE_MEMORY)) {
+ if ((g_test_mode == TEST_ENCODE_FILE) || (g_test_mode == TEST_ENCODE_BUFFER)) {
if (FALSE == _test_encode(g_test_mode)) {
fprintf(stderr, "\t[JPEG_testsuite] _test_encode(%s) failed\n", MODE_TO_STR[g_test_mode]);
goto out;
out:
g_free(g_path);
- SAFE_FREE(g_read_data);
- SAFE_IMAGE_FREE(g_decoded_data);
+ MMUTIL_SAFE_FREE(g_read_data);
+ MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
return 0;
}
#include <mm_util_jxl.h>
#include <mm_util_jpeg.h>
#include <mm_util_private.h>
+#include <mm_util_test_internal.h>
-#define SAFE_FREE(x) { g_free(x); x = NULL; }
-#define SAFE_IMAGE_FREE(x) { if (x != NULL) { mm_image_destroy_image(x); x = NULL; } }
#define MAX_QUALITY 4
-typedef enum {
- TEST_AUTO,
- TEST_DECODE_FILE,
- TEST_DECODE_BUFFER,
- TEST_ENCODE_FILE,
- TEST_ENCODE_BUFFER,
- TEST_NUM,
-} jxl_test_mode_e;
-
static char *MODE_TO_STR[] = {
"AUTO",
"DECODE_FILE",
g_print("\t[JXL_testsuite] __set_enc_opt lossless: %s\n", (lossless) ? "lossless" : "lossy");
}
-static gboolean __test_decode(const jxl_test_mode_e mode, mm_util_color_format_e color)
+static gboolean __test_decode(const mm_util_test_mode_e mode, mm_util_color_format_e color)
{
int ret = 0;
- SAFE_FREE(g_read_data);
- SAFE_IMAGE_FREE(g_decoded_data);
+ MMUTIL_SAFE_FREE(g_read_data);
+ MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
if ((mode != TEST_DECODE_FILE) && (mode != TEST_DECODE_BUFFER))
return TRUE;
return TRUE;
}
-static gboolean __test_encode(const jxl_test_mode_e mode, mm_util_color_format_e color)
+static gboolean __test_encode(const mm_util_test_mode_e mode, mm_util_color_format_e color)
{
int ret = 0;
void *encoded_data = NULL;
ret = mm_util_encode_jxl_to_buffer(g_decoded_data, g_enc_opt, &encoded_data, &encoded_size);
if (ret != MM_UTIL_ERROR_NONE) {
g_print("\t[JXL_testsuite] mm_util_encode_jxl_to_buffer failed : %d\n", ret);
- SAFE_FREE(encoded_data);
+ MMUTIL_SAFE_FREE(encoded_data);
return FALSE;
}
ret = mm_util_file_write(g_test_filename[mode][color], encoded_data, encoded_size);
if (ret != MM_UTIL_ERROR_NONE)
g_print("\t[JXL_testsuite] mm_util_file_write failed : %d\n", ret);
- SAFE_FREE(encoded_data);
+ MMUTIL_SAFE_FREE(encoded_data);
}
return TRUE;
}
out:
- g_free(g_path);
- SAFE_FREE(g_read_data);
- SAFE_IMAGE_FREE(g_decoded_data);
+ MMUTIL_SAFE_FREE(g_path);
+ MMUTIL_SAFE_FREE(g_read_data);
+ MMUTIL_SAFE_IMAGE_FREE(g_decoded_data);
mm_util_enc_opt_destroy(g_enc_opt);
return 0;
#include <string.h>
#include <mm_util_magick.h>
#include <mm_util_private.h>
+#include <mm_util_test_internal.h>
typedef enum {
MM_UTIL_RESIZE,
MM_UTIL_ROTATE,
} mm_util_func_e;
-#define MM_UTIL_SAFE_FREE(src) { if (src) { free(src); src = NULL; } }
-
static int __magick_rotate_P_P_test(mm_util_rotate_type_e rotation);
static int __magick_rotate_P_B_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format);
static int __magick_rotate_B_P_test(mm_util_rotate_type_e rotation, mm_util_color_format_e req_format);
if (ret != MM_UTIL_ERROR_NONE)
printf("Fail mm_util_file_write [%d]\n", ret);
- MM_UTIL_SAFE_FREE(buffer);
+ MMUTIL_SAFE_FREE(buffer);
return;
}
{
int ret = MM_UTIL_ERROR_NONE;
mm_util_image_h dst_handle = NULL;
- char * src_path = "/opt/usr/home/owner/origin.jpg";
+ const char * src_path = "/opt/usr/home/owner/origin.jpg";
ret = mm_util_resize_P_B(src_path, 4000, 3000, req_format, &dst_handle);
if (ret != MM_UTIL_ERROR_NONE) {
if (ret != MM_UTIL_ERROR_NONE) {
printf("Fail mm_image_get_image [%d]\n", ret);
mm_image_destroy_image(dst_handle);
- MM_UTIL_SAFE_FREE(*buffer);
+ MMUTIL_SAFE_FREE(*buffer);
return ret;
}
static int __magick_rotate_P_P_test(mm_util_rotate_type_e rotation)
{
int ret = MM_UTIL_ERROR_NONE;
- char * src_path = "/opt/usr/home/owner/origin.jpg";
+ const char * src_path = "/opt/usr/home/owner/origin.jpg";
printf("* Rotate P P Test * rotation = [%d]* \n", rotation);
static int __magick_resize_P_P_test(unsigned int req_width, unsigned int req_height)
{
int ret = MM_UTIL_ERROR_NONE;
- char * src_path = "/opt/usr/home/owner/origin.jpg";
+ const char * src_path = "/opt/usr/home/owner/origin.jpg";
char dst_path[1024] = {0, };
memset(dst_path, 0x00, sizeof(dst_path));
snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/resize_pp_%u_%u.jpg", req_width, req_height);
{
int ret = MM_UTIL_ERROR_NONE;
mm_util_image_h dst_handle = NULL;
- char * src_path = "/opt/usr/home/owner/origin.jpg";
+ const char * src_path = "/opt/usr/home/owner/origin.jpg";
printf("* Rotate P B Test * rotation = [%d] format = [%d] \n", rotation, req_format);
{
int ret = MM_UTIL_ERROR_NONE;
mm_util_image_h dst_handle = NULL;
- char * src_path = "/opt/usr/home/owner/origin.jpg";
+ const char * src_path = "/opt/usr/home/owner/origin.jpg";
char dst_path[1024] = {0, };
memset(dst_path, 0x00, sizeof(dst_path));
snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/resize_pb_%u_%u.raw", req_width, req_height);
ret = mm_image_create_image(width, height, format, buffer, size, &src_handle);
if (ret != MM_UTIL_ERROR_NONE) {
printf("Fail mm_image_create_image [%d]\n", ret);
- MM_UTIL_SAFE_FREE(buffer);
+ MMUTIL_SAFE_FREE(buffer);
return ret;
}
mm_image_destroy_image(src_handle);
- MM_UTIL_SAFE_FREE(buffer);
+ MMUTIL_SAFE_FREE(buffer);
return ret;
}
ret = mm_image_create_image(width, height, format, buffer, size, &src_handle);
if (ret != MM_UTIL_ERROR_NONE) {
printf("Fail mm_image_create_image [%d]\n", ret);
- MM_UTIL_SAFE_FREE(buffer);
+ MMUTIL_SAFE_FREE(buffer);
return ret;
}
mm_image_destroy_image(src_handle);
- MM_UTIL_SAFE_FREE(buffer);
+ MMUTIL_SAFE_FREE(buffer);
return ret;
}
ret = mm_image_create_image(width, height, format, buffer, size, &src_handle);
if (ret != MM_UTIL_ERROR_NONE) {
printf("Fail mm_image_create_image [%d]\n", ret);
- MM_UTIL_SAFE_FREE(buffer);
+ MMUTIL_SAFE_FREE(buffer);
return ret;
}
if (ret != MM_UTIL_ERROR_NONE)
printf("Fail mm_util_rotate_B_B [%d]\n", ret);
- MM_UTIL_SAFE_FREE(buffer);
+ MMUTIL_SAFE_FREE(buffer);
__save_to_file(dst_handle, __get_dst_raw_path(rotation));
ret = mm_image_create_image(width, height, format, buffer, size, &src_handle);
if (ret != MM_UTIL_ERROR_NONE) {
printf("Fail mm_image_create_image [%d]\n", ret);
- MM_UTIL_SAFE_FREE(buffer);
+ MMUTIL_SAFE_FREE(buffer);
return ret;
}
if (ret != MM_UTIL_ERROR_NONE)
printf("Fail mm_util_resize_B_B [%d]\n", ret);
- MM_UTIL_SAFE_FREE(buffer);
+ MMUTIL_SAFE_FREE(buffer);
__save_to_file(dst_handle, dst_path);
ret = mm_image_create_image(width, height, format, buffer, size, &src_handle);
if (ret != MM_UTIL_ERROR_NONE) {
printf("Fail mm_image_create_image [%d]\n", ret);
- MM_UTIL_SAFE_FREE(buffer);
+ MMUTIL_SAFE_FREE(buffer);
return ret;
}
if (ret != MM_UTIL_ERROR_NONE)
printf("Fail mm_util_convert_B_B [%d]\n", ret);
- MM_UTIL_SAFE_FREE(buffer);
+ MMUTIL_SAFE_FREE(buffer);
__save_to_file(dst_handle, dst_path);
static int __magick_resize_and_rotate_P_P_test(unsigned int req_width, unsigned int req_height)
{
int ret = MM_UTIL_ERROR_NONE;
- char * src_path = "/opt/usr/home/owner/origin.jpg";
+ const char * src_path = "/opt/usr/home/owner/origin.jpg";
char dst_path[1024] = {0, };
memset(dst_path, 0x00, sizeof(dst_path));
snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/resize_rotate_pp_%u_%u.jpg", req_width, req_height);
return ret;
}
-static int __magick_decenc_file_png_test(mm_util_color_format_e format, unsigned int comp_level)
+static int __magick_decode_file_test(const char *path, mm_util_color_format_e format, mm_util_image_h* decoded_image)
{
int ret = MM_UTIL_ERROR_NONE;
- char * src_path = "/opt/usr/home/owner/origin.png";
- char dst_path[1024] = {0, };
- mm_util_image_h decoded_image = NULL;
- mm_util_enc_opt_h enc_option = NULL;
- memset(dst_path, 0x00, sizeof(dst_path));
- snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_file_png_test_%d_%u.png", format, comp_level);
+ ret = mm_util_decode_image_from_file(path, format, decoded_image);
+ if (ret != MM_UTIL_ERROR_NONE)
+ printf("Fail mm_util_decode_image_from_file [0x%x]\n", ret);
- printf("* PNG test [%s] \n", dst_path);
+ return ret;
+}
+
+static int __magick_decode_buffer_test(const char *path, mm_util_color_format_e format, mm_util_image_h* decoded_image)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ void *src_buffer = NULL;
+ size_t src_buffer_size = 0;
- ret = mm_util_decode_image_from_file(src_path, format, &decoded_image);
+ ret = mm_util_file_read(path, &src_buffer, &src_buffer_size);
if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_decode_image_from_file [0x%x]\n", ret);
+ printf("Fail mm_util_file_read [%s: %d]\n", path, ret);
return ret;
}
+ ret = mm_util_decode_image_from_buffer(src_buffer, src_buffer_size, format, decoded_image);
+ if (ret != MM_UTIL_ERROR_NONE)
+ printf("Fail mm_util_decode_image_from_buffer [0x%x]\n", ret);
+
+ MMUTIL_SAFE_FREE(src_buffer);
+ return ret;
+}
+
+static int __magick_encode_setup(mm_util_img_codec_type codec, unsigned int compression, bool lossless, mm_util_enc_opt_h *enc_opt)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_util_enc_opt_h enc_option = NULL;
+
+ mm_util_retvm_if(!enc_opt, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid enc_opt");
+
ret = mm_util_enc_opt_create(&enc_option);
if (ret != MM_UTIL_ERROR_NONE) {
printf("Fail mm_util_enc_opt_create [0x%x]\n", ret);
- goto END;
+ return ret;
}
- ret = mm_util_enc_opt_set_codec(enc_option, IMG_CODEC_PNG);
+ ret = mm_util_enc_opt_set_codec(enc_option, codec);
if (ret != MM_UTIL_ERROR_NONE) {
printf("Fail mm_util_enc_opt_set_codec [0x%x]\n", ret);
- goto END;
- }
+ goto ERROR;
+ }
+
+ if (codec == IMG_CODEC_PNG) {
+ ret = mm_util_enc_opt_set_png_compression(enc_option, compression);
+ if (ret != MM_UTIL_ERROR_NONE) {
+ printf("Fail mm_util_enc_opt_set_png_compression [0x%x]\n", ret);
+ goto ERROR;
+ }
+ } else if (codec == IMG_CODEC_WEBP) {
+ ret = mm_util_enc_opt_set_lossless(enc_option, lossless);
+ if (ret != MM_UTIL_ERROR_NONE) {
+ printf("Fail mm_util_enc_opt_set_lossless [0x%x]\n", ret);
+ goto ERROR;
+ }
+ }
+
+ *enc_opt = enc_option;
+ return MM_UTIL_ERROR_NONE;
+ERROR:
+ mm_util_enc_opt_destroy(enc_option);
+
+ return ret;
+}
+
+static int __magick_encode_file_test(mm_util_image_h decoded_image, mm_util_img_codec_type codec, unsigned int compression, bool lossless, const char *path)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ mm_util_enc_opt_h enc_option = NULL;
- ret = mm_util_enc_opt_set_png_compression(enc_option, comp_level);
+ ret = __magick_encode_setup(codec, compression, lossless, &enc_option);
if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_enc_opt_set_png_compression [0x%x]\n", ret);
- goto END;
+ printf("Fail __magick_encode_setup [0x%x]\n", ret);
+ return ret;
}
- ret = mm_util_encode_image_to_file(decoded_image, enc_option, dst_path);
+ ret = mm_util_encode_image_to_file(decoded_image, enc_option, path);
if (ret != MM_UTIL_ERROR_NONE)
printf("Fail mm_util_encode_image_to_file [0x%x]\n", ret);
-END:
mm_util_enc_opt_destroy(enc_option);
- mm_image_destroy_image(decoded_image);
return ret;
}
-static int __magick_decenc_buffer_png_test(mm_util_color_format_e format, unsigned int comp_level)
+static int __magick_encode_buffer_test(mm_util_image_h decoded_image, mm_util_img_codec_type codec, unsigned int compression, bool lossless, const char *path)
{
int ret = MM_UTIL_ERROR_NONE;
- char * src_path = "/opt/usr/home/owner/origin.png";
- char dst_path[1024] = {0, };
- mm_util_image_h decoded_image = NULL;
mm_util_enc_opt_h enc_option = NULL;
- void *src_buffer = NULL;
- size_t src_buffer_size = 0;
void *buffer = NULL;
size_t buffer_size = 0;
- memset(dst_path, 0x00, sizeof(dst_path));
- snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_buffer_png_test_%d_%u.png", format, comp_level);
-
- printf("* PNG test [%s] \n", dst_path);
-
- ret = mm_util_file_read(src_path, &src_buffer, &src_buffer_size);
+ ret = __magick_encode_setup(codec, compression, lossless, &enc_option);
if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_file_read [%s: %d]\n", src_path, ret);
- return ret;
- }
-
- ret = mm_util_decode_image_from_buffer(src_buffer, src_buffer_size, format, &decoded_image);
- if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_decode_image_from_buffer [0x%x]\n", ret);
- g_free(src_buffer);
+ printf("Fail __magick_encode_setup [0x%x]\n", ret);
return ret;
}
- g_free(src_buffer);
-
- ret = mm_util_enc_opt_create(&enc_option);
- if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_enc_opt_create [0x%x]\n", ret);
- goto END;
- }
-
- ret = mm_util_enc_opt_set_codec(enc_option, IMG_CODEC_PNG);
- if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_enc_opt_set_codec [0x%x]\n", ret);
- goto END;
- }
-
- ret = mm_util_enc_opt_set_png_compression(enc_option, comp_level);
- if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_enc_opt_set_png_compression [0x%x]\n", ret);
- goto END;
- }
-
ret = mm_util_encode_image_to_buffer(decoded_image, enc_option, &buffer, &buffer_size);
if (ret != MM_UTIL_ERROR_NONE) {
printf("Fail mm_util_encode_image_to_buffer [0x%x]\n", ret);
goto END;
}
- ret = mm_util_file_write(dst_path, buffer, buffer_size);
+ ret = mm_util_file_write(path, buffer, buffer_size);
if (ret != MM_UTIL_ERROR_NONE)
printf("Fail mm_util_file_write [0x%x]\n", ret);
END:
mm_util_enc_opt_destroy(enc_option);
- mm_image_destroy_image(decoded_image);
- g_free(buffer);
+ MMUTIL_SAFE_FREE(buffer);
return ret;
}
-static int __magick_decenc_file_webp_test(mm_util_color_format_e format, bool lossless)
+static int __magick_decenc_file_png_test(mm_util_color_format_e format, unsigned int comp_level)
{
int ret = MM_UTIL_ERROR_NONE;
- char * src_path = "/opt/usr/home/owner/origin.webp";
+ const char * src_path = "/opt/usr/home/owner/origin.png";
char dst_path[1024] = {0, };
mm_util_image_h decoded_image = NULL;
- mm_util_enc_opt_h enc_option = NULL;
memset(dst_path, 0x00, sizeof(dst_path));
- snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_file_webp_test_%d_%s.webp", format, (lossless ? "ll" : "nor"));
+ snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_file_png_test_%d_%u.png", format, comp_level);
- printf("* WEBP test [%s] \n", dst_path);
+ printf("* PNG test [%s] \n", dst_path);
- ret = mm_util_decode_image_from_file(src_path, format, &decoded_image);
+ ret = __magick_decode_file_test(src_path, format, &decoded_image);
if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_decode_image_from_file [0x%x]\n", ret);
+ printf("Fail __magick_decode_file_test [0x%x]\n", ret);
return ret;
}
- ret = mm_util_enc_opt_create(&enc_option);
- if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_enc_opt_create [0x%x]\n", ret);
- goto END;
- }
+ ret = __magick_encode_file_test(decoded_image, IMG_CODEC_PNG, comp_level, false, dst_path);
+ if (ret != MM_UTIL_ERROR_NONE)
+ printf("Fail __magick_encode_file_test [0x%x]\n", ret);
- ret = mm_util_enc_opt_set_codec(enc_option, IMG_CODEC_WEBP);
- if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_enc_opt_set_codec [0x%x]\n", ret);
- goto END;
- }
+ mm_image_destroy_image(decoded_image);
+
+ return ret;
+}
+
+static int __magick_decenc_buffer_png_test(mm_util_color_format_e format, unsigned int comp_level)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ const char * src_path = "/opt/usr/home/owner/origin.png";
+ char dst_path[1024] = {0, };
+ mm_util_image_h decoded_image = NULL;
+
+ memset(dst_path, 0x00, sizeof(dst_path));
+ snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_buffer_png_test_%d_%u.png", format, comp_level);
+
+ printf("* PNG test [%s] \n", dst_path);
- ret = mm_util_enc_opt_set_lossless(enc_option, lossless);
+ ret = __magick_decode_buffer_test(src_path, format, &decoded_image);
if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_enc_opt_set_lossless [0x%x]\n", ret);
- goto END;
+ printf("Fail __magick_decode_buffer_test [0x%x]\n", ret);
+ return ret;
}
- ret = mm_util_encode_image_to_file(decoded_image, enc_option, dst_path);
+ ret = __magick_encode_buffer_test(decoded_image, IMG_CODEC_PNG, comp_level, false, dst_path);
if (ret != MM_UTIL_ERROR_NONE)
- printf("Fail mm_util_encode_image_to_file [0x%x]\n", ret);
+ printf("Fail __magick_encode_buffer_test [0x%x]\n", ret);
-END:
- mm_util_enc_opt_destroy(enc_option);
mm_image_destroy_image(decoded_image);
return ret;
}
-static int __magick_decenc_buffer_webp_test(mm_util_color_format_e format, bool lossless)
+static int __magick_decenc_file_webp_test(mm_util_color_format_e format, bool lossless)
{
int ret = MM_UTIL_ERROR_NONE;
- char * src_path = "/opt/usr/home/owner/origin.webp";
+ const char * src_path = "/opt/usr/home/owner/origin.webp";
char dst_path[1024] = {0, };
mm_util_image_h decoded_image = NULL;
- mm_util_enc_opt_h enc_option = NULL;
- void *src_buffer = NULL;
- size_t src_buffer_size = 0;
- void *buffer = NULL;
- size_t buffer_size = 0;
memset(dst_path, 0x00, sizeof(dst_path));
- snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_buffer_webp_test_%d_%s.webp", format, (lossless ? "ll" : "nor"));
+ snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_file_webp_test_%d_%s.webp", format, (lossless ? "ll" : "nor"));
printf("* WEBP test [%s] \n", dst_path);
- ret = mm_util_file_read(src_path, &src_buffer, &src_buffer_size);
+ ret = __magick_decode_file_test(src_path, format, &decoded_image);
if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_file_read [%s: %d]\n", src_path, ret);
+ printf("Fail __magick_decode_file_test [0x%x]\n", ret);
return ret;
}
- ret = mm_util_decode_image_from_buffer(src_buffer, src_buffer_size, format, &decoded_image);
- if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_decode_image_from_buffer [0x%x]\n", ret);
- g_free(src_buffer);
- return ret;
- }
+ ret = __magick_encode_file_test(decoded_image, IMG_CODEC_WEBP, 0, lossless, dst_path);
+ if (ret != MM_UTIL_ERROR_NONE)
+ printf("Fail __magick_encode_file_test [0x%x]\n", ret);
- g_free(src_buffer);
+ mm_image_destroy_image(decoded_image);
- ret = mm_util_enc_opt_create(&enc_option);
- if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_enc_opt_create [0x%x]\n", ret);
- goto END;
- }
+ return ret;
+}
- ret = mm_util_enc_opt_set_codec(enc_option, IMG_CODEC_WEBP);
- if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_enc_opt_set_codec [0x%x]\n", ret);
- goto END;
- }
+static int __magick_decenc_buffer_webp_test(mm_util_color_format_e format, bool lossless)
+{
+ int ret = MM_UTIL_ERROR_NONE;
+ const char * src_path = "/opt/usr/home/owner/origin.webp";
+ char dst_path[1024] = {0, };
+ mm_util_image_h decoded_image = NULL;
- ret = mm_util_enc_opt_set_lossless(enc_option, lossless);
- if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_enc_opt_set_lossless [0x%x]\n", ret);
- goto END;
- }
+ memset(dst_path, 0x00, sizeof(dst_path));
+ snprintf(dst_path, sizeof(dst_path), "/opt/usr/home/owner/media/decenc_buffer_webp_test_%d_%s.webp", format, (lossless ? "ll" : "nor"));
- ret = mm_util_encode_image_to_buffer(decoded_image, enc_option, &buffer, &buffer_size);
+ printf("* WEBP test [%s] \n", dst_path);
+
+ ret = __magick_decode_buffer_test(src_path, format, &decoded_image);
if (ret != MM_UTIL_ERROR_NONE) {
- printf("Fail mm_util_encode_image_to_buffer [0x%x]\n", ret);
- goto END;
+ printf("Fail __magick_decode_buffer_test [0x%x]\n", ret);
+ return ret;
}
- ret = mm_util_file_write(dst_path, buffer, buffer_size);
+ ret = __magick_encode_buffer_test(decoded_image, IMG_CODEC_WEBP, 0, lossless, dst_path);
if (ret != MM_UTIL_ERROR_NONE)
- printf("Fail mm_util_file_write [0x%x]\n", ret);
+ printf("Fail __magick_encode_buffer_test [0x%x]\n", ret);
-END:
- mm_util_enc_opt_destroy(enc_option);
mm_image_destroy_image(decoded_image);
- g_free(buffer);
return ret;
}
Name: libmm-utility
Summary: Multimedia Framework Utility Library
-Version: 0.4.4
+Version: 0.4.5
Release: 0
Group: System/Libraries
License: Apache-2.0
#include <mm_util_private.h>
#include <tzplatform_config.h>
-#define TEST_STRING_VALID(str) ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
#define ENCODE_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "webp_test_enc_file.webp")
#define ENCODE_MEM_PATH tzplatform_mkpath(TZ_USER_CONTENT, "webp_test_enc_mem.webp")
char *path = (char *)data;
mm_util_image_h image = NULL;
- if (!TEST_STRING_VALID(path)) {
+ if (!MMUTIL_STRING_VALID(path)) {
g_print("invalid path %s\n", path);
return;
}
{
g_path = g_strdup(argv[1]);
- if (!TEST_STRING_VALID(g_path)) {
+ if (!MMUTIL_STRING_VALID(g_path)) {
fprintf(stderr, "\t[WEBP_testsuite] invalid path %s\n", argv[1]);
return FALSE;
}
fprintf(stderr, "\t[WEBP_testsuite] mm_util_webp_anim_enc_add_image failed : %d\n", ret);
}
-static gboolean __test_encode_to_file()
+static int __webp_encode_setup(mm_util_webp_anim_enc_h *webp_encode)
{
int ret = 0;
- mm_util_webp_anim_enc_h anim_enc = NULL;
+ mm_util_webp_anim_enc_h webp_enc = NULL;
+
+ mm_util_retvm_if(!webp_encode, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid webp_encode");
- ret = mm_util_webp_anim_enc_create(&anim_enc);
+ ret = mm_util_webp_anim_enc_create(&webp_enc);
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\t[WEBP_testsuite] mm_util_webp_anim_enc_create failed : %d\n", ret);
- return FALSE;
+ return ret;
}
- ret = mm_util_webp_anim_enc_set_bgcolor(anim_enc, g_bgcolor[0], g_bgcolor[1], g_bgcolor[2], g_bgcolor[3]);
+ ret = mm_util_webp_anim_enc_set_bgcolor(webp_enc, g_bgcolor[0], g_bgcolor[1], g_bgcolor[2], g_bgcolor[3]);
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\t[WEBP_testsuite] mm_util_webp_anim_enc_set_bgcolor failed : %d\n", ret);
goto END;
}
- ret = mm_util_webp_anim_enc_set_loop_count(anim_enc, g_loop_count);
+ ret = mm_util_webp_anim_enc_set_loop_count(webp_enc, g_loop_count);
if (ret != MM_UTIL_ERROR_NONE) {
fprintf(stderr, "\t[WEBP_testsuite] mm_util_webp_anim_enc_set_loop_count failed : %d\n", ret);
goto END;
}
+ *webp_encode = webp_enc;
+END:
+ if (ret != MM_UTIL_ERROR_NONE)
+ mm_util_webp_anim_enc_destroy(webp_enc);
+
+ return ret;
+}
+
+static gboolean __test_encode_to_file()
+{
+ int ret = 0;
+ mm_util_webp_anim_enc_h anim_enc = NULL;
+
+ ret = __webp_encode_setup(&anim_enc);
+ if (ret != MM_UTIL_ERROR_NONE) {
+ fprintf(stderr, "\t[WEBP_testsuite] __webp_encode_setup failed : %d\n", ret);
+ return FALSE;
+ }
+
g_queue_foreach(g_queue_images, __add_image, anim_enc);
ret = mm_util_webp_anim_enc_save_to_file(anim_enc, ENCODE_FILE_PATH);
END:
mm_util_webp_anim_enc_destroy(anim_enc);
- if (ret != MM_UTIL_ERROR_NONE)
- return FALSE;
-
- return TRUE;
+ return (ret == MM_UTIL_ERROR_NONE);
}
static gboolean __test_encode_to_buffer()
void *encoded_data = NULL;
size_t encoded_size = 0;
- ret = mm_util_webp_anim_enc_create(&anim_enc);
+ ret = __webp_encode_setup(&anim_enc);
if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[WEBP_testsuite] mm_util_webp_anim_enc_create failed : %d\n", ret);
+ fprintf(stderr, "\t[WEBP_testsuite] __webp_encode_setup failed : %d\n", ret);
return FALSE;
}
- ret = mm_util_webp_anim_enc_set_bgcolor(anim_enc, g_bgcolor[0], g_bgcolor[1], g_bgcolor[2], g_bgcolor[3]);
- if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[WEBP_testsuite] mm_util_webp_anim_enc_set_bgcolor failed : %d\n", ret);
- goto END;
- }
-
- ret = mm_util_webp_anim_enc_set_loop_count(anim_enc, g_loop_count);
- if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[WEBP_testsuite] mm_util_webp_anim_enc_set_loop_count failed : %d\n", ret);
- goto END;
- }
-
g_queue_foreach(g_queue_images, __add_image, anim_enc);
ret = mm_util_webp_anim_enc_save_to_buffer(anim_enc, &encoded_data, &encoded_size);
g_free(encoded_data);
- if (ret != MM_UTIL_ERROR_NONE)
- return FALSE;
-
- return TRUE;
+ return (ret == MM_UTIL_ERROR_NONE);
}
int main(int argc, char *argv[])
return 0;
}
- if (FALSE == __get_arguments(argc, argv)) {
+ if (!__get_arguments(argc, argv)) {
fprintf(stderr, "\t[WEBP_testsuite] _get_arguments failed\n");
goto out;
}
/* test encoding animation webp to file */
- if (FALSE == __test_encode_to_file()) {
+ if (!__test_encode_to_file()) {
fprintf(stderr, "\t[WEBP_testsuite] __test_encode_to_file failed\n");
goto out;
}
/* test encoding animation webp to buffer */
- if (FALSE == __test_encode_to_buffer()) {
+ if (!__test_encode_to_buffer()) {
fprintf(stderr, "\t[WEBP_testsuite] __test_encode_to_buffer failed\n");
goto out;
}