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


#include "drv_MapleApi.h"
#include "nptv_debug.h"
#include "bepqapi.h"

////////////////////////////////////////////////////////////////////////////////
EXTERN AUTO_BACKLIGHT_SETS_INFO_T stBLight;
EXTERN AUTO_COLORTEMP_SETS_INFO_T stCTInfo;
EXTERN UINT32 bi1GammaOfst;
EXTERN INT16 i2WB10PUIValue[3][11];
EXTERN D_AP_BT_DELAY_MODE gBTDelay ;

extern UINT8 gServiceInit;



////////////////////////////////////////////////////////////////////////////////
#define MAPLE_AP_DEBUG 1

////////////////////////////////////////////////////////////////////////////////
static void DEBUG_GetPictureSetting(CUST_PIC_SETTING_T* pPictureSetting)
{
    #if MAPLE_AP_DEBUG
    LOG(2, "====== DRVCUST_GetPictureSetting ======\n"); 
    LOG(2, "ePicMode            %d\n", pPictureSetting->ePicMode);                            
    LOG(2, "u1Backlight         %d\n", pPictureSetting->u1Backlight);                                 
    LOG(2, "u1Contrast          %d\n", pPictureSetting->u1Contrast);                                  
    LOG(2, "u1Brightness        %d\n", pPictureSetting->u1Brightness);                                
    LOG(2, "u1Color             %d\n", pPictureSetting->u1Color);                                     
    LOG(2, "u1Hue               %d\n", pPictureSetting->u1Hue);                                       
    LOG(2, "u1Sharpness         %d\n", pPictureSetting->u1Sharpness);                                 
    LOG(2, "eColTmp             %d\n", pPictureSetting->eColTmp);                             
    LOG(2, "eNoiseReduction     %d\n", pPictureSetting->eNoiseReduction);             
    LOG(2, "eMpegNoiseReduction %d\n", pPictureSetting->eMpegNoiseReduction);     
	LOG(2, "eRealityCreation	%d\n", pPictureSetting->eRealityCreation);                                 
    LOG(2, "eMasteredIn4K       %d\n", pPictureSetting->eMasteredIn4K);                             
    LOG(2, "i2Resolution	     %d\n", pPictureSetting->i2Resolution);             
    LOG(2, "i2NoiseFiltering	 %d\n", pPictureSetting->i2NoiseFiltering);  
    LOG(2, "eMotionFlow         %d\n", pPictureSetting->eMotionFlow);                     
	LOG(2, "i2MotionFlowSmoothness	     %d\n", pPictureSetting->i2MotionFlowSmoothness);             
    LOG(2, "i2MotionFlowClearness	 %d\n", pPictureSetting->i2MotionFlowClearness);  
    LOG(2, "eFilmMode           %d\n", pPictureSetting->eFilmMode);                       
    LOG(2, "eAdvContrastEnhancer    %d\n", pPictureSetting->eAdvContrastEnhancer);
    LOG(2, "eBlackCorrector     %d\n", pPictureSetting->eBlackCorrector);             
    LOG(2, "i2Gamma             %d\n", pPictureSetting->i2Gamma);    
	LOG(2, "eLedDynamicCtrl     %d\n", pPictureSetting->eLedDynamicCtrl); 
    LOG(2, "eLiveColor          %d\n", pPictureSetting->eLiveColor);                      
    LOG(2, "i2RGain			    %d\n", pPictureSetting->i2RGain);     
	LOG(2, "i2GGain			    %d\n", pPictureSetting->i2GGain);   
	LOG(2, "i2RGain			    %d\n", pPictureSetting->i2BGain);   
	LOG(2, "i2RBias			    %d\n", pPictureSetting->i2RBias);   
	LOG(2, "i2GBias			    %d\n", pPictureSetting->i2GBias);   
	LOG(2, "i2BBias			    %d\n", pPictureSetting->i2BBias);   
    LOG(2, "eSpeedPreference    %d\n", pPictureSetting->eSpeedPreference);   
	LOG(2, "eLedMotionMode   	%d\n", pPictureSetting->eLedMotionMode);
	LOG(2, "eXdr			    %d\n", pPictureSetting->eXdr);   
    LOG(2, "eDrange    			%d\n", pPictureSetting->eDrange);   
	LOG(2, "eColorSpace   	%d\n", pPictureSetting->eColorSpace);
    #endif
}

