/* 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_cl_zip_eng.h 
 *  $RCSfile: $
 *  $Revision: #1 $
 *  $Date: 2015/05/29 $
 *  $Author: brianpc.huang $
 *  
 *  @par Description:
 *         This file exports all compression library specific definitions and structures.
 */
/*----------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------*/
/*! @addtogroup groupMW_CL
  *  @{  
  */
/*----------------------------------------------------------------------------*/
#ifndef _U_CL_ZIP_ENG_H_
#define _U_CL_ZIP_ENG_H_

/*-----------------------------------------------------------------------------
                    include files
 ----------------------------------------------------------------------------*/

/*-----------------------------------------------------------------------------
                    macros, defines, typedefs, enums
 ----------------------------------------------------------------------------*/

/****************************************************************************/
/*                       zlib compression parameter                         */
/****************************************************************************/
#define CL_ZIP_NO_COMPRESSION         0    /**<0 gives no compression at all (the input data is simply copied a block at a time).       */
#define CL_ZIP_BEST_SPEED             1    /**<1 gives best speed.        */
#define CL_ZIP_BEST_COMPRESSION       9    /**<9 gives best compression.        */
#define CL_ZIP_DEFAULT_COMPRESSION    CL_ZIP_BEST_COMPRESSION    /**<Default compression level.        */
/* compression levels */
/*
The compression level must be between 0 and 9: 
1 gives best speed, 
9 gives best compression, 
0 gives no compression at all (the input data is simply copied a block at a time).
*/
#define CL_ZIP_MAX_WBITS               15    /**<The windowBits parameter is the base two logarithm of the window size (the size of the history buffer). It should be in the range 8..15 for this version of the library. Larger values of this parameter result in better compression at the expense of memory usage.         */
#define CL_ZIP_DEF_WBITS               CL_ZIP_MAX_WBITS    /**<The default value is 15 if deflateInit is used instead.CAUTION: The decompression window bits should be larger than compression.        */
/*
The windowBits parameter is the base two logarithm of the window size (the size of the history buffer). 
It should be in the range 8..15 for this version of the library. 
Larger values of this parameter result in better compression at the expense of memory usage. 
The default value is 15 if deflateInit is used instead.
CAUTION: The decompression window bits should be larger than compression.
*/
#define CL_ZIP_DEF_MEM_LEVEL 8    /**<Specifies how much memory should be allocated for the internal compression state.  The default value is 8. Deflate memory usage (bytes) = (1 << (windowBits+2)) + (1 << (memLevel+9)) .      */
#define CL_ZIP_MAX_MEM_LEVEL 9    /**<Maximum memory for optimal speed.         */
#define CL_ZIP_MIN_MEM_LEVEL 1    /**<Minimum memory but is slow and reduces compression ratio.        */
/*
The memLevel parameter specifies how much memory should be allocated for the internal compression state. 
memLevel=1 uses minimum memory but is slow and reduces compression ratio ; 
memLevel=9 uses maximum memory for optimal speed. 
The default value is 8. 
*/

/*
The memory requirements for compression depend on two parameters, windowBits and memLevel:

    deflate memory usage (bytes) = (1 << (windowBits+2)) + (1 << (memLevel+9)) 
    inflate memory usage (bytes) = (1 << windowBits) + 1440*2*sizeof(int)
*/

/*------------------------------------------------------------------*/
/*! @enum CL_ZIP_COMPRESSION_STRATEGY_T
 *  @brief   The strategy parameter is used to tune the compression algorithm. Use the
 *              value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
 *              filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
 *              string match), or Z_RLE to limit match distances to one (run-length
 *              encoding). Filtered data consists mostly of small values with a somewhat
 *              random distribution. In this case, the compression algorithm is tuned to
 *              compress them better. The effect of Z_FILTERED is to force more Huffman
 *              coding and less string matching; it is somewhat intermediate between
 *              Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
 *              Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
 *              parameter only affects the compression ratio but not the correctness of the
 *              compressed output even if it is not set appropriately.
 *  @code
 *  typedef enum 
 *  {
 *      CL_ZIP_DEFAULT_STRATEGY = 0,
 *      CL_ZIP_FILTERED,
 *      CL_ZIP_HUFFMAN_ONLY,
 *      CL_ZIP_RLE,
 *      CL_ZIP_LAST_ONE 
 *  } CL_ZIP_COMPRESSION_STRATEGY_T;
 *  @endcode
 *  @li@c  CL_ZIP_DEFAULT_STRATEGY                           -Normal data.
 *  @li@c  CL_ZIP_FILTERED                                   -Data produced by a filter (or predictor).
 *  @li@c  CL_ZIP_HUFFMAN_ONLY                               -Force Huffman encoding only (no string match).
 *  @li@c  CL_ZIP_RLE                                        - Limit match distances to one (run-length encoding).
 *  @li@c  CL_ZIP_LAST_ONE                                   - No use, just a latest one indicator.
 */
