/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

/*----------------------------------------------------------------------------*/
/*! @file u_wgl_image.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/11/10 $
 *  $Author: dtvbm11 $
 *  
 *  @par Description:
 *         This header file contains public interfaces, constant and type 
 *         definitions of the Widget Library.
 */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*! @addtogroup groupMW_WGL
 *  @{ 
 */
/*----------------------------------------------------------------------------*/
 
#ifndef _U_WGL_IMAGE_H_
#define _U_WGL_IMAGE_H_

/*-----------------------------------------------------------------------------
                    include files
 ----------------------------------------------------------------------------*/
#include "u_wgl.h"
#include "u_gl.h"
#include "u_wgl_common.h"

#ifdef __cplusplus
extern "C" {
#endif

/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
 ----------------------------------------------------------------------------*/
/*------------------------------------------------------------------*/
/*! @enum WGL_TPL_PAINT_METHOD_T
 *  @brief
 *  @code
 *  typedef enum _WGL_TPL_PAINT_METHOD_T
 *  {
 *      WGL_TPL_PAINT_BITBLT = 0,
 *      WGL_TPL_PAINT_COMPOSE
 *  } WGL_TPL_PAINT_METHOD_T;
 *  @endcode
 *  @li@c  WGL_TPL_PAINT_BITBLT                              -Specify the source surface pixel data will replace the destination surface pixel data at the same position.
 *  @li@c  WGL_TPL_PAINT_COMPOSE                             -Specify the source surface pixel data will do alpha composition with the destination surface pixel data at the same position.
 */
/*------------------------------------------------------------------*/
typedef enum _WGL_TPL_PAINT_METHOD_T
{
    WGL_TPL_PAINT_BITBLT = 0,
    WGL_TPL_PAINT_COMPOSE
} WGL_TPL_PAINT_METHOD_T;

#define WGL_IMG_TYPE_ALIGN_MASK                 ((UINT32) 0x80)    /**< image data is four bytes aligned       */
#define WGL_IMG_TYPE_COMPRESSED_MASK            ((UINT32) 0x40)    /**< image is compressed       */
#define WGL_IMG_TYPE_ZIPPED_MASK                ((UINT32) 0x20)    /**<  image is zipped      */

/*Image Type*/
#define WGL_IMG_TYPE_1555                       ((UINT32) 0x01)    /**< Indicate every pixel in WGL_IMAGE_T occupies 16 bits, and 1 bit for alpha, 5 bits for R, 5 bits for G, and 5 bits for B. Besides, it's image data is linear without 4 bytes alignment.     */
#define WGL_IMG_TYPE_1555_ALIGN                 (WGL_IMG_TYPE_1555            | WGL_IMG_TYPE_ALIGN_MASK)    /**< It is the same to WGL_IMG_TYPE_1555 except the image data is 4 bytes alignment. */
#define WGL_IMG_TYPE_1555_ALIGN_ZIPPED          (WGL_IMG_TYPE_1555_ALIGN      | WGL_IMG_TYPE_ZIPPED_MASK)    /**<   image's color mode is ARGB(1555) ,data is four bytes aligned and image is zipped     */
#define WGL_IMG_TYPE_1555_ALIGN_COMPRESSED      (WGL_IMG_TYPE_1555_ALIGN      | WGL_IMG_TYPE_COMPRESSED_MASK)    /**<    image's color mode is ARGB(1555)  ,data is four bytes aligned and image is compressed     */

#define WGL_IMG_TYPE_4444                       ((UINT32) 0x03)    /**<Indicate every pixel in WGL_IMAGE_T occupies 16 bits, and 4 bit for alpha, 4 bits for R, 4 bits for G, and 4 bits for B. Besides, it's image data is linear without 4 bytes alignment.         */
#define WGL_IMG_TYPE_4444_ALIGN                 (WGL_IMG_TYPE_4444            | WGL_IMG_TYPE_ALIGN_MASK)    /**<  		It is the same to WGL_IMG_TYPE_4444 except the image data is 4 bytes alignment.   */
#define WGL_IMG_TYPE_4444_ALIGN_ZIPPED          (WGL_IMG_TYPE_4444_ALIGN      | WGL_IMG_TYPE_ZIPPED_MASK)    /**<  image's color mode is ARGB(4444) ,data is four bytes aligned and image is zipped    */
#define WGL_IMG_TYPE_4444_ALIGN_COMPRESSED      (WGL_IMG_TYPE_4444_ALIGN      | WGL_IMG_TYPE_COMPRESSED_MASK)    /**<  image's color mode is ARGB(4444)  ,data is four bytes aligned and image is compressed     */

#define WGL_IMG_TYPE_CLUT8                      ((UINT32) 0x04)    /**<  image's color mode is CLUT8        */
#define WGL_IMG_TYPE_CLUT8_ALIGN                (WGL_IMG_TYPE_CLUT8           | WGL_IMG_TYPE_ALIGN_MASK)    /**<      image's color mode is CLUT8  and data is four bytes aligned   */
#define WGL_IMG_TYPE_CLUT8_ALIGN_ZIPPED         (WGL_IMG_TYPE_CLUT8_ALIGN     | WGL_IMG_TYPE_ZIPPED_MASK)    /**<      image's color mode is CLUT8 ,data is four bytes aligned and image is zipped    */
#define WGL_IMG_TYPE_CLUT8_ALIGN_COMPRESSED     (WGL_IMG_TYPE_CLUT8_ALIGN     | WGL_IMG_TYPE_COMPRESSED_MASK)    /**<   image's color mode is CLUT8  ,data is four bytes aligned and image is compressed       */

#define WGL_IMG_TYPE_YUV_CLUT8                  ((UINT32) 0x05)    /**<image's color mode is YUV CLUT8        */
#define WGL_IMG_TYPE_YUV_CLUT8_ALIGN            (WGL_IMG_TYPE_YUV_CLUT8       | WGL_IMG_TYPE_ALIGN_MASK)    /**< image's color mode is YUV CLUT8  and data is four bytes aligned     */
#define WGL_IMG_TYPE_YUV_CLUT8_ALIGN_ZIPPED     (WGL_IMG_TYPE_YUV_CLUT8_ALIGN | WGL_IMG_TYPE_ZIPPED_MASK)    /**< image's color mode is YUV CLUT8 ,data is four bytes aligned and image is zipped         */
#define WGL_IMG_TYPE_YUV_CLUT8_ALIGN_COMPRESSED (WGL_IMG_TYPE_YUV_CLUT8_ALIGN | WGL_IMG_TYPE_COMPRESSED_MASK)    /**< image's color mode is YUV CLUT8,data is four bytes aligned and image is compressed          */

#define WGL_IMG_TYPE_8888                       ((UINT32) 0x06)    /**< image's color mode is ARGB(8888)         */
#define WGL_IMG_TYPE_8888_ALIGN                 (WGL_IMG_TYPE_8888            | WGL_IMG_TYPE_ALIGN_MASK)    /**<   image's color mode is ARGB(8888)  and data is four bytes aligned      */
#define WGL_IMG_TYPE_8888_ALIGN_ZIPPED          (WGL_IMG_TYPE_8888_ALIGN      | WGL_IMG_TYPE_ZIPPED_MASK)    /**< image's color mode is ARGB(8888) ,data is four bytes aligned and image is zipped        */
#define WGL_IMG_TYPE_8888_ALIGN_COMPRESSED      (WGL_IMG_TYPE_8888_ALIGN      | WGL_IMG_TYPE_COMPRESSED_MASK)    /**<   image's color mode is ARGB(8888) ,data is four bytes aligned and image is compressed      */

#define WGL_IMG_TYPE_STRETCH_MASK               ((UINT32) 0x01000000)  /**<  Indicate this image should stretch when repaint */


#define WGL_IMG_TYPE_JPG                        ((UINT32) 0x10000000)    /**<  Indicate the buffer in WGL_IMAGE_T is JPG format      */
#define WGL_IMG_TYPE_JPG_4444                   (WGL_IMG_TYPE_4444 | WGL_IMG_TYPE_JPG)    /**<  Indicate the buffer in WGL_IMAGE_T is JPG format      */

#define WGL_IMG_TYPE_PNG                        ((UINT32) 0x20000000)    /**<  Indicate the buffer in WGL_IMAGE_T is JPG format      */
#define WGL_IMG_TYPE_PNG_4444                   (WGL_IMG_TYPE_4444 | WGL_IMG_TYPE_PNG)    /**<  Indicate the buffer in WGL_IMAGE_T is JPG format      */

#define WGL_IMG_TYPE_BMP                        ((UINT32) 0x40000000)    /**<  Indicate the buffer in WGL_IMAGE_T is JPG format      */
#define WGL_IMG_TYPE_BMP_4444                   (WGL_IMG_TYPE_4444 | WGL_IMG_TYPE_BMP)     /**<  Indicate the buffer in WGL_IMAGE_T is JPG format      */

#define WGL_IMG_TYPE_GIF                        ((UINT32) 0x80000000)    /**<  Indicate the buffer in WGL_IMAGE_T is JPG format      */
#define WGL_IMG_TYPE_GIF_4444                   (WGL_IMG_TYPE_4444 | WGL_IMG_TYPE_GIF)     /**<  Indicate the buffer in WGL_IMAGE_T is JPG format      */

#define WGL_IMG_SEGMENT_OFFSET                  (8)    /**< image's segment  is offset       */
#define WGL_IMG_SEGMENT_MASK                    ((UINT32)(0xFF << WGL_IMG_SEGMENT_OFFSET))    /**< image's segment  is mask        */

#define WGL_IMG_PER_DECODE                      ((UINT32) 0x02000000)  /**<  Indicate the image is buffered in cached after decoded once      */


#define WGL_IMG_SEGMENT_TYPE(e_seg_type)        ((UINT32)(e_seg_type << WGL_IMG_SEGMENT_OFFSET))    /**<  image's segment type      */

/*-----------------------------------------------------------------------------
                    structures
 ----------------------------------------------------------------------------*/
/*Image Structure*/
/*------------------------------------------------------------------*/
/*! @struct WGL_IMG_T
 *  @brief image related data info
 *  @code
 *  typedef struct _WGL_IMG_T
 *  {
 *          UINT16                          ui2_width;
 *          UINT16                          ui2_lines;
 *          UINT8                           ui1_bits_per_pixel;
 *          UINT32                          ui4_image_type;
 *          UINT16                          ui2_table_columns;
 *          GL_COLOR_T*                     pt_table_data;
 *          UINT32                          ui4_image_size;
 *          UINT8*                          pui1_image_data;
 *  } WGL_IMG_T;
 *  @endcode
 *  @li@c  ui2_width                                         -Specify image's width in pixel.
 *  @li@c  ui2_lines                                         -Specify image's line number.
 *  @li@c  ui1_bits_per_pixel                                -Specify the bit number for each pixel. It must be 16 now.
 *  @li@c  ui4_image_type                                    -Specify the type of the image. It cannot be WGL_IMG_TYPE_JPG now.
 *  @li@c  ui2_table_columns                                 -Specify the count of color index table. It must be 0 now
 *  @li@c  pt_table_data                                     -Specify the color table. It must be NULL now.
 *  @li@c  ui4_image_size                                    -Specify the buffer size pointed by pui1_image_data in bytes.
 *  @li@c  pui1_image_data                                   -Pointer to the image buffer.
 */
/*------------------------------------------------------------------*/
typedef struct _WGL_IMG_T
{
        UINT16                          ui2_width;
        UINT16                          ui2_lines;
        UINT8                           ui1_bits_per_pixel;
        UINT32                          ui4_image_type;
        UINT16                          ui2_table_columns;
        GL_COLOR_T*                     pt_table_data;
        UINT32                          ui4_image_size;
        UINT8*                          pui1_image_data;
} WGL_IMG_T;


/*-----------------------------------------------------------------------------
                    functions
 ----------------------------------------------------------------------------*/

#ifdef __cplusplus
}
#endif

#endif

/*----------------------------------------------------------------------------*/
/*! @} */   /* end of  groupMW_WGL*/
/*----------------------------------------------------------------------------*/