static void DEBUG_GetScreenSetting(CUST_SCREEN_SETTING_T* pScreenSetting)
{
    #if MAPLE_AP_DEBUG
    LOG(2, "====== DRVCUST_GetPictureSetting ======\n"); 
    LOG(2, "eWideMode            %d\n", pScreenSetting->eWideMode);   
	LOG(2, "eDisplayArea            %d\n", pScreenSetting->eDisplayArea);   
	LOG(2, "i2HCenter            %d\n", pScreenSetting->i2HCenter);   
	LOG(2, "i2VCenter            %d\n", pScreenSetting->i2VCenter);   
	LOG(2, "i2VerticalSize            %d\n", pScreenSetting->i2VerticalSize);   
	LOG(2, "eZoom            %d\n", pScreenSetting->eZoom);   
	LOG(2, "ePcWIdeMode            %d\n", pScreenSetting->ePcWIdeMode);   
	LOG(2, "i2PcPhase            %d\n", pScreenSetting->i2PcPhase);   
	LOG(2, "i2PcPitch            %d\n", pScreenSetting->i2PcPitch);   
	LOG(2, "i2PcHCenter            %d\n", pScreenSetting->i2PcHCenter);   
	LOG(2, "i2PcVCenter            %d\n", pScreenSetting->i2PcVCenter);   

    #endif
}

static void DEBUG_Get3DSetting(CUST_3D_SETTING_T* p3DSetting)
{
    #if MAPLE_AP_DEBUG
    LOG(2, "====== DEBUG_Get3DSetting ======\n"); 
    LOG(2, "e3dDisplay            %d\n", p3DSetting->e3dDisplay);   
	LOG(2, "i23dDepthAdjustment            %d\n", p3DSetting->i23dDepthAdjustment);   
	LOG(2, "e3dGlassBrightness            %d\n", p3DSetting->e3dGlassBrightness);   
    #endif
}

static void DEBUG_GetECOSetting(CUST_ECO_SETTING_T* pEcoSetting)
{
    #if MAPLE_AP_DEBUG
    LOG(2, "====== DEBUG_GetECOSetting ======\n"); 
    LOG(2, "ePowerSaving            %d\n", pEcoSetting->ePowerSaving);   
	LOG(2, "eLightSensor            %d\n", pEcoSetting->eLightSensor);   
    #endif
}

static void DEBUG_GetDemoModeSetting(CUST_DEMO_MODE_T* pDemoMode)
{
    #if MAPLE_AP_DEBUG
    LOG(2, "====== DEBUG_GetDemoModeSetting ======\n"); 
    LOG(2, "eDemoMode            %d\n", pDemoMode->eDemoMode);   
	LOG(2, "eDemoPattern            %d\n", pDemoMode->eDemoPattern);   
	LOG(2, "u4DemoOption            %d\n", pDemoMode->u4DemoOption);   
    #endif
}

