/*
 * Copyright (c) 2014 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 __IMAGE_SAMPLE_UTILS_H__
#define __IMAGE_SAMPLE_UTILS_H__

#include <Evas.h>
#include <image_util.h>

/**
 * @brief Enumeration for image file format.
 */
typedef enum
{
    IMAGE_FILE_FORMAT_UNKNOWN,                 /**< unknown file format */
    IMAGE_FILE_FORMAT_JPG,                     /**< JPG file format */
    IMAGE_FILE_FORMAT_PNG,                     /**< PNG file format */
    IMAGE_FILE_FORMAT_GIF,                     /**< GIF file format */
    IMAGE_FILE_FORMAT_BMP,                     /**< BMP file format */
    IMAGE_FILE_FORMAT_TIFF,                    /**< TIFF file format */
} image_file_format_e;

/**
 * @brief Convert format(int) to C string
 * @param[in] format Image format
 * @return Image format as C string
 */
const char *image_file_format_to_str(image_file_format_e format);

/**
 * @brief Return passed milliseconds since the epoch beginning
 * @return Passed milliseconds since the epoch beginning
 */
long long get_ticks();

/**
 * @brief A pointer to file extension in passed path.

 * @param[in]   file_path   Resource path relative to shared resources directory
 * @return A pointer to file extension in file_path on success, otherwise @c NULL on failure
 */
const char *filename_extenstion_get(const char *file_path);

/**
 * @brief Image file format id

 * @param[in]   format   Extension of file
 * @return Image file format id
 */
image_file_format_e image_file_format_to_id(const char *format);

/**
 * @brief Converts the image's colorspace.
 *
 * @remarks You must get the @a dest buffer size using image_util_calculate_buffer_size().
 *
 * @param[in/out] dest The image buffer for result \n
 *                     Must be allocated by the user
 * @param[in] dest_colorspace The colorspace to be converted
 * @param[in] src The source image buffer
 * @param[in] width The width of the source image
 * @param[in] height The height of the source image
 * @param[in] src_colorspace The colorspace of the source image buffer
 * @return %c 0 on success
 *            otherwise a negative error value
 * @retval #IMAGE_UTIL_ERROR_NONE Successful
 *
 * @see image_util_calculate_buffer_size()
 */
int image_sample_util_convert_colorspace(unsigned char *dest, image_util_colorspace_e dest_colorspace,
                                   const unsigned char *src, int width, int height,
                                  image_util_colorspace_e src_colorspace);

/**
 * @brief Resizes the image buffer of colorspace BGRA8888 to specified destination width and height
 *
 * @param[in]   src_w       The origin image width
 * @param[in]   src_h       The origin image height
 * @param[in]   src         The source buffer of origin image
 * @param[in]   dest_w      The image width to resize, and resized width
 * @param[in]   dest_h      The image height to resize, and resized height
 * @param[in/out]   dest    The image buffer for result. Must be allocated by you
 *
 * @return    0 on success, otherwise a negative error value
 * @retval    #IMAGE_UTIL_ERROR_NONE Successful
 * @retval    #IMAGE_UTIL_ERROR_INVALID_PARAMETER Invalid parameter
 */
int image_sample_util_resize(const int src_w, const int src_h, const unsigned char *src, const int dest_w, const int dest_h, unsigned char *dest);


/**
 * @brief Load image file by name into elm_image.
 * @param[in,out] image   Evas_Object elm_image object
 * @param[in] file_name   Image file name relative to shared images resources directory
 * @param[in] colorspace  The colorspace of the image file ( BGRA8888, YUV420, YUV422 formats supported )
 * @param[in] width       The origin image width
 * @param[in] height      The origin image height
 * @return true if success, false otherwise
 */
bool image_sample_util_load_image(Evas_Object *image, const char *file_name,
                                  image_util_colorspace_e colorspace, const int width, const int height);

#endif // __IMAGE_SAMPLE_UTILS_H__

