+++ /dev/null
-/*
- * image-utility
- *
- * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * Contact: Vineeth T M <vineeth.tm@samsung.com>
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <image_util.h>
-#include <glib.h>
-#include <tzplatform_config.h>
-
-#define DECODE_RESULT_PATH tzplatform_mkpath(TZ_USER_CONTENT, "decode_test.")
-#define ENCODE_RESULT_PATH tzplatform_mkpath(TZ_USER_CONTENT, "encode_test.")
-
-#define ARGC_MIN 3
-#define CMD_MAX 30
-#define TEST_FILE_MAX 100
-
-typedef enum {
- TEST_DECODE_FILE = 0,
- TEST_DECODE_MEM,
- TEST_DECODE_ASYNC,
- TEST_DECODE_MEM_ASYNC,
- LAST_DECODE_TEST = TEST_DECODE_MEM_ASYNC,
- FIRST_GIF_TEST,
- GIFTEST_ENCODE_FILE = FIRST_GIF_TEST,
- GIFTEST_ENCODE_MEM,
- TEST_COMMAND_NUM,
-} test_command_e;
-
-typedef struct {
- test_command_e cmd;
- char *path;
- unsigned int image_type;
- void *buffer;
- unsigned long long buffer_size;
-} test_inputs_s;
-
-typedef struct {
- gboolean decode_result;
- char filepath[PATH_MAX];
- unsigned long width;
- unsigned long height;
- unsigned char *decoded;
- unsigned long long decode_size;
-} test_decode_s;
-
-typedef struct {
- char out_path[PATH_MAX];
- unsigned char *encoded;
- unsigned long long encode_size;
-} test_encode_s;
-
-static unsigned int g_num_of_files; //only for agif
-static unsigned int g_num_of_decoded;
-
-static test_inputs_s g_test_input;
-static test_decode_s g_test_decode[TEST_FILE_MAX];
-static test_encode_s g_test_encode;
-image_util_image_h g_decoded_image = NULL;
-
-static char TEST_CMD[][CMD_MAX] = {
- "decode",
- "decode-mem",
- "decode-async",
- "decode-mem-async",
- "encode-gif",
- "encode-gif-mem",
- "encode-gif-frame", /* internal */
- "encode-gif-frame-mem", /* internal */
-};
-
-GCond g_thread_cond;
-GMutex g_thread_mutex;
-
-void _wait()
-{
- g_mutex_lock(&g_thread_mutex);
- fprintf(stderr, "waiting... until finishing \n");
- g_cond_wait(&g_thread_cond, &g_thread_mutex);
- fprintf(stderr, "<=== get signal from callback \n");
- g_mutex_unlock(&g_thread_mutex);
-}
-
-void _signal()
-{
- g_mutex_lock(&g_thread_mutex);
- g_cond_signal(&g_thread_cond);
- fprintf(stderr, "===> send signal to test proc \n");
- g_mutex_unlock(&g_thread_mutex);
-}
-
-static inline void flush_stdin()
-{
- int ch;
- while ((ch = getchar()) != EOF && ch != '\n') ;
-}
-
-static gboolean _read_file(const char *file_name, void **data, size_t *data_size)
-{
- FILE *fp = NULL;
- long file_size = 0;
-
- if (!file_name || !data || !data_size) {
- fprintf(stderr, "\tNULL pointer\n");
- return FALSE;
- }
-
- fprintf(stderr, "\tTry to open %s to read\n", file_name);
-
- fp = fopen(file_name, "r");
- if (fp == NULL) {
- fprintf(stderr, "\tfile open failed %d\n", errno);
- return FALSE;
- }
-
- if (fseek(fp, 0, SEEK_END) < 0) {
- fprintf(stderr, "\t[JPEG_testsuite] fseek failed \n");
- fclose(fp);
- fp = NULL;
- return FALSE;
- }
-
- file_size = ftell(fp);
- if (file_size < 0) {
- fprintf(stderr, "\t[JPEG_testsuite] ftell failed \n");
- fclose(fp);
- fp = NULL;
- return FALSE;
- }
-
- rewind(fp);
- *data = (void *)malloc(file_size);
- if (*data == NULL) {
- fprintf(stderr, "\tmalloc failed %d\n", errno);
- fclose(fp);
- fp = NULL;
- return FALSE;
- }
-
- *data_size = fread(*data, 1, file_size, fp);
- if (*data_size != (size_t)file_size) {
- fprintf(stderr, "#Error# fread\n");
- fclose(fp);
- fp = NULL;
- free(*data);
- *data = NULL;
- *data_size = 0;
- return FALSE;
- }
-
- fprintf(stderr, "#Success# fread\n");
-
- fclose(fp);
- fp = NULL;
-
- return TRUE;
-}
-
-static gboolean _write_file(const char *file_name, void *data, size_t data_size)
-{
- FILE *fp = NULL;
-
- if (!file_name || !data || data_size == 0) {
- fprintf(stderr, "\tinvalid data %s %p size:%zu\n", file_name, data, data_size);
- return FALSE;
- }
-
- fprintf(stderr, "\tTry to open %s to write\n", file_name);
-
- fp = fopen(file_name, "w");
- if (fp == NULL) {
- fprintf(stderr, "\tfile open failed %d\n", errno);
- return FALSE;
- }
-
- fwrite(data, 1, data_size, fp);
- fclose(fp);
- fp = NULL;
-
- fprintf(stderr, "\tfile [%s] write DONE\n", file_name);
-
- return TRUE;
-}
-
-bool decode_completed_cb(int error, void *user_param, unsigned long width, unsigned long height, unsigned long long size)
-{
- test_decode_s *user_data = (test_decode_s *)user_param;
- user_data->width = width;
- user_data->height = height;
- user_data->decode_size = size;
- _signal();
-
- return TRUE;
-}
-
-bool encode_completed_cb(int error, void *user_param, unsigned long long size)
-{
- test_encode_s *user_data = (test_encode_s *)user_param;
- user_data->encode_size = size;
- _signal();
-
- return TRUE;
-}
-
-void _free_inputs()
-{
- if (g_test_input.path != NULL) {
- g_free(g_test_input.path);
- g_test_input.path = NULL;
- }
- if (g_test_input.buffer != NULL) {
- g_free(g_test_input.buffer);
- g_test_input.buffer = NULL;
- }
-}
-
-void _free_decode()
-{
- unsigned int i = 0;
-
- for (i = 0; i < g_num_of_files; i++) {
- if (g_test_decode[i].decoded != NULL) {
- free(g_test_decode[i].decoded);
- g_test_decode[i].decoded = NULL;
- }
- }
-}
-
-void _free_encode()
-{
- if (g_test_encode.encoded != NULL) {
- free(g_test_encode.encoded);
- g_test_encode.encoded = NULL;
- }
-}
-
-void _free_datas()
-{
- _free_inputs();
- _free_decode();
- _free_encode();
- image_util_destroy_image(g_decoded_image);
-}
-
-gboolean _init_datas()
-{
- memset(&g_test_input, 0, sizeof(test_inputs_s));
- memset(&g_test_decode, 0, sizeof(test_decode_s) * TEST_FILE_MAX);
- memset(&g_test_encode, 0, sizeof(test_encode_s));
-
- g_num_of_files = 0;
- g_num_of_decoded = 0;
-
- return TRUE;
-}
-
-gboolean _read_dir()
-{
- struct dirent *dp = NULL;
- DIR *fd = opendir(g_test_input.
-path);
- unsigned int i = 0, j = 0;
- if (fd == NULL) {
- fprintf(stderr, "\tlistdir: can't open %s\n", g_test_input.
-path);
- return FALSE;
- }
-
- while ((dp = readdir(fd)) != NULL) {
- if (strlen(dp->d_name) == 0)
- continue;
- if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
- continue; /* skip self and parent */
- size_t nbytes = g_snprintf(g_test_decode[g_num_of_files].filepath, sizeof(g_test_decode[g_num_of_files].filepath), "%s%s", g_test_input.
-path, dp->d_name);
- if (nbytes == 0)
- continue;
- g_num_of_files++;
- }
-
- closedir(fd);
-
- if (g_num_of_files == 0) {
- fprintf(stderr, "\tNo Test File!\n");
- return FALSE;
- }
-
- /* sort file_name */
- char temp[PATH_MAX];
- for (i = 0; i < g_num_of_files; i++) {
- for (j = 0; j < g_num_of_files - 1; j++) {
- if ((strlen(g_test_decode[j].filepath) > strlen(g_test_decode[j + 1].filepath)) ||
- (strcmp(g_test_decode[j].filepath, g_test_decode[j + 1].filepath) > 0 && strlen(g_test_decode[j].filepath) == strlen(g_test_decode[j + 1].filepath))) {
- memset(temp, 0, PATH_MAX);
- g_strlcpy(temp, g_test_decode[j].filepath, sizeof(temp));
- g_strlcpy(g_test_decode[j].filepath, g_test_decode[j + 1].filepath, sizeof(g_test_decode[j].filepath));
- g_strlcpy(g_test_decode[j + 1].filepath, temp, sizeof(g_test_decode[j + 1].filepath));
- }
- }
- }
-
- return TRUE;
-}
-
-gboolean _parse_inputs(int argc, char *argv[])
-{
- unsigned int i = 0;
- gboolean result = FALSE;
-
- if (argv[1] == NULL || strlen(argv[1]) == 0) return FALSE;
-
- for (i = 0; i < TEST_COMMAND_NUM; i++) {
- if (g_strcmp0(argv[1], TEST_CMD[i]) == 0) {
- g_test_input.cmd = i;
- result = TRUE;
- }
- }
- if (!result) return FALSE;
-
- if (argv[2] == NULL || strlen(argv[2]) == 0) return FALSE;
-
- g_test_input.path = g_strdup(argv[2]);
- if (g_test_input.path == NULL)
- return FALSE;
-
- if (g_test_input.cmd >= FIRST_GIF_TEST) {
- g_test_input.image_type = IMAGE_UTIL_GIF;
- size_t nbytes = g_snprintf(g_test_encode.out_path, PATH_MAX, "%s%s", ENCODE_RESULT_PATH, "gif");
- if (nbytes == 0)
- return FALSE;
- return result;
- }
-
- if (argv[3] == NULL || strlen(argv[3]) == 0) return FALSE;
-
- long temp = g_ascii_strtoll(argv[3], NULL, 10);
- if (temp < 0 || temp > (long)IMAGE_UTIL_BMP)
- return FALSE;
- g_test_input.image_type = (unsigned int)temp;
-
- char ext[4];
- memset(g_test_encode.out_path, 0, PATH_MAX);
- memset(ext, 0, 4);
- switch (g_test_input.image_type) {
- case IMAGE_UTIL_JPEG:
- snprintf(ext, 4, "%s", "jpg");
- break;
- case IMAGE_UTIL_PNG:
- snprintf(ext, 4, "%s", "png");
- break;
- case IMAGE_UTIL_GIF:
- snprintf(ext, 4, "%s", "gif");
- break;
- case IMAGE_UTIL_BMP:
- snprintf(ext, 4, "%s", "bmp");
- break;
- default:
- fprintf(stderr, "\tNot supported image type!\n");
- _free_datas();
- return FALSE;
- }
- snprintf(g_test_encode.out_path, PATH_MAX, "%s%s", ENCODE_RESULT_PATH, ext);
-
- return result;
-}
-
-void _print_help(int argc, char *argv[])
-{
- unsigned int i = 0;
-
- fprintf(stderr, "\t[usage]\n");
- fprintf(stderr, "\t\t1. decode & encode : %s ", argv[0]);
- for (i = 0; i <= LAST_DECODE_TEST; i++) {
- fprintf(stderr, "%s", TEST_CMD[i]);
- if (i != LAST_DECODE_TEST)
- fprintf(stderr, "/");
- }
- fprintf(stderr, " filepath encode_image_type\n");
- fprintf(stderr, "\t\t2. encode animated-gif : %s ", argv[0]);
- for (i = FIRST_GIF_TEST; i < TEST_COMMAND_NUM; i++) {
- fprintf(stderr, "%s", TEST_CMD[i]);
- if (i != TEST_COMMAND_NUM - 1)
- fprintf(stderr, "/");
- }
- fprintf(stderr, " folderpath containing png images named \
- with number prefix according to the animation order'\n");
-}
-
-gboolean _read_test_files()
-{
- if (g_test_input.cmd >= FIRST_GIF_TEST) {
- if (_read_dir() == FALSE)
- return FALSE;
- } else {
- if ((g_test_input.cmd == TEST_DECODE_MEM) || (g_test_input.cmd == TEST_DECODE_MEM_ASYNC)) {
- size_t read_size = 0;
- if (_read_file(g_test_input.path, &g_test_input.buffer, &read_size) == FALSE) {
- fprintf(stderr, "\tRead test file failed!\n");
- return FALSE;
- }
- g_test_input.buffer_size = (unsigned long long)read_size;
- } else {
- size_t nbytes = g_snprintf(g_test_decode[0].filepath, PATH_MAX, "%s", g_test_input.
-path);
- if (nbytes == 0) return FALSE;
- }
- g_num_of_files = 1;
- }
-
- fprintf(stderr, "\tThe %d files are readed!\n", g_num_of_files);
-
- return TRUE;
-}
-
-
-gboolean test_decode()
-{
- int ret = 0;
- unsigned int i = 0;
- image_util_decode_h decoded = NULL;
-
- for (i = 0; i < g_num_of_files; i++) {
- g_test_decode[i].decode_result = FALSE;
-
- ret = image_util_decode_create(&decoded);
- if (ret != IMAGE_UTIL_ERROR_NONE)
- return FALSE;
-
- if ((g_test_input.cmd == TEST_DECODE_MEM) || (g_test_input.cmd == TEST_DECODE_MEM_ASYNC))
- ret = image_util_decode_set_input_buffer(decoded, (unsigned char *)g_test_input.buffer, g_test_input.buffer_size);
- else
- ret = image_util_decode_set_input_path(decoded, g_test_decode[i].filepath);
-
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_decode_destroy(decoded);
- return FALSE;
- }
-
- ret = image_util_decode_set_output_buffer(decoded, &(g_test_decode[i].decoded));
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_decode_destroy(decoded);
- return FALSE;
- }
-
- if ((g_test_input.cmd == TEST_DECODE_ASYNC) || (g_test_input.cmd == TEST_DECODE_MEM_ASYNC)) {
- ret = image_util_decode_run_async(decoded, (image_util_decode_completed_cb) decode_completed_cb, &g_test_decode[i]);
- if (ret == IMAGE_UTIL_ERROR_NONE)
- _wait();
- } else {
- ret = image_util_decode_run(decoded, &g_test_decode[i].width, &g_test_decode[i].height, &g_test_decode[i].decode_size);
- }
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_decode_destroy(decoded);
- return FALSE;
- }
-
- image_util_decode_destroy(decoded);
- g_test_decode[i].decode_result = TRUE;
- g_num_of_decoded++;
- }
-
- if (g_num_of_decoded == 0) {
- fprintf(stderr, "\tNo decoded data!\n");
- return FALSE;
- } else {
- fprintf(stderr, "\tThe %d images are decoded!(0: %p %llu)\n", g_num_of_decoded, g_test_decode[0].decoded, g_test_decode[0].decode_size);
- }
-
- /* write the decoded result to the file */
- if (g_test_input.cmd <= LAST_DECODE_TEST) {
- char temp[PATH_MAX];
- memset(temp, 0, PATH_MAX);
- snprintf(temp, PATH_MAX, "%s%s", DECODE_RESULT_PATH, "raw");
- if (_write_file(temp, g_test_decode[0].decoded, (size_t)g_test_decode[0].decode_size) == FALSE) {
- fprintf(stderr, "\tWrite the decoded result failed!\n");
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-static void __decode_completed2_cb(int error_code, image_util_image_h image, void *user_data)
-{
- fprintf(stderr, "__decode_completed2_cb invoked [%d]\n", error_code);
-
- if (error_code == IMAGE_UTIL_ERROR_NONE)
- image_util_clone_image(image, &g_decoded_image);
-
- _signal();
-
- return;
-}
-
-gboolean test_new_decode()
-{
- int ret = IMAGE_UTIL_ERROR_NONE;
- unsigned int i = 0;
- image_util_decode_h decoded = NULL;
-
- ret = image_util_decode_create(&decoded);
- if (ret != IMAGE_UTIL_ERROR_NONE)
- return FALSE;
-
- if ((g_test_input.cmd == TEST_DECODE_MEM) || (g_test_input.cmd == TEST_DECODE_MEM_ASYNC))
- ret = image_util_decode_set_input_buffer(decoded, (unsigned char *)g_test_input.buffer, g_test_input.buffer_size);
- else
- ret = image_util_decode_set_input_path(decoded, g_test_decode[i].filepath);
-
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_decode_destroy(decoded);
- return FALSE;
- }
-
- if ((g_test_input.cmd == TEST_DECODE_ASYNC) || (g_test_input.cmd == TEST_DECODE_MEM_ASYNC)) {
- ret = image_util_decode_run_async2(decoded, __decode_completed2_cb, NULL);
- if (ret == IMAGE_UTIL_ERROR_NONE)
- _wait();
- } else {
- ret = image_util_decode_run2(decoded, &g_decoded_image);
- }
-
- image_util_decode_destroy(decoded);
-
- return TRUE;
-}
-
-gboolean test_encode()
-{
- int ret = 0;
- image_util_encode_h encoded = NULL;
-
- ret = image_util_encode_create(g_test_input.image_type, &encoded);
- if (ret != IMAGE_UTIL_ERROR_NONE)
- return FALSE;
-
- ret = image_util_encode_set_input_buffer(encoded, g_test_decode[0].decoded);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_encode_destroy(encoded);
- return FALSE;
- }
-
- ret = image_util_encode_set_resolution(encoded, g_test_decode[0].width, g_test_decode[0].height);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_encode_destroy(encoded);
- return FALSE;
- }
-
- if ((g_test_input.cmd == TEST_DECODE_MEM) || (g_test_input.cmd == TEST_DECODE_MEM_ASYNC))
- ret = image_util_encode_set_output_buffer(encoded, &g_test_encode.encoded);
- else
- ret = image_util_encode_set_output_path(encoded, g_test_encode.out_path);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_encode_destroy(encoded);
- return FALSE;
- }
-
- if ((g_test_input.cmd == TEST_DECODE_ASYNC) || (g_test_input.cmd == TEST_DECODE_MEM_ASYNC)) {
- ret = image_util_encode_run_async(encoded, (image_util_encode_completed_cb) encode_completed_cb, &g_test_encode);
- if (ret == IMAGE_UTIL_ERROR_NONE)
- _wait();
- } else {
- ret = image_util_encode_run(encoded, &g_test_encode.encode_size);
- }
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_encode_destroy(encoded);
- return FALSE;
- }
-
- image_util_encode_destroy(encoded);
-
- if ((g_test_input.cmd == TEST_DECODE_MEM) ||
- (g_test_input.cmd == TEST_DECODE_MEM_ASYNC)) {
- if (_write_file(g_test_encode.out_path, g_test_encode.encoded, (size_t)g_test_encode.encode_size) == FALSE) {
- fprintf(stderr, "\tWrite the encoded result failed!\n");
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-static void __encode_to_file_completed_cb(int error_code, void *user_data)
-{
- fprintf(stderr, "__encode_to_file_completed_cb invoked [%d]\n", error_code);
- _signal();
-
- return;
-}
-
-static void __encode_to_buffer_completed_cb(int error_code, unsigned char *buffer, size_t buffer_size, void *user_data)
-{
- fprintf(stderr, "__encode_to_buffer_completed_cb invoked [%d]\n", error_code);
-
- if (_write_file(g_test_encode.out_path, buffer, buffer_size) == FALSE)
- fprintf(stderr, "\tWrite the encoded result failed!\n");
-
- _signal();
-
- return;
-}
-
-gboolean test_new_encode()
-{
- int ret = IMAGE_UTIL_ERROR_NONE;
- image_util_encode_h encoded = NULL;
- image_util_image_h _image = NULL;
- unsigned char *buffer = NULL;
- size_t buffer_size = 0;
-
-
- ret = image_util_encode_create(g_test_input.image_type, &encoded);
- if (ret != IMAGE_UTIL_ERROR_NONE)
- return FALSE;
-
- ret = image_util_create_image(g_test_decode[0].width, g_test_decode[0].height, IMAGE_UTIL_COLORSPACE_RGBA8888, g_test_decode[0].decoded, g_test_decode[0].decode_size, &_image);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_encode_destroy(encoded);
- return FALSE;
- }
-
- if (g_test_input.cmd == TEST_DECODE_FILE) {
- ret = image_util_encode_run_to_file(encoded, _image, g_test_encode.out_path);
- } else if (g_test_input.cmd == TEST_DECODE_MEM) {
- ret = image_util_encode_run_to_buffer(encoded, _image, &buffer, &buffer_size);
- } else if (g_test_input.cmd == TEST_DECODE_ASYNC) {
- ret = image_util_encode_run_async_to_file(encoded, _image, g_test_encode.out_path, __encode_to_file_completed_cb, NULL);
- if (ret == IMAGE_UTIL_ERROR_NONE)
- _wait();
- } else if (g_test_input.cmd == TEST_DECODE_MEM_ASYNC) {
- ret = image_util_encode_run_async_to_buffer(encoded, _image, __encode_to_buffer_completed_cb, NULL);
- if (ret == IMAGE_UTIL_ERROR_NONE)
- _wait();
- }
-
- image_util_encode_destroy(encoded);
-
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- fprintf(stderr, "\timage_util_encode_run_to_file failed!\n");
- if (buffer)
- free(buffer);
- return FALSE;
- }
-
- if (g_test_input.cmd == TEST_DECODE_MEM) {
- if (_write_file(g_test_encode.out_path, buffer, buffer_size) == FALSE)
- fprintf(stderr, "\tWrite the encoded result failed!\n");
- }
-
- if (buffer)
- free(buffer);
-
- return TRUE;
-}
-
-gboolean test_new_decode_encode()
-{
- int ret = IMAGE_UTIL_ERROR_NONE;
- unsigned int i = 0;
- image_util_decode_h decoded = NULL;
- image_util_encode_h encoded = NULL;
- unsigned char *buffer = NULL;
- size_t buffer_size = 0;
-
- //Decode
- ret = image_util_decode_create(&decoded);
- if (ret != IMAGE_UTIL_ERROR_NONE)
- return FALSE;
-
- if ((g_test_input.cmd == TEST_DECODE_MEM) || (g_test_input.cmd == TEST_DECODE_MEM_ASYNC))
- ret = image_util_decode_set_input_buffer(decoded, (unsigned char *)g_test_input.buffer, g_test_input.buffer_size);
- else
- ret = image_util_decode_set_input_path(decoded, g_test_decode[i].filepath);
-
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_decode_destroy(decoded);
- return FALSE;
- }
-
- if ((g_test_input.cmd == TEST_DECODE_ASYNC) || (g_test_input.cmd == TEST_DECODE_MEM_ASYNC)) {
- ret = image_util_decode_run_async2(decoded, __decode_completed2_cb, NULL);
- if (ret == IMAGE_UTIL_ERROR_NONE)
- _wait();
- } else {
- ret = image_util_decode_run2(decoded, &g_decoded_image);
- }
-
- image_util_decode_destroy(decoded);
-
- //Encode
- ret = image_util_encode_create(g_test_input.image_type, &encoded);
- if (ret != IMAGE_UTIL_ERROR_NONE)
- return FALSE;
-
- if (g_test_input.cmd == TEST_DECODE_FILE) {
- ret = image_util_encode_run_to_file(encoded, g_decoded_image, g_test_encode.out_path);
- } else if (g_test_input.cmd == TEST_DECODE_MEM) {
- ret = image_util_encode_run_to_buffer(encoded, g_decoded_image, &buffer, &buffer_size);
-
- if (_write_file(g_test_encode.out_path, buffer, buffer_size) == FALSE)
- fprintf(stderr, "\tWrite the encoded result failed!\n");
-
- if (buffer)
- free(buffer);
-
- } else if (g_test_input.cmd == TEST_DECODE_ASYNC) {
- ret = image_util_encode_run_async_to_file(encoded, g_decoded_image, g_test_encode.out_path, __encode_to_file_completed_cb, NULL);
- _wait();
- } else if (g_test_input.cmd == TEST_DECODE_MEM_ASYNC) {
- ret = image_util_encode_run_async_to_buffer(encoded, g_decoded_image, __encode_to_buffer_completed_cb, NULL);
- _wait();
- }
-
- image_util_encode_destroy(encoded);
-
- return TRUE;
-}
-
-gboolean test_new_encode_agif()
-{
- int ret = IMAGE_UTIL_ERROR_NONE;
- image_util_agif_encode_h agif_enc = NULL;
- image_util_image_h _image = NULL;
- unsigned char *buffer = NULL;
- size_t buffer_size = 0;
- unsigned int i = 0;
-
- ret = image_util_agif_encode_create(&agif_enc);
- if (ret != IMAGE_UTIL_ERROR_NONE)
- return FALSE;
-
- // repeat start
- for (i = 0; i < g_num_of_files; i++) {
- if (g_test_decode[i].decode_result == FALSE)
- continue;
-
- ret = image_util_create_image(g_test_decode[i].width, g_test_decode[i].height, IMAGE_UTIL_COLORSPACE_RGBA8888, g_test_decode[i].decoded, g_test_decode[i].decode_size, &_image);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_agif_encode_destroy(agif_enc);
- return FALSE;
- }
-
- ret = image_util_agif_encode_add_frame(agif_enc, _image, 50); /* 500ms */
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_destroy_image(_image);
- image_util_agif_encode_destroy(agif_enc);
- return FALSE;
- }
-
- image_util_destroy_image(_image);
- }
- // repeat end
-
- if (g_test_input.cmd == GIFTEST_ENCODE_FILE)
- ret = image_util_agif_encode_save_to_file(agif_enc, g_test_encode.out_path);
- else if (g_test_input.cmd == GIFTEST_ENCODE_MEM)
- ret = image_util_agif_encode_save_to_buffer(agif_enc, &buffer, &buffer_size);
- else
- fprintf(stderr, "\tDo not save the encoded GIF!\n");
-
- image_util_agif_encode_destroy(agif_enc);
-
- if (g_test_input.cmd == GIFTEST_ENCODE_MEM) {
- if (_write_file(g_test_encode.out_path, buffer, buffer_size) == FALSE)
- fprintf(stderr, "\tWrite the encoded result failed!\n");
- }
-
- if (buffer)
- free(buffer);
-
- return TRUE;
-}
-
-gboolean test_encode_gif()
-{
- int ret = 0;
- unsigned int i = 0;
- image_util_encode_h encoded = NULL;
-
- ret = image_util_encode_create(g_test_input.image_type, &encoded);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_encode_destroy(encoded);
- return FALSE;
- }
-
- for (i = 0; i < g_num_of_files; i++) {
- if (g_test_decode[i].decode_result == FALSE)
- continue;
-
- ret = image_util_encode_set_resolution(encoded, g_test_decode[i].width, g_test_decode[i].height);
- if (ret != IMAGE_UTIL_ERROR_NONE)
- continue;
-
- ret = image_util_encode_set_input_buffer(encoded, g_test_decode[i].decoded);
- if (ret != IMAGE_UTIL_ERROR_NONE)
- continue;
-
- ret = image_util_encode_set_gif_frame_delay_time(encoded, 50); /* 500ms */
- if (ret != IMAGE_UTIL_ERROR_NONE)
- continue;
- }
-
- if (g_test_input.cmd == GIFTEST_ENCODE_MEM)
- ret = image_util_encode_set_output_buffer(encoded, &g_test_encode.encoded);
- else
- ret = image_util_encode_set_output_path(encoded, g_test_encode.out_path);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_encode_destroy(encoded);
- return FALSE;
- }
-
- ret = image_util_encode_run(encoded, &g_test_encode.encode_size);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- image_util_encode_destroy(encoded);
- return FALSE;
- }
-
- image_util_encode_destroy(encoded);
-
- if (g_test_input.cmd == GIFTEST_ENCODE_MEM) {
- if (_write_file(g_test_encode.out_path, g_test_encode.encoded, (size_t)g_test_encode.encode_size) == FALSE) {
- fprintf(stderr, "\tWrite the encoded result failed!\n");
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-int main(int argc, char *argv[])
-{
- if (argc < ARGC_MIN) {
- _print_help(argc, argv);
- return 0;
- }
-
- if (_init_datas() == FALSE) {
- fprintf(stderr, "\tInit failed!\n");
- _free_datas();
- return 0;
- }
-
- if (_parse_inputs(argc, argv) == FALSE) {
- fprintf(stderr, "\tInput was wrong!\n");
- _free_datas();
- return 0;
- }
-
- if (_read_test_files() == FALSE) {
- fprintf(stderr, "\tCan not read the test files!\n");
- _free_datas();
- return 0;
- }
-
- fprintf(stderr, "\tTests Start!\n");
-
-#if 0
- if (!test_new_decode_encode()) {
- fprintf(stderr, "\tNew Decode Encode Tests failed!\n");
- _free_datas();
- return 0;
- }
-#endif
-
- if (test_decode() == FALSE) {
- //if (test_new_decode() == FALSE) {
- fprintf(stderr, "\tDecode Tests failed!\n");
- _free_datas();
- return 0;
- }
-
- fprintf(stderr, "\tDecoding is done!\n");
-
- if ((g_test_input.cmd == GIFTEST_ENCODE_FILE) || (g_test_input.cmd == GIFTEST_ENCODE_MEM)) {
- if (test_encode_gif() == FALSE) {
- //if (test_new_encode_agif() == FALSE) {
- fprintf(stderr, "\tEncode(gif) Tests failed!\n");
- _free_datas();
- return 0;
- }
- } else {
- if (test_encode() == FALSE) {
- //if (test_new_encode() == FALSE) {
- fprintf(stderr, "\tEncode(default) Tests failed!\n");
- _free_datas();
- return 0;
- }
- }
-
- _free_datas();
-
- fprintf(stderr, "\tEncoding is done!\n");
-
- fprintf(stderr, "\tTests Finished!\n");
-
- return 0;
-}
+++ /dev/null
-/*
-* Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
-*
-* Licensed under the Apache License, Version 2.0 (the "License");
-* you may not use this file except in compliance with the License.
-* You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-
-#include <glib.h>
-#include <glib/gprintf.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <inttypes.h>
-#include <image_util.h>
-#include <image_util_type.h>
-
-#define MAX_STRING_LEN 128
-#define IMAGE_FORMAT_LABEL_BUFFER_SIZE 4
-#define MAX_REPEAT_COUNT 100
-
-#define IMAGE_UTIL_SAFE_FREE(src) { if (src) {free(src); src = NULL; } }
-
-
-GMainLoop *g_loop = NULL;
-transformation_h g_handle = NULL;
-static media_packet_h g_src_packet = NULL;
-static image_util_image_h g_src_image = NULL;
-char *g_path = NULL;
-unsigned int g_width = 0;
-unsigned int g_height = 0;
-image_util_rotation_e g_angle = IMAGE_UTIL_ROTATION_NONE;
-int g_format = -1;
-static unsigned int g_request_count = 0;
-
-enum {
- CURRENT_STATE_MAIN_MENU,
- CURRENT_STATE_SET_ROTATION_PARAMETER_MENU,
-};
-
-int g_menu_state = CURRENT_STATE_MAIN_MENU;
-int g_menu_rotation_parameter = IMAGE_UTIL_ROTATION_NONE;
-
-static void display_menu(void);
-
-media_format_mimetype_e
-_image_util_mapping_imgp_format_to_mime(image_util_colorspace_e colorspace)
-{
- media_format_mimetype_e mimetype = -1;
-
- switch (colorspace) {
- case IMAGE_UTIL_COLORSPACE_NV12:
- mimetype = MEDIA_FORMAT_NV12;
- break;
- case IMAGE_UTIL_COLORSPACE_NV16:
- mimetype = MEDIA_FORMAT_NV16;
- break;
- case IMAGE_UTIL_COLORSPACE_YUYV:
- mimetype = MEDIA_FORMAT_YUYV;
- break;
- case IMAGE_UTIL_COLORSPACE_UYVY:
- mimetype = MEDIA_FORMAT_UYVY;
- break;
- case IMAGE_UTIL_COLORSPACE_YUV422:
- mimetype = MEDIA_FORMAT_422P;
- break;
- case IMAGE_UTIL_COLORSPACE_I420:
- mimetype = MEDIA_FORMAT_I420;
- break;
- case IMAGE_UTIL_COLORSPACE_YV12:
- case IMAGE_UTIL_COLORSPACE_NV21:
- mimetype = MEDIA_FORMAT_YV12;
- break;
- case IMAGE_UTIL_COLORSPACE_RGB565:
- mimetype = MEDIA_FORMAT_RGB565;
- break;
- case IMAGE_UTIL_COLORSPACE_RGB888:
- mimetype = MEDIA_FORMAT_RGB888;
- break;
- case IMAGE_UTIL_COLORSPACE_RGBA8888:
- mimetype = MEDIA_FORMAT_RGBA;
- break;
- case IMAGE_UTIL_COLORSPACE_ARGB8888:
- mimetype = MEDIA_FORMAT_ARGB;
- break;
- case IMAGE_UTIL_COLORSPACE_BGRA8888:
- case IMAGE_UTIL_COLORSPACE_BGRX8888:
- case IMAGE_UTIL_COLORSPACE_NV61:
- default:
- mimetype = -1;
- g_printf("Not Supported Format");
- break;
- }
-
- g_printf("imgp fmt[%d] mimetype fmt[%d]\n", colorspace, mimetype);
-
- return mimetype;
-}
-
-static gboolean __read_file(char *path, void **data, size_t *length)
-{
- FILE *fp = NULL;
- long len = 0;
-
- if (!path || !data || length == 0) {
- fprintf(stderr, "\tinvalid data %s %p %p\n", path, data, length);
- return FALSE;
- }
-
- fprintf(stderr, "\t%s read\n", path);
-
- fp = fopen(path, "r");
- if (fp == NULL) {
- fprintf(stderr, "\tfopen failed (%d) \n", errno);
- return FALSE;
- }
-
- if (fseek(fp, 0, SEEK_END) < 0) {
- fprintf(stderr, "\tfseek failed \n");
- fclose(fp);
- return FALSE;
- }
-
- len = ftell(fp);
- if (len < 0) {
- fprintf(stderr, "\tftell failed \n");
- fclose(fp);
- return FALSE;
- }
-
- rewind(fp);
- *data = (void *)calloc(1, len);
- if (*data == NULL) {
- fprintf(stderr, "\tmemory allocation failed \n");
- fclose(fp);
- return FALSE;
- }
-
- *length = fread(*data, 1, (size_t)len, fp);
- if (*length != (size_t)len) {
- fprintf(stderr, "\tfread failed \n");
- }
-
- fclose(fp);
-
- if (*data == NULL) {
- *length = 0;
- return FALSE;
- }
-
- *length = (size_t)len;
-
- fprintf(stderr, "\t%s %zu read DONE\n", path, *length);
-
- return TRUE;
-}
-
-static gboolean __write_file(const char *path, void *data, size_t length)
-{
- FILE *fp = NULL;
- size_t len = 0;
-
- if (!path || !data || length == 0) {
- g_printf("\tinvalid data %s %p %zu\n", path, data, length);
- return FALSE;
- }
-
- g_printf("\t%s %p %zu write\n", path, data, length);
-
- fp = fopen(path, "w");
- if (fp == NULL) {
- g_printf("\tfopen failed (%d) \n", errno);
- return FALSE;
- }
-
- len = fwrite(data, 1, length, fp);
- if (len != length) {
- g_printf("\tfwrite failed \n");
- }
-
- fclose(fp);
- fp = NULL;
-
- g_printf("\t%s write DONE\n", path);
-
- return TRUE;
-}
-
-static gboolean __save_image(image_util_image_h image)
-{
- int ret = IMAGE_UTIL_ERROR_NONE;
- char out_file[PATH_MAX] = { 0, };
-
- unsigned int width = 0, height = 0;
- image_util_colorspace_e color = 0;
- unsigned char *buf = NULL;
- size_t buf_size = 0;
-
- ret = image_util_get_image(image, &width, &height, &color, &buf, &buf_size);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- g_printf("image_util_get_image failed (%d)", ret);
- return FALSE;;
- }
-
- snprintf(out_file, PATH_MAX, "result2_%dx%d_%d.raw", width, height, color);
-
- if (!__write_file(out_file, (void *)buf, buf_size))
- g_printf("__write_file failed");
-
- IMAGE_UTIL_SAFE_FREE(buf);
-
- return TRUE;
-}
-
-void test_transform_completed2_cb(image_util_image_h image, image_util_error_e error, void *user_data)
-{
- g_printf("completed_cb [%d][%d] \n", error, --g_request_count);
-
- if (error != IMAGE_UTIL_ERROR_NONE) {
- g_printf("Invalid error_code (%d)", error);
- goto END;
- }
-
- if (!image) {
- g_printf("Invalid image");
- goto END;
- }
-
- if (!__save_image(image))
- g_printf("_save_image failed");
-
- g_printf("<<<<< SUCCESS >>>>>\n");
-END:
- if (g_request_count == 0)
- display_menu();
-}
-
-static gboolean __create_src_image()
-{
- int ret = 0;
- void *buf = NULL;
- size_t buf_size = 0;
-
- if (!__read_file(g_path, &buf, &buf_size)) {
- g_printf("__read_file failed\n");
- return FALSE;
- }
-
- ret = image_util_create_image(g_width, g_height, g_format, buf, buf_size, &g_src_image);
- IMAGE_UTIL_SAFE_FREE(buf);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- g_printf("image_util_create_image failed (%d)", ret);
- return FALSE;
- }
-
- return TRUE;
-}
-
-void test_transform_completed_cb(media_packet_h *packet, image_util_error_e error, void *user_data)
-{
- char output_file[25] = {};
-
- media_format_h dst_fmt;
- media_format_mimetype_e dst_mimetype;
- int dst_width, dst_height, dst_avg_bps, dst_max_bps;
- char *output_fmt = NULL;
- unsigned int i = 0;
- uint32_t plane_num = 0;
- int stride_width = 0, stride_height = 0;
- void *plane_ptr = NULL;
- size_t plane_size = 0;
- void *ptr = NULL;
- size_t size = 0;
-
- g_printf("test_transform_completed_cb [%d][%d] \n", error, --g_request_count);
- if (error != IMAGE_UTIL_ERROR_NONE) {
- goto END;
- }
-
- output_fmt = (char *)malloc(sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
- if (!output_fmt) {
- g_printf("memory allocation failed\n");
- goto END;
- }
-
- if (media_packet_get_format(*packet, &dst_fmt) != MEDIA_PACKET_ERROR_NONE) {
- g_printf("Imedia_packet_get_format\n");
- goto END;
- }
-
- if (media_format_get_video_info(dst_fmt, &dst_mimetype, &dst_width, &dst_height, &dst_avg_bps, &dst_max_bps) == MEDIA_FORMAT_ERROR_NONE) {
- memset(output_fmt, 0, IMAGE_FORMAT_LABEL_BUFFER_SIZE);
- if (dst_mimetype == MEDIA_FORMAT_YV12 || dst_mimetype == MEDIA_FORMAT_422P || dst_mimetype == MEDIA_FORMAT_I420
- || dst_mimetype == MEDIA_FORMAT_NV12 || dst_mimetype == MEDIA_FORMAT_UYVY || dst_mimetype == MEDIA_FORMAT_YUYV) {
- strncpy(output_fmt, "yuv", strlen("yuv"));
- } else {
- strncpy(output_fmt, "rgb", strlen("rgb"));
- }
- g_printf("[mimetype: %d] W x H : %d x %d \n", dst_mimetype, dst_width, dst_height);
- snprintf(output_file, 25, "result_%dx%d.%s", dst_width, dst_height, output_fmt);
- }
-
- if (MEDIA_PACKET_ERROR_NONE != media_packet_get_number_of_video_planes(*packet, &plane_num)) {
- g_printf("media_packet_get_number_of_video_plances failed\n");
- goto END;
- }
-
- g_printf("plane_num: %u\n", plane_num);
-
- for (i = 0; i < plane_num; i++) {
- if (MEDIA_PACKET_ERROR_NONE != media_packet_get_video_stride_width(*packet, i, &stride_width)) {
- g_printf("media_packet_get_number_of_video_plances failed\n");
- goto END;
- }
-
- if (MEDIA_PACKET_ERROR_NONE != media_packet_get_video_stride_height(*packet, i, &stride_height)) {
- g_printf("media_packet_get_number_of_video_plances failed\n");
- goto END;
- }
-
- plane_size = stride_width * stride_height;
-
- if (MEDIA_PACKET_ERROR_NONE != media_packet_get_video_plane_data_ptr(*packet, i, &plane_ptr)) {
- g_printf("media_packet_get_number_of_video_plances failed\n");
- goto END;
- }
-
- g_printf("stride_width: %d, stride_height: %d, plane_ptr: %p, plane_size: %zu\n",
- stride_width, stride_height, plane_ptr,plane_size);
-
- ptr = realloc(ptr, size + plane_size);
- if (!ptr) {
- g_printf("Memory allocation failed");
- goto END;
- }
-
- memcpy(ptr + size, plane_ptr, plane_size);
- size += plane_size;
- }
-
- if (!__write_file(output_file, ptr, size)) {
- g_printf("__write_file failed\n");
- goto END;
- }
- g_printf("<<<<< SUCCESS >>>>>\n");
-
-END:
-
- IMAGE_UTIL_SAFE_FREE(output_fmt);
- media_packet_destroy(*packet);
- IMAGE_UTIL_SAFE_FREE(ptr);
-
- if (g_request_count == 0)
- display_menu();
-}
-
-static gboolean __create_src_packet()
-{
- int ret = 0;
- media_format_h fmt;
- void *buf = NULL;
- size_t buf_size = 0;
- void *ptr = NULL;
- uint64_t ptr_size = 0;
- if (media_format_create(&fmt) == MEDIA_FORMAT_ERROR_NONE) {
- if (media_format_set_video_mime(fmt, _image_util_mapping_imgp_format_to_mime(g_format)) != MEDIA_FORMAT_ERROR_NONE) {
- media_format_unref(fmt);
- g_printf("[Error] Set - video mime\n");
- return FALSE;
- }
-
- if (media_format_set_video_width(fmt, g_width) != MEDIA_FORMAT_ERROR_NONE) {
- media_format_unref(fmt);
- g_printf("[Error] Set - video width\n");
- return FALSE;
- }
-
- if (media_format_set_video_height(fmt, g_height) != MEDIA_FORMAT_ERROR_NONE) {
- media_format_unref(fmt);
- g_printf("[Error] Set - video heigh\nt");
- return FALSE;
- }
-
- g_printf("media_format_set_video_info success! file[%s] w[%d] h[%d] mime[%d]\n", g_path, g_width, g_height, _image_util_mapping_imgp_format_to_mime(g_format));
- } else {
- g_printf("media_format_create failed...");
- }
-
- ret = media_packet_create_alloc(fmt, NULL, NULL, &g_src_packet);
- if (ret == MEDIA_PACKET_ERROR_NONE) {
- g_printf("Success - media_packet_create_alloc\n");
- if (media_packet_get_buffer_size(g_src_packet, &ptr_size) == MEDIA_PACKET_ERROR_NONE) {
- if (media_packet_get_buffer_data_ptr(g_src_packet, &ptr) == MEDIA_PACKET_ERROR_NONE) {
- if (!__read_file(g_path, &buf, &buf_size)) {
- g_printf("\t__read_file failed\n");
- media_format_unref(fmt);
- return FALSE;
- }
- if (buf_size <= ptr_size) {
- g_printf("#Success# fread\n");
- memcpy(ptr, buf, (int)ptr_size);
- g_printf("memcpy\n");
- } else {
- g_printf("#Error# fread readed[%zu] size[%" PRIu64 "]\n", buf_size, ptr_size);
- }
- IMAGE_UTIL_SAFE_FREE(buf);
- }
- }
- } else {
- g_printf("ERROR - media_packet_create_alloc");
- media_format_unref(fmt);
- return FALSE;
- }
- media_format_unref(fmt);
- return TRUE;
-}
-
-static void _create()
-{
- int ret = 0;
- if (g_handle != NULL) {
- ret = image_util_transform_destroy(g_handle);
- if (ret != IMAGE_UTIL_ERROR_NONE)
- g_printf("[%d]Error image_util_transform_destroy [%d]\n", __LINE__, ret);
- else
- g_printf("[%d]Success image_util_transform_destroy [%d]\n", __LINE__, ret);
- }
- ret = image_util_transform_create(&g_handle);
- if (ret != IMAGE_UTIL_ERROR_NONE)
- g_printf("[%d]Error image_util_transform_create [%d]\n", __LINE__, ret);
- else
- g_printf("[%d]Success image_util_transform_create [%d]\n", __LINE__, ret);
- g_request_count = 0;
-}
-
-static void _destroy()
-{
- int ret = 0;
-
- if (g_handle) {
- ret = image_util_transform_destroy(g_handle);
- if (ret != IMAGE_UTIL_ERROR_NONE)
- g_printf("[%d]Error image_util_transform_destroy [%d]\n", __LINE__, ret);
- else
- g_printf("[%d]Success image_util_transform_destroy [%d]\n", __LINE__, ret);
- } else {
- g_printf("[%d]Error handle was already destroyed \n", __LINE__);
- }
- g_handle = NULL;
-}
-
-static void _transform(const char *cmd)
-{
- int ret = 0;
- unsigned int width = 0;
- unsigned int height = 0;
- image_util_colorspace_e colorspace = IMAGE_UTIL_COLORSPACE_ARGB8888;
- int start_x;
- int start_y;
- int end_x;
- int end_y;
-
- if (!strcmp("convert", cmd)) {
- ret = image_util_transform_set_colorspace(g_handle, colorspace);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- g_printf("[%d]error image_util_transform_set_colorspace [%d]\n", __LINE__, ret);
- return;
- }
- }
-
- if (!strcmp("resize", cmd)) {
- width = g_width/2;
- height = g_height/2;
-
- ret = image_util_transform_set_resolution(g_handle, width, height);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- g_printf("[%d]Error image_util_transform_set_resolution [%d]\n", __LINE__, ret);
- return;
- }
- }
-
- if (!strcmp("rotate", cmd)) {
- ret = image_util_transform_set_rotation(g_handle, g_angle);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- g_printf("[%d]Error image_util_transform_set_rotation [%d]\n", __LINE__, ret);
- return;
- }
- }
-
- if (!strcmp("crop", cmd)) {
- start_x = g_width/4;
- start_y = g_height/3;
- end_x = g_width*3/4;
- end_y = g_height;
-
- ret = image_util_transform_set_crop_area(g_handle, start_x, start_y, end_x, end_y);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- g_printf("[%d]Error image_util_transform_set_crop_area [%d]\n", __LINE__, ret);
- return;
- }
- }
-
- if (!strcmp("run", cmd)) {
- ret = image_util_transform_run(g_handle, g_src_packet, (image_util_transform_completed_cb)test_transform_completed_cb, NULL);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- g_printf("[%d]Error image_util_transform_run [%d]\n", __LINE__, ret);
- return;
- }
- g_request_count++;
- }
-
- if (!strcmp("run2", cmd)) {
- image_util_image_h transformed_image = NULL;
-
- ret = image_util_transform_run2(g_handle, g_src_image, &transformed_image);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- g_printf("[%d]Error image_util_transform_run2 [%d]\n", __LINE__, ret);
- return;
- }
- __save_image(transformed_image);
- g_printf("<<<<< SUCCESS >>>>>\n");
- }
-
- if (!strcmp("run2_async", cmd)) {
- ret = image_util_transform_run2_async(g_handle, g_src_image, (image_util_transform_completed2_cb)test_transform_completed2_cb, NULL);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- g_printf("[%d]Error image_util_transform_run2_async [%d]\n", __LINE__, ret);
- return;
- }
- g_request_count++;
- }
-}
-
-static void _async_test()
-{
- int i = 0;
- g_request_count = 0;
- for (i = 0; i < MAX_REPEAT_COUNT; i++) {
- _transform("run");
- g_printf("<<<<< %03d >>>>>\n", g_request_count);
- }
-}
-
-static void _async_test2()
-{
- int i = 0;
- g_request_count = 0;
- for (i = 0; i < MAX_REPEAT_COUNT; i++) {
- _transform("run2_async");
- g_printf("<<<<< %03d >>>>>\n", g_request_count);
- }
-}
-
-void quit(void)
-{
- if (g_loop)
- g_main_loop_quit(g_loop);
-}
-
-void reset_current_menu_state()
-{
- g_menu_state = CURRENT_STATE_MAIN_MENU;
- return;
-}
-
-static void display_set_rotation_parameter_menu(void)
-{
- g_print("\n");
- g_print("====================================================\n");
- g_print(" Enter number of rotate operation parameter\n");
- g_print("----------------------------------------------------\n");
- g_print("0. None\n");
- g_print("1. Rotation 90 degrees\n");
- g_print("2. Rotation 180 degrees\n");
- g_print("3. Rotation 270 degrees\n");
- g_print("4. Flip horizontal\n");
- g_print("5. Flip vertical\n");
- g_print("====================================================\n");
-}
-
-static void display_menu(void)
-{
- g_print("\n");
- g_print("====================================================\n");
- g_print(" image-util Core-API test: Main menu v0.2\n");
- g_print("----------------------------------------------------\n");
- g_print("1. create handle \n");
- g_print("2. set convert \n");
- g_print("3. set crop \n");
- g_print("4. set resize \n");
- g_print("5. set rotate \n");
- g_print("6. run \n");
- g_print("7. run2 \n");
- g_print("8. run2_async \n");
- g_print("9. destroy handle \n");
- g_print("11. run %d times \n", MAX_REPEAT_COUNT);
- g_print("12. run2_async %d times \n", MAX_REPEAT_COUNT);
- g_print("0. quit \n");
- g_print("----------------------------------------------------\n");
- g_print("====================================================\n");
-
-}
-
-static void interpret_rotation_parameter_cmd(char *cmd)
-{
- int choice = atoi(cmd);
-
- if (choice < IMAGE_UTIL_ROTATION_NONE || choice > IMAGE_UTIL_ROTATION_FLIP_VERT) {
- g_print("wrong rotation parameter\n");
- display_set_rotation_parameter_menu();
- }
- g_angle = choice;
-}
-
-static void interpret_cmd(char *cmd)
-{
- int len = strlen(cmd);
- if (g_menu_state == CURRENT_STATE_MAIN_MENU) {
- if (len == 1) {
- if (!strncmp(cmd, "1", len)) {
- _create();
- } else if (!strncmp(cmd, "2", len)) {
- _transform("convert");
- } else if (!strncmp(cmd, "3", len)) {
- _transform("crop");
- } else if (!strncmp(cmd, "4", len)) {
- _transform("resize");
- } else if (!strncmp(cmd, "5", len)) {
- g_menu_state = CURRENT_STATE_SET_ROTATION_PARAMETER_MENU;
- display_set_rotation_parameter_menu();
- return;
- } else if (!strncmp(cmd, "6", len)) {
- _transform("run");
- return;
- } else if (!strncmp(cmd, "7", len)) {
- _transform("run2");
- } else if (!strncmp(cmd, "8", len)) {
- _transform("run2_async");
- return;
- } else if (!strncmp(cmd, "9", len)) {
- _destroy();
- } else if (!strncmp(cmd, "0", len)) {
- quit();
- }
- } else if (len == 2) {
- if (!strncmp(cmd, "11", len)) {
- _async_test();
- return;
- } else if (!strncmp(cmd, "12", len)) {
- _async_test2();
- return;
- } else {
- g_print("wrong command\n");
- }
- } else {
- g_print("wrong command\n");
- }
-
- display_menu();
- } else if (g_menu_state == CURRENT_STATE_SET_ROTATION_PARAMETER_MENU) {
- interpret_rotation_parameter_cmd(cmd);
- _transform("rotate");
- reset_current_menu_state();
- display_menu();
- } else {
- g_print("wrong menu state\n");
- }
-}
-
-gboolean input(GIOChannel *channel)
-{
- gchar buf[MAX_STRING_LEN];
- gsize read;
- GError *error = NULL;
-
- g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error);
-
- buf[read] = '\0';
- g_strstrip(buf);
- interpret_cmd(buf);
-
- return TRUE;
-}
-
-int main(int argc, char **argv)
-{
- int ret = IMAGE_UTIL_ERROR_NONE;
-
- GIOChannel *stdin_channel = NULL;
- stdin_channel = g_io_channel_unix_new(0);
- g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
- g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)input, NULL);
-
- if (argc < 4) {
- g_printf("Do: export XDG_RUNTIME_DIR=/run \n");
- g_printf("Usage: image_utl_test filename width height format \n");
- return ret;
- }
-
- g_handle = NULL;
- g_src_packet = NULL;
- g_path = (char *)g_malloc(MAX_STRING_LEN * sizeof(char));
- if (g_path == NULL) {
- g_printf("memory allocation fail. \n");
- return ret;
- }
-
- snprintf(g_path, MAX_STRING_LEN, "%s", argv[1]);
- g_width = atoi(argv[2]);
- g_height = atoi(argv[3]);
- g_format = atoi(argv[4]);
-
- ret = image_util_transform_create(&g_handle);
- if (ret != IMAGE_UTIL_ERROR_NONE) {
- g_printf("[%d]Error image_util_transform_create [%d]\n", __LINE__, ret);
- goto Exit;
- }
-
- if (!__create_src_image()) {
- g_printf("Error - Create_src_image\n");
- goto Exit;
- }
-
- if (!__create_src_packet()) {
- g_printf("Error - Create_src_packet\n");
- goto Exit;
- }
-
- display_menu();
-
- g_loop = g_main_loop_new(NULL, FALSE);
-
- g_main_loop_run(g_loop);
- g_main_loop_unref(g_loop);
-
-Exit:
- if (g_path) {
- IMAGE_UTIL_SAFE_FREE(g_path);
- g_printf("[%d]Success file path is destroyed \n", __LINE__);
- }
-
- if (g_src_image) {
- image_util_destroy_image(g_src_image);
- g_printf("[%d]Success source image is destroyed \n", __LINE__);
- }
-
- if (g_src_packet) {
- media_packet_destroy(g_src_packet);
- g_printf("[%d]Success source packet is destroyed \n", __LINE__);
- }
- _destroy();
-
- return 0;
-}
--- /dev/null
+/*
+* Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+#include <dlog.h>
+#include <glib.h>
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#include <tzplatform_config.h>
+#include <image_util.h>
+
+/* logs for testsuite */
+#define VERSION 0.1
+#define DEBUG_QUEUE 0
+#define DUMP_RAW_IMAGE 0
+
+/* commons for testsuite */
+#define MAX_STRING_LEN PATH_MAX
+#define MAX_AGIF_CNT 100
+#define IMAGE_UTIL_COLOR_NUM IMAGE_UTIL_COLORSPACE_NV61 + 1
+
+#define SAFE_FREE(src) { if (src) {free(src); src = NULL; } }
+#define SAFE_G_FREE(src) { if (src) {g_free(src); src = NULL; } }
+
+#define IS_RAW_FILE(x) ((g_strrstr(x, ".raw")) ? TRUE : FALSE)
+
+#define RETM_IF(expr, fmt, arg...) do { \
+ if (expr) { \
+ g_print(fmt, ##arg); \
+ return; \
+ } \
+ } while (0)
+#define RETVM_IF(expr, val, fmt, arg...) do { \
+ if (expr) { \
+ g_print(fmt, ##arg); \
+ return (val); \
+ } \
+ } while (0)
+
+/* output file */
+#define FILE_FOR_DUMP_RAW_IMAGE tzplatform_mkpath(TZ_USER_CONTENT, "imgutil_test_raw")
+#define FILE_FOR_AUTO tzplatform_mkpath(TZ_USER_CONTENT, "imgutil_test_auto")
+#define FILE_FOR_ENCODE tzplatform_mkpath(TZ_USER_CONTENT, "imgutil_test_encode")
+#define FILE_FOR_ENCODE_AGIF tzplatform_mkpath(TZ_USER_CONTENT, "imgutil_test_encode_agif")
+
+/* parameters for testsuite */
+typedef enum {
+ MAIN_MENU = 0,
+ SET_PATH_MENU,
+ SET_PATH_SUB_MENU,
+ DECODE_MENU,
+ ENCODE_MENU,
+ ENCODE_AGIF_MENU,
+ TRANSFORM_MENU,
+
+ /* set menu */
+ SET_BUFFER_MENU = 20,
+ SET_TO_BUFFER_MENU,
+ SET_COLOR_MENU,
+ SET_RAW_COLOR_MENU,
+ SET_COMPRESSION_MENU,
+ SET_CONVERT_MENU,
+ SET_CROP_MENU,
+ SET_DELAY_MENU,
+ SET_DIR_MENU,
+ SET_DOWNSCALE_MENU,
+ SET_QUALITY_MENU,
+ SET_RESIZE_MENU,
+ SET_ROTATE_MENU,
+ SET_SIZE_MENU,
+ SET_TYPE_MENU,
+ SET_LAST_MENU,
+} test_menu_state_e;
+
+typedef struct {
+ test_menu_state_e menu_state;
+} test_queue_menu_s;
+
+typedef struct {
+ unsigned int x;
+ unsigned int y;
+ unsigned int w;
+ unsigned int h;
+} test_size_s;
+
+typedef struct {
+ /* for input */
+ char *path;
+
+ gboolean has_buffer;
+ unsigned char *buffer;
+ size_t buffer_size;
+
+ gboolean is_raw;
+ test_size_s size;
+ image_util_colorspace_e color;
+
+ /* for result of test or pass through */
+ image_util_image_h image;
+
+ /* for a-gif */
+ unsigned int image_cnt;
+ image_util_image_h images[MAX_AGIF_CNT];
+} test_complex_data_s;
+
+typedef struct {
+ test_complex_data_s *cdata;
+} test_queue_data_s;
+
+typedef struct {
+ image_util_colorspace_e color;
+ image_util_scale_e downscale;
+} test_decode_params_s;
+
+typedef struct {
+ image_util_type_e type;
+ int quality;
+ image_util_png_compression_e compression;
+ gboolean use_buffer;
+} test_encode_params_s;
+
+typedef struct {
+ int delay;
+ gboolean use_buffer;
+} test_encode_agif_params_s;
+
+typedef struct {
+ gboolean has_convert_color;
+ image_util_colorspace_e convert_color;
+ gboolean has_crop;
+ test_size_s crop_area;
+ gboolean has_resize;
+ test_size_s resize;
+ gboolean has_rotation;
+ image_util_rotation_e rotation;
+} test_transform_params_s;
+
+static test_menu_state_e g_current_menu = MAIN_MENU;
+static test_menu_state_e g_previous_menu = MAIN_MENU;
+
+static test_complex_data_s g_input_data;
+
+/* decode */
+static test_decode_params_s g_decode_params;
+static test_complex_data_s g_decode_result;
+/* encode */
+static test_encode_params_s g_encode_params;
+static test_complex_data_s g_encode_result;
+
+/* encode a-gif */
+static test_encode_agif_params_s g_encode_agif_params;
+static test_complex_data_s g_encode_agif_result;
+/* transform */
+static test_transform_params_s g_transform_params;
+static test_complex_data_s g_transform_result;
+
+static GQueue *g_queue_menu = NULL;
+static GQueue *g_queue_agif_images = NULL;
+static GQueue *g_queue_data = NULL;
+
+static GMainLoop *g_mainloop = NULL;
+/* parameters for testsuite */
+
+
+
+/* display menu for testsuite */
+static void __display_set(const char *text, const char *ex)
+{
+ g_print("\n");
+ g_print("\tPlease type 'b' to go back and 'q' to quit at any time.\n");
+
+ if (ex)
+ g_print("*** input %s [ex. %s] : ", text, ex);
+ else
+ g_print("*** input %s: ", text);
+}
+
+typedef enum {
+ RAW_IMG_SET_COLOR,
+ RAW_IMG_SET_SIZE,
+ RAW_IMG_MENU_MAX,
+} test_raw_img_menu_e;
+
+typedef struct {
+ test_raw_img_menu_e e;
+ const char *t;
+} test_raw_img_menu_s;
+
+static const test_raw_img_menu_s g_disp_raw_img_menu[RAW_IMG_MENU_MAX] = {
+ { RAW_IMG_SET_COLOR, "set colorspace (opt. default=IMAGE_UTIL_COLORSPACE_RGBA8888)" },
+ { RAW_IMG_SET_SIZE, "set width & height" },
+};
+
+static void __display_set_raw_menu(void)
+{
+ unsigned int idx = 0;
+ g_print("\n");
+ g_print("====================================================\n");
+ g_print(" image-util Core-API test: Set raw data menu v%2.1f\n", VERSION);
+ g_print("----------------------------------------------------\n");
+ for (idx = 0; idx < RAW_IMG_MENU_MAX; idx++)
+ g_print("%u. %s\n", g_disp_raw_img_menu[idx].e, g_disp_raw_img_menu[idx].t);
+ g_print("b. back\n");
+ g_print("q. quit\n");
+ g_print("----------------------------------------------------\n");
+ g_print("====================================================\n");
+}
+
+typedef enum {
+ DECODE_SET_BUFFER = 0,
+ DECODE_SET_COLOR,
+ DECODE_SET_DOWNSCALE,
+ DECODE_RUN,
+ DECODE_RUN_ASYNC,
+ DECODE_RUN2,
+ DECODE_RUN_ASYNC2,
+ DECODE_SAVE_TO_JPEG,
+ DECODE_MENU_MAX,
+} test_decode_menu_e;
+
+typedef struct {
+ test_decode_menu_e e;
+ const char *t;
+} test_decode_menu_s;
+
+static const test_decode_menu_s g_disp_decode_menu[DECODE_MENU_MAX] = {
+ { DECODE_SET_BUFFER, "set input buffer" },
+ { DECODE_SET_COLOR, "set color (mand. default=IMAGE_UTIL_COLORSPACE_RGBA8888)" },
+ { DECODE_SET_DOWNSCALE, "set downscale (opt. for jpeg only)" },
+ { DECODE_RUN, "decode run (will be deprecated)" },
+ { DECODE_RUN_ASYNC, "decode run async (will be deprecated)" },
+ { DECODE_RUN2, "decode run2" },
+ { DECODE_RUN_ASYNC2, "decode run async2" },
+ { DECODE_SAVE_TO_JPEG, "save decode result to jpg" },
+};
+
+static void __display_decode_menu(void)
+{
+ unsigned int idx = 0;
+ g_print("\n");
+ g_print("====================================================\n");
+ g_print(" image-util Core-API test: Decode menu v%2.1f\n", VERSION);
+ g_print("----------------------------------------------------\n");
+ for (idx = 0; idx < DECODE_MENU_MAX; idx++)
+ g_print("%u. %s\n", g_disp_decode_menu[idx].e, g_disp_decode_menu[idx].t);
+ g_print("b. back\n");
+ g_print("q. quit\n");
+ g_print("----------------------------------------------------\n");
+ g_print("====================================================\n");
+}
+
+typedef enum {
+ ENCODE_SET_TYPE = 0,
+ ENCODE_SET_QUALITY,
+ ENCODE_SET_COMPRESIION,
+ ENCODE_SET_TO_BUFFER,
+ ENCODE_RUN,
+ ENCODE_RUN_ASYNC,
+ ENCODE_RUN_TO_FILE,
+ ENCODE_RUN_TO_BUFFER,
+ ENCODE_RUN_ASYNC_TO_FILE,
+ ENCODE_RUN_ASYNC_TO_BUFFER,
+ ENCODE_MENU_MAX,
+} test_encode_menu_e;
+
+typedef struct {
+ test_encode_menu_e e;
+ const char *t;
+} test_encode_menu_s;
+
+static const test_encode_menu_s g_disp_encode_menu[ENCODE_MENU_MAX] = {
+ { ENCODE_SET_TYPE, "set image_type (mand. default=IMAGE_UTIL_JPEG)" },
+ { ENCODE_SET_QUALITY, "set quality (opt. for jpeg only)" },
+ { ENCODE_SET_COMPRESIION, "set compression (opt. for png only)" },
+ { ENCODE_SET_TO_BUFFER, "set output buffer (opt. deprecated)" },
+ { ENCODE_RUN, "encode run (will be deprecated)" },
+ { ENCODE_RUN_ASYNC, "encode run async (will be deprecated)" },
+ { ENCODE_RUN_TO_FILE, "encode run to file" },
+ { ENCODE_RUN_TO_BUFFER, "encode run to buffer" },
+ { ENCODE_RUN_ASYNC_TO_FILE, "encode run async to file" },
+ { ENCODE_RUN_ASYNC_TO_BUFFER, "encode run async to buffer" },
+};
+
+static void __display_encode_menu(void)
+{
+ unsigned int idx = 0;
+ g_print("\n");
+ g_print("====================================================\n");
+ g_print(" image-util Core-API test: Encode menu v%2.1f\n", VERSION);
+ g_print("----------------------------------------------------\n");
+ for (idx = 0; idx < ENCODE_MENU_MAX; idx++)
+ g_print("%u. %s\n", g_disp_encode_menu[idx].e, g_disp_encode_menu[idx].t);
+ g_print("b. back\n");
+ g_print("q. quit\n");
+ g_print("----------------------------------------------------\n");
+ g_print("====================================================\n");
+}
+
+typedef enum {
+ ENCODE_AGIF_SET_DIR = 0,
+ ENCODE_AGIF_SET_DELAY,
+ ENCODE_AGIF_SET_TO_BUFFER,
+ ENCODE_AGIF_RUN,
+ ENCODE_AGIF_RUN_ASYNC,
+ ENCODE_AGIF_SAVE_TO_FILE,
+ ENCODE_AGIF_SAVE_TO_BUFFER,
+ ENCODE_AGIF_MENU_MAX,
+} test_encode_agif_menu_e;
+
+typedef struct {
+ test_encode_agif_menu_e e;
+ const char *t;
+} test_encode_agif_menu_s;
+
+static const test_encode_agif_menu_s g_disp_encode_agif_menu[ENCODE_AGIF_MENU_MAX] = {
+ { ENCODE_AGIF_SET_DIR, "set directory" },
+ { ENCODE_AGIF_SET_DELAY, "set dealy time (mand. default = 100)" },
+ { ENCODE_AGIF_SET_TO_BUFFER, "set output buffer (opt. will be deprecated)" },
+ { ENCODE_AGIF_RUN, "run agif (will be deprecated)" },
+ { ENCODE_AGIF_RUN_ASYNC, "run async agif (will be deprecated)" },
+ { ENCODE_AGIF_SAVE_TO_FILE, "add frame by frame and save to file" },
+ { ENCODE_AGIF_SAVE_TO_BUFFER, "add frame by frame and save to buffer" },
+};
+
+static void __display_encode_agif_menu(void)
+{
+ unsigned int idx = 0;
+ g_print("\n");
+ g_print("====================================================\n");
+ g_print(" image-util Core-API test: Encode A-GIF menu v%2.1f\n", VERSION);
+ g_print("----------------------------------------------------\n");
+ for (idx = 0; idx < ENCODE_AGIF_MENU_MAX; idx++)
+ g_print("%u. %s\n", g_disp_encode_agif_menu[idx].e, g_disp_encode_agif_menu[idx].t);
+ g_print("b. back\n");
+ g_print("q. quit\n");
+ g_print("----------------------------------------------------\n");
+ g_print("====================================================\n");
+}
+
+typedef enum {
+ TRANSFORM_SET_CONVERT = 0,
+ TRANSFORM_SET_CROP,
+ TRANSFORM_SET_RESIZE,
+ TRANSFORM_SET_ROTATE,
+ TRANSFORM_RUN,
+ TRANSFORM_RUN2,
+ TRANSFORM_RUN2_ASYNC,
+ TRANSFORM_MENU_MAX,
+} test_transform_menu_e;
+
+typedef struct {
+ test_transform_menu_e e;
+ const char *t;
+} test_transform_menu_s;
+
+static const test_transform_menu_s g_disp_transform_menu[TRANSFORM_MENU_MAX] = {
+ { TRANSFORM_SET_CONVERT, "set convert" },
+ { TRANSFORM_SET_CROP, "set crop" },
+ { TRANSFORM_SET_RESIZE, "set resize" },
+ { TRANSFORM_SET_ROTATE, "set rotate" },
+ { TRANSFORM_RUN, "transform run" },
+ { TRANSFORM_RUN2, "transform run2" },
+ { TRANSFORM_RUN2_ASYNC, "transform run2 async" },
+};
+
+static void __display_transform_menu(void)
+{
+ unsigned int idx = 0;
+ g_print("\n");
+ g_print("====================================================\n");
+ g_print(" image-util Core-API test: Transform menu v%2.1f\n", VERSION);
+ g_print("----------------------------------------------------\n");
+ for (idx = 0; idx < TRANSFORM_MENU_MAX; idx++)
+ g_print("%u. %s\n", g_disp_transform_menu[idx].e, g_disp_transform_menu[idx].t);
+ g_print("b. back\n");
+ g_print("q. quit\n");
+ g_print("----------------------------------------------------\n");
+ g_print("====================================================\n");
+}
+
+typedef enum {
+ TEST_AUTO = 0,
+ TEST_DECODE,
+ TEST_ENCODE,
+ TEST_ENCODE_AGIF,
+ TEST_TRANSFORM,
+ SET_PATH,
+ MAIN_MENU_MAX,
+} test_main_menu_e;
+
+typedef struct {
+ test_main_menu_e e;
+ const char *t;
+} test_main_menu_s;
+
+static const test_main_menu_s g_disp_main_menu[MAIN_MENU_MAX] = {
+ { TEST_AUTO, "test auto" },
+ { TEST_DECODE, "test decode" },
+ { TEST_ENCODE, "test encode" },
+ { TEST_ENCODE_AGIF, "test encode a-gif" },
+ { TEST_TRANSFORM, "test transform" },
+ { SET_PATH, "set path" },
+};
+
+static void __display_main_menu(void)
+{
+ unsigned int idx = 0;
+ g_print("\n");
+ g_print("====================================================\n");
+ g_print(" image-util Core-API test: Main menu v%2.1f\n", VERSION);
+ g_print("----------------------------------------------------\n");
+ for (idx = 0; idx < MAIN_MENU_MAX; idx++)
+ g_print("%u. %s\n", g_disp_main_menu[idx].e, g_disp_main_menu[idx].t);
+ g_print("q. quit\n");
+ g_print("----------------------------------------------------\n");
+ g_print("====================================================\n");
+}
+
+static void __display_menu(test_menu_state_e menu_state)
+{
+ switch(menu_state) {
+ case DECODE_MENU:
+ __display_decode_menu();
+ break;
+ case ENCODE_MENU:
+ __display_encode_menu();
+ break;
+ case ENCODE_AGIF_MENU:
+ __display_encode_agif_menu();
+ break;
+ case TRANSFORM_MENU:
+ __display_transform_menu();
+ break;
+
+ /* set menus */
+ case SET_PATH_MENU:
+ __display_set("path", "/home/owner/media/test.jpg");
+ break;
+ case SET_DIR_MENU:
+ __display_set("dir", "/home/owner/media/Images");
+ break;
+ case SET_PATH_SUB_MENU:
+ __display_set_raw_menu();
+ break;
+
+ case SET_BUFFER_MENU:
+ __display_set("set buffer", "yes/no");
+ break;
+ case SET_COLOR_MENU:
+ case SET_RAW_COLOR_MENU:
+ case SET_CONVERT_MENU:
+ __display_set("colorspace", "10");
+ break;
+ case SET_COMPRESSION_MENU:
+ __display_set("comprssion", "0~9");
+ break;
+ case SET_CROP_MENU:
+ __display_set("crop", "(sx)x(sy)x(w)x(h), 0x0x1920x1080");
+ break;
+ case SET_DELAY_MENU:
+ __display_set("delay", "20~");
+ break;
+ case SET_DOWNSCALE_MENU:
+ __display_set("downscale", "0~3");
+ break;
+ case SET_QUALITY_MENU:
+ __display_set("quality", "1~100");
+ break;
+ case SET_RESIZE_MENU:
+ case SET_SIZE_MENU:
+ __display_set("size", "1920x1080");
+ break;
+ case SET_ROTATE_MENU:
+ __display_set("rotation", "0=none, 1=90, 2=180, 3=270");
+ break;
+ case SET_TYPE_MENU:
+ __display_set("image_type", "0:jpeg, 1:png, 2:gif, 3:bmp");
+ break;
+ /* set menus */
+
+ case MAIN_MENU:
+ default:
+ __display_main_menu();
+ break;
+ }
+}
+/* display menu for testsuite */
+
+
+
+/* internal functions for testsuite */
+GCond g_thread_cond;
+GMutex g_thread_mutex;
+
+void __wait()
+{
+ g_mutex_lock(&g_thread_mutex);
+ g_print("\t[__wait] waiting... until finishing\n");
+ g_cond_wait(&g_thread_cond, &g_thread_mutex);
+ g_print("\t[__wait] get signal from callback\n");
+ g_mutex_unlock(&g_thread_mutex);
+}
+
+void __signal()
+{
+ g_mutex_lock(&g_thread_mutex);
+ g_cond_signal(&g_thread_cond);
+ g_print("\t[__signal] send signal to test proc\n");
+ g_mutex_unlock(&g_thread_mutex);
+}
+
+static gboolean __read_file(char *path, void **data, size_t *length)
+{
+ FILE *fp = NULL;
+ long len = 0;
+
+ if (!path || !data || length == 0) {
+ g_print("\t[__read_file] invalid data %s %p %p\n", path, data, length);
+ return FALSE;
+ }
+
+ g_print("\t[__read_file] %s read\n", path);
+
+ fp = fopen(path, "r");
+ if (fp == NULL) {
+ g_print("\t[__read_file] fopen failed (%d)\n", errno);
+ return FALSE;
+ }
+
+ if (fseek(fp, 0, SEEK_END) < 0) {
+ g_print("\t[__read_file] fseek failed\n");
+ fclose(fp);
+ return FALSE;
+ }
+
+ len = ftell(fp);
+ if (len < 0) {
+ g_print("\t[__read_file] ftell failed\n");
+ fclose(fp);
+ return FALSE;
+ }
+
+ rewind(fp);
+ *data = (void *)calloc(1, (size_t)len);
+ if (*data == NULL) {
+ g_print("\t[__read_file] memory allocation failed\n");
+ fclose(fp);
+ return FALSE;
+ }
+
+ *length = fread(*data, 1, (size_t)len, fp);
+ if (*length != (size_t)len) {
+ g_print("\t[__read_file] fread failed\n");
+ }
+
+ fclose(fp);
+
+ if (*data == NULL) {
+ *length = 0;
+ return FALSE;
+ }
+
+ *length = (size_t)len;
+
+ g_print("\t[__read_file] %s %zu read DONE\n", path, *length);
+
+ return TRUE;
+}
+
+static gboolean __write_file(const char *path, void *data, size_t length)
+{
+ FILE *fp = NULL;
+ size_t len = 0;
+
+ if (!path || !data || length == 0) {
+ g_print("\t[__write_file] invalid data %s %p %zu\n", path, data, length);
+ return FALSE;
+ }
+
+ g_print("\t[__write_file] %s %p %zu write\n", path, data, length);
+
+ fp = fopen(path, "w");
+ if (fp == NULL) {
+ g_print("\t[__write_file] fopen failed (%d)\n", errno);
+ return FALSE;
+ }
+
+ len = fwrite(data, 1, length, fp);
+ if (len != length) {
+ g_print("\t[__write_file] fwrite failed\n");
+ }
+
+ fclose(fp);
+ fp = NULL;
+
+ g_print("\t[__write_file] %s write DONE\n", path);
+
+ return TRUE;
+}
+
+#if DUMP_RAW_IMAGE
+static int __write_jpeg(const char *name, image_util_image_h image)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ image_util_encode_h handle = NULL;
+ char *path = NULL;
+
+ path = g_strdup_printf("%s_%s.jpg", FILE_FOR_DUMP_RAW_IMAGE, name);
+ RETVM_IF(!path, IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "Memory allocation failed");
+
+ ret = image_util_encode_create(IMAGE_UTIL_JPEG, &handle);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_create failed %d", ret);
+ return ret;
+ }
+
+ ret = image_util_encode_run_to_file(handle, image, path);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_run_to_file failed %d", ret);
+ goto ERROR;
+ }
+
+ERROR:
+ image_util_encode_destroy(handle);
+
+ return ret;
+}
+#endif
+
+static void __queue_free_func(gpointer data)
+{
+ SAFE_FREE(data);
+}
+
+static gboolean __safe_atoui(char *buffer, unsigned int *ui)
+{
+ char *end = NULL;
+ errno = 0;
+ if (buffer == NULL || ui == NULL)
+ return FALSE;
+
+ const long sl = strtol(buffer, &end, 10);
+
+ if (end == buffer)
+ return FALSE;
+ if ('\0' != *end)
+ return FALSE;
+ if ((LONG_MIN == sl || LONG_MAX == sl) && (ERANGE == errno))
+ return FALSE;
+ if (sl < 0)
+ return FALSE;
+
+ *ui = (unsigned int)sl;
+
+ return TRUE;
+}
+
+static void __decode_func(gpointer data, gpointer user_data)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ image_util_decode_h decoder = (image_util_decode_h)user_data;
+ char *path = (char *)data;
+
+ if (path == NULL || strlen(path) == 0)
+ return;
+
+ ret = image_util_decode_set_input_path(decoder, path);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_set_input_path failed %d\n", ret);
+ return;
+ }
+
+ ret = image_util_decode_run2(decoder, &g_input_data.images[g_input_data.image_cnt]);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_run2 failed %d\n", ret);
+ return;
+ }
+ g_input_data.image_cnt++;
+}
+
+static gboolean __decode_file_in_dir()
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ image_util_decode_h decoder = NULL;
+
+ ret = image_util_decode_create(&decoder);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_create failed %d\n", ret);
+ return FALSE;
+ }
+
+ g_queue_foreach(g_queue_agif_images, __decode_func, decoder);
+
+ if (g_input_data.image_cnt == 0) {
+ g_print("No valid image\n");
+ return FALSE;
+ }
+
+ image_util_decode_destroy(decoder);
+
+ g_print("%u valid image have been decoded.\n", g_input_data.image_cnt);
+
+ return TRUE;
+}
+
+static int __sort_compare(gconstpointer a, gconstpointer b, gpointer user_data)
+{
+ const char *_a = (const char *)a;
+ const char *_b = (const char *)b;
+ if (strlen(_a) < strlen(_b))
+ return -1;
+
+ if (strlen(_a) > strlen(_b))
+ return 1;
+
+ return g_ascii_strcasecmp(_a, _b);
+}
+
+static gboolean __set_input_dir(const char *path)
+{
+ struct dirent *dp = NULL;
+ DIR *fd = NULL;
+
+ if (path == NULL || strlen(path) == 0)
+ return FALSE;
+
+ if (!g_queue_agif_images) {
+ g_queue_agif_images = g_queue_new();
+ if (!g_queue_agif_images) {
+ g_print("g_queue_new failed\n");
+ return FALSE;
+ }
+ }
+
+ fd = opendir(path);
+ if (fd == NULL) {
+ g_print("\tlistdir: can't open %s\n", path);
+ return FALSE;
+ }
+
+ g_queue_free_full(g_queue_agif_images, __queue_free_func);
+
+ while ((dp = readdir(fd)) != NULL) {
+ if (strlen(dp->d_name) == 0)
+ continue;
+ if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
+ continue; /* skip self and parent */
+
+ g_queue_push_tail(g_queue_agif_images, g_strdup_printf("%s/%s", path, dp->d_name));
+ }
+
+ closedir(fd);
+
+ if (g_queue_get_length(g_queue_agif_images) == 0) {
+ g_print("\tNo Test File in directory(%s)!\n", path);
+ return FALSE;
+ }
+
+ /* sort files */
+ g_queue_sort(g_queue_agif_images, __sort_compare, NULL);
+
+ if (!__decode_file_in_dir()) {
+ g_print("Fail to decode file from dir! %s\n", path);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static gboolean __set_input_path(const char *path)
+{
+ if (path == NULL || strlen(path) == 0)
+ return FALSE;
+
+ SAFE_G_FREE(g_input_data.path);
+
+ g_input_data.path = g_strdup(path);
+ if (!g_input_data.path) {
+ g_print("Memory allocation failed\n");
+ return FALSE;
+ }
+
+ if (g_file_test(path, G_FILE_TEST_IS_DIR)) {
+ g_print("file path is a directory (%s)\n", path);
+ return __set_input_dir(path);
+ }
+
+ return TRUE;
+}
+
+static gboolean __set_input_crop_area(const char *data, test_size_s *size)
+{
+ gchar **params = NULL;
+ gboolean ret = FALSE;
+
+ if (data == NULL || strlen(data) == 0)
+ return FALSE;
+
+ params = g_strsplit(data, "x", 0);
+
+ if (params == NULL || params[0] == NULL || params[1] == NULL || params[2] == NULL || params[3] == NULL)
+ return FALSE;
+
+ if (!__safe_atoui(params[0], &size->x)) {
+ g_print("wrong width! %s\n", params[0]);
+ goto ERROR;
+ }
+ if (!__safe_atoui(params[1], &size->y)) {
+ g_print("wrong height! %s\n", params[1]);
+ goto ERROR;
+ }
+
+ if (!__safe_atoui(params[2], &size->w)) {
+ g_print("wrong width! %s\n", params[0]);
+ goto ERROR;
+ }
+ if (!__safe_atoui(params[3], &size->h)) {
+ g_print("wrong height! %s\n", params[1]);
+ goto ERROR;
+ }
+
+ ret = TRUE;
+
+ERROR:
+ g_strfreev(params);
+
+ return ret;
+}
+
+static gboolean __set_input_size(const char *data, test_size_s *size)
+{
+ gchar **params = NULL;
+ gboolean ret = FALSE;
+
+ if (data == NULL || strlen(data) == 0)
+ return FALSE;
+
+ params = g_strsplit(data, "x", 0);
+
+ if (params == NULL || params[0] == NULL || params[1] == NULL)
+ return FALSE;
+
+ if (!__safe_atoui(params[0], &size->w)) {
+ g_print("wrong width! %s\n", params[0]);
+ goto ERROR;
+ }
+ if (!__safe_atoui(params[1], &size->h)) {
+ g_print("wrong height! %s\n", params[1]);
+ goto ERROR;
+ }
+
+ ret = TRUE;
+
+ERROR:
+ g_strfreev(params);
+
+ return ret;
+}
+
+static int __get_raw_data(test_complex_data_s *test_data)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ void *buffer = NULL;
+ size_t buffer_size = 0;
+
+ if (test_data->is_raw) {
+ if (!__read_file(test_data->path, &buffer, &buffer_size)) {
+ g_print("__read_file failed %s\n", test_data->path);
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = image_util_create_image(test_data->size.w, test_data->size.h, test_data->color,
+ buffer, buffer_size, &test_data->image);
+ if (ret != IMAGE_UTIL_ERROR_NONE)
+ g_print("image_util_create_image failed %d\n", ret);
+ }
+
+ return ret;
+}
+
+static unsigned int g_num_of_file = 0;
+static void __set_auto_file(image_util_type_e image_type, char **path)
+{
+ char ext[4];
+
+ SAFE_G_FREE(*path);
+
+ switch (image_type) {
+ case IMAGE_UTIL_JPEG:
+ snprintf(ext, 4, "%s", "jpg");
+ break;
+ case IMAGE_UTIL_PNG:
+ snprintf(ext, 4, "%s", "png");
+ break;
+ case IMAGE_UTIL_GIF:
+ snprintf(ext, 4, "%s", "gif");
+ break;
+ case IMAGE_UTIL_BMP:
+ snprintf(ext, 4, "%s", "bmp");
+ break;
+ default:
+ g_print("Not supported encode format!\n");
+ return;
+ }
+
+ *path = g_strdup_printf("%s_%02d.%s", FILE_FOR_AUTO, g_num_of_file++, ext);
+
+ g_print("\t__set_auto_file: %s!\n", *path);
+}
+
+static void __set_encode_file(image_util_type_e image_type, const char *base, char **path)
+{
+ char ext[4];
+
+ SAFE_G_FREE(*path);
+
+ switch (image_type) {
+ case IMAGE_UTIL_JPEG:
+ snprintf(ext, 4, "%s", "jpg");
+ break;
+ case IMAGE_UTIL_PNG:
+ snprintf(ext, 4, "%s", "png");
+ break;
+ case IMAGE_UTIL_GIF:
+ snprintf(ext, 4, "%s", "gif");
+ break;
+ case IMAGE_UTIL_BMP:
+ snprintf(ext, 4, "%s", "bmp");
+ break;
+ default:
+ g_print("Not supported encode format!\n");
+ return;
+ }
+
+ *path = g_strdup_printf("%s.%s", base, ext);
+}
+
+typedef struct {
+ image_util_colorspace_e image_format;
+ media_format_mimetype_e mimetype;
+ const char *mimetype_name;
+} image_format_mimetype_pair_s;
+
+static const image_format_mimetype_pair_s image_format_mimetype_table[IMAGE_UTIL_COLOR_NUM] = {
+ { IMAGE_UTIL_COLORSPACE_YV12, MEDIA_FORMAT_YV12, "MEDIA_FORMAT_YV12" },
+ { IMAGE_UTIL_COLORSPACE_YUV422, MEDIA_FORMAT_422P, "MEDIA_FORMAT_422P" },
+ { IMAGE_UTIL_COLORSPACE_I420, MEDIA_FORMAT_I420, "MEDIA_FORMAT_I420" },
+ { IMAGE_UTIL_COLORSPACE_NV12, MEDIA_FORMAT_NV12, "Not support" },
+ { IMAGE_UTIL_COLORSPACE_UYVY, MEDIA_FORMAT_UYVY, "MEDIA_FORMAT_UYVY" },
+ { IMAGE_UTIL_COLORSPACE_YUYV, MEDIA_FORMAT_YUYV, "MEDIA_FORMAT_YUYV" },
+ { IMAGE_UTIL_COLORSPACE_RGB565, MEDIA_FORMAT_RGB565, "MEDIA_FORMAT_RGB565" },
+ { IMAGE_UTIL_COLORSPACE_RGB888, MEDIA_FORMAT_RGB888, "MEDIA_FORMAT_RGB888" },
+ { IMAGE_UTIL_COLORSPACE_ARGB8888, MEDIA_FORMAT_ARGB, "MEDIA_FORMAT_ARGB" },
+ { IMAGE_UTIL_COLORSPACE_BGRA8888, MEDIA_FORMAT_BGRA, "MEDIA_FORMAT_BGRA" },
+ { IMAGE_UTIL_COLORSPACE_RGBA8888, MEDIA_FORMAT_RGBA, "MEDIA_FORMAT_RGBA" },
+ { IMAGE_UTIL_COLORSPACE_BGRX8888, -1, "Not support" },
+ { IMAGE_UTIL_COLORSPACE_NV21, MEDIA_FORMAT_NV12T, "MEDIA_FORMAT_NV12T" },
+ { IMAGE_UTIL_COLORSPACE_NV16, MEDIA_FORMAT_NV16, "MEDIA_FORMAT_NV16" },
+ { IMAGE_UTIL_COLORSPACE_NV61, -1, "Not support" }
+};
+
+static media_format_mimetype_e __image_format_to_mimetype(image_util_colorspace_e format)
+{
+ unsigned int i = 0;
+ media_format_mimetype_e mimetype = -1;
+
+ for (i = 0; i < IMAGE_UTIL_COLOR_NUM; i++) {
+ if (image_format_mimetype_table[i].image_format == format) {
+ mimetype = image_format_mimetype_table[i].mimetype;
+ break;
+ }
+ }
+
+ g_print("\t\timgp fmt: %d mimetype fmt: %s", format, image_format_mimetype_table[i].mimetype_name);
+
+ return mimetype;
+}
+
+static image_util_colorspace_e __mimetype_to_image_format(media_format_mimetype_e mimetype)
+{
+ unsigned int i = 0;
+ image_util_colorspace_e format = -1;
+
+ for (i = 0; i < IMAGE_UTIL_COLOR_NUM; i++) {
+ if (image_format_mimetype_table[i].mimetype == mimetype) {
+ format = image_format_mimetype_table[i].image_format;
+ break;
+ }
+ }
+
+ g_print("\t\tmimetype: %s imgp fmt: %d", image_format_mimetype_table[i].mimetype_name, format);
+
+ return format;
+}
+
+static int __create_media_format(media_format_mimetype_e mimetype, unsigned int width, unsigned int height, media_format_h *new_fmt)
+{
+ int err = MEDIA_FORMAT_ERROR_NONE;
+
+ RETVM_IF((new_fmt == NULL) || (width == 0) || (height == 0), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid parameter");
+
+ err = media_format_create(new_fmt);
+ RETVM_IF((err != MEDIA_FORMAT_ERROR_NONE), IMAGE_UTIL_ERROR_INVALID_OPERATION, "media_format_make_writable failed (%d)", err);
+
+ err = media_format_set_video_mime(*new_fmt, mimetype);
+ if (err != MEDIA_FORMAT_ERROR_NONE) {
+ media_format_unref(*new_fmt);
+ g_print("\tmedia_format_set_video_mime failed (%d)\n", err);
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ err = media_format_set_video_width(*new_fmt, width);
+ if (err != MEDIA_FORMAT_ERROR_NONE) {
+ media_format_unref(*new_fmt);
+ g_print("\tmedia_format_set_video_width failed (%d)\n", err);
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ err = media_format_set_video_height(*new_fmt, height);
+ if (err != MEDIA_FORMAT_ERROR_NONE) {
+ media_format_unref(*new_fmt);
+ g_print("\tmedia_format_set_video_height failed (%d)\n", err);
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ return IMAGE_UTIL_ERROR_NONE;
+}
+
+static int __create_media_packet(media_format_h fmt, unsigned char *buffer, size_t buffer_size, media_packet_h *packet)
+{
+ int ret = MEDIA_FORMAT_ERROR_NONE;
+ unsigned int i = 0;
+ uint32_t plane_num = 0;
+ int stride_width = 0, stride_height = 0;
+ void *plane_ptr = NULL;
+ size_t plane_size = 0;
+ size_t buffer_offset = 0;
+ size_t memcpy_size = 0;
+
+ RETVM_IF(!fmt, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid fmt");
+ RETVM_IF(!packet, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid new_pkt");
+ RETVM_IF(!buffer, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid pkt_ptr");
+ RETVM_IF(buffer_size == 0, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid pkt_size");
+
+ ret = media_packet_create_alloc(fmt, NULL, NULL, packet);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ g_print("\tmedia_packet_create_from_external_memory failed (%d)\n", ret);
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ ret = media_packet_get_number_of_video_planes(*packet, &plane_num);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ g_print("\tmedia_packet_get_number_of_video_plances failed (%d)\n", ret);
+ ret = IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ goto ERROR;
+ }
+
+ g_print("\tplane_num: %u\n", plane_num);
+
+ for (i = 0; i < plane_num; i++) {
+ ret = media_packet_get_video_stride_width(*packet, i, &stride_width);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ g_print("\tmedia_packet_get_video_stride_width failed (%d)\n", ret);
+ ret = IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ goto ERROR;
+ }
+
+ ret = media_packet_get_video_stride_height(*packet, i, &stride_height);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ g_print("\tmedia_packet_get_video_stride_height failed (%d)\n", ret);
+ ret = IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ goto ERROR;
+ }
+
+ plane_size = stride_width * stride_height;
+
+ ret = media_packet_get_video_plane_data_ptr(*packet, i, &plane_ptr);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ g_print("\tmedia_packet_get_video_plane_data_ptr failed (%d)\n", ret);
+ ret = IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ goto ERROR;
+ }
+
+ g_print("\tstride_width: %d, stride_height: %d, plane_ptr: %p, plane_size: %zu\n",
+ stride_width, stride_height, plane_ptr,plane_size);
+
+ if (buffer_offset + plane_size > buffer_size)
+ memcpy_size = buffer_size - buffer_offset;
+ else
+ memcpy_size = plane_size;
+
+ memcpy(plane_ptr, buffer + buffer_offset, memcpy_size);
+ buffer_offset += memcpy_size;
+ }
+
+ g_print("\tSuccess - media_packet is created (%p)\n", *packet);
+
+ return IMAGE_UTIL_ERROR_NONE;
+
+ERROR:
+ if (*packet != NULL)
+ media_packet_destroy(*packet);
+ *packet = NULL;
+
+ return ret;
+}
+
+static int __convert_image_to_packet(image_util_image_h image, media_packet_h *packet)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ image_util_colorspace_e color = 0;
+ unsigned int width = 0, height = 0;
+ unsigned char *buffer = NULL;
+ size_t buffer_size = 0;
+ media_format_h fmt = NULL;
+
+ RETVM_IF(!image, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid image");
+ RETVM_IF(!packet, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid packet");
+
+ ret = image_util_get_image(image, &width, &height, &color, &buffer, &buffer_size);
+ RETVM_IF((ret != IMAGE_UTIL_ERROR_NONE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "mm_image_get_image failed");
+
+ g_print("\tBuffer: %p buffer_size: %zu\n", buffer, buffer_size);
+
+ ret = __create_media_format(__image_format_to_mimetype(color), width, height, &fmt);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("\t__create_media_format failed (%d)\n", ret);
+ SAFE_FREE(buffer);
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ ret = __create_media_packet(fmt, buffer, buffer_size, packet);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ g_print("\t__create_media_packet failed (%d)\n", ret);
+ media_format_unref(fmt);
+ SAFE_FREE(buffer);
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+ }
+
+ return IMAGE_UTIL_ERROR_NONE;
+}
+
+static int __convert_packet_to_image(media_packet_h packet, image_util_image_h *image)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ media_format_mimetype_e mimetype = 0;
+ int width = 0, height = 0;
+ media_format_h fmt = NULL;
+ unsigned int i = 0;
+ uint32_t plane_num = 0;
+ int stride_width = 0, stride_height = 0;
+ void *plane_ptr = NULL;
+ size_t plane_size = 0;
+ void *ptr = NULL;
+ size_t size = 0;
+
+ RETVM_IF(!packet, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid packet");
+ RETVM_IF(!image, IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid image");
+
+ ret = media_packet_get_format(packet, &fmt);
+ RETVM_IF((ret != MEDIA_PACKET_ERROR_NONE), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "media_packet_get_format failed (%d)", ret);
+
+ ret = media_format_get_video_info(fmt, &mimetype, &width, &height, NULL, NULL);
+ if (ret != MEDIA_FORMAT_ERROR_NONE) {
+ g_print("\tmedia_packet_get_format failed (%d)\n", ret);
+ media_format_unref(fmt);
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+ media_format_unref(fmt);
+
+ ret = media_packet_get_number_of_video_planes(packet, &plane_num);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ g_print("\tmedia_packet_get_number_of_video_plances failed (%d)\n", ret);
+ goto ERROR;
+ }
+
+ g_print("\tplane_num: %u", plane_num);
+
+ for (i = 0; i < plane_num; i++) {
+ ret = media_packet_get_video_stride_width(packet, i, &stride_width);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ g_print("\tmedia_packet_get_number_of_video_plances failed (%d)\n", ret);
+ goto ERROR;
+ }
+
+ ret = media_packet_get_video_stride_height(packet, i, &stride_height);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ g_print("\tmedia_packet_get_number_of_video_plances failed (%d)\n", ret);
+ goto ERROR;
+ }
+
+ plane_size = stride_width * stride_height;
+
+ ret = media_packet_get_video_plane_data_ptr(packet, i, &plane_ptr);
+ if (ret != MEDIA_PACKET_ERROR_NONE) {
+ g_print("\tmedia_packet_get_number_of_video_plances failed (%d)\n", ret);
+ goto ERROR;
+ }
+
+ g_print("\tstride_width: %d, stride_height: %d, plane_ptr: %p, plane_size: %zu\n",
+ stride_width, stride_height, plane_ptr,plane_size);
+
+ ptr = realloc(ptr, size + plane_size);
+ RETVM_IF(!ptr, IMAGE_UTIL_ERROR_OUT_OF_MEMORY, "Memory allocation failed");
+
+ memcpy(ptr + size, plane_ptr, plane_size);
+ size += plane_size;
+ }
+
+ g_print("\t[Fotmat: %u] W x H : %d x %d\n", mimetype, width, height);
+ RETVM_IF(((width <= 0) || (height <= 0) || (size == 0) || (ptr == NULL)), IMAGE_UTIL_ERROR_INVALID_PARAMETER, "Invalid source packet");
+
+ ret = image_util_create_image(width, height, __mimetype_to_image_format(mimetype), ptr, size, image);
+ SAFE_FREE(ptr);
+ RETVM_IF((ret != IMAGE_UTIL_ERROR_NONE), ret, "mm_image_create_image failed (%d)", ret);
+
+ g_print("\t__image_util_packet_to_image succeed\n");
+
+ return IMAGE_UTIL_ERROR_NONE;
+
+ERROR:
+ SAFE_FREE(ptr);
+ return IMAGE_UTIL_ERROR_INVALID_OPERATION;
+}
+
+/* internal functions for testsuite */
+
+
+/* callback functions for test */
+static void __decode_completed_cb(int error_code, void *user_data, unsigned long width, unsigned long height, unsigned long long size)
+{
+ test_complex_data_s *result = (test_complex_data_s *)user_data;
+
+ g_print("\t__decode_completed_cb invoked %d\n", error_code);
+
+ if (error_code != IMAGE_UTIL_ERROR_NONE) {
+ g_print("Fail to decode image %d\n", error_code);
+ __signal();
+ return;
+ }
+
+ result->size.w = (unsigned int)width;
+ result->size.h = (unsigned int)height;
+ result->buffer_size = (size_t)size;
+ __signal();
+}
+
+static void __decode_completed2_cb(int error_code, image_util_image_h image, void *user_data)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ test_complex_data_s *result = (test_complex_data_s *)user_data;
+
+ g_print("\t__decode_completed2_cb invoked %d\n", error_code);
+
+ if (error_code != IMAGE_UTIL_ERROR_NONE) {
+ g_print("Fail to decode image %d", error_code);
+ __signal();
+ return;
+ }
+
+ ret = image_util_clone_image(image, &result->image);
+ if (ret != IMAGE_UTIL_ERROR_NONE)
+ g_print("image_util_clone_image failed %d\n", ret);
+
+ __signal();
+}
+
+static void __encode_completed_cb(int error_code, void *user_data, unsigned long long size)
+{
+ test_complex_data_s *result = (test_complex_data_s *)user_data;
+
+ g_print("\t__encode_to_file_completed_cb invoked %d\n", error_code);
+
+ if (error_code != IMAGE_UTIL_ERROR_NONE)
+ g_print("Fail to decode image %d\n", error_code);
+
+ result->buffer_size = (size_t)size;
+ __signal();
+}
+
+static void __encode_to_file_completed_cb(image_util_error_e error_code, void *user_data)
+{
+ g_print("\t__encode_to_file_completed_cb invoked %d\n", error_code);
+
+ if (error_code != IMAGE_UTIL_ERROR_NONE)
+ g_print("Fail to decode image %d\n", error_code);
+
+ __signal();
+}
+
+static void __encode_to_buffer_completed_cb(image_util_error_e error_code, unsigned char *buffer, size_t buffer_size, void *user_data)
+{
+ test_complex_data_s *result = (test_complex_data_s *)user_data;
+
+ g_print("\t__encode_to_buffer_completed_cb invoked %d\n", error_code);
+
+ if (error_code != IMAGE_UTIL_ERROR_NONE) {
+ g_print("Fail to decode image %d\n", error_code);
+ __signal();
+ return;
+ }
+
+ result->buffer = calloc(1, buffer_size);
+ if (result->buffer) {
+ memcpy(result->buffer, buffer, buffer_size);
+ result->buffer_size = buffer_size;
+ }
+ __signal();
+}
+
+static void __transform_completed_cb(media_packet_h *dst, int error_code, void *user_data)
+{
+ media_packet_h *result = (media_packet_h *)user_data;
+
+ g_print("\t__transform_completed_cb invoked %d\n", error_code);
+
+ if (error_code != IMAGE_UTIL_ERROR_NONE) {
+ g_print("Fail to transform image %d\n", error_code);
+ __signal();
+ return;
+ }
+
+ *result = *dst;
+
+ __signal();
+}
+
+static void __transform_completed2_cb(image_util_image_h dst, int error_code, void *user_data)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ test_complex_data_s *result = (test_complex_data_s *)user_data;
+
+ g_print("\t__transform_completed2_cb invoked %d\n", error_code);
+
+ if (error_code != IMAGE_UTIL_ERROR_NONE) {
+ g_print("Fail to transform image %d\n", error_code);
+ __signal();
+ return;
+ }
+
+ ret = image_util_clone_image(dst, &result->image);
+ if (ret != IMAGE_UTIL_ERROR_NONE)
+ g_print("image_util_clone_image failed %d\n", ret);
+
+ __signal();
+}
+
+/* callback functions for test */
+
+
+/* test functions for testsuite */
+/* decode JPE, PNG, GIF and BMP with params
+ * input : use path or buffer(buffer_size)
+ * output : use image
+ */
+static int __run_decode(test_decode_menu_e menu, test_complex_data_s *input,
+ test_decode_params_s *params, test_complex_data_s *result)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ image_util_decode_h handle = NULL;
+ unsigned long width = 0;
+ unsigned long height = 0;
+ unsigned long long buffer_size = 0;
+
+ if (!input || !params || !result) {
+ g_print("invalid parameter!!! input: %p, params: %p, result: %p\n", input, params, result);
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ if (result->image) {
+ image_util_destroy_image(result->image);
+ result->image = NULL;
+ }
+
+ ret = image_util_decode_create(&handle);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_create failed %d\n", ret);
+ return ret;
+ }
+
+ if (input->has_buffer) {
+ ret = image_util_decode_set_input_buffer(handle, input->buffer, input->buffer_size);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_set_input_buffer failed %d\n", ret);
+ goto ERROR;
+ }
+ } else {
+ ret = image_util_decode_set_input_path(handle, input->path);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_set_input_path failed %d\n", ret);
+ goto ERROR;
+ }
+ }
+
+ ret = image_util_decode_set_colorspace(handle, params->color);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_set_colorspace failed %d\n", ret);
+ goto ERROR;
+ }
+
+ switch(menu) {
+ case DECODE_RUN:
+ ret = image_util_decode_set_output_buffer(handle, &result->buffer);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_run failed %d\n", ret);
+ break;
+ }
+
+ ret = image_util_decode_run(handle, &width, &height, &buffer_size);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_run failed %d\n", ret);
+ break;
+ }
+
+ ret = image_util_create_image((unsigned int)width, (unsigned int)height, params->color,
+ result->buffer, buffer_size, &result->image);
+ SAFE_FREE(result->buffer);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_create_image failed %d\n", ret);
+ break;
+ }
+ break;
+
+ case DECODE_RUN_ASYNC:
+ ret = image_util_decode_set_output_buffer(handle, &result->buffer);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_run failed %d\n", ret);
+ break;
+ }
+
+ ret = image_util_decode_run_async(handle, __decode_completed_cb, result);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_run failed %d\n", ret);
+ break;
+ }
+ __wait();
+
+ ret = image_util_create_image(result->size.w, result->size.h, params->color,
+ result->buffer, result->buffer_size, &result->image);
+ SAFE_FREE(result->buffer);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_create_image failed %d\n", ret);
+ break;
+ }
+ break;
+
+ case DECODE_RUN2:
+ ret = image_util_decode_run2(handle, &result->image);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_run2 failed %d\n", ret);
+ goto ERROR;
+ }
+ break;
+
+ case DECODE_RUN_ASYNC2:
+ ret = image_util_decode_run_async2(handle, __decode_completed2_cb, result);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_run2 failed %d\n", ret);
+ goto ERROR;
+ }
+ __wait();
+ break;
+
+ default:
+ g_print("wrong decode menu %u\n", menu);
+ break;
+ }
+
+ERROR:
+ image_util_decode_destroy(handle);
+
+ return ret;
+}
+
+/* encode JPE, PNG, GIF and BMP with params
+ * input : use image
+ * output : use path or buffer(buffer_size)
+ */
+static int __run_encode(test_encode_menu_e menu, test_complex_data_s *input,
+ test_encode_params_s *params, test_complex_data_s *result)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ image_util_encode_h handle = NULL;
+ unsigned long long buffer_size = 0;
+
+ if (!input || !params || !result) {
+ g_print("invalid parameter!!! input: %p, params: %p, result: %p\n", input, params, result);
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = __get_raw_data(input);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("__get_raw_data failed %d\n", ret);
+ return ret;
+ }
+
+ if (result->buffer) {
+ SAFE_FREE(result->buffer);
+ result->image = NULL;
+ }
+
+ ret = image_util_encode_create(params->type, &handle);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_create failed %d\n", ret);
+ return ret;
+ }
+
+ if (params->type == IMAGE_UTIL_JPEG) {
+ ret = image_util_encode_set_quality(handle, params->quality);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_set_input_buffer failed %d\n", ret);
+ goto ERROR;
+ }
+ } else if (params->type == IMAGE_UTIL_PNG) {
+ ret = image_util_encode_set_png_compression(handle, params->compression);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_set_input_buffer failed %d\n", ret);
+ goto ERROR;
+ }
+ }
+
+ switch(menu) {
+ case ENCODE_RUN:
+ if (input->image) {
+ SAFE_FREE(input->buffer);
+ ret = image_util_get_image(input->image, &input->size.w, &input->size.h, &input->color, &input->buffer, &input->buffer_size);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_get_image failed %d\n", ret);
+ break;
+ }
+ }
+
+ ret = image_util_encode_set_resolution(handle, input->size.w, input->size.h);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_resolution failed %d\n", ret);
+ break;
+ }
+
+ ret = image_util_encode_set_colorspace(handle, input->color);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_run failed %d\n", ret);
+ break;
+ }
+
+ ret = image_util_encode_set_input_buffer(handle, input->buffer);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_input_buffer failed %d\n", ret);
+ break;
+ }
+
+ if (params->use_buffer) {
+ ret = image_util_encode_set_output_buffer(handle, &result->buffer);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_output_buffer failed %d\n", ret);
+ break;
+ }
+ } else {
+ ret = image_util_encode_set_output_path(handle, result->path);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_output_path failed %d\n", ret);
+ break;
+ }
+ }
+
+ ret = image_util_encode_run(handle, &buffer_size);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_run failed %d\n", ret);
+ break;
+ }
+ result->buffer_size = buffer_size;
+
+ if (params->use_buffer) {
+ __write_file(result->path, result->buffer, result->buffer_size);
+ SAFE_FREE(result->buffer);
+ }
+ break;
+
+ case ENCODE_RUN_ASYNC:
+ if (input->image) {
+ SAFE_FREE(input->buffer);
+ ret = image_util_get_image(input->image, &input->size.w, &input->size.h, &input->color, &input->buffer, &input->buffer_size);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_get_image failed %d\n", ret);
+ break;
+ }
+ }
+
+ ret = image_util_encode_set_resolution(handle, input->size.w, input->size.h);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_resolution failed %d\n", ret);
+ break;
+ }
+
+ ret = image_util_encode_set_colorspace(handle, input->color);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_decode_run failed %d\n", ret);
+ break;
+ }
+
+ ret = image_util_encode_set_input_buffer(handle, input->buffer);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_input_buffer failed %d\n", ret);
+ break;
+ }
+
+ if (params->use_buffer) {
+ ret = image_util_encode_set_output_buffer(handle, &result->buffer);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_output_buffer failed %d\n", ret);
+ break;
+ }
+ } else {
+ ret = image_util_encode_set_output_path(handle, result->path);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_output_path failed %d\n", ret);
+ break;
+ }
+ }
+
+ ret = image_util_encode_run_async(handle, __encode_completed_cb, result);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_run_async failed %d\n", ret);
+ break;
+ }
+ __wait();
+
+ if (params->use_buffer) {
+ __write_file(result->path, result->buffer, result->buffer_size);
+ SAFE_FREE(result->buffer);
+ }
+ break;
+
+ case ENCODE_RUN_TO_FILE:
+ ret = image_util_encode_run_to_file(handle, input->image, result->path);
+ if (ret != IMAGE_UTIL_ERROR_NONE)
+ g_print("image_util_encode_run_to_file failed %d\n", ret);
+ break;
+ case ENCODE_RUN_TO_BUFFER:
+ ret = image_util_encode_run_to_buffer(handle, input->image, &result->buffer, &result->buffer_size);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_run_to_buffer failed %d\n", ret);
+ break;
+ }
+ __write_file(result->path, result->buffer, result->buffer_size);
+ break;
+ case ENCODE_RUN_ASYNC_TO_FILE:
+ ret = image_util_encode_run_async_to_file(handle, input->image, result->path,
+ __encode_to_file_completed_cb, NULL);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_run_async_to_file failed %d\n", ret);
+ break;
+ }
+ __wait();
+ break;
+ case ENCODE_RUN_ASYNC_TO_BUFFER:
+ ret = image_util_encode_run_async_to_buffer(handle, input->image,
+ __encode_to_buffer_completed_cb, result);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_run_async_to_buffer failed %d\n", ret);
+ break;
+ }
+ __wait();
+ __write_file(result->path, result->buffer, result->buffer_size);
+ break;
+
+ default:
+ g_print("wrong encode menu %u", menu);
+ break;
+ }
+
+ERROR:
+ image_util_encode_destroy(handle);
+
+ return ret;
+}
+
+/* encode animated GIF with deprecated APIs
+ * input : use image_cnt & images
+ * output : use path or buffer(buffer_size)
+ */
+static int __run_encode_agif_deprecated(test_encode_menu_e menu, test_complex_data_s *input,
+ test_encode_agif_params_s *params, test_complex_data_s *result)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ image_util_encode_h handle = NULL;
+ unsigned int i = 0;
+ unsigned int width = 0, height = 0;
+ unsigned char **buffer = NULL;
+ size_t buffer_size = 0;
+ unsigned long long size = 0;
+
+ if (!input || !params || !result) {
+ g_print("invalid parameter!!! input: %p, params: %p, result: %p\n", input, params, result);
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ buffer = calloc(1, sizeof(char *) * input->image_cnt);
+ if (!buffer) {
+ g_print("Memory allocation failed %d\n", ret);
+ return IMAGE_UTIL_ERROR_OUT_OF_MEMORY;
+ }
+
+ ret = image_util_encode_create(IMAGE_UTIL_GIF, &handle);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_create failed %d\n", ret);
+ SAFE_FREE(buffer);
+ return ret;
+ }
+
+ for (i = 0; i < input->image_cnt; i++) {
+ ret = image_util_get_image(input->images[i], &width, &height, NULL, &buffer[i], &buffer_size);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_get_image failed %d\n", ret);
+ goto ERROR;
+ }
+
+ ret = image_util_encode_set_resolution(handle, (unsigned long) width, (unsigned long) height);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_resolution failed %d\n", ret);
+ goto ERROR;
+ }
+
+ ret = image_util_encode_set_gif_frame_delay_time(handle, params->delay);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_gif_frame_delay_time failed %d\n", ret);
+ goto ERROR;
+ }
+
+ ret = image_util_encode_set_input_buffer(handle, buffer[i]);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_input_buffer failed %d\n", ret);
+ goto ERROR;
+ }
+ }
+
+ switch(menu) {
+ case ENCODE_AGIF_RUN:
+ if (params->use_buffer) {
+ ret = image_util_encode_set_output_buffer(handle, &result->buffer);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_output_buffer failed %d\n", ret);
+ break;
+ }
+ } else {
+ ret = image_util_encode_set_output_path(handle, result->path);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_output_path failed %d\n", ret);
+ break;
+ }
+ }
+
+ ret = image_util_encode_run(handle, &size);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_run failed %d\n", ret);
+ break;
+ }
+
+ result->buffer_size = (size_t)size;
+ if (params->use_buffer) {
+ __write_file(result->path, result->buffer, result->buffer_size);
+ SAFE_FREE(result->buffer);
+ }
+ break;
+
+ case ENCODE_AGIF_RUN_ASYNC:
+ if (params->use_buffer) {
+ ret = image_util_encode_set_output_buffer(handle, &result->buffer);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_output_buffer failed %d\n", ret);
+ break;
+ }
+ } else {
+ ret = image_util_encode_set_output_path(handle, result->path);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_set_output_path failed %d\n", ret);
+ break;
+ }
+ }
+
+ ret = image_util_encode_run_async(handle, __encode_completed_cb, &result);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_encode_run_async failed %d\n", ret);
+ break;
+ }
+ __wait();
+
+ if (params->use_buffer) {
+ __write_file(result->path, result->buffer, result->buffer_size);
+ SAFE_FREE(result->buffer);
+ }
+ break;
+ default:
+ g_print("wrong encode agif menu %u", menu);
+ break;
+ }
+
+ERROR:
+ image_util_encode_destroy(handle);
+
+ for (i = 0; i < input->image_cnt; i++)
+ SAFE_FREE(buffer[i]);
+
+ SAFE_FREE(buffer);
+
+ return ret;
+}
+
+/* encode animated GIF frame by frame
+ * input : use image_cnt & images
+ * output : use path or buffer(buffer_size)
+ */
+static int __run_encode_agif(test_encode_menu_e menu, test_complex_data_s *input,
+ test_encode_agif_params_s *params, test_complex_data_s *result)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ image_util_agif_encode_h handle = NULL;
+ unsigned int i = 0;
+
+ if (!input || !params || !result) {
+ g_print("invalid parameter!!! input: %p, params: %p, result: %p\n", input, params, result);
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = image_util_agif_encode_create(&handle);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_agif_encode_create failed %d\n", ret);
+ return ret;
+ }
+
+ for (i = 0; i < input->image_cnt; i++) {
+ ret = image_util_agif_encode_add_frame(handle, input->images[i], params->delay);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_agif_encode_add_frame failed %d\n", ret);
+ goto ERROR;
+ }
+ }
+
+ switch(menu) {
+ case ENCODE_AGIF_SAVE_TO_FILE:
+ ret = image_util_agif_encode_save_to_file(handle, result->path);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_agif_encode_save_to_file failed %d\n", ret);
+ break;
+ }
+ break;
+
+ case ENCODE_AGIF_SAVE_TO_BUFFER:
+ ret = image_util_agif_encode_save_to_buffer(handle, &result->buffer, &result->buffer_size);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_agif_encode_save_to_buffer failed %d\n", ret);
+ break;
+ }
+ __write_file(result->path, result->buffer, result->buffer_size);
+ SAFE_FREE(result->buffer);
+ break;
+ default:
+ g_print("wrong encode agif menu %u", menu);
+ break;
+ }
+
+ERROR:
+ image_util_agif_encode_destroy(handle);
+
+ return ret;
+}
+
+/* run transform with parameters
+ * input/output : use only image_h
+ */
+static int __run_transform(test_transform_menu_e menu, test_complex_data_s *input,
+ test_transform_params_s *params, test_complex_data_s *result)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ transformation_h handle = NULL;
+ media_packet_h mpacket = NULL;
+ media_packet_h res_mpacket = NULL;
+
+ if (!input || !params || !result) {
+ g_print("invalid parameter!!! input: %p, params: %p, result: %p\n", input, params, result);
+ return IMAGE_UTIL_ERROR_INVALID_PARAMETER;
+ }
+
+ ret = __get_raw_data(input);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("__get_raw_data failed %d\n", ret);
+ return ret;
+ }
+
+ if (result->image) {
+ image_util_destroy_image(result->image);
+ result->image = NULL;
+ }
+
+ ret = image_util_transform_create(&handle);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_transform_create failed %d\n", ret);
+ return ret;
+ }
+
+ if (params->has_convert_color) {
+ ret = image_util_transform_set_colorspace(handle, params->convert_color);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_transform_set_colorspace failed %d\n", ret);
+ goto ERROR;
+ }
+ }
+
+ if (params->has_crop) {
+ ret = image_util_transform_set_crop_area(handle, params->crop_area.x, params->crop_area.y, params->crop_area.w, params->crop_area.h);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_transform_set_crop_area failed %d\n", ret);
+ goto ERROR;
+ }
+ }
+
+ if (params->has_resize) {
+ ret = image_util_transform_set_resolution(handle, params->resize.w, params->resize.h);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_transform_set_resolution failed %d\n", ret);
+ goto ERROR;
+ }
+ }
+
+ if (params->has_rotation) {
+ ret = image_util_transform_set_rotation(handle, params->rotation);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_transform_set_rotation failed %d\n", ret);
+ goto ERROR;
+ }
+ }
+
+ switch(menu) {
+ case TRANSFORM_RUN:
+ ret = __convert_image_to_packet(input->image, &mpacket);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("__convert_image_to_packet failed %d\n", ret);
+ break;
+ }
+
+ ret = image_util_transform_run(handle, mpacket, __transform_completed_cb, &res_mpacket);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_transform_run failed %d\n", ret);
+ break;
+ }
+ __wait();
+
+ ret = __convert_packet_to_image(res_mpacket, &result->image);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("__convert_packet_to_image failed %d\n", ret);
+ break;
+ }
+ break;
+ case TRANSFORM_RUN2:
+ ret = image_util_transform_run2(handle, input->image, &result->image);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_transform_run2 failed %d\n", ret);
+ break;
+ }
+ break;
+ case TRANSFORM_RUN2_ASYNC:
+ ret = image_util_transform_run2_async(handle, input->image, __transform_completed2_cb, result);
+ if (ret != IMAGE_UTIL_ERROR_NONE) {
+ g_print("image_util_transform_run2_async failed %d\n", ret);
+ break;
+ }
+ __wait();
+ break;
+ default:
+ g_print("wrong transform menu %u\n", menu);
+ break;
+ }
+
+ERROR:
+ image_util_transform_destroy(handle);
+
+ return ret;
+}
+
+static int __run_auto(void)
+{
+ int ret = IMAGE_UTIL_ERROR_NONE;
+ image_util_type_e image_type = IMAGE_UTIL_JPEG;
+ static test_complex_data_s encode_temp_result;
+
+ g_num_of_file = 0;
+
+ g_decode_params.color = IMAGE_UTIL_COLORSPACE_RGBA8888;
+ g_decode_params.downscale = IMAGE_UTIL_DOWNSCALE_1_1;
+
+ ret = __run_decode(DECODE_RUN2, &g_input_data, &g_decode_params, &g_decode_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE)
+ g_print("Success DECODE_RUN2!!!\n");
+ else
+ g_print("Fail DECODE_RUN2!!!\n");
+
+ g_encode_params.type = IMAGE_UTIL_JPEG;
+ g_encode_params.quality = 100;
+ __set_auto_file(g_encode_params.type, &g_encode_result.path);
+
+ g_transform_params.crop_area.x = 0;
+ g_transform_params.crop_area.y = 0;
+ g_transform_params.crop_area.w = 640;
+ g_transform_params.crop_area.h = 480;
+
+ g_transform_params.resize.w = 320;
+ g_transform_params.resize.h = 240;
+
+ g_transform_params.rotation = IMAGE_UTIL_ROTATION_90;
+
+ ret = __run_encode(ENCODE_RUN_TO_FILE, &g_decode_result, &g_encode_params, &g_encode_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE)
+ g_print("Success ENCODE_RUN_TO_FILE!!!\n");
+ else
+ g_print("Fail ENCODE_RUN_TO_FILE!!!\n");
+
+ for (image_type = IMAGE_UTIL_JPEG; image_type <= IMAGE_UTIL_BMP; image_type++) {
+ g_print("[[[ IMAGE_TYPE %d ]]]\n", image_type);
+
+ ret = __run_decode(DECODE_RUN2, &g_encode_result, &g_decode_params, &g_decode_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE)
+ g_print("Success DECODE_RUN2!!!\n");
+ else
+ g_print("Fail DECODE_RUN2!!!\n");
+
+ g_transform_params.has_crop = TRUE;
+ __run_transform(TRANSFORM_RUN2, &g_decode_result, &g_transform_params, &g_transform_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE)
+ g_print("Success TRANSFORM_RUN2(crop)!!!\n");
+ else
+ g_print("Fail TRANSFORM_RUN2(crop)!!!\n");
+
+ g_transform_params.has_crop = FALSE;
+
+ __set_auto_file(image_type, &encode_temp_result.path);
+ ret = __run_encode(ENCODE_RUN_TO_FILE, &g_decode_result, &g_encode_params, &encode_temp_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE)
+ g_print("Success ENCODE_RUN_TO_FILE!!!\n");
+ else
+ g_print("Fail ENCODE_RUN_TO_FILE!!!\n");
+
+ __run_decode(DECODE_RUN_ASYNC2, &g_encode_result, &g_decode_params, &g_decode_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE)
+ g_print("Success DECODE_RUN_ASYNC2!!!\n");
+ else
+ g_print("Fail DECODE_RUN_ASYNC2!!!\n");
+
+ g_transform_params.has_resize = TRUE;
+ __run_transform(TRANSFORM_RUN2, &g_decode_result, &g_transform_params, &g_transform_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE)
+ g_print("Success TRANSFORM_RUN2(resize)!!!\n");
+ else
+ g_print("Fail TRANSFORM_RUN2(resize)!!!\n");
+
+ g_transform_params.has_resize = FALSE;
+
+ __set_auto_file(image_type, &encode_temp_result.path);
+ ret = __run_encode(ENCODE_RUN_TO_BUFFER, &g_transform_result, &g_encode_params, &encode_temp_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE)
+ g_print("Success ENCODE_RUN_TO_BUFFER!!!\n");
+ else
+ g_print("Fail ENCODE_RUN_TO_BUFFER!!!\n");
+
+ __run_decode(DECODE_RUN_ASYNC2, &g_encode_result, &g_decode_params, &g_decode_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE)
+ g_print("Success DECODE_RUN_ASYNC2!!!\n");
+ else
+ g_print("Fail DECODE_RUN_ASYNC2!!!\n");
+
+ g_transform_params.has_rotation = TRUE;
+ __run_transform(TRANSFORM_RUN2, &g_decode_result, &g_transform_params, &g_transform_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE)
+ g_print("Success TRANSFORM_RUN2(rotate)!!!\n");
+ else
+ g_print("Fail TRANSFORM_RUN2(rotate)!!!\n");
+
+ g_transform_params.has_rotation = FALSE;
+
+ /* change next image_type */
+ g_encode_params.type = ((image_type + 1 > IMAGE_UTIL_BMP) ? IMAGE_UTIL_BMP : (image_type + 1));
+ __set_auto_file(g_encode_params.type, &g_encode_result.path);
+
+ ret = __run_encode(ENCODE_RUN_ASYNC_TO_BUFFER, &g_transform_result, &g_encode_params, &g_encode_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE)
+ g_print("Success ENCODE_RUN_ASYNC_TO_BUFFER!!!\n");
+ else
+ g_print("Fail ENCODE_RUN_ASYNC_TO_BUFFER!!!\n");
+ }
+
+ return ret;
+}
+/* test functions for testsuite */
+
+
+/* interprete menu */
+
+/* push result data-set of test to stack */
+static void __data_push(test_complex_data_s *comp_data)
+{
+ if (!comp_data)
+ return;
+
+ if (!g_queue_data) {
+ g_queue_data = g_queue_new();
+ if (!g_queue_data) {
+ g_print("g_queue_new failed\n");
+ return;
+ }
+ }
+
+#if DEBUG_QUEUE
+ g_print("[push data] %u\n", comp_data->type);
+#endif
+
+ g_queue_push_tail(g_queue_data, comp_data);
+}
+
+static void __data_push_if_empty(test_complex_data_s *comp_data)
+{
+ if (g_queue_data) {
+ if (!g_queue_is_empty(g_queue_data)) {
+ g_print("data queue is not empty\n");
+ return ;
+ }
+ }
+
+ __data_push(comp_data);
+}
+
+/* pop input data-set of test from stack */
+static gboolean __data_pop(test_complex_data_s **comp_data)
+{
+ test_complex_data_s *get = NULL;
+
+ if (g_queue_is_empty(g_queue_data)) {
+ return FALSE;
+ }
+
+ get = g_queue_pop_tail(g_queue_data);
+ if (!get) {
+ g_print("wrong data!\n\n");
+ return FALSE;
+ }
+
+#if DEBUG_QUEUE
+ g_print("[pop data] %u\n", get->type);
+#endif
+
+ *comp_data = get;
+
+ return TRUE;
+}
+
+static void __menu_move(test_menu_state_e new_menu)
+{
+ test_queue_menu_s *data = NULL;
+
+ if (!g_queue_menu) {
+ g_queue_menu = g_queue_new();
+ if (!g_queue_menu) {
+ g_print("g_queue_new failed\n");
+ return;
+ }
+ }
+
+ data = calloc(1, sizeof(test_queue_menu_s));
+ if (!data) {
+ g_print("Memory allocation failed\n");
+ return;
+ }
+
+#if DEBUG_QUEUE
+ g_print("[menu move] %u -> %u\n", g_current_menu, new_menu);
+#endif
+
+ data->menu_state = g_current_menu;
+ g_queue_push_tail(g_queue_menu, data);
+
+ g_previous_menu = g_current_menu;
+
+ g_current_menu = new_menu;
+}
+
+static void __menu_back(void)
+{
+ test_queue_menu_s *data = NULL;
+
+ if (g_queue_is_empty(g_queue_menu)) {
+ return;
+ }
+
+ data = g_queue_pop_tail(g_queue_menu);
+ if (!data) {
+ g_print("wrong menu data!\n\n");
+ return;
+ }
+
+#if DEBUG_QUEUE
+ g_print("[menu back] %u -> %u\n", g_current_menu, data->menu_state);
+#endif
+
+ g_previous_menu = g_current_menu;
+
+ g_current_menu = data->menu_state;
+
+ SAFE_FREE(data);
+}
+
+static void __quit(void)
+{
+ if (g_mainloop)
+ g_main_loop_quit(g_mainloop);
+}
+
+static void __interpret_decode(const char *cmd, unsigned int index)
+{
+ int ret = 0;
+ test_complex_data_s *input_data = NULL;
+
+ switch(index) {
+ case DECODE_SET_BUFFER:
+ __menu_move(SET_BUFFER_MENU);
+ break;
+ case DECODE_SET_COLOR:
+ __menu_move(SET_COLOR_MENU);
+ break;
+ case DECODE_SET_DOWNSCALE:
+ __menu_move(SET_DOWNSCALE_MENU);
+ break;
+ case DECODE_RUN:
+ case DECODE_RUN_ASYNC:
+ case DECODE_RUN2:
+ case DECODE_RUN_ASYNC2:
+ if (!__data_pop(&input_data)) {
+ g_print("There is no test data for decode.\n");
+ break;
+ }
+ ret = __run_decode(index, input_data, &g_decode_params, &g_decode_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE) {
+ g_print("Success to decode image!!!\n");
+#if DUMP_RAW_IMAGE
+ __write_jpeg("decode", g_decode_result.image);
+#endif
+ __data_push(&g_decode_result);
+ } else {
+ g_print("Fail to decode image!!!\n");
+ __data_push(input_data);
+ }
+ break;
+ default:
+ g_print("wrong command! %s\n\n", cmd);
+ break;
+ }
+}
+
+static void __interpret_encode(const char *cmd, unsigned int index)
+{
+ int ret = 0;
+ test_complex_data_s *input_data = NULL;
+
+ switch(index) {
+ case ENCODE_SET_TYPE:
+ __menu_move(SET_TYPE_MENU);
+ break;
+ case ENCODE_SET_QUALITY:
+ __menu_move(SET_QUALITY_MENU);
+ break;
+ case ENCODE_SET_COMPRESIION:
+ __menu_move(SET_COMPRESSION_MENU);
+ break;
+ case ENCODE_SET_TO_BUFFER:
+ __menu_move(SET_TO_BUFFER_MENU);
+ break;
+ case ENCODE_RUN:
+ case ENCODE_RUN_ASYNC:
+ case ENCODE_RUN_TO_FILE:
+ case ENCODE_RUN_TO_BUFFER:
+ case ENCODE_RUN_ASYNC_TO_FILE:
+ case ENCODE_RUN_ASYNC_TO_BUFFER:
+ if (!__data_pop(&input_data)) {
+ g_print("There is no test data for encode.\n");
+ break;
+ }
+ __set_encode_file(g_encode_params.type, FILE_FOR_ENCODE, &g_encode_result.path);
+ ret = __run_encode(index, input_data, &g_encode_params, &g_encode_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE) {
+ g_print("Success to encode image!!!\n");
+ __data_push(&g_encode_result);
+ } else {
+ g_print("Fail to encode image!!!\n");
+ __data_push(input_data);
+ }
+ break;
+ default:
+ g_print("wrong command! %s\n\n", cmd);
+ break;
+ }
+}
+
+static void __interpret_encode_agif(const char *cmd, unsigned int index)
+{
+ int ret = 0;
+ test_complex_data_s *input_data = NULL;
+
+ switch(index) {
+ case ENCODE_AGIF_SET_DIR:
+ __menu_move(SET_DIR_MENU);
+ break;
+ case ENCODE_AGIF_SET_DELAY:
+ __menu_move(SET_DELAY_MENU);
+ break;
+ case ENCODE_AGIF_SET_TO_BUFFER:
+ __menu_move(SET_TO_BUFFER_MENU);
+ break;
+ case ENCODE_AGIF_RUN:
+ case ENCODE_AGIF_RUN_ASYNC:
+ if (!__data_pop(&input_data)) {
+ g_print("There is no test data for decode.\n");
+ break;
+ }
+ __set_encode_file(IMAGE_UTIL_GIF, FILE_FOR_ENCODE_AGIF, &g_encode_agif_result.path);
+ ret = __run_encode_agif_deprecated(index, input_data, &g_encode_agif_params, &g_encode_agif_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE) {
+ g_print("Success to encode image!!!\n");
+ __data_push(&g_encode_agif_result);
+ } else {
+ g_print("Fail to encode image!!!\n");
+ __data_push(input_data);
+ }
+ break;
+ case ENCODE_AGIF_SAVE_TO_FILE:
+ case ENCODE_AGIF_SAVE_TO_BUFFER:
+ if (!__data_pop(&input_data)) {
+ g_print("There is no test data for decode.\n");
+ break;
+ }
+ __set_encode_file(IMAGE_UTIL_GIF, FILE_FOR_ENCODE_AGIF, &g_encode_agif_result.path);
+ ret = __run_encode_agif(index, input_data, &g_encode_agif_params, &g_encode_agif_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE) {
+ g_print("Success to encode image!!!\n");
+ __data_push(&g_encode_agif_result);
+ } else {
+ g_print("Fail to encode image!!!\n");
+ __data_push(input_data);
+ }
+ break;
+ default:
+ g_print("wrong command! %s\n\n", cmd);
+ break;
+ }
+}
+
+static void __interpret_transform(const char *cmd, unsigned int index)
+{
+ int ret = 0;
+ test_complex_data_s *input_data = NULL;
+
+ switch(index) {
+ case TRANSFORM_SET_CONVERT:
+ __menu_move(SET_CONVERT_MENU);
+ break;
+ case TRANSFORM_SET_CROP:
+ __menu_move(SET_CROP_MENU);
+ break;
+ case TRANSFORM_SET_RESIZE:
+ __menu_move(SET_RESIZE_MENU);
+ break;
+ case TRANSFORM_SET_ROTATE:
+ __menu_move(SET_ROTATE_MENU);
+ break;
+ case TRANSFORM_RUN:
+ case TRANSFORM_RUN2:
+ case TRANSFORM_RUN2_ASYNC:
+ if (!__data_pop(&input_data)) {
+ g_print("There is no test data for decode.\n");
+ break;
+ }
+ ret = __run_transform(index, input_data, &g_transform_params, &g_transform_result);
+ if (ret == IMAGE_UTIL_ERROR_NONE) {
+ g_print("Success to transform image!!!\n");
+#if DUMP_RAW_IMAGE
+ __write_jpeg("transform", g_transform_result.image);
+#endif
+ __data_push(&g_transform_result);
+ } else {
+ g_print("Fail to transform image!!!\n");
+ __data_push(input_data);
+ }
+ break;
+ default:
+ g_print("wrong command! %s\n\n", cmd);
+ break;
+ }
+}
+
+static gboolean __interpret_set_menu(test_menu_state_e menu_state, const char *cmd, unsigned int index)
+{
+ switch(menu_state) {
+ case SET_BUFFER_MENU:
+ if (g_ascii_strcasecmp(cmd, "y") == 0) {
+ SAFE_FREE(g_input_data.buffer);
+ if (__read_file(g_input_data.path, (void **)&g_input_data.buffer, &g_input_data.buffer_size))
+ g_input_data.has_buffer = TRUE;
+ }
+ break;
+ case SET_TO_BUFFER_MENU:
+ if (g_ascii_strcasecmp(cmd, "y") == 0) {
+ if (g_previous_menu == ENCODE_MENU) {
+ g_encode_params.use_buffer = TRUE;
+ g_print("Data will be encoded to buffer\n");
+ } else if (g_previous_menu == ENCODE_AGIF_MENU) {
+ g_encode_agif_params.use_buffer = TRUE;
+ g_print("Data will be encoded to buffer\n");
+ }
+ } else {
+ g_encode_params.use_buffer = FALSE;
+ g_encode_agif_params.use_buffer = FALSE;
+ }
+ break;
+ case SET_RAW_COLOR_MENU:
+ g_input_data.color = index;
+ g_print("Success to set raw path color (%u)\n", g_input_data.color);
+ break;
+ case SET_COLOR_MENU:
+ g_decode_params.color = index;
+ g_print("Success to set color (%u)\n", g_decode_params.color);
+ break;
+ case SET_COMPRESSION_MENU:
+ g_encode_params.compression = index;
+ g_print("Success to set compression (%u)\n", g_encode_params.compression);
+ break;
+ case SET_CONVERT_MENU:
+ g_transform_params.convert_color = index;
+ g_transform_params.has_convert_color = TRUE;
+ g_print("Success to set convert_color (%u)\n", g_transform_params.convert_color);
+ break;
+ case SET_CROP_MENU:
+ if (!__set_input_crop_area(cmd, &g_transform_params.crop_area)) {
+ g_print("wrong size! %s\n\n", cmd);
+ return FALSE;
+ }
+ g_transform_params.has_crop = TRUE;
+ g_print("Success to set crop_area(%ux%u, %ux%u)\n", g_transform_params.crop_area.x,
+ g_transform_params.crop_area.y, g_transform_params.crop_area.w, g_transform_params.crop_area.h);
+ break;
+ case SET_DELAY_MENU:
+ g_encode_agif_params.delay = index;
+ g_print("Success to set agif delay (%u)\n", g_encode_agif_params.delay);
+ break;
+ case SET_DOWNSCALE_MENU:
+ g_decode_params.downscale = index;
+ break;
+ case SET_QUALITY_MENU:
+ g_encode_params.quality = index;
+ g_print("Success to set quality (%u)\n", g_encode_params.quality);
+ break;
+ case SET_RESIZE_MENU:
+ if (!__set_input_size(cmd, &g_transform_params.resize)) {
+ g_print("wrong size! %s\n\n", cmd);
+ return FALSE;
+ }
+ g_transform_params.has_resize = TRUE;
+ g_print("Success to set resize (%ux%u)\n", g_transform_params.resize.w, g_transform_params.resize.h);
+ break;
+ case SET_ROTATE_MENU:
+ g_transform_params.rotation = index;
+ g_transform_params.has_rotation = TRUE;
+ g_print("Success to set rotate (%u)\n", g_transform_params.rotation);
+ break;
+ case SET_SIZE_MENU:
+ if (!__set_input_size(cmd, &g_input_data.size)) {
+ g_print("wrong size! %s\n\n", cmd);
+ return FALSE;
+ }
+ g_print("Success to set size (%ux%u)\n", g_input_data.size.w, g_input_data.size.h);
+ break;
+ case SET_TYPE_MENU:
+ g_encode_params.type = index;
+ __set_encode_file(g_encode_params.type, FILE_FOR_ENCODE, &g_encode_result.path);
+ g_print("Success to set image_type (%u)\n", g_encode_params.type);
+ break;
+ default:
+ g_print("wrong command! %s\n\n", cmd);
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+static void __interpret_main(const char *cmd, unsigned int index)
+{
+ __data_push_if_empty(&g_input_data);
+
+ switch(index) {
+ case SET_PATH:
+ __menu_move(SET_PATH_MENU);
+ break;
+ case TEST_AUTO:
+ __run_auto();
+ break;
+ case TEST_DECODE:
+ __menu_move(DECODE_MENU);
+ break;
+ case TEST_ENCODE:
+ __menu_move(ENCODE_MENU);
+ break;
+ case TEST_ENCODE_AGIF:
+ __menu_move(ENCODE_AGIF_MENU);
+ break;
+ case TEST_TRANSFORM:
+ __menu_move(TRANSFORM_MENU);
+ break;
+ default:
+ g_print("wrong command! %s\n\n", cmd);
+ break;
+ }
+}
+
+static void __interpret_cmd(char *cmd)
+{
+ unsigned int index = 0;
+
+ if (cmd == NULL || strlen(cmd) == 0) {
+ g_print("No input!\n");
+ return;
+ }
+
+ if (strncmp(cmd, "q", strlen(cmd)) == 0) {
+ __quit();
+ return;
+ }
+
+ if (strncmp(cmd, "b", strlen(cmd)) == 0) {
+ __menu_back();
+ __display_menu(g_current_menu);
+ return;
+ }
+
+ __safe_atoui(cmd, &index);
+
+ switch(g_current_menu) {
+ /* Main menu */
+ case MAIN_MENU:
+ __interpret_main(cmd, index);
+ break;
+
+ /* Decode menu */
+ case DECODE_MENU:
+ __interpret_decode(cmd, index);
+ break;
+
+ /* Encode menu */
+ case ENCODE_MENU:
+ __interpret_encode(cmd, index);
+ break;
+
+ /* Encode A-GIF menu */
+ case ENCODE_AGIF_MENU:
+ __interpret_encode_agif(cmd, index);
+ break;
+
+ /* Transform menu */
+ case TRANSFORM_MENU:
+ __interpret_transform(cmd, index);
+ break;
+
+ /* Set path menu */
+ case SET_PATH_MENU:
+ if (!__set_input_path(cmd)) {
+ g_print("[Warn] Fail to set input path! %s\n", cmd);
+ goto ERROR;
+ }
+ __menu_back();
+ if (IS_RAW_FILE(g_input_data.path)) {
+ g_input_data.is_raw = TRUE;
+ __menu_move(SET_PATH_SUB_MENU);
+ }
+ break;
+ case SET_PATH_SUB_MENU:
+ switch(index) {
+ case RAW_IMG_SET_COLOR:
+ __menu_move(SET_RAW_COLOR_MENU);
+ break;
+ case RAW_IMG_SET_SIZE:
+ __menu_move(SET_SIZE_MENU);
+ break;
+ default:
+ g_print("wrong raw path menu! %s\n\n", cmd);
+ break;
+ }
+ break;
+ case SET_DIR_MENU:
+ if (!__set_input_path(cmd)) {
+ g_print("[Warn] Fail to set input path! %s\n", cmd);
+ break;
+ }
+ __menu_back();
+ break;
+
+ /* Set optional parameters menu */
+ case SET_BUFFER_MENU:
+ case SET_TO_BUFFER_MENU:
+ case SET_COLOR_MENU:
+ case SET_RAW_COLOR_MENU:
+ case SET_COMPRESSION_MENU:
+ case SET_CONVERT_MENU:
+ case SET_CROP_MENU:
+ case SET_DELAY_MENU:
+ case SET_DOWNSCALE_MENU:
+ case SET_QUALITY_MENU:
+ case SET_RESIZE_MENU:
+ case SET_ROTATE_MENU:
+ case SET_SIZE_MENU:
+ case SET_TYPE_MENU:
+ if (__interpret_set_menu(g_current_menu, cmd, index))
+ __menu_back();
+ break;
+
+ default:
+ g_print("wrong menu state\n");
+ break;
+ }
+
+ __display_menu(g_current_menu);
+ return;
+
+ERROR:
+ __menu_back();
+ __display_menu(g_current_menu);
+ return;
+}
+/* interprete menu */
+
+
+/* testsuite mainloop */
+/*
+ * This function initializes and sets default values for testsuite
+ */
+static void _init_data(void)
+{
+ memset(&g_input_data, 0, sizeof(test_complex_data_s));
+
+ /* init & set default parameters */
+ memset(&g_decode_params, 0, sizeof(test_decode_params_s));
+ memset(&g_encode_params, 0, sizeof(test_encode_params_s));
+ memset(&g_encode_agif_params, 0, sizeof(test_encode_agif_params_s));
+ memset(&g_transform_params, 0, sizeof(test_transform_params_s));
+
+ /* If you want to change default value, change the value here!!! */
+ /* common */
+
+ /* decode */
+ g_decode_params.color = IMAGE_UTIL_COLORSPACE_RGBA8888;
+ g_decode_params.downscale = IMAGE_UTIL_DOWNSCALE_1_1;
+
+ /* encode */
+ g_encode_params.type = IMAGE_UTIL_JPEG;
+ g_encode_params.quality = 75;
+ g_encode_params.compression = IMAGE_UTIL_PNG_COMPRESSION_6;
+
+ /* encode_agif */
+ g_encode_agif_params.delay = 10;
+
+ /* transform, not used yet */
+ g_transform_params.convert_color = IMAGE_UTIL_COLORSPACE_RGB888;
+ g_transform_params.crop_area.x = g_transform_params.crop_area.y = 100;
+ g_transform_params.crop_area.w = g_transform_params.crop_area.h = 200;
+ g_transform_params.resize.x = g_transform_params.resize.y = 0;
+ g_transform_params.resize.w = g_transform_params.resize.h = 100;
+ g_transform_params.rotation = IMAGE_UTIL_ROTATION_90;
+
+ /* init results */
+ memset(&g_decode_result, 0, sizeof(test_complex_data_s));
+ memset(&g_encode_result, 0, sizeof(test_complex_data_s));
+ memset(&g_transform_result, 0, sizeof(test_complex_data_s));
+}
+
+/*
+ * This function releases allocated memory for testsuite when program finish
+ */
+static void _destroy_data(void)
+{
+ unsigned int i = 0;
+
+ g_queue_free_full(g_queue_menu, __queue_free_func);
+ g_queue_free_full(g_queue_agif_images, __queue_free_func);
+
+ SAFE_G_FREE(g_input_data.path);
+ SAFE_FREE(g_input_data.buffer);
+
+ for (i = 0; i < g_input_data.image_cnt; i++)
+ image_util_destroy_image(g_input_data.images[i]);
+
+ SAFE_FREE(g_decode_result.buffer);
+ SAFE_FREE(g_transform_result.buffer);
+ SAFE_FREE(g_encode_result.buffer);
+
+ image_util_destroy_image(g_decode_result.image);
+ image_util_destroy_image(g_transform_result.image);
+ image_util_destroy_image(g_encode_result.image);
+}
+
+/*
+ * This function gets input
+ */
+static gboolean _input_func(GIOChannel *channel)
+{
+ gchar buf[MAX_STRING_LEN];
+ gsize read = 0;
+ guint condition = 0;
+ GError *error = NULL;
+
+ condition = g_io_channel_read_chars(channel, buf, MAX_STRING_LEN, &read, &error);
+ if (!condition) {
+ g_print("g_io_channel_read_chars failed : %s", error ? error->message : "none");
+ if (error) g_error_free(error);
+ return TRUE;
+ }
+
+ buf[read] = '\0';
+ g_strstrip(buf);
+
+ __interpret_cmd(buf);
+
+ return TRUE;
+}
+
+/*
+ * This function displays help
+ */
+static void _display_help(const char *cmd)
+{
+ g_print("====================================================\n");
+ g_print("[image-util CAPI test: v%2.1f\n", VERSION);
+ g_print("%s {file_path} {test_mode} [for jpg/png/gif/bmp]\n", cmd);
+ g_print("%s {directory} {test_mode} [for a-gif]\n", cmd);
+ g_print("{test_mode} 0:auto, 1:decode, 2:encode, 3:a-gif, 4:transform\n");
+ g_print("\n[Note]\n");
+ g_print(" The {file_path}/{directory} are mandotary. but the {test_mode} is optional.\n");
+ g_print("\n[usage]\n");
+ g_print(" 1. %s test.jpg\n", cmd);
+ g_print(" 2. %s test.jpg %d\n", cmd, TEST_AUTO);
+ g_print(" 3. %s test_dir %d\n", cmd, TEST_ENCODE_AGIF);
+ g_print("====================================================\n");
+}
+
+/*
+ * Main
+ */
+int main(int argc, char **argv)
+{
+ GIOChannel *stdin_channel = NULL;
+ stdin_channel = g_io_channel_unix_new(0);
+ g_io_channel_set_flags(stdin_channel, G_IO_FLAG_NONBLOCK, NULL);
+ g_io_add_watch(stdin_channel, G_IO_IN, (GIOFunc)_input_func, NULL);
+
+ _init_data();
+
+ if (argc > 1 && argv[1]) {
+ if ((strcmp(argv[1], "help") == 0)
+ || (strcmp(argv[1], "-h") == 0)
+ || (strcmp(argv[1], "-help") == 0)
+ || (strcmp(argv[1], "--help") == 0)) {
+ _display_help(argv[0]);
+ return 0;
+ }
+
+ __set_input_path(argv[1]);
+ }
+
+ /*
+ * if there is no argument for path, go to set path menu.
+ * else if there is raw data image, go to set path sub menu.
+ */
+ if (!g_input_data.path) {
+ __menu_move(MAIN_MENU);
+ __menu_move(SET_PATH_MENU);
+ } else if (IS_RAW_FILE(g_input_data.path)) {
+ g_input_data.is_raw = TRUE;
+ __menu_move(MAIN_MENU);
+ __menu_move(SET_PATH_SUB_MENU);
+ }
+
+ if (argc > 2) {
+ __menu_move(MAIN_MENU);
+ __interpret_cmd(argv[2]);
+ } else {
+ __display_menu(g_current_menu);
+ }
+
+ g_mainloop = g_main_loop_new(NULL, FALSE);
+
+ g_main_loop_run(g_mainloop);
+ g_main_loop_unref(g_mainloop);
+
+ _destroy_data();
+
+ g_io_channel_unref(stdin_channel);
+
+ return 0;
+}