static void DEBUG_GetDemoOSDMaskSetting(CUST_DEMO_OSD_MASK_T* pOsdMask)
{
    #if MAPLE_AP_DEBUG
	UINT32 i;
	
    LOG(2, "====== DEBUG_GetDemoOSDMaskSetting ======\n"); 
    LOG(2, "u1Num            %d\n", pOsdMask->u1Num);
	for(i = 0; i < 7; i++)
	{
		LOG(2, "rectArea[%d] u2X           %d\n", i, pOsdMask->rectArea[i].u2X);  
		LOG(2, "rectArea[%d] u2Y           %d\n", i, pOsdMask->rectArea[i].u2Y); 
		LOG(2, "rectArea[%d] u2Width       %d\n", i, pOsdMask->rectArea[i].u2Width); 
		LOG(2, "rectArea[%d] u2Height      %d\n", i, pOsdMask->rectArea[i].u2Height); 
	}
	LOG(2, "b4KCoordinate            %d\n", pOsdMask->b4KCoordinate);   
    #endif
}

static void DEBUG_GetWBOffsetSetting(CUST_WB_OFFSET_T* pWbOffset)
{
    #if MAPLE_AP_DEBUG
    LOG(2, "====== DEBUG_GetWBOffsetSetting ======\n"); 
    LOG(2, "i2ROffset1            %d\n", pWbOffset->i2ROffset1);
	LOG(2, "i2ROffset2            %d\n", pWbOffset->i2ROffset2);
	LOG(2, "i2ROffset3            %d\n", pWbOffset->i2ROffset3);
	LOG(2, "i2ROffset4            %d\n", pWbOffset->i2ROffset4);
	LOG(2, "i2ROffset5            %d\n", pWbOffset->i2ROffset5);
	LOG(2, "i2ROffset6            %d\n", pWbOffset->i2ROffset6);
	LOG(2, "i2ROffset7            %d\n", pWbOffset->i2ROffset7);
	LOG(2, "i2ROffset8            %d\n", pWbOffset->i2ROffset8);
	LOG(2, "i2ROffset9            %d\n", pWbOffset->i2ROffset9);
	LOG(2, "i2ROffset10            %d\n", pWbOffset->i2ROffset10);
	LOG(2, "i2GOffset1            %d\n", pWbOffset->i2GOffset1);
	LOG(2, "i2GOffset2            %d\n", pWbOffset->i2GOffset2);
	LOG(2, "i2GOffset3            %d\n", pWbOffset->i2GOffset3);
	LOG(2, "i2GOffset4            %d\n", pWbOffset->i2GOffset4);
	LOG(2, "i2GOffset5            %d\n", pWbOffset->i2GOffset5);
	LOG(2, "i2GOffset6            %d\n", pWbOffset->i2GOffset6);
	LOG(2, "i2GOffset7            %d\n", pWbOffset->i2GOffset7);
	LOG(2, "i2GOffset8            %d\n", pWbOffset->i2GOffset8);
	LOG(2, "i2GOffset9            %d\n", pWbOffset->i2GOffset9);
	LOG(2, "i2GOffset10            %d\n", pWbOffset->i2GOffset10);
	LOG(2, "i2BOffset1            %d\n", pWbOffset->i2BOffset1);
	LOG(2, "i2BOffset2            %d\n", pWbOffset->i2BOffset2);
	LOG(2, "i2BOffset3            %d\n", pWbOffset->i2BOffset3);
	LOG(2, "i2BOffset4            %d\n", pWbOffset->i2BOffset4);
	LOG(2, "i2BOffset5            %d\n", pWbOffset->i2BOffset5);
	LOG(2, "i2BOffset6            %d\n", pWbOffset->i2BOffset6);
	LOG(2, "i2BOffset7            %d\n", pWbOffset->i2BOffset7);
	LOG(2, "i2BOffset8            %d\n", pWbOffset->i2BOffset8);
	LOG(2, "i2BOffset9            %d\n", pWbOffset->i2BOffset9);
	LOG(2, "i2BOffset10            %d\n", pWbOffset->i2BOffset10);
    #endif
}