/*------------------------------------------------------------------*/
typedef enum 
{
    CL_ZIP_DEFAULT_STRATEGY = 0,
    CL_ZIP_FILTERED,
    CL_ZIP_HUFFMAN_ONLY,
    CL_ZIP_RLE,
    CL_ZIP_LAST_ONE /* no use, just a latest one indicator*/
} CL_ZIP_COMPRESSION_STRATEGY_T;
/* The strategy parameter is used to tune the compression algorithm. Use the
   value Z_DEFAULT_STRATEGY for normal data, Z_FILTERED for data produced by a
   filter (or predictor), Z_HUFFMAN_ONLY to force Huffman encoding only (no
   string match), or Z_RLE to limit match distances to one (run-length
   encoding). Filtered data consists mostly of small values with a somewhat
   random distribution. In this case, the compression algorithm is tuned to
   compress them better. The effect of Z_FILTERED is to force more Huffman
   coding and less string matching; it is somewhat intermediate between
   Z_DEFAULT and Z_HUFFMAN_ONLY. Z_RLE is designed to be almost as fast as
   Z_HUFFMAN_ONLY, but give better compression for PNG image data. The strategy
   parameter only affects the compression ratio but not the correctness of the
   compressed output even if it is not set appropriately.
 */
/*------------------------------------------------------------------*/
/*! @struct CL_ZIP_COMPRESSION_T
 *  @brief   Compression parameter.
 *  @code
 *  typedef struct _CL_ZIP_COMPRESSION_T
 *  {
 *      UINT8                           ui1_level;
 *      UINT8                           ui1_windowbits;
 *      UINT8                           ui1_mem_level;
 *      CL_ZIP_COMPRESSION_STRATEGY_T   e_strategy;
 *  } CL_ZIP_COMPRESSION_T;
 *  @endcode
 *  @li@c  ui1_level                                         - Compression levels,The compression level must be between 0 and 9: 1 gives best speed, 9 gives best compression, 0 gives no compression at all (the input data is simply copied a block at a time).
 *  @li@c  ui1_windowbits                                    - The windowBits parameter is the base two logarithm of the window size (the size of the history buffer). It should be in the range 8..15 for this version of the library. 
 *  @li@c  ui1_mem_level                                     - The memLevel parameter specifies how much memory should be allocated for the internal compression state.
 *  @li@c  e_strategy                                        - The strategy parameter is used to tune the compression algorithm.
 */
/*------------------------------------------------------------------*/
typedef struct _CL_ZIP_COMPRESSION_T
{
    UINT8                           ui1_level;/*0~9*/
    UINT8                           ui1_windowbits;/*8~15*/
    UINT8                           ui1_mem_level;/*1~9*/
    CL_ZIP_COMPRESSION_STRATEGY_T   e_strategy;
} CL_ZIP_COMPRESSION_T;

/*------------------------------------------------------------------*/
/*! @struct CL_ZIP_DECOMPRESSION_T
 *  @brief The memory requirements for compression depend on two parameters, windowBits and memLevel: deflate memory usage (bytes) = (1 << (windowBits+2)) + (1 << (memLevel+9))  inflate memory usage (bytes) = (1 << windowBits) + 1440*2*sizeof(int)
 *  @code
 *  typedef struct _CL_ZIP_DECOMPRESSION_T
 *  {
 *      UINT8                           ui1_windowbits;
 *  } CL_ZIP_DECOMPRESSION_T;
 *  @endcode
 *  @li@c  ui1_windowbits                                    - The windowBits parameter is the base two logarithm of the window size (the size of the history buffer). It should be in the range 8..15 for this version of the library. 
 */
/*------------------------------------------------------------------*/
typedef struct _CL_ZIP_DECOMPRESSION_T
{
    UINT8                           ui1_windowbits;/*8~15*/
} CL_ZIP_DECOMPRESSION_T;

#define CL_ZIP_ENGINE_COMPRESS_PARAM_TYPE    0x2    /**<Compress parameter type.        */
#define CL_ZIP_ENGINE_DECOMPRESS_PARAM_TYPE  0x3    /**<Decompress parameter type.        */

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

#endif /* _U_CL_ZIP_ENG_H_ */
/*----------------------------------------------------------------------------*/
/*! @} */                                                 /* end of groupMW_CL*/
/*----------------------------------------------------------------------------*/
