ADD_SUBDIRECTORY(imgcv)
ADD_SUBDIRECTORY(imgp)
ADD_SUBDIRECTORY(jpeg)
-ADD_SUBDIRECTORY(png)
ADD_SUBDIRECTORY(magick)
IF(UNIX)
Name: libmm-utility
Summary: Multimedia Framework Utility Library
-Version: 0.1.48
+Version: 0.2.0
Release: 0
Group: System/Libraries
License: Apache-2.0
BuildRequires: libjpeg-turbo-devel
BuildRequires: pkgconfig(libtzplatform-config)
BuildRequires: pkgconfig(opencv) >= 3.4.1
-BuildRequires: pkgconfig(libpng)
BuildRequires: giflib-devel
BuildRequires: pkgconfig(GraphicsMagick)
%if 0%{?gtests:1}
+++ /dev/null
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-SET(fw_name "mmutil_png")
-
-PROJECT(${fw_name})
-
-SET(VERSION_MAJOR 0)
-SET(VERSION "${VERSION_MAJOR}.0.0")
-SET(CMAKE_INSTALL_PREFIX /usr)
-SET(PREFIX ${CMAKE_INSTALL_PREFIX})
-
-SET(INC_DIR
- include
- )
-INCLUDE_DIRECTORIES(${INC_DIR}
- ../common/include
- ../imgp/include
- )
-
-SET(dependents "dlog glib-2.0 libpng")
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(${fw_name} REQUIRED ${dependents})
-FOREACH(flag ${${fw_name}_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -fPIC -Wall -Werror")
-SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
-
-IF("${ARCH}" STREQUAL "arm")
- ADD_DEFINITIONS("-DTARGET")
-ENDIF("${ARCH}" STREQUAL "arm")
-
-ADD_DEFINITIONS("-DPREFIX=\"${CMAKE_INSTALL_PREFIX}\"")
-ADD_DEFINITIONS("-DLIBPREFIX=\"${LIB_INSTALL_DIR}\"")
-ADD_DEFINITIONS("-DTIZEN_DEBUG")
-
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -Wl,--rpath=${LIB_INSTALL_DIR}")
-
-aux_source_directory(. SOURCES)
-ADD_LIBRARY(${fw_name} SHARED ${SOURCES})
-TARGET_LINK_LIBRARIES(${fw_name} ${${fw_name}_LDFLAGS} mmutil_common mmutil_imgp)
-SET_TARGET_PROPERTIES(${fw_name}
- PROPERTIES
- VERSION ${VERSION}
- SOVERSION ${VERSION_MAJOR}
- CLEAN_DIRECT_OUTPUT 1
-)
-
-INSTALL(TARGETS ${fw_name} DESTINATION ${LIB_INSTALL_DIR})
-INSTALL(
- DIRECTORY ${INC_DIR}/ DESTINATION include/mmf
- FILES_MATCHING
- PATTERN "*_internal.h" EXCLUDE
- PATTERN "*_private.h" EXCLUDE
- PATTERN "${INC_DIR}/*.h"
- )
-
-SET(PC_NAME mmutil-png)
-SET(PC_LDFLAGS -l${fw_name})
-SET(PC_FILE_NAME ${PC_NAME}.pc.in)
-
-CONFIGURE_FILE(
- ${PC_FILE_NAME}
- ${CMAKE_CURRENT_SOURCE_DIR}/${PC_NAME}.pc
- @ONLY
-)
-INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${PC_NAME}.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
-
-ADD_SUBDIRECTORY(test)
-IF(BUILD_GTESTS)
- ADD_SUBDIRECTORY(unittest)
-ENDIF(BUILD_GTESTS)
+++ /dev/null
-/*
- * libmm-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.
- *
- */
-
-#ifndef __MM_UTIL_PNG_H__
-#define __MM_UTIL_PNG_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stdint.h>
-#include "mm_util_type.h"
-
-/**
- @addtogroup UTILITY
- @{
-
- @par
- This part describes the APIs with repect to multimedia image library.
-*/
-
-typedef enum {
- MM_UTIL_COMPRESSION_0 = 0, /* No compression */
- MM_UTIL_COMPRESSION_1 = 1, /* Best speed */
- MM_UTIL_COMPRESSION_2 = 2,
- MM_UTIL_COMPRESSION_3 = 3,
- MM_UTIL_COMPRESSION_4 = 4,
- MM_UTIL_COMPRESSION_5 = 5,
- MM_UTIL_COMPRESSION_6 = 6, /* Default compression */
- MM_UTIL_COMPRESSION_7 = 7,
- MM_UTIL_COMPRESSION_8 = 8,
- MM_UTIL_COMPRESSION_9 = 9 /* Best compression */
-} mm_util_png_compression;
-
-int mm_util_decode_from_png_file(const char *file_path, mm_util_image_h *decoded);
-int mm_util_decode_from_png_memory(void *memory, const size_t src_size, mm_util_image_h *decoded);
-int mm_util_encode_to_png_file(mm_util_image_h decoded, mm_util_png_compression compression_level, const char *file_path);
-int mm_util_encode_to_png_memory(mm_util_image_h decoded, mm_util_png_compression compression_level, void **buffer, size_t *size);
-
-#ifdef __cplusplus
-}
-#endif
-#endif /*__MM_UTIL_PNG_H__*/
+++ /dev/null
-/*
- * libmm-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> /* fopen() */
-
-#include <glib.h>
-#include <png.h>
-
-#include "mm_util_png.h"
-#include "mm_util_imgp.h"
-#include "mm_util_private.h"
-
-#define MM_UTIL_PNG_BYTES_TO_CHECK 4
-#define MM_UTIL_BIT_DEPTH_8 8
-
-#define png_infopp_NULL (png_infopp)NULL
-
-typedef struct {
- uint32_t width;
- uint32_t height;
- int bit_depth; /**< Bit depth*/
- int color_type; /**< Color type*/
- int interlace_type; /**< Interlace type */
- int compression_type; /**< compression type */
- int filter_type; /**< Filter type*/
- int filter; /**< Filter */
-} png_property_s;
-
-
-typedef struct {
- void *buf;
- png_size_t buf_size;
- png_size_t pos;
-} png_io_buf_s;
-
-static void __user_error_fn(png_structp png_ptr, png_const_charp error_msg)
-{
- mm_util_error("%s", error_msg);
-}
-
-static void __user_warning_fn(png_structp png_ptr, png_const_charp warning_msg)
-{
- mm_util_warn("%s", warning_msg);
-}
-
-static void __read_data_fn(png_structp png_ptr, png_bytep data, png_size_t size)
-{
- png_io_buf_s *io_buf = (png_io_buf_s *) png_get_io_ptr(png_ptr);
-
- mm_util_retm_if(!io_buf || !io_buf->buf || io_buf->buf_size == 0, "Invalid io_buf");
- mm_util_retm_if(!data, "Invalid data");
- mm_util_retm_if(size == 0, "Invalid size");
- mm_util_retm_if(io_buf->pos + size > io_buf->buf_size, "Invalid read due to buffer overflow [%zu/%zu/%zu].", io_buf->pos, size, io_buf->buf_size);
-
- memcpy(data, io_buf->buf + io_buf->pos, size);
- io_buf->pos += size;
-}
-
-static void __flush_data_fn(png_structp png_ptr G_GNUC_UNUSED)
-{
- /* do nothing */
-}
-
-static void __write_data_fn(png_structp png_ptr, png_bytep data, png_uint_32 size)
-{
- png_io_buf_s *io_buf = (png_io_buf_s *) png_get_io_ptr(png_ptr);
-
- mm_util_retm_if(!io_buf, "Invalid io_buf");
- mm_util_retm_if(!data, "Invalid data");
- mm_util_retm_if(size == 0, "Invalid size");
-
- io_buf->buf = (void *)realloc(io_buf->buf, sizeof(png_bytep) * (io_buf->buf_size + size));
- mm_util_retm_if(!io_buf->buf, "Memory allocation failed");
-
- memcpy(io_buf->buf + io_buf->buf_size, data, size);
- io_buf->buf_size += size;
-}
-
-static void __get_property(png_property_s *png_prop, png_structp png_ptr, png_infop info_ptr)
-{
- png_color_16 *image_background = NULL;
-
- mm_util_fenter();
-
- png_read_info(png_ptr, info_ptr);
-
- png_get_IHDR(png_ptr, info_ptr, &png_prop->width, &png_prop->height, &png_prop->bit_depth, &png_prop->color_type, &png_prop->interlace_type, &png_prop->compression_type, &png_prop->filter_type);
-
- /* Get bits per channel */
- png_prop->bit_depth = png_get_bit_depth(png_ptr, info_ptr);
-
- /* Get Color type */
- png_prop->color_type = png_get_color_type(png_ptr, info_ptr);
-
- /* Gray scale converted to upscaled to 8 bits */
- if ((png_prop->color_type == PNG_COLOR_TYPE_GRAY_ALPHA) || (png_prop->color_type == PNG_COLOR_TYPE_GRAY)) {
- /* Gray scale converted to RGB */
- png_set_gray_to_rgb(png_ptr);
- if (png_prop->bit_depth < MM_UTIL_BIT_DEPTH_8)/* Convert to 8 bits */
- png_set_expand_gray_1_2_4_to_8(png_ptr);
- }
- /* Palette converted to RGB */
- else if (png_prop->color_type == PNG_COLOR_TYPE_PALETTE)
- png_set_palette_to_rgb(png_ptr);
-
- /* Add alpha channel, but not for GRAY images */
- if ((png_prop->bit_depth >= MM_UTIL_BIT_DEPTH_8)
- && (png_prop->color_type != PNG_COLOR_TYPE_GRAY)) {
- png_set_add_alpha(png_ptr, 0xff, PNG_FILLER_AFTER);
- }
-
- if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) != 0)
- png_set_tRNS_to_alpha(png_ptr);
-
- if (png_get_bKGD(png_ptr, info_ptr, &image_background) != 0)
- png_set_background(png_ptr, image_background, PNG_BACKGROUND_GAMMA_FILE, 1, 1.0);
-
- png_set_interlace_handling(png_ptr);
-
- /* Update the info structure */
- png_read_update_info(png_ptr, info_ptr);
-
- mm_util_fleave();
-
-}
-
-static int __read_png(FILE *fp, void *memory, const size_t memory_size, mm_util_image_h *decoded)
-{
- int ret = MM_UTIL_ERROR_NONE;
- png_structp png_ptr;
- png_infop info_ptr;
- guint row_index;
- png_io_buf_s io_buf = {memory, memory_size, 0};
- png_property_s png_prop;
- void *_data = NULL;
- mm_util_image_h decoded_image = NULL, converted_image = NULL;
-
- mm_util_retvm_if(((fp == NULL) && (memory == NULL)), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid png image");
- mm_util_retvm_if(!decoded, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image handle");
-
- mm_util_fenter();
-
- /* create libpng structures to read png */
- png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, (png_voidp) NULL, __user_error_fn, __user_warning_fn);
-
- if (png_ptr == NULL) {
- mm_util_error("could not create read struct");
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- info_ptr = png_create_info_struct(png_ptr);
- if (info_ptr == NULL) {
- mm_util_error("could not create info struct");
- png_destroy_read_struct(&png_ptr, png_infopp_NULL, png_infopp_NULL);
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- if (setjmp(png_jmpbuf(png_ptr))) {
- mm_util_error("setjmp called due to internal libpng error");
- png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- /* set file i/o or data function to read png */
- if (fp)
- png_init_io(png_ptr, fp);
- else
- png_set_read_fn(png_ptr, &io_buf, __read_data_fn);
-
- /* get properties(header) to png_prop */
- __get_property(&png_prop, png_ptr, info_ptr);
-
- png_bytep row_pointers[png_prop.height];
- png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
- size_t data_size = ((size_t)(png_prop.height) * rowbytes);
- if (data_size == 0) {
- mm_util_error("wrong data size");
- png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- for (row_index = 0; row_index < png_prop.height; row_index++)
- row_pointers[row_index] = png_malloc(png_ptr, rowbytes);
-
- png_read_image(png_ptr, row_pointers);
-
- mm_util_sec_debug("Decoding with libpng is done!");
-
- _data = (void *)png_malloc(png_ptr, sizeof(png_bytep) * data_size);
- if (!_data) {
- mm_util_error("Failed to memory allocation");
- png_read_end(png_ptr, info_ptr);
- png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
- return MM_UTIL_ERROR_OUT_OF_MEMORY;
- }
-
- /* read png data */
- for (row_index = 0; row_index < png_prop.height; row_index++) {
- memcpy(_data + (row_index * rowbytes), row_pointers[row_index], rowbytes);
- png_free(png_ptr, row_pointers[row_index]);
- }
-
- mm_util_sec_debug("The decoded data has been copied from png_ptr to out-buffer!");
-
- png_read_end(png_ptr, info_ptr);
- png_destroy_read_struct(&png_ptr, &info_ptr, png_infopp_NULL);
-
- if ((png_prop.color_type == PNG_COLOR_TYPE_GRAY_ALPHA) || (png_prop.color_type == PNG_COLOR_TYPE_GRAY)) {
- ret = mm_image_create_image((unsigned int)png_prop.width, (unsigned int)png_prop.height, MM_UTIL_COLOR_RGB24,
- _data, data_size, &decoded_image);
- if (ret != MM_UTIL_ERROR_NONE) {
- mm_util_error("mm_image_create_image failed (%d)", ret);
- MMUTIL_SAFE_FREE(_data);
- return ret;
- }
-
- ret = mm_util_convert_colorspace(decoded_image, MM_UTIL_COLOR_RGBA, &converted_image);
- mm_image_destroy_image(decoded_image);
- decoded_image = NULL;
- } else {
- ret = mm_image_create_image((unsigned int)png_prop.width, (unsigned int)png_prop.height, MM_UTIL_COLOR_RGBA,
- _data, data_size, &decoded_image);
- }
-
- *decoded = (converted_image) ? converted_image : decoded_image;
-
- MMUTIL_SAFE_FREE(_data);
-
- mm_util_fleave();
-
- return ret;
-}
-
-static int __write_png(mm_util_image_h *decoded, mm_util_png_compression compression_level, FILE *fp, void **buffer, size_t *size)
-{
- mm_image_info_s *_decoded = (mm_image_info_s *)decoded;
- png_structp png_ptr;
- png_infop info_ptr;
- guint row_index;
- static png_bytepp row_pointers = NULL;
- png_size_t rowbytes = 0;
- png_io_buf_s io_buf = {NULL, 0};
- png_property_s png_prop;
-
- mm_util_retvm_if(!decoded, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image src");
- mm_util_retvm_if(!fp && (!buffer || !size), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid parameter");
- mm_util_retvm_if(_decoded->color != MM_UTIL_COLOR_RGBA, MM_UTIL_ERROR_NOT_SUPPORTED_FORMAT, "not supported color [%d]", _decoded->color);
-
- mm_util_fenter();
-
- /* initialize png_prop */
- png_prop.filter = PNG_FILTER_NONE;
- png_prop.color_type = PNG_COLOR_TYPE_RGB_ALPHA;
- png_prop.compression_type = PNG_COMPRESSION_TYPE_BASE;
- png_prop.filter_type = PNG_FILTER_TYPE_BASE;
- png_prop.interlace_type = PNG_INTERLACE_NONE;
- png_prop.bit_depth = MM_UTIL_BIT_DEPTH_8;
-
- /* create libpng structures to write png */
- png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, (png_voidp) NULL, __user_error_fn, __user_warning_fn);
-
- if (png_ptr == NULL) {
- mm_util_error("could not create read struct");
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- info_ptr = png_create_info_struct(png_ptr);
- if (info_ptr == NULL) {
- mm_util_error("could not create info struct");
- png_destroy_write_struct(&png_ptr, png_infopp_NULL);
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- if (setjmp(png_jmpbuf(png_ptr))) {
- mm_util_error("setjmp called due to internal libpng error");
- png_destroy_write_struct(&png_ptr, &info_ptr);
- return MM_UTIL_ERROR_INVALID_OPERATION;
- }
-
- /* set file i/o or data function to write png */
- if (fp)
- png_init_io(png_ptr, fp);
- else
- png_set_write_fn(png_ptr, &io_buf, (png_rw_ptr) __write_data_fn, __flush_data_fn);
-
- /* set properties(header) from png_prop */
- png_set_filter(png_ptr, 0, png_prop.filter);
- png_set_compression_level(png_ptr, compression_level);
- png_set_IHDR(png_ptr, info_ptr, _decoded->width, _decoded->height, png_prop.bit_depth, png_prop.color_type, png_prop.interlace_type, png_prop.compression_type, png_prop.filter_type);
-
- rowbytes = (size_t)png_get_rowbytes(png_ptr, info_ptr);
-
- row_pointers = png_malloc(png_ptr, sizeof(png_bytep) * _decoded->height);
- if (row_pointers == NULL) {
- mm_util_error("out of memory");
- png_destroy_write_struct(&png_ptr, &info_ptr);
- return MM_UTIL_ERROR_OUT_OF_MEMORY;
- }
-
- /* write png data */
- for (row_index = 0; row_index < _decoded->height; row_index++)
- row_pointers[row_index] = _decoded->data + (row_index * rowbytes);
-
- png_write_info(png_ptr, info_ptr);
- png_write_image(png_ptr, row_pointers);
- png_write_end(png_ptr, NULL);
-
- png_free(png_ptr, row_pointers);
- png_destroy_write_struct(&png_ptr, &info_ptr);
-
- /* set result */
- if (!fp && io_buf.buf) {
- *buffer = (void *)io_buf.buf;
- *size = io_buf.buf_size;
- }
-
- mm_util_fleave();
-
- return MM_UTIL_ERROR_NONE;
-}
-
-int mm_util_decode_from_png_file(const char *file_path, mm_util_image_h *decoded)
-{
- int ret = MM_UTIL_ERROR_NONE;
- FILE *fp = NULL;
-
- mm_util_retvm_if(!MMUTIL_STRING_VALID(file_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid file_path");
- mm_util_retvm_if(!decoded, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid image handle");
-
- mm_util_sec_debug("file_path [%s]", file_path);
-
- ret = mm_util_safe_fopen(file_path, "r", &fp);
- mm_util_retvm_if(ret != MM_UTIL_ERROR_NONE, ret, "fail to mm_util_safe_fopen [%d]", ret);
-
- ret = __read_png(fp, NULL, 0, decoded);
-
- mm_util_safe_fclose(fp);
-
- return ret;
-}
-
-int mm_util_decode_from_png_memory(void *memory, const size_t src_size, mm_util_image_h *decoded)
-{
- mm_util_retvm_if(!memory, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid png image");
- mm_util_retvm_if(!src_size, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid src_size");
-
- return __read_png(NULL, memory, src_size, decoded);
-}
-
-int mm_util_encode_to_png_file(mm_util_image_h decoded, mm_util_png_compression compression_level, const char *file_path)
-{
- int ret = MM_UTIL_ERROR_NONE;
- FILE *fp = NULL;
-
- mm_util_retvm_if((decoded == NULL), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid color image");
- mm_util_retvm_if(!MMUTIL_STRING_VALID(file_path), MM_UTIL_ERROR_INVALID_PARAMETER, "invalid file_path");
-
- mm_util_sec_debug("Save to file [%s]", file_path);
-
- ret = mm_util_safe_fopen(file_path, "w", &fp);
- if (ret != MM_UTIL_ERROR_NONE) {
- mm_util_error("mm_util_safe_fopen failed (%d)", ret);
- mm_util_safe_fclose(fp);
- mm_util_fleave();
- return ret;
- }
-
- ret = __write_png(decoded, compression_level, fp, NULL, NULL);
-
- mm_util_safe_fclose(fp);
-
- return ret;
-}
-
-int mm_util_encode_to_png_memory(mm_util_image_h decoded, mm_util_png_compression compression_level, void **buffer, size_t *size)
-{
- mm_util_retvm_if(!buffer, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid buffer");
- mm_util_retvm_if(!size, MM_UTIL_ERROR_INVALID_PARAMETER, "invalid size");
-
- return __write_png(decoded, compression_level, NULL, buffer, size);
-}
+++ /dev/null
-prefix=@PREFIX@
-exec_prefix=/usr
-libdir=@LIB_INSTALL_DIR@
-includedir=/usr/include/mmf
-
-Name : @PC_NAME@
-Description : Multimedia Framework Utility Library
-Requires :
-Version : @VERSION@
-Libs : -L${libdir} @PC_LDFLAGS@
-Cflags : -I${includedir}
+++ /dev/null
-SET(fw_name "mmutil_png")
-SET(fw_test "${fw_name}-test")
-
-INCLUDE(FindPkgConfig)
-pkg_check_modules(${fw_test} REQUIRED glib-2.0 dlog libtzplatform-config)
-FOREACH(flag ${${fw_test}_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS} -Wall -fPIE")
-
-aux_source_directory(. sources)
-FOREACH(src ${sources})
- GET_FILENAME_COMPONENT(src_name ${src} NAME_WE)
- MESSAGE("${src_name}")
- ADD_EXECUTABLE(${src_name} ${src})
- TARGET_LINK_LIBRARIES(${src_name} ${fw_name} ${${fw_test}_LDFLAGS} mmutil_common)
-ENDFOREACH()
+++ /dev/null
-/*
- * libmm-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 <glib.h>
-#include <limits.h>
-#include <mm_util_png.h>
-#include <mm_util_image.h>
-#include <tzplatform_config.h>
-
-#define SAFE_FREE(x) { if (x != NULL) { free(x); x = NULL; } }
-#define SAFE_IMAGE_FREE(x) { if (x != NULL) { mm_image_destroy_image(x); x = NULL; } }
-
-#define DECODE_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "png_test_dec_file.raw")
-#define DECODE_MEM_PATH tzplatform_mkpath(TZ_USER_CONTENT, "png_test_dec_mem.raw")
-#define ENCODE_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "png_test_enc_file.png")
-#define ENCODE_MEM_PATH tzplatform_mkpath(TZ_USER_CONTENT, "png_test_enc_mem.png")
-
-typedef enum {
- TEST_AUTO,
- TEST_DECODE_FILE,
- TEST_DECODE_MEMORY,
- TEST_ENCODE_FILE,
- TEST_ENCODE_MEMORY,
- TEST_NUM,
-} png_test_mode_e;
-
-static char *MODE_TO_STR[] = {
- "AUTO",
- "DECODE_FILE",
- "DECODE_MEMORY",
- "ENCODE_FILE",
- "ENCODE_MEMORY",
- "",
-};
-
-/* for arguments */
-static int g_test_mode = 0;
-static char *g_path = NULL;
-static unsigned int g_width = 0;
-static unsigned int g_height = 0;
-static int g_compression = MM_UTIL_COMPRESSION_6;
-
-/* for reading file */
-static void *g_readed_data = NULL;
-static size_t g_readed_size = 0;
-
-static mm_util_image_h g_decoded_data = NULL;
-
-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[PNG_testsuite] invalid data\n");
- return FALSE;
- }
-
- fprintf(stderr, "\t[PNG_testsuite] %s read\n", path);
-
- fp = fopen(path, "r");
- if (fp == NULL) {
- fprintf(stderr, "\t[PNG_testsuite] fopen failed (%d) \n", errno);
- return FALSE;
- }
-
- if (fseek(fp, 0, SEEK_END) < 0) {
- fprintf(stderr, "\t[PNG_testsuite] fseek failed \n");
- fclose(fp);
- return FALSE;
- }
-
- len = ftell(fp);
- if (len < 0) {
- fprintf(stderr, "\t[PNG_testsuite] ftell failed \n");
- fclose(fp);
- return FALSE;
- }
-
- rewind(fp);
- *data = (void *)g_malloc0(len);
- *length = fread(*data, 1, (size_t)len, fp);
- if (*length != len) {
- fprintf(stderr, "\t[PNG_testsuite] fread failed \n");
- }
-
- fclose(fp);
-
- *length = (size_t)len;
-
- fprintf(stderr, "\t[PNG_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[PNG_testsuite] invalid data\n");
- return FALSE;
- }
-
- fprintf(stderr, "\t[PNG_testsuite] %s %p %zu write\n", path, data, length);
-
- fp = fopen(path, "w");
- if (fp == NULL) {
- fprintf(stderr, "\t[PNG_testsuite] fopen failed (%d) \n", errno);
- return FALSE;
- }
-
- len = fwrite(data, 1, length, fp);
- if (len != length) {
- fprintf(stderr, "\t[PNG_testsuite] fwrite failed \n");
- }
-
- fclose(fp);
- fp = NULL;
-
- fprintf(stderr, "\t[PNG_testsuite] %s write DONE\n", path);
-
- return TRUE;
-}
-
-gboolean _get_input_data(const char *argv, const long min, const long max, 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 = (int)temp;
-
- return TRUE;
-}
-
-void _print_help(const char *argv0)
-{
- fprintf(stderr, "\t[usage]\n");
- fprintf(stderr, "\t\t1. decode & encode : %s mode path compression_level(opt.)\n", argv0);
- fprintf(stderr, "\t\t2. decode : %s mode path\n", argv0);
- fprintf(stderr, "\t\t3. encode : %s mode path width(mand.) height(mand.) compression_level(opt.)\n", argv0);
- fprintf(stderr, "\t\t4. mode : 0 - auto, 1 - decode from file, 2 - decode from memory, 3 - encode to file, 4 - encode to memory\n");
-}
-
-gboolean _get_arguments(int argc, char *argv[])
-{
- int width = 0, height = 0;
-
- if (FALSE == _get_input_data(argv[1], TEST_AUTO, TEST_NUM - 1, &g_test_mode)) {
- fprintf(stderr, "\t[PNG_testsuite] wrong mode(%s) for test\n", argv[1]);
- _print_help(argv[0]);
- return FALSE;
- }
-
- g_path = g_strdup(argv[2]);
-
- if (g_test_mode == TEST_AUTO) {
- if (FALSE == _get_input_data(argv[3], MM_UTIL_COMPRESSION_1, MM_UTIL_COMPRESSION_9, &g_compression))
- fprintf(stderr, "\t[PNG_testsuite] compression_level is default(%d)\n", g_compression);
- } else if ((g_test_mode == TEST_DECODE_FILE) || (g_test_mode == TEST_DECODE_MEMORY)) {
- /* do nothing */
- } else if (g_test_mode == TEST_ENCODE_FILE || g_test_mode == TEST_ENCODE_MEMORY) {
- if (argc < 4) {
- fprintf(stderr, "\t[PNG_testsuite] not enough args\n");
- _print_help(argv[0]);
- return FALSE;
- }
- if (FALSE == _get_input_data(argv[3], 0, INT_MAX, &width)) {
- fprintf(stderr, "\t[PNG_testsuite] wrong width %s\n", argv[3]);
- return FALSE;
- }
- g_width = (unsigned int)width;
- if (FALSE == _get_input_data(argv[4], 0, INT_MAX, &height)) {
- fprintf(stderr, "\t[PNG_testsuite] wrong height %s\n", argv[4]);
- return FALSE;
- }
- g_height = (unsigned int)height;
- if (FALSE == _get_input_data(argv[5], MM_UTIL_COMPRESSION_1, MM_UTIL_COMPRESSION_9, &g_compression))
- fprintf(stderr, "\t[PNG_testsuite] wrong compression_level %s\n", argv[5]);
- } else {
- fprintf(stderr, "\t[PNG_testsuite] wrong mode for test %s\n", argv[1]);
- return FALSE;
- }
-
- return TRUE;
-}
-
-gboolean _test_decode(const png_test_mode_e mode)
-{
- int ret = 0;
- unsigned char *data = NULL;
- size_t size = 0;
-
- /* test decoding png */
- if (mode == TEST_DECODE_FILE) {
- ret = mm_util_decode_from_png_file(g_path, &g_decoded_data);
- if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[PNG_testsuite] mm_util_decode_from_png_file failed %d\n", ret);
- return FALSE;
- }
- ret = mm_image_get_image(g_decoded_data, &g_width, &g_height, NULL, &data, &size);
- if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[PNG_testsuite] mm_image_get_image failed %d\n", ret);
- return FALSE;
- }
- if (FALSE == _write_file(DECODE_FILE_PATH, data, size)) {
- fprintf(stderr, "\t[PNG_testsuite] writing decoded data failed : %s\n", DECODE_FILE_PATH);
- SAFE_FREE(data);
- return FALSE;
- }
- SAFE_FREE(data);
- } else if (mode == TEST_DECODE_MEMORY) {
- if (FALSE == _read_file(g_path, &g_readed_data, &g_readed_size)) {
- fprintf(stderr, "\t[PNG_testsuite] reading file error\n");
- return FALSE;
- }
-
- ret = mm_util_decode_from_png_memory(g_readed_data, g_readed_size, &g_decoded_data);
- if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[PNG_testsuite] mm_util_decode_from_png_memory failed %d\n", ret);
- return FALSE;
- }
- ret = mm_image_get_image(g_decoded_data, &g_width, &g_height, NULL, &data, &size);
- if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[PNG_testsuite] mm_image_get_image failed %d\n", ret);
- return FALSE;
- }
- if (FALSE == _write_file(DECODE_MEM_PATH, data, size)) {
- fprintf(stderr, "\t[PNG_testsuite] writing decoded data failed : %s\n", DECODE_MEM_PATH);
- SAFE_FREE(data);
- return FALSE;
- }
- SAFE_FREE(data);
- }
-
- return TRUE;
-}
-
-gboolean _test_encode(const png_test_mode_e mode)
-{
- int ret = 0;
- /* for encoding png to memory */
- void *encoded_data = NULL;
- size_t encoded_size = 0;
-
- if ((mode != TEST_ENCODE_FILE) && (mode != TEST_ENCODE_MEMORY))
- return TRUE;
-
- if (FALSE == _read_file(g_path, &g_readed_data, &g_readed_size)) {
- fprintf(stderr, "\t[PNG_testsuite] reading file error\n");
- return FALSE;
- }
- ret = mm_image_create_image(g_width, g_height, MM_UTIL_COLOR_RGBA, (unsigned char *)g_readed_data,
- g_readed_size, &g_decoded_data);
- if (ret != MM_UTIL_ERROR_NONE) {
- fprintf(stderr, "\t[PNG_testsuite] mm_image_create_image failed : %d\n", ret);
- return FALSE;
- }
-
- /* 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_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_encode_to_png_memory failed : %d\n", ret);
- SAFE_FREE(encoded_data);
- return FALSE;
- }
- if (FALSE == _write_file(ENCODE_MEM_PATH, encoded_data, (size_t)encoded_size)) {
- fprintf(stderr, "\t[PNG_testsuite] writing decoded data failed : %s\n", ENCODE_MEM_PATH);
- SAFE_FREE(encoded_data);
- return FALSE;
- }
- }
-
- SAFE_FREE(encoded_data);
- return TRUE;
-}
-
-gboolean _test_auto()
-{
- png_test_mode_e test_mode = TEST_DECODE_FILE;
-
- while (test_mode < TEST_NUM) {
- fprintf(stderr, "\t[PNG_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST START\n", MODE_TO_STR[test_mode]);
- if (TEST_ENCODE_FILE == test_mode) {
- g_free(g_path);
- g_path = g_strdup(DECODE_FILE_PATH);
- }
- /* 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]);
- return FALSE;
- }
- }
-
- /* 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]);
- return FALSE;
- }
- }
-
- fprintf(stderr, "\t[PNG_testsuite] >>>>>>>>>>>>>>>>>>>>>> \'%s\' TEST SUCCESS\n", MODE_TO_STR[test_mode]);
-
- SAFE_FREE(g_readed_data);
- SAFE_IMAGE_FREE(g_decoded_data);
- test_mode++;
- }
-
- return TRUE;
-}
-
-int main(int argc, char *argv[])
-{
- if (argc < 2) {
- _print_help(argv[0]);
- return 0;
- }
-
- if (FALSE == _get_arguments(argc, argv)) {
- fprintf(stderr, "\t[PNG_testsuite] _get_arguments failed\n");
- goto out;
- }
-
- /* 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 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]);
- goto out;
- }
- }
-
- /* 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]);
- goto out;
- }
- }
-
-out:
- g_free(g_path);
- SAFE_FREE(g_readed_data);
- SAFE_IMAGE_FREE(g_decoded_data);
-
- return 0;
-}
+++ /dev/null
-CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
-PROJECT(gtest-libmm-png C CXX)
-
-SET(GTEST_TEST "gtest-libmm-png")
-ADD_DEFINITIONS("-DUSE_DLOG")
-
-SET(REQUIRES_LIST ${REQUIRES_LIST}
- glib-2.0
- gio-2.0
- gmock
- dlog
- libtzplatform-config
-)
-
-SET(PKG_LIBRARIES ${PKG_LIBRARIES}
- "mmutil_common"
- "mmutil_png"
-)
-
-SET(RESOURCE_LIST ${RESOURCE_LIST}
- "libmm-png-unittest.png"
-)
-
-INCLUDE(FindPkgConfig)
-PKG_CHECK_MODULES(GTEST_TEST_PKG REQUIRED ${REQUIRES_LIST})
-
-FOREACH(flag ${GTEST_TEST_PKG_CFLAGS})
- SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
-ENDFOREACH(flag)
-
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -fPIE")
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
-SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${EXTRA_CFLAGS}")
-SET(CMAKE_EXE_LINKER_FLAGS "-Wl,--as-needed -pie")
-
-FILE(GLOB GTEST_TEST_SRCS *.cpp)
-SET(GTEST_TEST_SRCS ${GTEST_TEST_SRCS})
-
-ADD_EXECUTABLE(${GTEST_TEST} ${GTEST_TEST_SRCS})
-TARGET_LINK_LIBRARIES(${GTEST_TEST} ${PKG_LIBRARIES} ${GTEST_TEST_LDFLAGS} ${GTEST_TEST_PKG_LDFLAGS} -ldl)
-
-INSTALL(TARGETS ${GTEST_TEST} RUNTIME DESTINATION bin)
-INSTALL(FILES ${RESOURCE_LIST} DESTINATION bin)
+++ /dev/null
-/*
- * Copyright (c) 2018 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 "FileInterface.h"
-
-FileInterface::FileInterface(const char *path)
-{
- fp = NULL;
- fileSize = 0;
-
- FileInterface::Open(path);
-}
-
-FileInterface::~FileInterface(void)
-{
- if (fp)
- fclose(fp);
- fp = NULL;
-
- if (readData)
- free(readData);
- readData = NULL;
-}
-
-void FileInterface::Open(const char *path)
-{
- fp = fopen(path, "r");
- if (!fp)
- return ;
-
- long size = 0;
-
- if (fseek(fp, 0, SEEK_END) < 0)
- return ;
-
- size = (size_t)ftell(fp);
- rewind(fp);
-
- if (size < 0)
- return ;
- fileSize = (size_t)size;
-}
-
-gboolean FileInterface::ReadData()
-{
- if (!fp || fileSize == 0)
- return FALSE;
-
- readData = (unsigned char *)calloc(1, fileSize);
- if (fread(readData, 1, fileSize, fp) != fileSize) {
- return FALSE;
- }
- readDataSize = fileSize;
- return TRUE;
-}
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __FILE_INTERFACE_H__
-#define __FILE_INTERFACE_H__
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib.h>
-
-class FileInterface {
- private:
- FILE *fp;
- size_t fileSize;
-
- void Open(const char *path);
- public:
- unsigned char *readData;
- size_t readDataSize;
-
- FileInterface(const char *path);
- ~FileInterface(void);
- gboolean ReadData();
-};
-
-#endif /*__FILE_INTERFACE_H__*/
+++ /dev/null
-/*
- * Copyright (c) 2018 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 <tzplatform_config.h>
-
-#include "libmm_png_unittest.h"
-#include "FileInterface.h"
-#include "mm_util_png.h"
-#include "mm_util_image.h"
-
-#define DECODE_FILE_PATH tzplatform_mkpath(TZ_SYS_BIN, "libmm-png-unittest.png")
-#define ENCODE_FILE_PATH tzplatform_mkpath(TZ_USER_CONTENT, "libmm-png-result.png")
-
-using ::testing::InitGoogleTest;
-using ::testing::Test;
-using ::testing::TestCase;
-
-class libmm_png_Test : public ::testing::Test {
- protected:
- void SetUp() {
- std::cout << "SetUp()" << std::endl;
- }
-
- void TearDown() {
- std::cout << "TearDown()" << std::endl;
- }
-};
-
-TEST(libmm_png_Test, mm_util_decode_from_png_file_p)
-{
- int ret = MM_UTIL_ERROR_NONE;
- mm_util_image_h decode_image = NULL;
-
- ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, &decode_image);
- EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
- EXPECT_TRUE(mm_image_is_valid_image(decode_image));
-
- mm_image_destroy_image(decode_image);
-}
-
-TEST(libmm_png_Test, mm_util_decode_from_png_file_n)
-{
- int ret = MM_UTIL_ERROR_NONE;
- mm_util_image_h decode_image = NULL;
-
- ret = mm_util_decode_from_png_file(NULL, &decode_image);
- EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
-
- ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, NULL);
- EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
-}
-
-TEST(libmm_png_Test, mm_util_decode_from_png_memory_p)
-{
- int ret = MM_UTIL_ERROR_NONE;
- gboolean err = TRUE;
- mm_util_image_h decode_image = NULL;
-
- FileInterface IFile = FileInterface(DECODE_FILE_PATH);
- err = IFile.ReadData();
- EXPECT_TRUE(err);
-
- ret = mm_util_decode_from_png_memory(IFile.readData, IFile.readDataSize, &decode_image);
- EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
- EXPECT_TRUE(mm_image_is_valid_image(decode_image));
-
- mm_image_destroy_image(decode_image);
-}
-
-TEST(libmm_png_Test, mm_util_decode_from_png_memory_n)
-{
- int ret = MM_UTIL_ERROR_NONE;
- gboolean err = TRUE;
- mm_util_image_h decode_image = NULL;
-
- FileInterface IFile = FileInterface(DECODE_FILE_PATH);
- err = IFile.ReadData();
- EXPECT_TRUE(err);
-
- ret = mm_util_decode_from_png_memory(NULL, IFile.readDataSize, &decode_image);
- EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
-
- ret = mm_util_decode_from_png_memory(IFile.readData, IFile.readDataSize, NULL);
- EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
-}
-
-TEST(libmm_png_Test, mm_util_encode_to_png_file_p)
-{
- int ret = MM_UTIL_ERROR_NONE;
- mm_util_image_h decode_image = NULL;
-
- ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, &decode_image);
- EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
- EXPECT_TRUE(mm_image_is_valid_image(decode_image));
-
- ret = mm_util_encode_to_png_file(decode_image, MM_UTIL_COMPRESSION_6, ENCODE_FILE_PATH);
- EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
-
- mm_image_destroy_image(decode_image);
-}
-
-TEST(libmm_png_Test, mm_util_encode_to_png_file_n)
-{
- int ret = MM_UTIL_ERROR_NONE;
- mm_util_image_h decode_image = NULL;
-
- ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, &decode_image);
- EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
- EXPECT_TRUE(mm_image_is_valid_image(decode_image));
-
- ret = mm_util_encode_to_png_file(NULL, MM_UTIL_COMPRESSION_6, ENCODE_FILE_PATH);
- EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
-
- ret = mm_util_encode_to_png_file(decode_image, MM_UTIL_COMPRESSION_6, NULL);
- EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
-
- mm_image_destroy_image(decode_image);
-}
-
-TEST(libmm_png_Test, mm_util_encode_to_png_memory_p)
-{
- int ret = MM_UTIL_ERROR_NONE;
- mm_util_image_h decode_image = NULL;
- void *buffer = NULL;
- size_t size = 0;
-
- ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, &decode_image);
- EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
- EXPECT_TRUE(mm_image_is_valid_image(decode_image));
-
- ret = mm_util_encode_to_png_memory(decode_image, MM_UTIL_COMPRESSION_6, &buffer, &size);
- EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
- EXPECT_TRUE(buffer != NULL);
- EXPECT_NE(size, 0);
-
- mm_image_destroy_image(decode_image);
-
- if (buffer != NULL)
- free(buffer);
-}
-
-TEST(libmm_png_Test, mm_util_encode_to_png_memory_n)
-{
- int ret = MM_UTIL_ERROR_NONE;
- mm_util_image_h decode_image = NULL;
- void *buffer = NULL;
- size_t size = 0;
-
- ret = mm_util_decode_from_png_file(DECODE_FILE_PATH, &decode_image);
- EXPECT_EQ(ret, MM_UTIL_ERROR_NONE);
- EXPECT_TRUE(mm_image_is_valid_image(decode_image));
-
- ret = mm_util_encode_to_png_memory(NULL, MM_UTIL_COMPRESSION_6, &buffer, &size);
- EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
-
- ret = mm_util_encode_to_png_memory(decode_image, MM_UTIL_COMPRESSION_6, NULL, &size);
- EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
-
- ret = mm_util_encode_to_png_memory(decode_image, MM_UTIL_COMPRESSION_6, &buffer, NULL);
- EXPECT_EQ(ret, MM_UTIL_ERROR_INVALID_PARAMETER);
-
- mm_image_destroy_image(decode_image);
-}
-
-int main(int argc, char **argv)
-{
- InitGoogleTest(&argc, argv);
-
- return RUN_ALL_TESTS();
-}
-
+++ /dev/null
-/*
- * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef __LIB_MM_PNG_UNITTEST_H__
-#define __LIB_MM_PNG_UNITTEST_H__
-
-#include <gmock/gmock.h>
-#include <gtest/gtest.h>
-
-#undef LOG_TAG
-#define LOG_TAG "GTEST_LIBMM_PNG"
-
-#endif /*__LIB_MM_PNG_UNITTEST_H__*/