static void DEBUG_GetServiceSetting(CUST_SERVICE_SETTING_T* pServiceSetting)
{
    #if MAPLE_AP_DEBUG
    LOG(2, "====== DEBUG_GetServiceSetting ======\n"); 
    LOG(2, "u2RGain            %d\n", pServiceSetting->u2RGain);
	LOG(2, "u2GGain            %d\n", pServiceSetting->u2GGain);
	LOG(2, "u2BGain            %d\n", pServiceSetting->u2BGain);
	LOG(2, "u2ROffset            %d\n", pServiceSetting->u2ROffset);
	LOG(2, "u2GOffset            %d\n", pServiceSetting->u2GOffset);
	LOG(2, "u2BOffset            %d\n", pServiceSetting->u2BOffset);
    #endif
}


////////////////////////////////////////////////////////////////////////////////
void DRVCUST_GetPictureSetting(CUST_PIC_SETTING_T* pPictureSetting)
{
    INT16 i2Cur;

	BEPQ_AP_Get_Pic_Setting(pPictureSetting);

	switch((D_AP_PIC_MODE)DRVCUST_GetUISmartPicId())
    {
        case D_AP_PIC_MODE_VIVID:
            pPictureSetting->ePicMode = E_CUST_PIC_MODE_VIVID;
            break;
		case D_AP_PIC_MODE_STANDARD:
            pPictureSetting->ePicMode = E_CUST_PIC_MODE_STANDARD;
            break;
		case D_AP_PIC_MODE_CUSTOM:
            pPictureSetting->ePicMode = E_CUST_PIC_MODE_CUSTOM;
            break;
		case D_AP_PIC_MODE_CINEMA_PRO:
            pPictureSetting->ePicMode = E_CUST_PIC_MODE_CINEMA1;
            break;
		case D_AP_PIC_MODE_CINEMA_HOME:
            pPictureSetting->ePicMode = E_CUST_PIC_MODE_CINEMA2;
            break;
		case D_AP_PIC_MODE_SPORTS:
            pPictureSetting->ePicMode = E_CUST_PIC_MODE_SPORTS;
            break;
		case D_AP_PIC_MODE_ANIMATION:
            pPictureSetting->ePicMode = E_CUST_PIC_MODE_ANIME;
            break;
		case D_AP_PIC_MODE_PHOTO_VIVID:
            pPictureSetting->ePicMode = E_CUST_PIC_MODE_PHOTO_VIVID;
            break;
		case D_AP_PIC_MODE_PHOTO_STD:
            pPictureSetting->ePicMode = E_CUST_PIC_MODE_PHOTO_STD;
            break;
		case D_AP_PIC_MODE_PHOTO_CUST:
            pPictureSetting->ePicMode = E_CUST_PIC_MODE_PHOTO_CUST;
            break;
		case D_AP_PIC_MODE_GAME:
            pPictureSetting->ePicMode = E_CUST_PIC_MODE_GAME_STD;
            break;
		case D_AP_PIC_MODE_GRAPHICS:
            pPictureSetting->ePicMode = E_CUST_PIC_MODE_GRAPHICS;
            break;
		case D_AP_PIC_MODE_RESERVE1:
			pPictureSetting->ePicMode = E_CUST_PIC_MODE_RESERVE1;
            break;
		default:
            pPictureSetting->ePicMode = E_CUST_PIC_MODE_VIVID;
            break;
    }
	

    pPictureSetting->u1Backlight = stBLight.ui1BacklightLevel;    // d interface ??   
    
    PE_GetArg(0, PE_ARG_CONTRAST, &i2Cur);
    pPictureSetting->u1Contrast = (UINT8)i2Cur;   
    
    PE_GetArg(0, PE_ARG_BRIGHTNESS, &i2Cur);
    pPictureSetting->u1Brightness = (UINT8)i2Cur; 
    
    PE_GetArg(0, PE_ARG_SATURATION, &i2Cur);
    pPictureSetting->u1Color = (UINT8)i2Cur;  
    
    PE_GetArg(0, PE_ARG_HUE, &i2Cur);
    pPictureSetting->u1Hue = (UINT8)i2Cur;    
    
    PE_GetArg(0, PE_ARG_SHARPNESS, &i2Cur);    
    pPictureSetting->u1Sharpness = (UINT8)i2Cur;   
    
	switch((D_AP_PIC_COL_TMP)stCTInfo.ui1CTIndex)
    {
        case D_AP_PIC_COL_TMP_COOL:
            pPictureSetting->eColTmp = E_CUST_COL_TMP_COOL;
            break;
		case D_AP_PIC_COL_TMP_NATURAL:
            pPictureSetting->eColTmp = E_CUST_COL_TMP_NATURAL;
            break;
		case D_AP_PIC_COL_TMP_WARM:
            pPictureSetting->eColTmp = E_CUST_COL_TMP_WARM1;
            break;
		case D_AP_PIC_COL_TMP_EXPERT1:
            pPictureSetting->eColTmp = E_CUST_COL_TMP_EXPERT1;
            break;
		case D_AP_PIC_COL_TMP_EXPERT2:
		default:
            pPictureSetting->eColTmp = E_CUST_COL_TMP_EXPERT2;
            break;
    }
        
    PE_GetArg(0, PE_ARG_3D_NR, &i2Cur);
	switch((D_AP_PIC_NOISE_REDUCTION)i2Cur)
    {
        case D_AP_PIC_NOISE_REDUCTION_OFF:
            pPictureSetting->eNoiseReduction = E_CUST_NOISE_REDUCTION_OFF;
            break;
		case D_AP_PIC_NOISE_REDUCTION_LOW:
            pPictureSetting->eNoiseReduction = E_CUST_NOISE_REDUCTION_LOW;
            break;
		case D_AP_PIC_NOISE_REDUCTION_MID:
            pPictureSetting->eNoiseReduction = E_CUST_NOISE_REDUCTION_MID;
            break;
		case D_AP_PIC_NOISE_REDUCTION_HIGH:
            pPictureSetting->eNoiseReduction = E_CUST_NOISE_REDUCTION_HIGH;
            break;
		case D_AP_PIC_NOISE_REDUCTION_AUTO:
		default:
            pPictureSetting->eNoiseReduction = E_CUST_NOISE_REDUCTION_AUTO;
            break;
    }

    PE_GetArg(0, PE_ARG_MPEG_NR, &i2Cur);
	switch((D_AP_PIC_MPEG_NOISE_REDUCTION)i2Cur)
    {
        case D_AP_PIC_MPEG_NOISE_REDUCTION_OFF:
            pPictureSetting->eMpegNoiseReduction = E_CUST_MPEG_NOISE_REDUCTION_OFF;
            break;
		case D_AP_PIC_MPEG_NOISE_REDUCTION_LOW:
            pPictureSetting->eMpegNoiseReduction = E_CUST_MPEG_NOISE_REDUCTION_LOW;
            break;
		case D_AP_PIC_MPEG_NOISE_REDUCTION_MID:
            pPictureSetting->eMpegNoiseReduction = E_CUST_MPEG_NOISE_REDUCTION_MID;
            break;
		case D_AP_PIC_MPEG_NOISE_REDUCTION_HIGH:
            pPictureSetting->eMpegNoiseReduction = E_CUST_MPEG_NOISE_REDUCTION_HIGH;
            break;
		case D_AP_PIC_MPEG_NOISE_REDUCTION_AUTO:
		default:
            pPictureSetting->eMpegNoiseReduction = E_CUST_MPEG_NOISE_REDUCTION_AUTO;
            break;
    }

	//pPictureSetting->eRealityCreation = 0; //TBD
	//pPictureSetting->eMasteredIn4K = 0; //TBD
	//pPictureSetting->i2Resolution = 0; //TBD
	pPictureSetting->i2NoiseFiltering = 0; //TBD

	//pPictureSetting->eMotionFlow =0;

	//pPictureSetting->i2MotionFlowSmoothness = 0; //TBD

	//pPictureSetting->i2MotionFlowClearness = 0; //TBD

	//pPictureSetting->eFilmMode = 0; 


    PE_GetArg(0, PE_ARG_ADAPTIVE_LUMA, &i2Cur);  
	switch((D_AP_PIC_ADV_CONTRAST_ENHANCER)i2Cur)
    {
        case D_AP_PIC_ADV_CONTRAST_ENHANCER_OFF:
            pPictureSetting->eAdvContrastEnhancer = E_CUST_ADV_CONTRAST_ENHANCER_OFF;
            break;
		case D_AP_PIC_ADV_CONTRAST_ENHANCER_LOW:
            pPictureSetting->eAdvContrastEnhancer = E_CUST_ADV_CONTRAST_ENHANCER_LOW;
            break;
		case D_AP_PIC_ADV_CONTRAST_ENHANCER_MID:
            pPictureSetting->eAdvContrastEnhancer = E_CUST_ADV_CONTRAST_ENHANCER_MID;
            break;
		case D_AP_PIC_ADV_CONTRAST_ENHANCER_HIGH:
		default:
            pPictureSetting->eAdvContrastEnhancer = E_CUST_ADV_CONTRAST_ENHANCER_HIGH;
            break;
    }
    PE_GetArg(0, PE_ARG_BLACK_STRETCH, &i2Cur);
	switch((D_AP_PIC_BLACK_CORRECTOR)i2Cur)
    {
        case D_AP_PIC_BLACK_CORRECTOR_OFF:
            pPictureSetting->eBlackCorrector = E_CUST_BLACK_CORRECTOR_OFF;
            break;
		case D_AP_PIC_BLACK_CORRECTOR_LOW:
            pPictureSetting->eBlackCorrector = E_CUST_BLACK_CORRECTOR_LOW;
            break;
		case D_AP_PIC_BLACK_CORRECTOR_MID:
            pPictureSetting->eBlackCorrector = E_CUST_BLACK_CORRECTOR_MID;
            break;
		case D_AP_PIC_BLACK_CORRECTOR_HIGH:
		default:
            pPictureSetting->eBlackCorrector = E_CUST_BLACK_CORRECTOR_HIGH;
            break;
    }
  
    pPictureSetting->i2Gamma = (INT16)bi1GammaOfst;

	//pPictureSetting->eLedDynamicCtrl = 0; //TBD

    PE_GetArg(0, PE_ARG_SCE, &i2Cur);
	switch((D_AP_PIC_LIVE_COLOR)i2Cur)
    {
        case D_AP_PIC_LIVE_COLOR_OFF:
            pPictureSetting->eLiveColor = E_CUST_LIVE_COLOR_OFF;
            break;
		case D_AP_PIC_LIVE_COLOR_LOW:
            pPictureSetting->eLiveColor = E_CUST_LIVE_COLOR_LOW;
            break;
		case D_AP_PIC_LIVE_COLOR_MID:
            pPictureSetting->eLiveColor = E_CUST_LIVE_COLOR_MID;
            break;
		case D_AP_PIC_LIVE_COLOR_HIGH:
		default:
            pPictureSetting->eLiveColor = E_CUST_LIVE_COLOR_HIGH;
            break;
    }

	//pPictureSetting->i2RGain = 0; //TBD

	//pPictureSetting->i2GGain = 0; //TBD

	//pPictureSetting->i2BGain = 0; //TBD
    
	//pPictureSetting->i2RBias = 0; //TBD

	//pPictureSetting->i2GBias = 0; //TBD

	//pPictureSetting->i2BBias = 0; //TBD

    pPictureSetting->eSpeedPreference = 0;

	pPictureSetting->eLedMotionMode = (E_CUST_LED_MOTION_MODE)DRVCUST_GetLEDMotionFlag();

	//pPictureSetting->eXdr = 0; //TBD

	//pPictureSetting->eDrange= 0; //TBD

	//pPictureSetting->eColorSpace= 0; //TBD

}

