/* 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.
 *
 *****************************************************************************/


/*************************************************************************
 *
 * Filename:
 * ---------
 *   $Workfile: drv_contrast.h $
 *
 * Project:
 * --------
 *
 *
 * Description:
 * ------------
 *
 *
 * Author:
 * -------
 *
 *
 * Last changed:
 * -------------
 * $Author: robin.zhang $
 *
 * $Modtime: 04/05/23 2:49p $
 *
 * $Revision: #2 $
*************************************************************************/

#ifndef _DRV_METER_H_
#define _DRV_METER_H_

#include "general.h"

#define LUMA_HIST_NUM	        32
#define LUMA_HIST_NUM_WEIGHT    (LUMA_HIST_NUM + 1)
#define LUMA_HIST_NUM_65	    65
#define LUMA_HIST_NUM_113		113
#define SAT_HIST_NUM            8
#define HUE_HIST_NUM            8
#define RGB_MAX_HIST_NUM        33
#define SAT_HUE_2DWIN_NUM       3

typedef enum
{
    E_HUE_DIST_R,     
    E_HUE_DIST_G,     
    E_HUE_DIST_B,     
    E_HUE_DIST_C,     
    E_HUE_DIST_Y,    
    E_HUE_DIST_M,  
    E_HUE_DIST_W,
    E_HUE_DIST_SKIN
} E_HUE_DIST;


// ---- General API ------
void vDrvMeterInit(void);
void vDrvMeterProc(void);
void vDrvMeterISR(void);

// ---- Luma Info ------
void vDrvGetLumaInfoHW(void);
UINT8 bDrvGetAPL(void);
void vDrvGetAPLLR(UINT8* bAPLL, UINT8* bAPLLR);
UINT8 u1DrvGetLumaHist(UINT16 waHistCur[LUMA_HIST_NUM], UINT16 u2NormBase);
UINT8 u1DrvGetLumaHistWeight(UINT16 waHistCur[LUMA_HIST_NUM_WEIGHT], UINT16 u2NormBase);
void vDrvGetLumaHistLR(UINT16 waHistL[LUMA_HIST_NUM], UINT16 waHistR[LUMA_HIST_NUM], UINT16 u2NormBase);
void vDrvGetLuma65HistLR(UINT16 waHistL[65], UINT16 waHistR[65], UINT16 u2NormBase);
void vDrvGetLuma113HistLR(UINT16 waHistL[LUMA_HIST_NUM_113], UINT16 waHistR[LUMA_HIST_NUM_113], UINT16 u2NormBase);
void vDrvGetInputLumaMaxLR(UINT8* bMaxL, UINT8* bMaxR);
void vDrvGetInputLumaMinLR(UINT8* bMinL, UINT8* bMinR);
void vDrvGetInputLumaSumLR(UINT32* u4SumL, UINT32* u4SumR);
void vDrvSetLumaMaxLPF(UINT8 bLPFSel);
void vDrvSetLumaMinLPF(UINT8 bLPFSel);

// ---- RGB Max Meter ------
UINT8 u1DrvGetRGBHist(UINT16 u4aHist[RGB_MAX_HIST_NUM], UINT16 u2NormBase);
void vDrvSetRGBMaxBoundary(UINT8 * bBoundary);
UINT16 u2GetRGBAverage(const UINT16 *u2aHist, UINT16 u2NormBase);

// ---- Saturation Histogram ------
UINT8 u1DrvGetASL(void);
void vDrvGetASLLR(UINT8* bASLL, UINT8* bASLR);
void vDrvSetSatHistBoundary(UINT8* bBoundary);
void vDrvSetSatHistWindow(UINT16* u2Window);
void vDrvGetSatHistWindow(UINT16 * u2Window);
UINT8 u1DrvGetSatHist(UINT16 u2aHist[SAT_HIST_NUM], UINT16 u2NormBase);
void vDrvGetSatHistLR(UINT16 u2aHistL[SAT_HIST_NUM], UINT16 u2aHistR[SAT_HIST_NUM], UINT16 u2NormBase);

// ---- Hue Histogram ------
void vDrvSetHueHistBoundary(UINT8* bBoundary);
UINT8 u1DrvGetHueHist(UINT16 u2aHist[HUE_HIST_NUM], UINT32 *u4PixNumNorm, UINT16 u2NormBase);
void vDrvGetHueHistLR(UINT16 u2aHistL[HUE_HIST_NUM], UINT16 u2aHistR[HUE_HIST_NUM], UINT16 u2NormBase);
void vDrvSatHistWinReconfig(void);

// ---- Sat & Hue 2D Histogram ------
void vDrvSetSatHue2DWindowBound(UINT8 bWinSel, UINT8 bSatUpper, UINT8 bSatLower, UINT8 bHueUpper, UINT8 bHueLower);
UINT32 u4DrvGetSatHue2DWindowResult(UINT8 bWinSel, UINT16 u2NormBase);
void vDrvGet2DWindowLR(UINT16 u2WinL[3], UINT16 u2WinR[3], UINT16 u2NormBase);

#endif
