{
int ret = 0;
- /* test decoding jpeg */
+ /* test decoding bmp */
if (mode == TEST_DECODE_FILE) {
ret = mm_util_decode_from_bmp_file(&g_decoded_data, g_path);
if (ret != MM_UTIL_ERROR_NONE) {
gboolean _test_encode(const bmp_test_mode_e mode)
{
int ret = 0;
- /* for encoding jpeg to memory */
+ /* for encoding bmp to memory */
void *encoded_data = NULL;
unsigned int encoded_size = 0;
}
g_decoded_data.size = (unsigned int)g_readed_size;
- /* test encoding jpeg */
+ /* test encoding bmp */
if (mode == TEST_ENCODE_FILE) {
ret = mm_util_encode_bmp_to_file(&g_decoded_data, ENCODE_FILE_PATH);
if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[BMP_testsuite] mm_util_jpeg_encode_to_file failed : %d\n", ret);
+ fprintf(stderr, "\t[BMP_testsuite] mm_util_encode_bmp_to_file failed : %d\n", ret);
return FALSE;
}
} else if (mode == TEST_ENCODE_MEMORY) {
ret = mm_util_encode_bmp_to_memory(&g_decoded_data, &encoded_data, &encoded_size);
if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[BMP_testsuite] mm_util_jpeg_encode_to_file failed : %d\n", ret);
+ fprintf(stderr, "\t[BMP_testsuite] mm_util_encode_bmp_to_memory failed : %d\n", ret);
SAFE_FREE(encoded_data);
return FALSE;
}
return FALSE;
}
}
- /* test decoding jpeg */
+ /* test decoding bmp */
if ((test_mode == TEST_DECODE_FILE) || (test_mode == TEST_DECODE_MEMORY)) {
if (FALSE == _test_decode(test_mode)) {
fprintf(stderr, "\t[BMP_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]);
}
}
- /* test encoding jpeg */
+ /* test encoding bmp */
if ((test_mode == TEST_ENCODE_FILE) || (test_mode == TEST_ENCODE_MEMORY)) {
if (FALSE == _test_encode(test_mode)) {
fprintf(stderr, "\t[BMP_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]);
goto out;
}
- /* test full functions automatically */
+ /* test all functions automatically */
if (g_test_mode == TEST_AUTO) {
if (FALSE == _test_auto())
fprintf(stderr, "\t[BMP_testsuite] _test_auto failed\n");
goto out;
}
- /* test decoding jpeg */
+ /* test decoding bmp */
if ((g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_MEMORY)) {
if (FALSE == _test_decode(g_test_mode)) {
fprintf(stderr, "\t[BMP_testsuite] _test_decode(%s) failed\n", MODE_TO_STR[g_test_mode]);
}
}
- /* test encoding jpeg */
+ /* test encoding bmp */
if ((g_test_mode == TEST_ENCODE_FILE) || (g_test_mode == TEST_ENCODE_MEMORY)) {
if (FALSE == _test_encode(g_test_mode)) {
fprintf(stderr, "\t[BMP_testsuite] _test_encode(%s) failed\n", MODE_TO_STR[g_test_mode]);
#include <errno.h>
#include <mm_util_imgp.h>
#include <mm_util_common.h>
+#include <limits.h>
+#include <tzplatform_config.h>
+
+#define TRANSFORM_TEST_PATH tzplatform_mkpath(TZ_USER_CONTENT, "imgp_result")
#define MAX_STRING_LEN 128
#define IMAGE_FORMAT_LABEL_BUFFER_SIZE 4
#define IMGP_FREE(src) { if (src != NULL) {g_free(src); src = NULL; } }
mm_util_imgp_h imgp_handle = NULL;
-bool completed = false;
GCond g_thread_cond;
GMutex 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) {
+ fprintf(stderr, "\t[JPEG_testsuite] invalid data %s %p %p\n", path, data, length);
+ return FALSE;
+ }
+
+ fprintf(stderr, "\t[JPEG_testsuite] %s read\n", path);
+
+ fp = fopen(path, "r");
+ if (fp == NULL) {
+ fprintf(stderr, "\t[JPEG_testsuite] fopen failed (%d) \n", errno);
+ return FALSE;
+ }
+
+ fseek(fp, 0, SEEK_END);
+ len = ftell(fp);
+ if (len < 0) {
+ fprintf(stderr, "\t[JPEG_testsuite] ftell 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 != len) {
+ fprintf(stderr, "\t[JPEG_testsuite] fread failed \n");
+ }
+
+ fclose(fp);
+
+ if (*data == NULL) {
+ *length = 0;
+ return FALSE;
+ }
+
+ *length = (size_t)len;
+
+ fprintf(stderr, "\t[JPEG_testsuite] %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) {
+ fprintf(stderr, "\t[JPEG_testsuite] invalid data %s %p %zu\n", path, data, length);
+ return FALSE;
+ }
+
+ fprintf(stderr, "\t[JPEG_testsuite] %s %p %zu write\n", path, data, length);
+
+ fp = fopen(path, "w");
+ if (fp == NULL) {
+ fprintf(stderr, "\t[JPEG_testsuite] fopen failed (%d) \n", errno);
+ return FALSE;
+ }
+
+ len = fwrite(data, 1, length, fp);
+ if (len != length) {
+ fprintf(stderr, "\t[JPEG_testsuite] fwrite failed \n");
+ }
+
+ fclose(fp);
+ fp = NULL;
+
+ fprintf(stderr, "\t[JPEG_testsuite] %s write DONE\n", path);
+
+ return TRUE;
+}
+
void _wait()
{
g_mutex_lock(&g_thread_mutex);
if (error == MM_UTIL_ERROR_NONE) {
fprintf(stderr, "completed\n");
- FILE *fp = fopen(output_file, "w");
- if (fp) {
- void *dst = NULL;
- err = mm_util_get_color_image(image, NULL, NULL, NULL, &dst, &size);
- if (err != MM_UTIL_ERROR_NONE) {
- IMGP_FREE(dst);
- fclose(fp);
- fprintf(stderr, "Error mm_util_get_color_image (%d)\n", err);
- _signal();
- return FALSE;
- }
- fprintf(stderr, "dst: %p [%zu]\n", dst, size);
- fwrite(dst, 1, size, fp);
- fprintf(stderr, "FREE\n");
- fclose(fp);
+ void *dst = NULL;
+ err = mm_util_get_color_image(image, NULL, NULL, NULL, &dst, &size);
+ if (err != MM_UTIL_ERROR_NONE) {
+ fprintf(stderr, "Error mm_util_get_color_image (%d)\n", err);
+ goto out;
}
- fprintf(stderr, "write result\n");
+ if (FALSE == _write_file(output_file, dst, size)) {
+ fprintf(stderr, "\t[IMGP_testsuite] writing file(%s) error\n", output_file);
+ goto out;
+ }
+ fprintf(stderr, "write success\n");
} else {
fprintf(stderr, "[Error] complete cb (%d)\n", error);
}
- completed = true;
+out:
fprintf(stderr, "Destory - destroy image\n");
+ mm_util_destroy_color_image(image);
_signal();
return TRUE;
}
+gboolean _get_input_data(const char *argv, const long min, const long max, unsigned int *data)
+{
+ if (argv == NULL || strlen(argv) == 0)
+ return FALSE;
+
+ long temp = g_ascii_strtoll(argv, NULL, 10);
+ if (temp < min || temp > max)
+ return FALSE;
+
+ *data = (unsigned int)temp;
+
+ return TRUE;
+}
+
int main(int argc, char *argv[])
{
int ret = 0;
bool sync_mode = (strcmp(argv[1], "sync") == 0) ? TRUE : FALSE;
char *filename = strdup(argv[2]);
char *command = strdup(argv[3]);
- unsigned int src_width = (unsigned int)atoi(argv[4]);
- unsigned int src_height = (unsigned int)atoi(argv[5]);
- mm_util_color_format_e src_format = atoi(argv[6]);
- unsigned int dst_width = (unsigned int)atoi(argv[7]);
- unsigned int dst_height = (unsigned int)atoi(argv[8]);
- mm_util_color_format_e dst_format = atoi(argv[9]);
- mm_util_img_rotate_type rotation = atoi(argv[10]);
- unsigned int start_x = (unsigned int)atoi(argv[11]);
- unsigned int start_y = (unsigned int)atoi(argv[12]);
+ unsigned int src_width = 0;
+ unsigned int src_height = 0;
+ mm_util_color_format_e src_format = 0;
+ unsigned int dst_width = 0;
+ unsigned int dst_height = 0;
+ mm_util_color_format_e dst_format = 0;
+ mm_util_img_rotate_type rotation = 0;
+ unsigned int start_x = 0;
+ unsigned int start_y = 0;
char output_file[40] = {};
unsigned int res_w = 0;
unsigned int res_h = 0;
/* async mode */
mm_util_color_image_h orig_image = NULL;
- fprintf(stderr, "command: %s src_width: %d, src_height: %d, src_format: %d, dst_width: %d, dst_height: %d, dst_format:%d, rotation:%d\n", command, src_width, src_height, src_format, dst_width, dst_height, dst_format, rotation);
-
- { /* read input file */
- FILE *fp = fopen(filename, "r");
- if (fp == NULL) {
- fprintf(stderr, "\tfile open failed %d\n", errno);
- goto TEST_FAIL;
- }
-
- fseek(fp, 0, SEEK_END);
- src_size = ftell(fp);
- fseek(fp, 0, SEEK_SET);
-
- src = calloc(1, src_size);
- if (src == NULL) {
- fprintf(stderr, "\tmemory allocation failed\n");
- goto TEST_FAIL;
- }
-
- if (fread(src, 1, src_size, fp) == src_size)
- fprintf(stderr, "#Success# fread\n");
- else
- fprintf(stderr, "#Error# fread\n");
-
- if (src == NULL || src_size <= 0) {
- fprintf(stderr, "#Error# fread\n");
- goto TEST_FAIL;
- }
-
+ /* get arguments */
+ if (FALSE == _get_input_data(argv[4], 0, (long)UINT_MAX, &src_width)) {
+ fprintf(stderr, "\t[IMGP_testsuite] wrong src_width %s\n", argv[4]);
+ goto TEST_FAIL;
+ }
+ if (FALSE == _get_input_data(argv[5], 0, (long)UINT_MAX, &src_height)) {
+ fprintf(stderr, "\t[IMGP_testsuite] wrong src_height %s\n", argv[5]);
+ goto TEST_FAIL;
+ }
+ if (FALSE == _get_input_data(argv[6], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &src_format)) {
+ fprintf(stderr, "\t[IMGP_testsuite] wrong src_format %s\n", argv[6]);
+ goto TEST_FAIL;
+ }
+ if (FALSE == _get_input_data(argv[7], 0, (long)UINT_MAX, &dst_width)) {
+ fprintf(stderr, "\t[IMGP_testsuite] wrong dst_width %s\n", argv[7]);
+ goto TEST_FAIL;
+ }
+ if (FALSE == _get_input_data(argv[8], 0, (long)UINT_MAX, &dst_height)) {
+ fprintf(stderr, "\t[IMGP_testsuite] wrong dst_height %s\n", argv[8]);
+ goto TEST_FAIL;
+ }
+ if (FALSE == _get_input_data(argv[9], MM_UTIL_COLOR_YUV420, MM_UTIL_COLOR_NUM - 1, &dst_format)) {
+ fprintf(stderr, "\t[IMGP_testsuite] wrong dst_format %s\n", argv[9]);
+ goto TEST_FAIL;
+ }
+ if (FALSE == _get_input_data(argv[10], MM_UTIL_ROTATE_0, MM_UTIL_ROTATE_NUM - 1, &rotation)) {
+ fprintf(stderr, "\t[IMGP_testsuite] wrong rotation %s\n", argv[10]);
+ goto TEST_FAIL;
+ }
+ if (FALSE == _get_input_data(argv[11], 0, (long)UINT_MAX, &start_x)) {
+ fprintf(stderr, "\t[IMGP_testsuite] wrong start_x %s\n", argv[11]);
+ goto TEST_FAIL;
+ }
+ if (FALSE == _get_input_data(argv[12], 0, (long)UINT_MAX, &start_y)) {
+ fprintf(stderr, "\t[IMGP_testsuite] wrong start_y %s\n", argv[12]);
+ goto TEST_FAIL;
}
- { /* ready output file */
- char *output_fmt = (char *) calloc(1, sizeof(char) * IMAGE_FORMAT_LABEL_BUFFER_SIZE);
- memset(output_fmt, 0, IMAGE_FORMAT_LABEL_BUFFER_SIZE);
- if (dst_format == MM_UTIL_COLOR_YUV420 ||
- dst_format == MM_UTIL_COLOR_YUV422 ||
- dst_format == MM_UTIL_COLOR_I420) {
- strncpy(output_fmt, "yuv", strlen("yuv"));
- } else {
- //strncpy(output_fmt, "rgb", strlen("rgb"));
- strncpy(output_fmt, "rgb", strlen("raw"));
- }
- snprintf(output_file, 40, "result_%s_%dx%d.%s", command, dst_width, dst_height, output_fmt);
+ /* read input file */
+ if (FALSE == _read_file(filename, &src, &src_size)) {
+ fprintf(stderr, "\t[IMGP_testsuite] reading file(%s) error\n", filename);
+ goto TEST_FAIL;
}
+ fprintf(stderr, "command: %s src_width: %d, src_height: %d, src_format: %d, dst_width: %d, dst_height: %d, dst_format:%d, rotation:%d\n", command, src_width, src_height, src_format, dst_width, dst_height, dst_format, rotation);
+
+ /* ready output file */
+ snprintf(output_file, 40, "%s_%s_%dx%d.raw", TRANSFORM_TEST_PATH, command, dst_width, dst_height);
+
if (sync_mode) {
fprintf(stderr, "SYNC\n");
if (strcmp(command, "convert") == 0)
goto TEST_FAIL;
}
- { /* write output file */
- FILE *fpout = fopen(output_file, "w");
- if (fpout) {
- fprintf(stderr, "dst: %p [%zu]\n", dst, res_buffer_size);
- fwrite(dst, 1, res_buffer_size, fpout);
- fprintf(stderr, "FREE\n");
- fclose(fpout);
- }
+ /* write output file */
+ if (FALSE == _write_file(output_file, dst, res_buffer_size)) {
+ fprintf(stderr, "\t[IMGP_testsuite] writing file(%s) error\n", output_file);
+ goto TEST_FAIL;
}
} else { /* Async mode */
fprintf(stderr, "ASYNC\n");
{
int ret = 0;
- /* test decoding jpeg */
+ /* test decoding png */
if (mode == TEST_DECODE_FILE) {
ret = mm_util_decode_from_png_file(&g_decoded_data, g_path);
if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[PNG_testsuite] mm_util_decode_from_jpeg_file_with_downscale failed %d\n", ret);
+ fprintf(stderr, "\t[PNG_testsuite] mm_util_decode_from_png_file failed %d\n", ret);
return FALSE;
}
if (FALSE == _write_file(DECODE_FILE_PATH, g_decoded_data.data, (size_t)g_decoded_data.size)) {
ret = mm_util_decode_from_png_memory(&g_decoded_data, g_readed_data, (unsigned long long)g_readed_size);
if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[PNG_testsuite] mm_util_decode_from_jpeg_memory_with_downscale failed %d\n", ret);
+ fprintf(stderr, "\t[PNG_testsuite] mm_util_decode_from_png_memory failed %d\n", ret);
return FALSE;
}
if (FALSE == _write_file(DECODE_MEM_PATH, g_decoded_data.data, (size_t)g_decoded_data.size)) {
gboolean _test_encode(const png_test_mode_e mode)
{
int ret = 0;
- /* for encoding jpeg to memory */
+ /* for encoding png to memory */
void *encoded_data = NULL;
size_t encoded_size = 0;
return FALSE;
}
- /* test encoding jpeg */
+ /* test encoding png */
if (mode == TEST_ENCODE_FILE) {
ret = mm_util_encode_to_png_file(&g_decoded_data, g_compression, ENCODE_FILE_PATH);
if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[PNG_testsuite] mm_util_jpeg_encode_to_file failed : %d\n", ret);
+ fprintf(stderr, "\t[PNG_testsuite] mm_util_encode_to_png_file failed : %d\n", ret);
return FALSE;
}
} else if (mode == TEST_ENCODE_MEMORY) {
ret = mm_util_encode_to_png_memory(&g_decoded_data, g_compression, &encoded_data, &encoded_size);
if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[PNG_testsuite] mm_util_jpeg_encode_to_file failed : %d\n", ret);
+ fprintf(stderr, "\t[PNG_testsuite] mm_util_encode_to_png_memory failed : %d\n", ret);
SAFE_FREE(encoded_data);
return FALSE;
}
return FALSE;
}
}
- /* test decoding jpeg */
+ /* test decoding png */
if ((test_mode == TEST_DECODE_FILE) || (test_mode == TEST_DECODE_MEMORY)) {
if (FALSE == _test_decode(test_mode)) {
fprintf(stderr, "\t[PNG_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]);
}
}
- /* test encoding jpeg */
+ /* test encoding png */
if ((test_mode == TEST_ENCODE_FILE) || (test_mode == TEST_ENCODE_MEMORY)) {
if (FALSE == _test_encode(test_mode)) {
fprintf(stderr, "\t[PNG_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST FAIL\n", MODE_TO_STR[test_mode]);
goto out;
}
- /* test full functions automatically */
+ /* test all functions automatically */
if (g_test_mode == TEST_AUTO) {
if (FALSE == _test_auto())
fprintf(stderr, "\t[PNG_testsuite] _test_auto failed\n");
goto out;
}
- /* test decoding jpeg */
+ /* test decoding png */
if ((g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_MEMORY)) {
if (FALSE == _test_decode(g_test_mode)) {
fprintf(stderr, "\t[PNG_testsuite] _test_decode(%s) failed\n", MODE_TO_STR[g_test_mode]);
}
}
- /* test encoding jpeg */
+ /* test encoding png */
if ((g_test_mode == TEST_ENCODE_FILE) || (g_test_mode == TEST_ENCODE_MEMORY)) {
if (FALSE == _test_encode(g_test_mode)) {
fprintf(stderr, "\t[PNG_testsuite] _test_encode(%s) failed\n", MODE_TO_STR[g_test_mode]);