void DRVCUST_GetScreenSetting(CUST_SCREEN_SETTING_T* pScreenSetting)
{
	BEPQ_AP_Get_WideMode_Setting(pScreenSetting);
}

void DRVCUST_Get3DSetting(CUST_3D_SETTING_T* p3dSetting)
{  
	BEPQ_AP_Get_3D_Setting(p3dSetting);
}

void DRVCUST_GetEcoSetting(CUST_ECO_SETTING_T* pEcoSetting)
{
    pEcoSetting->ePowerSaving = stBLight.ui1PowerSavingMode;     
    pEcoSetting->eLightSensor = stBLight.ui1LightSensorOnOff;    
}

void DRVCUST_GetPhotoSetting(CUST_PHOTO_SETTING_T* pPhotoSetting)
{
    // TBD
}

void DRVCUST_GetDemoMode(CUST_DEMO_MODE_T* pDemoMode)
{
    BESYS_AP_Get_Demo_Mode(pDemoMode);
}

void DRVCUST_GetDemoOsdMaskArea(CUST_DEMO_OSD_MASK_T* pOsdMask)
{
    BESYS_AP_Get_Demo_OSD_Mask(pOsdMask);
}


void DRVCUST_GetServiceSetting(CUST_SERVICE_SETTING_T* pServiceSetting)
{
	
	if(gServiceInit)
	{
		BEPQ_AP_Get_CustService_Setting(pServiceSetting);
	}
	else
	{
		pServiceSetting->u2RGain = (DRVCUST_EepromReadByte(0x6A1) << 8) + DRVCUST_EepromReadByte(0x6A0);
		pServiceSetting->u2GGain = (DRVCUST_EepromReadByte(0x6AB) << 8) + DRVCUST_EepromReadByte(0x6AA);
		pServiceSetting->u2BGain = (DRVCUST_EepromReadByte(0x6B5) << 8) + DRVCUST_EepromReadByte(0x6B4);
		pServiceSetting->u2ROffset= (DRVCUST_EepromReadByte(0x681) << 8) + DRVCUST_EepromReadByte(0x680);
		pServiceSetting->u2GOffset= (DRVCUST_EepromReadByte(0x68B) << 8) + DRVCUST_EepromReadByte(0x68A);
		pServiceSetting->u2BOffset= (DRVCUST_EepromReadByte(0x695) << 8) + DRVCUST_EepromReadByte(0x694);
	}
}

void DRVCUST_GetServiceTransferSetting(CUST_SERVICE_TRANS_T* pServiceTrans)
{
    BESYS_AP_Get_Service_Trans(pServiceTrans);
}

void DRVCUST_GetServiceVcomAdjust(CUST_SERVICE_VCOM_T* pServiceVcom)
{
    BESYS_AP_Get_Service_VCom(pServiceVcom);
}

E_CUST_UI_INPUT_TARGET DRVCUST_GetUiInputTarget(void)
{
    D_AP_INPUT_TYPE eType = BEPQ_AP_Get_Input_Type(SV_VP_MAIN);

    #if MAPLE_SYS_DEBUG    
    LOG(2, "====== DRVCUST_GetUiInputTarget ======\n"); 
    LOG(2, "InputType()        %d\n", eType); 
    #endif

	switch (eType)
    {
        case D_AP_INPUT_TYPE_A_RF:
        case D_AP_INPUT_TYPE_D_RF:	
		case D_AP_INPUT_TYPE_COMPOSITE:
		case D_AP_INPUT_TYPE_COMPONENT:
		case D_AP_INPUT_TYPE_SCART:
		case D_AP_INPUT_TYPE_A_PC:
		case D_AP_INPUT_TYPE_HDMI:
			return E_CUST_UI_INPUT_TARGET_DEFAULT;
			
		case D_AP_INPUT_TYPE_APPLICATION:
			return E_CUST_UI_INPUT_TARGET_VIDEO_APP;
			
		case D_AP_INPUT_TYPE_SONY_PHOTO_APP:
			return E_CUST_UI_INPUT_TARGET_PHOTO_APP;
			
		case D_AP_INPUT_TYPE_JELLY_FISH:
			return E_CUST_UI_INPUT_TARGET_GAME_APP;
			
		case D_AP_INPUT_TYPE_SKYPE:
			return E_CUST_UI_INPUT_TARGET_VIDEO_CHAT;
			
		case D_AP_INPUT_TYPE_MIRACAST:
			return E_CUST_UI_INPUT_TARGET_WIFI_DISPLAY;

		case D_AP_INPUT_TYPE_GENERAL_APP:
			return E_CUST_UI_INPUT_TARGET_GEN_APP;
		case D_AP_INPUT_TYPE_RESERVE_1: // Netflix
			return E_CUST_UI_INPUT_TARGET_OTT1;
        default:        
            return E_CUST_UI_INPUT_TARGET_UNKNOWN;
    }
}

void DRVCUST_GetWhiteBalanceOffset(CUST_WB_OFFSET_T* pWbOffset)
{
    pWbOffset->i2ROffset1= i2WB10PUIValue[0][1];
	pWbOffset->i2ROffset2= i2WB10PUIValue[0][2];
	pWbOffset->i2ROffset3= i2WB10PUIValue[0][3];
	pWbOffset->i2ROffset4= i2WB10PUIValue[0][4];
	pWbOffset->i2ROffset5= i2WB10PUIValue[0][5];
	pWbOffset->i2ROffset6= i2WB10PUIValue[0][6];
	pWbOffset->i2ROffset7= i2WB10PUIValue[0][7];
	pWbOffset->i2ROffset8= i2WB10PUIValue[0][8];
	pWbOffset->i2ROffset9= i2WB10PUIValue[0][9];
	pWbOffset->i2ROffset10= i2WB10PUIValue[0][10];
	pWbOffset->i2GOffset1= i2WB10PUIValue[1][1];
	pWbOffset->i2GOffset2= i2WB10PUIValue[1][2];
	pWbOffset->i2GOffset3= i2WB10PUIValue[1][3];
	pWbOffset->i2GOffset4= i2WB10PUIValue[1][4];
	pWbOffset->i2GOffset5= i2WB10PUIValue[1][5];
	pWbOffset->i2GOffset6= i2WB10PUIValue[1][6];
	pWbOffset->i2GOffset7= i2WB10PUIValue[1][7];
	pWbOffset->i2GOffset8= i2WB10PUIValue[1][8];
	pWbOffset->i2GOffset9= i2WB10PUIValue[1][9];
	pWbOffset->i2GOffset10= i2WB10PUIValue[1][10];
	pWbOffset->i2BOffset1= i2WB10PUIValue[2][1];
	pWbOffset->i2BOffset2= i2WB10PUIValue[2][2];
	pWbOffset->i2BOffset3= i2WB10PUIValue[2][3];
	pWbOffset->i2BOffset4= i2WB10PUIValue[2][4];
	pWbOffset->i2BOffset5= i2WB10PUIValue[2][5];
	pWbOffset->i2BOffset6= i2WB10PUIValue[2][6];
	pWbOffset->i2BOffset7= i2WB10PUIValue[2][7];
	pWbOffset->i2BOffset8= i2WB10PUIValue[2][8];
	pWbOffset->i2BOffset9= i2WB10PUIValue[2][9];
	pWbOffset->i2BOffset10= i2WB10PUIValue[2][10];

	//DEBUG_GetWBOffsetSetting(pWbOffset);
	
}

void DRVCUST_GetBTSetting(CUST_BT_SETTING_T* pBtSetting)
{
    pBtSetting->eDelayMode = gBTDelay;
}

