1 //<MStar Software>
2 //******************************************************************************
3 // MStar Software
4 // Copyright (c) 2010 - 2012 MStar Semiconductor, Inc. All rights reserved.
5 // All software, firmware and related documentation herein ("MStar Software") are
6 // intellectual property of MStar Semiconductor, Inc. ("MStar") and protected by
7 // law, including, but not limited to, copyright law and international treaties.
8 // Any use, modification, reproduction, retransmission, or republication of all
9 // or part of MStar Software is expressly prohibited, unless prior written
10 // permission has been granted by MStar.
11 //
12 // By accessing, browsing and/or using MStar Software, you acknowledge that you
13 // have read, understood, and agree, to be bound by below terms ("Terms") and to
14 // comply with all applicable laws and regulations:
15 //
16 // 1. MStar shall retain any and all right, ownership and interest to MStar
17 // Software and any modification/derivatives thereof.
18 // No right, ownership, or interest to MStar Software and any
19 // modification/derivatives thereof is transferred to you under Terms.
20 //
21 // 2. You understand that MStar Software might include, incorporate or be
22 // supplied together with third party`s software and the use of MStar
23 // Software may require additional licenses from third parties.
24 // Therefore, you hereby agree it is your sole responsibility to separately
25 // obtain any and all third party right and license necessary for your use of
26 // such third party`s software.
27 //
28 // 3. MStar Software and any modification/derivatives thereof shall be deemed as
29 // MStar`s confidential information and you agree to keep MStar`s
30 // confidential information in strictest confidence and not disclose to any
31 // third party.
32 //
33 // 4. MStar Software is provided on an "AS IS" basis without warranties of any
34 // kind. Any warranties are hereby expressly disclaimed by MStar, including
35 // without limitation, any warranties of merchantability, non-infringement of
36 // intellectual property rights, fitness for a particular purpose, error free
37 // and in conformity with any international standard. You agree to waive any
38 // claim against MStar for any loss, damage, cost or expense that you may
39 // incur related to your use of MStar Software.
40 // In no event shall MStar be liable for any direct, indirect, incidental or
41 // consequential damages, including without limitation, lost of profit or
42 // revenues, lost or damage of data, and unauthorized system use.
43 // You agree that this Section 4 shall still apply without being affected
44 // even if MStar Software has been modified by MStar in accordance with your
45 // request or instruction for your use, except otherwise agreed by both
46 // parties in writing.
47 //
48 // 5. If requested, MStar may from time to time provide technical supports or
49 // services in relation with MStar Software to you for your use of
50 // MStar Software in conjunction with your or your customer`s product
51 // ("Services").
52 // You understand and agree that, except otherwise agreed by both parties in
53 // writing, Services are provided on an "AS IS" basis and the warranty
54 // disclaimer set forth in Section 4 above shall apply.
55 //
56 // 6. Nothing contained herein shall be construed as by implication, estoppels
57 // or otherwise:
58 // (a) conferring any license or right to use MStar name, trademark, service
59 // mark, symbol or any other identification;
60 // (b) obligating MStar or any of its affiliates to furnish any person,
61 // including without limitation, you and your customers, any assistance
62 // of any kind whatsoever, or any information; or
63 // (c) conferring any license or right under any intellectual property right.
64 //
65 // 7. These terms shall be governed by and construed in accordance with the laws
66 // of Taiwan, R.O.C., excluding its conflict of law rules.
67 // Any and all dispute arising out hereof or related hereto shall be finally
68 // settled by arbitration referred to the Chinese Arbitration Association,
69 // Taipei in accordance with the ROC Arbitration Law and the Arbitration
70 // Rules of the Association by three (3) arbitrators appointed in accordance
71 // with the said Rules.
72 // The place of arbitration shall be in Taipei, Taiwan and the language shall
73 // be English.
74 // The arbitration award shall be final and binding to both parties.
75 //
76 //******************************************************************************
77 //<MStar Software>
78 ////////////////////////////////////////////////////////////////////////////////
79 //
80 // Copyright (c) 2006-2007 MStar Semiconductor, Inc.
81 // All rights reserved.
82 //
83 // Unless otherwise stipulated in writing, any and all information contained
84 // herein regardless in any format shall remain the sole proprietary of
85 // MStar Semiconductor Inc. and be kept in strict confidence
86 // ("MStar Confidential Information") by the recipient.
87 // Any unauthorized act including without limitation unauthorized disclosure,
88 // copying, use, reproduction, sale, distribution, modification, disassembling,
89 // reverse engineering and compiling of the contents of MStar Confidential
90 // Information is unlawful and strictly prohibited. MStar hereby reserves the
91 // rights to any and all damages, losses, costs and expenses resulting therefrom.
92 //
93 /// file drv_ACE.c
94 /// @brief Driver Interface
95 /// @author MStar Semiconductor Inc.
96 ///////////////////////////////////////////////////////////////////////////////////////////////////
97
98
99 #define _MDRV_DLC_C_
100 #ifdef MSOS_TYPE_LINUX_KERNEL
101 #include <linux/kernel.h>
102 #include <linux/string.h>
103 #include <linux/slab.h>
104 #include <linux/uaccess.h>
105 #include <linux/compat.h>
106 #include "MsTypes.h"
107 #include "utopia.h"
108 #else
109 #include <string.h>
110 #endif
111 #include "MsCommon.h"
112 #include "mhal_dlc.h"
113 #include "drvDLC.h"
114 #include "drvDLC_Cus.h"
115 #include "drvDBC_Cus.h"
116
117 #ifdef MSOS_TYPE_LINUX
118 #include <sys/ioctl.h>
119 #include <unistd.h>
120 #include <fcntl.h> // O_RDWR
121 #if !(defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2))
122 #include "../../../graphic/drv/gop/mdrv_gflip_io.h"
123 #endif
124
125 #elif defined(MSOS_TYPE_LINUX_KERNEL)
126
127 #if !(defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2))
128 #include "../../../graphic/drv/gop/mdrv_gflip_io.h"
129 #endif
130
131 #endif
132
133 #include "../../../xc/drv/xc/mdrv_xc_st.h"
134 #include "../../../xc/drv/xc/mdrv_xc_io.h"
135
136 #include "UFO.h"
137
138 #define DLC_DEBUG(x) //(x)
139 #define DLC_PRINT(fmt, args...) printf("[Dlc (Driver)][%05d] " fmt, __LINE__, ## args)
140
141 #define EN_DLC_METHOD_AVERAGELUMA 0x10
142
143 #define DLC_DEFLICK_BLEND_FACTOR 32UL
144 #define DLC_DEFLICK_PRECISION_SHIFT 64UL
145 #define DLC_AVERAGELUMA_HISTORGRAM_FACTOR 32UL
146
147 extern MS_S32 _DLC_Mutex;
148
149 #if(ENABLE_AVERAGELUMA)
150 static MS_U16 gu16AverageLuma_Delta;
151 static MS_U16 gu16AverageLuma_boundary_L;
152 static MS_U16 gu16AverageLuma_boundary_ML;
153 static MS_U16 gu16AverageLuma_boundary_MH;
154 static MS_U16 gu16AverageLuma_boundary_H;
155 static MS_U16 gu16LumaSum;
156 static MS_U16 gu16PreLumaSum;
157 static MS_U16 gu16PixelSum;
158 static MS_BOOL gbCGain_Ctrl;
159 static MS_U16 g_u16PreDLC_CGain;
160 static MS_U16 gu16FlickAlpha;
161 #endif
162
163 extern MS_U8 g_ucTable[16];
164 extern MS_U16 g_uwPreTable[16]; // New de-Flick
165 extern MS_U8 g_ucTmpAvgN_1; // Avg value (N-1)
166 extern MS_U8 g_ucTmpAvgN; // Avg value (current N)
167 //extern StuDlc_FinetuneParamaters_Lib g_DlcParameters;
168 extern StuDlc_FinetuneParamaters g_DlcParameters;
169 extern MS_U8 g_u8Chroma_OriGain;
170
171 #if(ENABLE_AVERAGELUMA)
172 static DLC_init_Ext gstDLCParamExt;
173 static MS_U16 g_u16TableExt[16];
174 static MS_U32 g_u32PreTableExt[16];
175 static MS_U16 g_u16SlowDonwStep = 0;
176 #endif
177 static MS_BOOL g_bSetDlcHandlerOn = TRUE;
178
179 #ifdef MSOS_TYPE_LINUX
180 extern MS_S32 s32FdDlcBle ;
181 #endif
182
183 ////////////////////////////////////////////////////////////////////////////////
184 //
185 // DLC library function start
186 //
187 ////////////////////////////////////////////////////////////////////////////////
188
189
190 MS_U8 DLC_VBuf[32] = {
191 'M','S','V','C','0','0', //0,0 fixed
192 'D','9', //LIB ID
193 '3','2', //Interface
194 '0','0','4','5', //Build number
195 '0','0','1','0','5','9','6','4', // Change List
196 'A','E','0','0','0','0','0','0','0', // AE:Saturn4LE 0: MStar Trunk
197 'T' // check sum
198 };
199
200 /******************************************************************************/
201 /* Function Prototypes */
202 /******************************************************************************/
203 ////////////////////////////////////////////////////////////////////////////////
204 /// @brief \b Function \b Name: MDrv_DLC_GetVersion()
205 /// @brief \b Function \b Description: Get version of DLC library
206 /// @param <IN> \b None
207 /// @param <OUT> \b None
208 /// @param <RET> \b Version
209 /// @param <GLOBAL> \b None
210 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_GetMFVer(void)211 MS_U16 MDrv_DLC_GetMFVer(void)
212 {
213 return msDlcLibVersionCheck();
214 }
215
216 ////////////////////////////////////////////////////////////////////////////////
217 /// @brief \b Function \b Name: MDrv_DLC_InitCurve()
218 /// @brief \b Function \b Description: Initiate DLC HW
219 /// @param <IN> \b wHStart
220 /// @param <IN> \b wHEnd
221 /// @param <IN> \b wVStart
222 /// @param <IN> \b wVEnd
223 /// @param <IN> \b dwCustomMode
224 /// @param <OUT> \b None
225 /// @param <RET> \b None
226 /// @param <GLOBAL> \b None
227 ////////////////////////////////////////////////////////////////////////////////
228 StuDbc_CAPTURE_Range g_DlcCapRange={0};
229
MDrv_DLC_InitCurve(MS_U16 u16HStart,MS_U16 u16HEnd,MS_U16 u16VStart,MS_U16 u16VEnd)230 void MDrv_DLC_InitCurve (MS_U16 u16HStart, MS_U16 u16HEnd, MS_U16 u16VStart, MS_U16 u16VEnd)
231 {
232 g_DlcCapRange.wHStart = u16HStart;
233 g_DlcCapRange.wHEnd= u16HEnd;
234 g_DlcCapRange.wVStart = u16VStart;
235 g_DlcCapRange.wVEnd= u16VEnd;
236
237 msDlcInitWithCurve(u16HStart, u16HEnd, u16VStart, u16VEnd);
238 }
239
240 ////////////////////////////////////////////////////////////////////////////////
241 /// @brief \b Function \b Name: MDrv_DLC_SetOnOff()
242 /// @brief \b Function \b Description: On/Off DLC function
243 /// @param <IN> \b bSwitch
244 /// @param <IN> \b bWindow
245 /// @param <OUT> \b None
246 /// @param <RET> \b None
247 /// @param <GLOBAL> \b None
248 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_SetOnOff(MS_BOOL bSwitch,MS_BOOL bWindow)249 void MDrv_DLC_SetOnOff(MS_BOOL bSwitch, MS_BOOL bWindow)
250 {
251 DLC_DEBUG(printf("MDrv_DLC_SetOnOff(): bSwitch: %x\n", bSwitch));
252
253 #if(ENABLE_AVERAGELUMA)
254 if( Hal_DLC_get_dlc_method() & EN_DLC_METHOD_AVERAGELUMA)
255 {
256 Hal_DLC_set_onoff(bWindow, bSwitch);
257 }
258 else
259 #endif
260 {
261 msDlcOnOff(bSwitch, bWindow);
262 }
263 }
264
265 //-------------------------------------------------------------------------------------------------
266 /// Enable/disable DLC to control MDrv_DLC_Handler .
267 /// @param bDlcEnable \b IN: # TRUE: DLC Enable # FALSE: DLC Disable
268 /// @return TRUE: DDI call success
269 /// @attention
270 /// <b>[MxLib] <em>Flip when vsync interrupt, and the DDI used for set dlc info to GFlip. </em></b>
271 //-------------------------------------------------------------------------------------------------
MDrv_DLC_SetDlcHandlerOnOff(MS_BOOL bSwitch)272 MS_BOOL MDrv_DLC_SetDlcHandlerOnOff(MS_BOOL bSwitch)
273 {
274 g_bSetDlcHandlerOn= bSwitch ;
275
276 #ifdef MSOS_TYPE_LINUX
277
278 if(0 > s32FdDlcBle)
279 {
280 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
281 s32FdDlcBle = open("/dev/scaler", O_RDWR);
282 #else
283 s32FdDlcBle = open("/dev/gflip", O_RDWR);
284 #endif
285
286 if(0 > s32FdDlcBle)
287 {
288 DLC_PRINT("DLC device not opened!!!!\n");
289 return FALSE;
290 }
291 }
292 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
293 if (ioctl(s32FdDlcBle, MDRV_XC_IOC_DLCONOFFINFO, &g_bSetDlcHandlerOn))
294 #else
295 if (ioctl(s32FdDlcBle, MDRV_GFLIP_IOC_DLCONOFFINFO, &g_bSetDlcHandlerOn))
296 #endif
297 {
298 DLC_PRINT("MDrv_DLC_SetDlcInfo fail!!!!\n");
299 return FALSE;
300 }
301
302 #endif
303 return TRUE;
304 }
305
306 //-------------------------------------------------------------------------------------------------
307 /// Enable/disable BLE control BLE function
308 /// @param bBleEnable \b IN: # TRUE: BLE Enable # FALSE: BLE Disable
309 /// @return TRUE: DDI call success
310 /// @attention
311 /// <b>[MxLib] <em>Flip when vsync interrupt, and the DDI used for set ble info to GFlip. </em></b>
312 //-------------------------------------------------------------------------------------------------
MDrv_DLC_SetBleOnOff(MS_BOOL bSwitch)313 MS_BOOL MDrv_DLC_SetBleOnOff(MS_BOOL bSwitch)
314 {
315 MS_BOOL g_bSetBleOn = TRUE;
316
317 msDlcSetBleOnOff(bSwitch);
318 g_bSetBleOn = bSwitch ;
319
320 #ifdef MSOS_TYPE_LINUX
321
322 if(0 > s32FdDlcBle)
323 {
324 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
325 s32FdDlcBle = open("/dev/scaler", O_RDWR);
326 #else
327 s32FdDlcBle = open("/dev/gflip", O_RDWR);
328 #endif
329
330 if(0 > s32FdDlcBle)
331 {
332 DLC_PRINT("BLE device not opened!!!!\n");
333 return FALSE;
334 }
335 }
336
337 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
338 if (ioctl(s32FdDlcBle, MDRV_XC_IOC_DLCBLEONOFFINFO, &g_bSetBleOn))
339 #else
340 if (ioctl(s32FdDlcBle, MDRV_GFLIP_IOC_BLEONOFFINFO, &g_bSetBleOn))
341 #endif
342 {
343 DLC_PRINT("MDrv_DLC_SetBleOnOff fail!!!!\n");
344 return FALSE;
345 }
346
347 #endif
348 return TRUE;
349 }
350
351 ////////////////////////////////////////////////////////////////////////////////
352 /// @brief \b Function \b Name: MDrv_DLC_EnableMainSubCurveSynchronization()
353 /// @brief \b Function \b Description: On/Off DLC Set Curve both for main and sub function
354 /// @param <IN> \b bEnable
355 /// @param <IN> \b None
356 /// @param <OUT> \b None
357 /// @param <RET> \b None
358 /// @param <GLOBAL> \b None
359 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_EnableMainSubCurveSynchronization(MS_BOOL bEnable)360 void MDrv_DLC_EnableMainSubCurveSynchronization(MS_BOOL bEnable)
361 {
362 msDlcEnableSetDLCCurveBoth(bEnable);
363 }
364
365 #if(ENABLE_AVERAGELUMA)
MDrv_DLC_Get_AverageLuma_Alpha(void)366 static MS_U16 MDrv_DLC_Get_AverageLuma_Alpha(void)
367 {
368 MS_U16 u16AvgDiff;
369 MS_U16 u16FlickAlpha;
370
371 u16AvgDiff = (gu16LumaSum >= gu16PreLumaSum) ?
372 gu16LumaSum - gu16PreLumaSum :
373 gu16PreLumaSum - gu16LumaSum;
374
375 u16FlickAlpha = (u16AvgDiff < gu16AverageLuma_Delta) ?
376 gu16FlickAlpha :
377 DLC_DEFLICK_BLEND_FACTOR;
378
379 return u16FlickAlpha;
380
381 }
382
383
MDrv_DLC_Set_SlowDwonStep(MS_BOOL bEn,MS_U8 u8Step)384 void MDrv_DLC_Set_SlowDwonStep(MS_BOOL bEn, MS_U8 u8Step)
385 {
386 if(bEn)
387 {
388 g_u16SlowDonwStep = u8Step;
389 }
390 else
391 {
392 g_u16SlowDonwStep = 0;
393 }
394 }
395
MDrv_DLC_AverateLuma_Handler_Ext(MS_BOOL bWindow)396 static void MDrv_DLC_AverateLuma_Handler_Ext(MS_BOOL bWindow)
397 {
398 MS_U16 u16FlickAlpha;
399 MS_U16 u16YAvg;
400 MS_U16 *pStaticCurveTbl_a, *pStaticCurveTbl_b;
401 MS_U16 u16Weight, u16Wegiht_Total;
402 MS_U8 i;
403 MS_U16 u16Step;
404
405 u16FlickAlpha = MDrv_DLC_Get_AverageLuma_Alpha();
406
407 if(u16FlickAlpha < 1)
408 u16FlickAlpha = 1;
409 if(u16FlickAlpha > DLC_DEFLICK_BLEND_FACTOR)
410 u16FlickAlpha = DLC_DEFLICK_BLEND_FACTOR;
411
412 if(gu16PixelSum != 0)
413 {
414 u16YAvg = (MS_U16)((256UL * (MS_U32)gu16LumaSum + (MS_U32)gu16PixelSum/2UL) / (MS_U32)gu16PixelSum);
415 }
416 else
417 {
418 u16YAvg = 0;
419 }
420
421 DLC_DEBUG(printf("FlickAlpha=%u, AvgLum=%u\n", u16FlickAlpha, u16YAvg));
422
423
424 if(u16YAvg <= gu16AverageLuma_boundary_L)
425 { // all dark
426 DLC_DEBUG(printf("All Dark\n"));
427 pStaticCurveTbl_a = &gstDLCParamExt.uwLumaCurve2_b[0];
428 pStaticCurveTbl_b = &gstDLCParamExt.uwLumaCurve2_b[0];
429 u16Wegiht_Total = gu16AverageLuma_boundary_L;
430 u16Weight = gu16AverageLuma_boundary_L;
431
432 }
433 else if(u16YAvg <= gu16AverageLuma_boundary_ML)
434 { // dark + normal
435 DLC_DEBUG(printf("dark + normal\n"));
436 pStaticCurveTbl_a = &gstDLCParamExt.uwLumaCurve2_b[0];
437 pStaticCurveTbl_b = &gstDLCParamExt.uwLumaCurve[0];
438 u16Wegiht_Total = gu16AverageLuma_boundary_ML - gu16AverageLuma_boundary_L;
439 u16Weight = gu16AverageLuma_boundary_ML - u16YAvg;
440
441 }
442 else if(u16YAvg <= gu16AverageLuma_boundary_MH)
443 { // all normal
444 DLC_DEBUG(printf("all normal\n"));
445 pStaticCurveTbl_a = &gstDLCParamExt.uwLumaCurve[0];
446 pStaticCurveTbl_b = &gstDLCParamExt.uwLumaCurve[0];
447 u16Wegiht_Total = gu16AverageLuma_boundary_MH - gu16AverageLuma_boundary_ML;
448 u16Weight = u16Wegiht_Total;
449
450 }
451 else if(u16YAvg <= gu16AverageLuma_boundary_H)
452 { // normal + light
453
454 DLC_DEBUG(printf("normal light \n"));
455 pStaticCurveTbl_a = &gstDLCParamExt.uwLumaCurve2_a[0];
456 pStaticCurveTbl_b = &gstDLCParamExt.uwLumaCurve[0];
457 u16Wegiht_Total = gu16AverageLuma_boundary_H - gu16AverageLuma_boundary_MH;
458 u16Weight = u16YAvg - gu16AverageLuma_boundary_MH;
459
460 }
461 else
462 { // all light
463
464 DLC_DEBUG(printf("all light\n"));
465 pStaticCurveTbl_a = &gstDLCParamExt.uwLumaCurve2_a[0];
466 pStaticCurveTbl_b = &gstDLCParamExt.uwLumaCurve2_a[0];
467 u16Wegiht_Total = gu16AverageLuma_boundary_H;
468 u16Weight = gu16AverageLuma_boundary_H;
469 }
470
471 DLC_DEBUG(printf("AverageLuma Target Curve\n"));
472 /* update luma curve */
473 for(i=0; i<16; i++)
474 {
475 if (u16Wegiht_Total == 0 )
476 {
477 return;
478 }
479
480 g_u16TableExt[i] = (MS_U16)((((MS_U32)(*pStaticCurveTbl_a) * (MS_U32) u16Weight) +
481 (MS_U32)(*pStaticCurveTbl_b) * (MS_U32)(u16Wegiht_Total - u16Weight)) / u16Wegiht_Total);
482 pStaticCurveTbl_a++;
483 pStaticCurveTbl_b++;
484
485 DLC_DEBUG(printf("%04x, ", g_u16TableExt[i]));
486 }
487 DLC_DEBUG(printf("\n"));
488
489
490 u16Step = (g_u16SlowDonwStep == 0) ? Hal_DLC_get_step() : g_u16SlowDonwStep;
491
492
493 DLC_DEBUG(printf("AverageLuma Final Curve: S:%x F:%x\n", u16Step, u16FlickAlpha));
494 for (i = 0; i <16; i++)
495 {
496 MS_U32 u32Blend;
497 MS_U32 u32a, u32b;
498 MS_U32 u32F;
499
500 u32a = ((MS_U32)g_u16TableExt[i] * (MS_U32)DLC_DEFLICK_PRECISION_SHIFT);
501 u32b = g_u32PreTableExt[i];
502
503 if((u32a >= u32b))
504 {
505 u32F = ((u32a-u32b) > (DLC_DEFLICK_PRECISION_SHIFT<<2)) ? DLC_DEFLICK_BLEND_FACTOR : (MS_U32)u16FlickAlpha;
506 }
507 else if(u32b > u32a)
508 {
509 u32F = ((u32b - u32a) > (DLC_DEFLICK_PRECISION_SHIFT<<2)) ? DLC_DEFLICK_BLEND_FACTOR : (MS_U32)u16FlickAlpha;
510 }
511
512 /*++ de-flicker (Step2) ++*/
513 u32Blend =( ( (u32F * (MS_U32)g_u16TableExt[i] * (MS_U32)DLC_DEFLICK_PRECISION_SHIFT) +
514 ((MS_U32)DLC_DEFLICK_BLEND_FACTOR-u32F) * (MS_U32)g_u32PreTableExt[i]) / DLC_DEFLICK_BLEND_FACTOR);
515
516 // the difference can't be too big
517 if(u32Blend > g_u32PreTableExt[i])
518 {
519 if((u32Blend - g_u32PreTableExt[i])> ((DLC_DEFLICK_PRECISION_SHIFT<<2) * (MS_U32)u16Step))
520 u32Blend = g_u32PreTableExt[i] + ((DLC_DEFLICK_PRECISION_SHIFT<<2) * (MS_U32)u16Step);
521 }
522 else if(u32Blend < g_u32PreTableExt[i])
523 {
524 if((g_u32PreTableExt[i] - u32Blend)> ((DLC_DEFLICK_PRECISION_SHIFT<<2) * (MS_U32)u16Step))
525 u32Blend = g_u32PreTableExt[i] - ((DLC_DEFLICK_PRECISION_SHIFT<<2) * (MS_U32)u16Step);
526 }
527
528 g_u32PreTableExt[i] = u32Blend;
529
530 g_u16TableExt[i] = (MS_U16)((g_u32PreTableExt[i] +(DLC_DEFLICK_PRECISION_SHIFT/2))/ DLC_DEFLICK_PRECISION_SHIFT);
531 DLC_DEBUG(printf("%04x, ", g_u16TableExt[i]));
532 /*-- de-flicker (Step2) --*/
533
534 }
535 DLC_DEBUG(printf("\n"));
536 // patch first level for YUV 6~235
537 // the middle point between 1st & 2nd level must be small or equal 0x10
538 if(g_u16TableExt[1] + g_u16TableExt[0] > 0x80)
539 {
540 g_u16TableExt[0] = (g_u16TableExt[1] < 0x80) ? 0x80 - g_u16TableExt[1] : 0;
541 }
542
543
544 Hal_DLC_set_curveExt(&g_u16TableExt[0]);
545
546 }
547
MDrv_DLC_AverateLuma_Handler(MS_BOOL bWindow)548 static void MDrv_DLC_AverateLuma_Handler(MS_BOOL bWindow)
549 {
550 MS_U16 u16FlickAlpha;
551 MS_U16 u16YAvg;
552 MS_U8 *pStaticCurveTbl_a, *pStaticCurveTbl_b;
553 MS_U16 u16Weight, u16Wegiht_Total;
554 MS_U8 i;
555 MS_U16 u16Step;
556
557 u16FlickAlpha = MDrv_DLC_Get_AverageLuma_Alpha();
558
559 if(u16FlickAlpha < 1)
560 u16FlickAlpha = 1;
561 if(u16FlickAlpha > DLC_DEFLICK_BLEND_FACTOR)
562 u16FlickAlpha = DLC_DEFLICK_BLEND_FACTOR;
563
564
565 if(gu16PixelSum != 0)
566 {
567 u16YAvg = (MS_U16)((256UL * (MS_U32)gu16LumaSum + (MS_U32)gu16PixelSum/2UL) / (MS_U32)gu16PixelSum);
568 }
569 else
570 {
571 u16YAvg = 0;
572 }
573
574 DLC_DEBUG(printf("CurLumaSum=%u, PreLumaSum=%u, FlickAlpha=%u, AvgLum=%u\n",
575 gu16LumaSum, gu16PreLumaSum, u16FlickAlpha, u16YAvg));
576
577
578 if(u16YAvg <= gu16AverageLuma_boundary_L)
579 { // all dark
580 DLC_DEBUG(printf("All Dark\n"));
581 pStaticCurveTbl_a = &g_DlcParameters.ucLumaCurve2_b[0];
582 pStaticCurveTbl_b = &g_DlcParameters.ucLumaCurve2_b[0];
583 u16Wegiht_Total = gu16AverageLuma_boundary_L;
584 u16Weight = gu16AverageLuma_boundary_L;
585
586 }
587 else if(u16YAvg <= gu16AverageLuma_boundary_ML)
588 { // dark + normal
589 DLC_DEBUG(printf("dark + normal\n"));
590 pStaticCurveTbl_a = &g_DlcParameters.ucLumaCurve2_b[0];
591 pStaticCurveTbl_b = &g_DlcParameters.ucLumaCurve[0];
592 u16Wegiht_Total = gu16AverageLuma_boundary_ML - gu16AverageLuma_boundary_L;
593 u16Weight = gu16AverageLuma_boundary_ML - u16YAvg;
594
595 }
596 else if(u16YAvg <= gu16AverageLuma_boundary_MH)
597 { // all normal
598 DLC_DEBUG(printf("all normal\n"));
599 pStaticCurveTbl_a = &g_DlcParameters.ucLumaCurve[0];
600 pStaticCurveTbl_b = &g_DlcParameters.ucLumaCurve[0];
601 u16Wegiht_Total = gu16AverageLuma_boundary_MH - gu16AverageLuma_boundary_ML;
602 u16Weight = u16Wegiht_Total;
603
604 }
605 else if(u16YAvg <= gu16AverageLuma_boundary_H)
606 { // normal + light
607
608 DLC_DEBUG(printf("normal light \n"));
609 pStaticCurveTbl_a = &g_DlcParameters.ucLumaCurve2_a[0];
610 pStaticCurveTbl_b = &g_DlcParameters.ucLumaCurve[0];
611 u16Wegiht_Total = gu16AverageLuma_boundary_H - gu16AverageLuma_boundary_MH;
612 u16Weight = u16YAvg - gu16AverageLuma_boundary_MH;
613
614 }
615 else
616 { // all light
617
618 DLC_DEBUG(printf("all light\n"));
619 pStaticCurveTbl_a = &g_DlcParameters.ucLumaCurve2_a[0];
620 pStaticCurveTbl_b = &g_DlcParameters.ucLumaCurve2_a[0];
621 u16Wegiht_Total = gu16AverageLuma_boundary_H;
622 u16Weight = gu16AverageLuma_boundary_H;
623 }
624
625 DLC_DEBUG(printf("AverageLuma Target Curve\n"));
626 /* update luma curve */
627 for(i=0; i<16; i++)
628 {
629
630 if (u16Wegiht_Total == 0 )
631 {
632 DLC_DEBUG(printf(" =================================================================== \n"));
633 DLC_DEBUG(printf(" ==== [DLC]Error divide 0 !!!!!!! ================================== \n"));
634 DLC_DEBUG(printf(" =================================================================== \n"));
635 return;
636 }
637 else
638 {
639 g_ucTable[i] = (MS_U8)((((MS_U32)(*pStaticCurveTbl_a) * (MS_U32) u16Weight) +
640 (MS_U32)(*pStaticCurveTbl_b) * (MS_U32)(u16Wegiht_Total - u16Weight)) / u16Wegiht_Total);
641 }
642 pStaticCurveTbl_a++;
643 pStaticCurveTbl_b++;
644
645 DLC_DEBUG(printf("%02x, ", g_ucTable[i]));
646 }
647 DLC_DEBUG(printf("\n"));
648
649
650 u16Step = Hal_DLC_get_step();
651
652
653 DLC_DEBUG(printf("AverageLuma Final Curve\n"));
654 for (i = 0; i <16; i++)
655 {
656 MS_U16 u16Blend;
657 MS_U32 u32a, u32b;
658 MS_U16 u16F;
659
660 u32a = ((MS_U32)g_ucTable[i] * (MS_U32)DLC_DEFLICK_PRECISION_SHIFT);
661 u32b = (MS_U32)g_uwPreTable[i];
662
663 if((u32a >= u32b))
664 {
665 u16F = ((u32a-u32b) > DLC_DEFLICK_PRECISION_SHIFT) ? DLC_DEFLICK_BLEND_FACTOR : u16FlickAlpha;
666 }
667 else if(u32b > u32a)
668 {
669 u16F = ((u32b - u32a) > DLC_DEFLICK_PRECISION_SHIFT) ? DLC_DEFLICK_BLEND_FACTOR : u16FlickAlpha;
670 }
671
672 /*++ de-flicker (Step2) ++*/
673 u16Blend =(MS_U16)( ( (((MS_U32)u16F) * (MS_U32)g_ucTable[i] * (MS_U32)DLC_DEFLICK_PRECISION_SHIFT) +
674 ((MS_U32)DLC_DEFLICK_BLEND_FACTOR-(MS_U32)u16F) * (MS_U32)g_uwPreTable[i]) / DLC_DEFLICK_BLEND_FACTOR);
675
676 // the difference can't be too big
677 if(u16Blend > g_uwPreTable[i])
678 {
679 if((u16Blend - g_uwPreTable[i])> (DLC_DEFLICK_PRECISION_SHIFT * (MS_U16)u16Step))
680 u16Blend = g_uwPreTable[i] + (DLC_DEFLICK_PRECISION_SHIFT * (MS_U16)u16Step);
681 }
682 else if(u16Blend < g_uwPreTable[i])
683 {
684 if((g_uwPreTable[i] - u16Blend)> (DLC_DEFLICK_PRECISION_SHIFT * (MS_U16)u16Step))
685 u16Blend = g_uwPreTable[i] - (DLC_DEFLICK_PRECISION_SHIFT * (MS_U16)u16Step);
686 }
687
688 g_uwPreTable[i] = u16Blend;
689
690 g_ucTable[i] = (MS_U8)(g_uwPreTable[i] / DLC_DEFLICK_PRECISION_SHIFT);
691
692 DLC_DEBUG(printf("%02x, ", g_ucTable[i]));
693 /*-- de-flicker (Step2) --*/
694
695 }
696 DLC_DEBUG(printf("\n"));
697
698 // patch first level for YUV 6~235
699 // the middle point between 1st & 2nd level must be small or equal 0x10
700
701 if(g_ucTable[1] + g_ucTable[0] > 0x20)
702 {
703 g_ucTable[0] = (g_ucTable[1] < 0x20) ? 0x20 - g_ucTable[1] : 0;
704 }
705
706
707 Hal_DLC_set_curve(&g_ucTable[0]);
708
709 }
710 #endif
711
712 ////////////////////////////////////////////////////////////////////////////////
713 /// @brief \b Function \b Name: MDrv_DLC_Handler()
714 /// @brief \b Function \b Description: Handle DLC function
715 /// @param <IN> \b bWindow
716 /// @param <OUT> \b None
717 /// @param <RET> \b None
718 /// @param <GLOBAL> \b None
719 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_Handler(MS_BOOL bWindow)720 void MDrv_DLC_Handler(MS_BOOL bWindow)
721 {
722 static MS_U8 s_uLastMsg = 0;
723
724 #if(ENABLE_AVERAGELUMA)
725 MS_U8 u8Method;
726
727
728 u8Method = Hal_DLC_get_dlc_method();
729
730
731 if( u8Method & EN_DLC_METHOD_AVERAGELUMA)
732 {
733 if (s_uLastMsg != 1)
734 {
735 s_uLastMsg = 1;
736 DLC_DEBUG(printf("MDrv_DLC_Handler(): Hal_DLC_get_dlc_method() EN_DLC_METHOD_AVERAGELUMA on\n"));
737 }
738
739 if(gstDLCParamExt.b10BitsCruveEn)
740 {
741 MDrv_DLC_AverateLuma_Handler_Ext(bWindow);
742 }
743 else
744 {
745 MDrv_DLC_AverateLuma_Handler(bWindow);
746 }
747 }
748 else
749 #endif
750 {
751 if (s_uLastMsg != 2)
752 {
753 s_uLastMsg = 2;
754 DLC_DEBUG(printf("MDrv_DLC_Handler(): Hal_DLC_get_dlc_method() EN_DLC_METHOD_AVERAGELUMA off\n"));
755 }
756
757 if(g_bSetDlcHandlerOn)
758 {
759 msDlcHandler(bWindow);
760 }
761 }
762 }
763
764 ////////////////////////////////////////////////////////////////////////////////
765 /// @brief \b Function \b Name: MDrv_DLC_GetHistogram()
766 /// @brief \b Function \b Description: Get Histogram
767 /// @param <IN> \b bWindow
768 /// @param <OUT> \b None
769 /// @param <RET> \b ucReturn
770 /// @param <GLOBAL> \b None
771 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_GetHistogram(MS_BOOL bWindow)772 MS_BOOL MDrv_DLC_GetHistogram(MS_BOOL bWindow)
773 {
774 MS_BOOL Ret;
775
776 Ret = msGetHistogramHandler(bWindow);
777
778 #if(ENABLE_AVERAGELUMA)
779 if(Hal_DLC_get_dlc_method() & EN_DLC_METHOD_AVERAGELUMA)
780 {
781 gu16AverageLuma_Delta = Hal_DLC_get_averageluma_delta();
782 gbCGain_Ctrl = Hal_DLC_get_c_gain_ctrl();
783 gu16FlickAlpha = Hal_DLC_get_flick_alpha();
784
785 if(Ret == TRUE)
786 {
787 gu16PreLumaSum = gu16LumaSum;
788 gu16LumaSum = Hal_DLC_get_histogram_y_sum();
789 gu16PixelSum = Hal_DLC_get_histogam_pixel_sum();
790 }
791
792 DLC_DEBUG(printf("PreYSum=%u, YSum=%u, PixelSum=%u\n", gu16PreLumaSum , gu16LumaSum, gu16PixelSum));
793 gu16AverageLuma_boundary_L = Hal_DLC_get_averageluma_boundary_low();
794 gu16AverageLuma_boundary_ML = Hal_DLC_get_averageluma_boundary_midlow();
795 gu16AverageLuma_boundary_MH = Hal_DLC_get_averageluma_boundary_midhigh();
796 gu16AverageLuma_boundary_H = Hal_DLC_get_averageluma_boundary_high();
797 }
798 #endif
799
800 return Ret;
801 }
802
803 ////////////////////////////////////////////////////////////////////////////////
804 /// @brief \b Function \b Name: MDrv_DLC_GetAverageValue()
805 /// @brief \b Function \b Description: Get Average of Luminous Value
806 /// @param <IN> \b None
807 /// @param <OUT> \b None
808 /// @param <RET> \b uwTmpAvr
809 /// @param <GLOBAL> \b None
810 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_GetAverageValue(void)811 MS_U8 MDrv_DLC_GetAverageValue(void)
812 {
813 MS_U8 u8ret;
814
815 u8ret = msGetAverageLuminous();
816
817 return u8ret;
818 }
819
820 ////////////////////////////////////////////////////////////////////////////////
821 /// @brief \b Function \b Name: MDrv_DLC_GetAverageValue_x4()
822 /// @brief \b Function \b Description: Get Average exactness of Luminous Value
823 /// @param <IN> \b None
824 /// @param <OUT> \b None
825 /// @param <RET> \b uwTmpAvr
826 /// @param <GLOBAL> \b None
827 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_GetAverageValue_x4(void)828 MS_U16 MDrv_DLC_GetAverageValue_x4(void)
829 {
830 MS_U16 u16ret;
831
832 u16ret = msGetAverageLuminous_x4();
833
834 return u16ret;
835 }
836
837 ////////////////////////////////////////////////////////////////////////////////
838 /// @brief \b Function \b Name: MDrv_DLC_SpeedupTrigger()
839 /// @brief \b Function \b Description: Speedup Trigger
840 /// @param <IN> \b ucLoop
841 /// @param <OUT> \b None
842 /// @param <RET> \b None
843 /// @param <GLOBAL> \b None
844 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_SpeedupTrigger(MS_U8 u8Loop)845 void MDrv_DLC_SpeedupTrigger(MS_U8 u8Loop)
846 {
847 msDlcSpeedupTrigger(u8Loop);
848 }
849
850 ////////////////////////////////////////////////////////////////////////////////
851 /// @brief \b Function \b Name: MDrv_DLC_CGC_ResetCGain()
852 /// @brief \b Function \b Description:
853 /// @param <IN> \b None
854 /// @param <OUT> \b None
855 /// @param <RET> \b None
856 /// @param <GLOBAL> \b None
857 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_CGC_ResetCGain(void)858 void MDrv_DLC_CGC_ResetCGain(void)
859 {
860 Hal_DLC_CGC_ResetCGain();
861 }
862
863 ////////////////////////////////////////////////////////////////////////////////
864 /// @brief \b Function \b Name: MDrv_DLC_CGC_GetCGain()
865 /// @brief \b Function \b Description:
866 /// @param <IN> \b None
867 /// @param <OUT> \b None
868 /// @param <RET> \b None
869 /// @param <GLOBAL> \b None
870 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_CGC_GetCGain(void)871 MS_U8 MDrv_DLC_CGC_GetCGain(void)
872 {
873 MS_U8 u8ret;
874
875 u8ret = Hal_DLC_CGC_GetCGain();
876 return u8ret;
877 }
878
879
880 ////////////////////////////////////////////////////////////////////////////////
881 /// @brief \b Function \b Name: MDrv_DLC_CGC_SetCGain()
882 /// @brief \b Function \b Description:
883 /// @param <IN> \b None
884 /// @param <OUT> \b None
885 /// @param <RET> \b None
886 /// @param <GLOBAL> \b None
887 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_CGC_SetCGain(MS_U8 u8CGain)888 void MDrv_DLC_CGC_SetCGain(MS_U8 u8CGain)
889 {
890 Hal_DLC_CGC_SetCGain(u8CGain);
891 }
892
893 ////////////////////////////////////////////////////////////////////////////////
894 /// @brief \b Function \b Name: MDrv_DLC_CGC_ResetYGain()
895 /// @brief \b Function \b Description:
896 /// @param <IN> \b None
897 /// @param <OUT> \b None
898 /// @param <RET> \b None
899 /// @param <GLOBAL> \b None
900 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_CGC_ResetYGain(void)901 void MDrv_DLC_CGC_ResetYGain(void)
902 {
903 Hal_DLC_CGC_ResetYGain();
904 }
905
906 ////////////////////////////////////////////////////////////////////////////////
907 /// @brief \b Function \b Name: MDrv_DLC_CGC_GetYGain()
908 /// @brief \b Function \b Description:
909 /// @param <IN> \b None
910 /// @param <OUT> \b None
911 /// @param <RET> \b None
912 /// @param <GLOBAL> \b None
913 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_CGC_GetYGain(void)914 MS_U8 MDrv_DLC_CGC_GetYGain(void)
915 {
916 MS_U8 u8ret;
917
918 u8ret = Hal_DLC_CGC_GetYGain();
919 return u8ret;
920 }
921
922
923 ////////////////////////////////////////////////////////////////////////////////
924 /// @brief \b Function \b Name: MDrv_DLC_CGC_SetYGain()
925 /// @brief \b Function \b Description:
926 /// @param <IN> \b None
927 /// @param <OUT> \b None
928 /// @param <RET> \b None
929 /// @param <GLOBAL> \b None
930 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_CGC_SetYGain(MS_U8 u8YGain)931 void MDrv_DLC_CGC_SetYGain(MS_U8 u8YGain)
932 {
933 Hal_DLC_CGC_SetYGain(u8YGain);
934 }
935
936 ////////////////////////////////////////////////////////////////////////////////
937 /// @brief \b Function \b Name: MDrv_DLC_CGC_Init()
938 /// @brief \b Function \b Description:
939 /// @param <IN> \b None
940 /// @param <OUT> \b None
941 /// @param <RET> \b None
942 /// @param <GLOBAL> \b None
943 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_CGC_Init(void)944 void MDrv_DLC_CGC_Init(void)
945 {
946 #if(ENABLE_AVERAGELUMA)
947 if( Hal_DLC_get_dlc_method() & EN_DLC_METHOD_AVERAGELUMA)
948 {
949 DLC_DEBUG(printf("MDrv_DLC_CGC_Init(): Hal_DLC_get_dlc_method() EN_DLC_METHOD_AVERAGELUMA on\n"));
950 if(Hal_DLC_get_c_gain_ctrl())
951 {
952 g_u16PreDLC_CGain = 0x40 * DLC_DEFLICK_PRECISION_SHIFT;
953 g_u8Chroma_OriGain = Hal_DLC_CGC_GetCGain();
954 }
955 }
956 else
957 #endif
958 {
959 DLC_DEBUG(printf("MDrv_DLC_CGC_Init(): Hal_DLC_get_dlc_method() EN_DLC_METHOD_AVERAGELUMA off\n"));
960 msDlc_CGC_Init();
961 }
962 }
963
964 ////////////////////////////////////////////////////////////////////////////////
965 /// @brief \b Function \b Name: MDrv_DLC_CGC_ReInit()
966 /// @brief \b Function \b Description:
967 /// @param <IN> \b None
968 /// @param <OUT> \b None
969 /// @param <RET> \b None
970 /// @param <GLOBAL> \b None
971 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_CGC_ReInit(void)972 void MDrv_DLC_CGC_ReInit(void)
973 {
974 msDlc_CGC_ReInit();
975 }
976
977 #if(ENABLE_AVERAGELUMA)
MDrv_DLC_AverageLuma_CGC_Handler(void)978 static void MDrv_DLC_AverageLuma_CGC_Handler(void)
979 {
980 MS_U16 u16CGain_Blend;
981 MS_U16 u16FlickAlpha;
982 MS_U16 u16Step;
983 MS_U16 u16NewDLC_CGain;
984 MS_U16 u16YAvg;
985 MS_U16 u16Strength;
986 MS_U16 u16Center_Boundary;
987
988 u16YAvg = msGetAverageLuminous();
989
990 u16Strength = Hal_DLC_get_c_gain_strength();
991
992 u16Center_Boundary = (gu16AverageLuma_boundary_ML + gu16AverageLuma_boundary_MH)/2;
993
994
995 if(u16YAvg > u16Center_Boundary)
996 u16YAvg = u16Center_Boundary - (u16YAvg - u16Center_Boundary);
997
998 if(u16YAvg < gu16AverageLuma_boundary_L)
999 {
1000 u16NewDLC_CGain = (u16YAvg * u16Strength)/256;
1001 }
1002 else if(u16YAvg < gu16AverageLuma_boundary_ML)
1003 {
1004 u16NewDLC_CGain = (u16YAvg * u16Strength)/192;
1005 }
1006 else //(u16YAvg <= u16Center_Boundary)
1007 {
1008 u16NewDLC_CGain = (u16YAvg * u16Strength)/128;
1009 }
1010
1011 u16NewDLC_CGain += g_u8Chroma_OriGain;
1012 // DLC_DEBUG(printk("CenterP =%x, AvergaeLuma=%x, YAvg=%bx, New_CGain=%x\n",
1013 // u16Center_Boundary, u16YAvg, u16YAvg, u16NewDLC_CGain));
1014
1015 if(u16NewDLC_CGain > 0x60)
1016 u16NewDLC_CGain = 0x60;
1017
1018
1019 u16FlickAlpha = MDrv_DLC_Get_AverageLuma_Alpha();
1020
1021 u16Step = Hal_DLC_get_step();
1022
1023 u16CGain_Blend =(MS_U16)( ( (((MS_U32)u16FlickAlpha) * (MS_U32)u16NewDLC_CGain * (MS_U32)DLC_DEFLICK_PRECISION_SHIFT) +
1024 ((MS_U32)DLC_DEFLICK_BLEND_FACTOR-(MS_U32)u16FlickAlpha) * (MS_U32)g_u16PreDLC_CGain) / DLC_DEFLICK_BLEND_FACTOR);
1025 if((u16CGain_Blend > g_u16PreDLC_CGain) )
1026 {
1027 if((u16CGain_Blend - g_u16PreDLC_CGain) > (DLC_DEFLICK_PRECISION_SHIFT * u16Step))
1028 u16CGain_Blend = g_u16PreDLC_CGain + (DLC_DEFLICK_PRECISION_SHIFT * u16Step);
1029 }
1030 else if(u16CGain_Blend < g_u16PreDLC_CGain)
1031 {
1032 if((g_u16PreDLC_CGain - u16CGain_Blend ) > (DLC_DEFLICK_PRECISION_SHIFT * u16Step))
1033 u16CGain_Blend = g_u16PreDLC_CGain - (DLC_DEFLICK_PRECISION_SHIFT * u16Step);
1034
1035 }
1036
1037 g_u16PreDLC_CGain = u16CGain_Blend;
1038
1039 u16NewDLC_CGain = u16CGain_Blend / DLC_DEFLICK_PRECISION_SHIFT;
1040
1041 Hal_DLC_CGC_SetCGain((MS_U8)(u16NewDLC_CGain & 0xFF));
1042 }
1043 #endif
1044
1045 ////////////////////////////////////////////////////////////////////////////////
1046 /// @brief \b Function \b Name: MDrv_DLC_CGC_Handler()
1047 /// @brief \b Function \b Description: Handle DLC CGC function
1048 /// @param <IN> \b None
1049 /// @param <OUT> \b None
1050 /// @param <RET> \b None
1051 /// @param <GLOBAL> \b None
1052 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_CGC_Handler(void)1053 void MDrv_DLC_CGC_Handler(void)
1054 {
1055 #if(ENABLE_AVERAGELUMA)
1056 MS_U8 u8Method;
1057 MS_BOOL bCGainCtrl;
1058
1059 u8Method = Hal_DLC_get_dlc_method();
1060 bCGainCtrl = Hal_DLC_get_c_gain_ctrl();
1061
1062 if( u8Method & EN_DLC_METHOD_AVERAGELUMA)
1063 {
1064 if(bCGainCtrl)
1065 {
1066 MDrv_DLC_AverageLuma_CGC_Handler();
1067 }
1068 }
1069 else
1070 #endif
1071 {
1072 msDlc_CGC_Handler();
1073 }
1074 }
1075
1076 ////////////////////////////////////////////////////////////////////////////////
1077 /// @brief \b Function \b Name: MDrv_DLC_CGC_GetMFVer()
1078 /// @brief \b Function \b Description:
1079 /// @param <IN> \b None
1080 /// @param <OUT> \b None
1081 /// @param <RET> \b None
1082 /// @param <GLOBAL> \b None
1083 ////////////////////////////////////////////////////////////////////////////////
MDrv_DLC_CGC_GetMFVer(void)1084 MS_U16 MDrv_DLC_CGC_GetMFVer(void)
1085 {
1086 return msDlcCGCLibVersionCheck();
1087 }
1088
1089 ////////////////////////////////////////////////////////////////////////////////
1090 //
1091 // DLC library function end
1092 //
1093 ////////////////////////////////////////////////////////////////////////////////
1094
1095
1096 ////////////////////////////////////////////////////////////////////////////////
1097 //
1098 // DrvDLC.c start
1099 //
1100 ////////////////////////////////////////////////////////////////////////////////
1101 extern MS_U16 g_wLumaHistogram32H[32];
1102 extern MS_U8 g_ucHistogramMax, g_ucHistogramMin;
1103 extern MS_U16 g_wLumiAverageTemp;
1104 extern MS_U8 g_ucTable[16];
1105 extern MS_U16 g_wLumiTotalCount;
1106
MDrv_DLC_SetCurve(MS_U8 * pNormal,MS_U8 * pLight,MS_U8 * pDark)1107 void MDrv_DLC_SetCurve(MS_U8 *pNormal, MS_U8 *pLight, MS_U8 *pDark )
1108 {
1109 MS_U8 i;
1110 for (i=0; i<16; ++i)
1111 {
1112 #if(ENABLE_AVERAGELUMA)
1113 gstDLCParamExt.uwLumaCurve[i] = ((MS_U16)pNormal[i])<<2;
1114 gstDLCParamExt.uwLumaCurve2_a[i] = ((MS_U16)pLight[i])<<2;
1115 gstDLCParamExt.uwLumaCurve2_b[i] = ((MS_U16)pDark[i])<<2;
1116 #endif
1117
1118 g_DlcParameters.ucLumaCurve[i] = pNormal[i];
1119 g_DlcParameters.ucLumaCurve2_a[i] = pLight[i];
1120 g_DlcParameters.ucLumaCurve2_b[i] = pDark[i];
1121
1122 DLC_DEBUG(printf("%x %x %x\n",
1123 gstDLCParamExt.uwLumaCurve[i] ,
1124 gstDLCParamExt.uwLumaCurve2_a[i],
1125 gstDLCParamExt.uwLumaCurve2_b[i]));
1126 }
1127 }
1128
1129 #ifdef MSOS_TYPE_LINUX_KERNEL
1130 extern MS_BOOL KDrv_DLC_SetInitInfo(ST_KDRV_XC_DLC_INIT_INFO stDlcInitInfo);
1131 #endif
MDrv_DLC_Init(StuDlc_FinetuneParamaters DLC_MFinit)1132 void MDrv_DLC_Init(StuDlc_FinetuneParamaters DLC_MFinit)
1133 {
1134 MS_U8 i;
1135
1136 char word[] = {"_XC_Mutex"};
1137 _DLC_Mutex = MsOS_CreateMutex(E_MSOS_FIFO, word, MSOS_PROCESS_SHARED);
1138
1139 if (_DLC_Mutex == -1)
1140 {
1141 (printf("[MAPI DLC][%06d] create mutex fail\n", __LINE__));
1142 }
1143
1144 memcpy(&g_DlcParameters, &DLC_MFinit, sizeof(StuDlc_FinetuneParamaters));
1145 for(i=0; i<16; i++)
1146 {
1147 g_uwPreTable[i] = (MS_U16)g_DlcParameters.ucLumaCurve[i] * (MS_U16)DLC_DEFLICK_PRECISION_SHIFT;
1148 }
1149
1150 Hal_DLC_init();
1151
1152
1153 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
1154 ST_KDRV_XC_DLC_INIT_INFO stDlcInitInfo;
1155 memset(&stDlcInitInfo, 0, sizeof(ST_KDRV_XC_DLC_INIT_INFO));
1156
1157 stDlcInitInfo.bInitInfoChange = TRUE;
1158
1159 for (i=0; i<16; ++i)
1160 {
1161 stDlcInitInfo.au8LumaCurve[i] = g_DlcParameters.ucLumaCurve[i];
1162 stDlcInitInfo.au8LumaCurve2_a[i] = g_DlcParameters.ucLumaCurve2_a[i];
1163 stDlcInitInfo.au8LumaCurve2_b[i] = g_DlcParameters.ucLumaCurve2_b[i];
1164 }
1165
1166 for (i=0; i<17; ++i)
1167 {
1168 stDlcInitInfo.au8DlcHistogramLimitCurve[i] = g_DlcParameters.ucDlcHistogramLimitCurve[i];
1169 }
1170
1171 stDlcInitInfo.u8DlcPureImageMode = g_DlcParameters.ucDlcPureImageMode; // Compare difference of max and min bright
1172 stDlcInitInfo.u8DlcLevelLimit = g_DlcParameters.ucDlcLevelLimit; // n = 0 ~ 4 => Limit n levels => ex. n=2, limit 2 level 0xF7, 0xE7
1173 stDlcInitInfo.u8DlcAvgDelta = g_DlcParameters.ucDlcAvgDelta; // n = 0 ~ 50, default value: 12
1174 stDlcInitInfo.u8DlcAvgDeltaStill = g_DlcParameters.ucDlcAvgDeltaStill; // n = 0 ~ 15 => 0: disable still curve, 1 ~ 15: enable still curve
1175 stDlcInitInfo.u8DlcFastAlphaBlending = g_DlcParameters.ucDlcFastAlphaBlending; // min 17 ~ max 32
1176 stDlcInitInfo.u8DlcYAvgThresholdL = g_DlcParameters.ucDlcYAvgThresholdL; // default value: 0
1177 stDlcInitInfo.u8DlcYAvgThresholdH = g_DlcParameters.ucDlcYAvgThresholdH; // default value: 128
1178 stDlcInitInfo.u8DlcBLEPoint = g_DlcParameters.ucDlcBLEPoint; // n = 24 ~ 64, default value: 48
1179 stDlcInitInfo.u8DlcWLEPoint = g_DlcParameters.ucDlcWLEPoint; // n = 24 ~ 64, default value: 48
1180 stDlcInitInfo.bEnableBLE = g_DlcParameters.bEnableBLE; // 1: enable; 0: disable
1181 stDlcInitInfo.bEnableWLE = g_DlcParameters.bEnableWLE; // 1: enable; 0: disable
1182 stDlcInitInfo.u8DlcYAvgThresholdM = g_DlcParameters.ucDlcYAvgThresholdM;
1183 stDlcInitInfo.u8DlcCurveMode = g_DlcParameters.ucDlcCurveMode;
1184 stDlcInitInfo.u8DlcCurveModeMixAlpha = g_DlcParameters.ucDlcCurveModeMixAlpha;
1185 stDlcInitInfo.u8DlcAlgorithmMode = g_DlcParameters.ucDlcAlgorithmMode;
1186 stDlcInitInfo.u8DlcSepPointH = g_DlcParameters.ucDlcSepPointH;
1187 stDlcInitInfo.u8DlcSepPointL = g_DlcParameters.ucDlcSepPointL;
1188 stDlcInitInfo.u16DlcBleStartPointTH = g_DlcParameters.uwDlcBleStartPointTH;
1189 stDlcInitInfo.u16DlcBleEndPointTH = g_DlcParameters.uwDlcBleEndPointTH;
1190 stDlcInitInfo.u8DlcCurveDiff_L_TH = g_DlcParameters.ucDlcCurveDiff_L_TH;
1191 stDlcInitInfo.u8DlcCurveDiff_H_TH = g_DlcParameters.ucDlcCurveDiff_H_TH;
1192 stDlcInitInfo.u16DlcBLESlopPoint_1 = g_DlcParameters.uwDlcBLESlopPoint_1;
1193 stDlcInitInfo.u16DlcBLESlopPoint_2 = g_DlcParameters.uwDlcBLESlopPoint_2;
1194 stDlcInitInfo.u16DlcBLESlopPoint_3 = g_DlcParameters.uwDlcBLESlopPoint_3;
1195 stDlcInitInfo.u16DlcBLESlopPoint_4 = g_DlcParameters.uwDlcBLESlopPoint_4;
1196 stDlcInitInfo.u16DlcBLESlopPoint_5 = g_DlcParameters.uwDlcBLESlopPoint_5;
1197 stDlcInitInfo.u16DlcDark_BLE_Slop_Min = g_DlcParameters.uwDlcDark_BLE_Slop_Min;
1198 stDlcInitInfo.u8DlcCurveDiffCoringTH = g_DlcParameters.ucDlcCurveDiffCoringTH;
1199 stDlcInitInfo.u8DlcAlphaBlendingMin = g_DlcParameters.ucDlcAlphaBlendingMin;
1200 stDlcInitInfo.u8DlcAlphaBlendingMax = g_DlcParameters.ucDlcAlphaBlendingMax;
1201 stDlcInitInfo.u8DlcFlicker_alpha = g_DlcParameters.ucDlcFlicker_alpha;
1202 stDlcInitInfo.u8DlcYAVG_L_TH = g_DlcParameters.ucDlcYAVG_L_TH;
1203 stDlcInitInfo.u8DlcYAVG_H_TH = g_DlcParameters.ucDlcYAVG_H_TH;
1204 stDlcInitInfo.u8DlcDiffBase_L = g_DlcParameters.ucDlcDiffBase_L;
1205 stDlcInitInfo.u8DlcDiffBase_M = g_DlcParameters.ucDlcDiffBase_M;
1206 stDlcInitInfo.u8DlcDiffBase_H = g_DlcParameters.ucDlcDiffBase_H;
1207 stDlcInitInfo.u8LMaxThreshold = g_DlcParameters.ucLMaxThreshold;
1208 stDlcInitInfo.u8LMinThreshold = g_DlcParameters.ucLMinThreshold;
1209 stDlcInitInfo.u8LMaxCorrection = g_DlcParameters.ucLMaxCorrection;
1210 stDlcInitInfo.u8LMinCorrection = g_DlcParameters.ucLMinCorrection;
1211 stDlcInitInfo.u8RMaxThreshold = g_DlcParameters.ucRMaxThreshold;
1212 stDlcInitInfo.u8RMinThreshold = g_DlcParameters.ucRMinThreshold;
1213 stDlcInitInfo.u8RMaxCorrection = g_DlcParameters.ucRMaxCorrection;
1214 stDlcInitInfo.u8RMinCorrection = g_DlcParameters.ucRMinCorrection;
1215 stDlcInitInfo.u8AllowLoseContrast = g_DlcParameters.ucAllowLoseContrast;
1216 #else
1217 MS_DLC_INIT_INFO MsDlcInitInfo;
1218
1219 MsDlcInitInfo.bInitInfoChange = TRUE;
1220
1221 for (i=0; i<16; ++i)
1222 {
1223 MsDlcInitInfo.ucLumaCurve[i] = g_DlcParameters.ucLumaCurve[i];
1224 MsDlcInitInfo.ucLumaCurve2_a[i] = g_DlcParameters.ucLumaCurve2_a[i];
1225 MsDlcInitInfo.ucLumaCurve2_b[i] = g_DlcParameters.ucLumaCurve2_b[i];
1226 }
1227
1228 for (i=0; i<17; ++i)
1229 {
1230 MsDlcInitInfo.ucDlcHistogramLimitCurve[i] = g_DlcParameters.ucDlcHistogramLimitCurve[i];
1231 }
1232
1233 MsDlcInitInfo.ucDlcPureImageMode = g_DlcParameters.ucDlcPureImageMode; // Compare difference of max and min bright
1234 MsDlcInitInfo.ucDlcLevelLimit = g_DlcParameters.ucDlcLevelLimit; // n = 0 ~ 4 => Limit n levels => ex. n=2, limit 2 level 0xF7, 0xE7
1235 MsDlcInitInfo.ucDlcAvgDelta = g_DlcParameters.ucDlcAvgDelta; // n = 0 ~ 50, default value: 12
1236 MsDlcInitInfo.ucDlcAvgDeltaStill = g_DlcParameters.ucDlcAvgDeltaStill; // n = 0 ~ 15 => 0: disable still curve, 1 ~ 15: enable still curve
1237 MsDlcInitInfo.ucDlcFastAlphaBlending = g_DlcParameters.ucDlcFastAlphaBlending; // min 17 ~ max 32
1238 MsDlcInitInfo.ucDlcYAvgThresholdL = g_DlcParameters.ucDlcYAvgThresholdL; // default value: 0
1239 MsDlcInitInfo.ucDlcYAvgThresholdH = g_DlcParameters.ucDlcYAvgThresholdH; // default value: 128
1240 MsDlcInitInfo.ucDlcBLEPoint = g_DlcParameters.ucDlcBLEPoint; // n = 24 ~ 64, default value: 48
1241 MsDlcInitInfo.ucDlcWLEPoint = g_DlcParameters.ucDlcWLEPoint; // n = 24 ~ 64, default value: 48
1242 MsDlcInitInfo.bEnableBLE = g_DlcParameters.bEnableBLE; // 1: enable; 0: disable
1243 MsDlcInitInfo.bEnableWLE = g_DlcParameters.bEnableWLE; // 1: enable; 0: disable
1244 MsDlcInitInfo.ucDlcYAvgThresholdM = g_DlcParameters.ucDlcYAvgThresholdM;
1245 MsDlcInitInfo.ucDlcCurveMode = g_DlcParameters.ucDlcCurveMode;
1246 MsDlcInitInfo.ucDlcCurveModeMixAlpha = g_DlcParameters.ucDlcCurveModeMixAlpha;
1247 MsDlcInitInfo.ucDlcAlgorithmMode = g_DlcParameters.ucDlcAlgorithmMode;
1248 MsDlcInitInfo.ucDlcSepPointH = g_DlcParameters.ucDlcSepPointH;
1249 MsDlcInitInfo.ucDlcSepPointL = g_DlcParameters.ucDlcSepPointL;
1250 MsDlcInitInfo.uwDlcBleStartPointTH = g_DlcParameters.uwDlcBleStartPointTH;
1251 MsDlcInitInfo.uwDlcBleEndPointTH = g_DlcParameters.uwDlcBleEndPointTH;
1252 MsDlcInitInfo.ucDlcCurveDiff_L_TH = g_DlcParameters.ucDlcCurveDiff_L_TH;
1253 MsDlcInitInfo.ucDlcCurveDiff_H_TH = g_DlcParameters.ucDlcCurveDiff_H_TH;
1254 MsDlcInitInfo.uwDlcBLESlopPoint_1 = g_DlcParameters.uwDlcBLESlopPoint_1;
1255 MsDlcInitInfo.uwDlcBLESlopPoint_2 = g_DlcParameters.uwDlcBLESlopPoint_2;
1256 MsDlcInitInfo.uwDlcBLESlopPoint_3 = g_DlcParameters.uwDlcBLESlopPoint_3;
1257 MsDlcInitInfo.uwDlcBLESlopPoint_4 = g_DlcParameters.uwDlcBLESlopPoint_4;
1258 MsDlcInitInfo.uwDlcBLESlopPoint_5 = g_DlcParameters.uwDlcBLESlopPoint_5;
1259 MsDlcInitInfo.uwDlcDark_BLE_Slop_Min = g_DlcParameters.uwDlcDark_BLE_Slop_Min;
1260 MsDlcInitInfo.ucDlcCurveDiffCoringTH = g_DlcParameters.ucDlcCurveDiffCoringTH;
1261 MsDlcInitInfo.ucDlcAlphaBlendingMin = g_DlcParameters.ucDlcAlphaBlendingMin;
1262 MsDlcInitInfo.ucDlcAlphaBlendingMax = g_DlcParameters.ucDlcAlphaBlendingMax;
1263 MsDlcInitInfo.ucDlcFlicker_alpha = g_DlcParameters.ucDlcFlicker_alpha;
1264 MsDlcInitInfo.ucDlcYAVG_L_TH = g_DlcParameters.ucDlcYAVG_L_TH;
1265 MsDlcInitInfo.ucDlcYAVG_H_TH = g_DlcParameters.ucDlcYAVG_H_TH;
1266 MsDlcInitInfo.ucDlcDiffBase_L = g_DlcParameters.ucDlcDiffBase_L;
1267 MsDlcInitInfo.ucDlcDiffBase_M = g_DlcParameters.ucDlcDiffBase_M;
1268 MsDlcInitInfo.ucDlcDiffBase_H = g_DlcParameters.ucDlcDiffBase_H;
1269 #endif
1270
1271 #ifdef MSOS_TYPE_LINUX
1272 if(0 > s32FdDlcBle)
1273 {
1274 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
1275 s32FdDlcBle = open("/dev/scaler", O_RDWR);
1276 #else
1277 s32FdDlcBle = open("/dev/gflip", O_RDWR);
1278 #endif
1279
1280 if(0 > s32FdDlcBle)
1281 {
1282 DLC_PRINT("DLC device not opened!!!!\n");
1283 return;
1284 }
1285 }
1286 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
1287 if (ioctl(s32FdDlcBle, MDRV_XC_IOC_DLCSETDLCINITINFO, &stDlcInitInfo))
1288 #else
1289 if (ioctl(s32FdDlcBle, MDRV_GFLIP_IOC_SETDLCINITINFO, &MsDlcInitInfo))
1290 #endif
1291 {
1292 DLC_PRINT("MDrv_DLC_SetDlcInitInfo fail!!!!\n");
1293 return;
1294 }
1295 #elif defined(MSOS_TYPE_LINUX_KERNEL)
1296 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
1297 KDrv_DLC_SetInitInfo(stDlcInitInfo);
1298 #else
1299 //_MDrv_GFLIPIO_IOC_DlcInitInfo is obsolete.
1300 #endif
1301
1302 #endif
1303
1304 }
1305
MDrv_DLC_Init_Ext(DLC_init_Ext * pDLC_InitExt)1306 void MDrv_DLC_Init_Ext(DLC_init_Ext *pDLC_InitExt)
1307 {
1308 #if(ENABLE_AVERAGELUMA)
1309
1310 MS_U8 i;
1311
1312 memcpy(&gstDLCParamExt, pDLC_InitExt, sizeof(DLC_init_Ext));
1313
1314 for(i=0; i<16; i++)
1315 {
1316 g_u32PreTableExt[i] = (MS_U32)gstDLCParamExt.uwLumaCurve[i] * (MS_U32)DLC_DEFLICK_PRECISION_SHIFT;
1317 }
1318 #endif
1319 }
1320
1321
MDrv_DLC_GetDLCInfo(StuDlc_FinetuneParamaters * DLC_MFinit,MS_U32 u32InitDataLen)1322 MS_BOOL MDrv_DLC_GetDLCInfo(StuDlc_FinetuneParamaters *DLC_MFinit, MS_U32 u32InitDataLen)
1323 {
1324 if(u32InitDataLen != sizeof(StuDlc_FinetuneParamaters))
1325 {
1326 return FALSE;
1327 }
1328 memcpy(DLC_MFinit, &g_DlcParameters, u32InitDataLen);
1329 return TRUE;
1330 }
1331
MDrv_DLC_GetLumaInfo(DLC_LUMADATA * pDLCLumaData,MS_U32 u32LumaDataLen)1332 MS_BOOL MDrv_DLC_GetLumaInfo(DLC_LUMADATA *pDLCLumaData, MS_U32 u32LumaDataLen)
1333 {
1334 MS_U8 i;
1335 if(u32LumaDataLen != sizeof(DLC_LUMADATA))
1336 {
1337 return FALSE;
1338 }
1339 for(i=0; i<32; i++)
1340 {
1341 pDLCLumaData->g_wLumaHistogram32H[i] = g_wLumaHistogram32H[i];
1342 }
1343 for(i=0; i<16; i++)
1344 {
1345 pDLCLumaData->g_ucTable[i] = g_ucTable[i];
1346 }
1347 pDLCLumaData->g_wLumiTotalCount = g_wLumiTotalCount;
1348 pDLCLumaData->g_wLumiAverageTemp = g_wLumiAverageTemp;
1349 pDLCLumaData->g_ucHistogramMax = g_ucHistogramMax;
1350 pDLCLumaData->g_ucHistogramMin = g_ucHistogramMin;
1351 return TRUE;
1352 }
1353
MDrv_DLC_init_riu_base(MS_VIRT ptr_riu_base)1354 void MDrv_DLC_init_riu_base( MS_VIRT ptr_riu_base )
1355 {
1356 Hal_DLC_init_riu_base(ptr_riu_base);
1357 }
1358
MDrv_DLC_GetLumaCurveStatus(void)1359 MS_BOOL MDrv_DLC_GetLumaCurveStatus( void )
1360 {
1361 MS_BOOL bret;
1362
1363 bret = Hal_DLC_GetLumaCurveStatus();
1364
1365 return bret;
1366 }
1367
1368 ////////////////////////////////////////////////////////////////////////////////
1369 //
1370 // DrvDLC.c end
1371 //
1372 ////////////////////////////////////////////////////////////////////////////////
1373
1374
1375 ////////////////////////////////////////////////////////////////////////////////
1376 //
1377 // DBC library function start
1378 //
1379 ////////////////////////////////////////////////////////////////////////////////
1380
1381 extern MS_U8 g_ucDBC_DebugMode;
1382
1383 /******************************************************************************/
1384 /* Function Prototypes */
1385 /******************************************************************************/
1386 extern StuDbc_FinetuneParamaters_Lib g_DbcParameters;
1387
MDrv_DLC_DBC_GetDebugMode(void)1388 MS_U8 MDrv_DLC_DBC_GetDebugMode(void)
1389 {
1390 return g_ucDBC_DebugMode;
1391 }
1392
MDrv_DLC_DBC_SetDebugMode(MS_U8 u8DBC_DebugMode)1393 void MDrv_DLC_DBC_SetDebugMode(MS_U8 u8DBC_DebugMode)
1394 {
1395 g_ucDBC_DebugMode = u8DBC_DebugMode;
1396 }
1397
MDrv_DLC_DBC_UpdatePWM(MS_U8 u8PWMvalue)1398 void MDrv_DLC_DBC_UpdatePWM(MS_U8 u8PWMvalue)
1399 {
1400 g_DbcParameters.ucCurrentPWM = u8PWMvalue;
1401 }
1402
MDrv_DLC_DBC_Init(StuDbc_FinetuneParamaters_Lib DLC_DBC_MFinit)1403 void MDrv_DLC_DBC_Init(StuDbc_FinetuneParamaters_Lib DLC_DBC_MFinit)
1404 {
1405 memcpy(&g_DbcParameters, &DLC_DBC_MFinit, sizeof(StuDbc_FinetuneParamaters_Lib));
1406 }
1407
MDrv_DLC_DBC_Handler(void)1408 MS_U16 MDrv_DLC_DBC_Handler(void)
1409 {
1410 return msBackLightHandler();
1411 }
1412
MDrv_DLC_DBC_GetMFVer(void)1413 MS_U16 MDrv_DLC_DBC_GetMFVer(void)
1414 {
1415 return msDbcLibVersionCheck();
1416 }
1417
MDrv_DLC_GetDBCInfo(StuDbc_FinetuneParamaters_Lib * pDLCDBCData,MS_U32 u32DBCDataLen)1418 MS_BOOL MDrv_DLC_GetDBCInfo(StuDbc_FinetuneParamaters_Lib *pDLCDBCData, MS_U32 u32DBCDataLen)
1419 {
1420
1421 if(u32DBCDataLen != sizeof(StuDbc_FinetuneParamaters_Lib))
1422 {
1423 return FALSE;
1424 }
1425
1426 memcpy(pDLCDBCData, &g_DbcParameters, sizeof(StuDbc_FinetuneParamaters_Lib));
1427 return TRUE;
1428 }
1429
MDrv_DLC_DBC_AdjustYCGain(void)1430 void MDrv_DLC_DBC_AdjustYCGain(void)
1431 {
1432 msAdjustYCGain(g_DbcParameters.ucY_Gain_H, g_DbcParameters.ucC_Gain_H);
1433 }
1434
MDrv_DLC_DBC_YCGainInit(MS_U8 u8YGain_M,MS_U8 u8YGain_L,MS_U8 u8CGain_M,MS_U8 u8CGain_L,MS_U8 u8YGain_H,MS_U8 u8CGain_H)1435 void MDrv_DLC_DBC_YCGainInit(MS_U8 u8YGain_M, MS_U8 u8YGain_L, MS_U8 u8CGain_M, MS_U8 u8CGain_L, MS_U8 u8YGain_H, MS_U8 u8CGain_H)
1436 {
1437
1438 g_DbcParameters.ucY_Gain_H = u8YGain_H;
1439 g_DbcParameters.ucC_Gain_H = u8CGain_H;
1440 if((u8YGain_M == 0) && (u8YGain_L == 0) && (u8CGain_M == 0) && (u8CGain_L == 0))
1441 {
1442 g_DbcParameters.ucY_Gain_M = g_DbcParameters.ucY_Gain_H;
1443 g_DbcParameters.ucY_Gain_L = g_DbcParameters.ucY_Gain_H;
1444 g_DbcParameters.ucC_Gain_M = g_DbcParameters.ucC_Gain_H;
1445 g_DbcParameters.ucC_Gain_L = g_DbcParameters.ucC_Gain_H;
1446 }
1447 else
1448 {
1449 g_DbcParameters.ucY_Gain_M = u8YGain_M;
1450 g_DbcParameters.ucY_Gain_L = u8YGain_L;
1451 g_DbcParameters.ucC_Gain_M = u8CGain_M;
1452 g_DbcParameters.ucC_Gain_L = u8CGain_L;
1453 }
1454
1455 msDBCInit();
1456 }
1457
MDrv_DLC_WriteCurve(MS_U8 * pu8Table)1458 void MDrv_DLC_WriteCurve(MS_U8 *pu8Table)
1459 {
1460 #if(ENABLE_AVERAGELUMA)
1461 Hal_DLC_set_curve(pu8Table);
1462 #endif
1463 }
1464
MDrv_DLC_WriteCurve_Sub(MS_U8 * pu8Table)1465 void MDrv_DLC_WriteCurve_Sub(MS_U8 *pu8Table)
1466 {
1467 #if(ENABLE_AVERAGELUMA)
1468 Hal_DLC_set_curve_sub(pu8Table);
1469 #endif
1470 }
1471
1472
MDrv_DLC_get_histogram32(MS_U16 * pu16Histogram32)1473 MS_BOOL MDrv_DLC_get_histogram32(MS_U16 *pu16Histogram32)
1474 {
1475 #if(ENABLE_AVERAGELUMA)
1476
1477 MS_BOOL bret = FALSE;
1478 if(Hal_DLC_get_histogram_ack())
1479 {
1480 Hal_DLC_get_histogram32(pu16Histogram32);
1481
1482 Hal_DLC_set_histogram_req();
1483 bret = TRUE;
1484 }
1485 return bret;
1486 #else
1487 return FALSE;
1488 #endif
1489 }
1490
MDrv_DLC_set_CaptureRange(StuDbc_CAPTURE_Range * pu16Cap_rang)1491 void MDrv_DLC_set_CaptureRange(StuDbc_CAPTURE_Range *pu16Cap_rang)
1492 {
1493 // if(pu16Cap_rang!=NULL)
1494 memcpy(&g_DlcCapRange, pu16Cap_rang, sizeof(StuDbc_CAPTURE_Range));
1495 /*
1496 else
1497 memcpy(pu16Cap_rang, &g_DlcCapRange, sizeof(StuDbc_CAPTURE_Range));
1498 */
1499 msDlc_SetCaptureRange(pu16Cap_rang->wHStart, pu16Cap_rang->wHEnd, pu16Cap_rang->wVStart, pu16Cap_rang->wVEnd);
1500
1501 }
1502
1503 //-------------------------------------------------------------------------------------------------
1504 ///Send Dlc Init Curve Change Info to Dlc kernel
1505 /// @param bCurveChange \b IN: the dlc static curve change
1506 /// @return TRUE: DDI call success
1507 /// @attention
1508 /// <b>[MxLib] <em>Flip when vsync interrupt, and the DDI used for set dlc info to GFlip. </em></b>
1509 //-------------------------------------------------------------------------------------------------
MDrv_DLC_SendDlcInitCurveChangeInfo(MS_BOOL bCurveChange,MS_U8 * pNormal,MS_U8 * pLight,MS_U8 * pDark)1510 MS_BOOL MDrv_DLC_SendDlcInitCurveChangeInfo(MS_BOOL bCurveChange,MS_U8 *pNormal, MS_U8 *pLight, MS_U8 *pDark)
1511 {
1512
1513 #ifdef MSOS_TYPE_LINUX
1514
1515 MS_U8 i;
1516 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
1517 ST_KDRV_XC_DLC_INFO stDlcInfo;
1518
1519 stDlcInfo.bCurveChange = bCurveChange;
1520
1521 for (i=0; i<16; ++i)
1522 {
1523 stDlcInfo.u8LumaCurve[i] = pNormal[i];
1524 stDlcInfo.u8LumaCurve2_a[i] = pLight[i];
1525 stDlcInfo.u8LumaCurve2_b[i] = pDark[i];
1526 }
1527 #else
1528 MS_DLC_INFO MsDlcInfo;
1529
1530 MsDlcInfo.bCurveChange = bCurveChange;
1531
1532 for (i=0; i<16; ++i)
1533 {
1534 MsDlcInfo.u8LumaCurve[i] = pNormal[i];
1535 MsDlcInfo.u8LumaCurve2_a[i] = pLight[i];
1536 MsDlcInfo.u8LumaCurve2_b[i] = pDark[i];
1537 }
1538 #endif
1539 if(0 > s32FdDlcBle)
1540 {
1541 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
1542 s32FdDlcBle = open("/dev/scaler", O_RDWR);
1543 #else
1544 s32FdDlcBle = open("/dev/gflip", O_RDWR);
1545 #endif
1546
1547 if(0 > s32FdDlcBle)
1548 {
1549 DLC_PRINT("DLC device not opened!!!!\n");
1550 return FALSE;
1551 }
1552 }
1553
1554 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
1555 if (ioctl(s32FdDlcBle, MDRV_XC_IOC_DLCCHANGECURVE, &stDlcInfo))
1556 #else
1557 if (ioctl(s32FdDlcBle, MDRV_GFLIP_IOC_DLCCHANGECURVE, &MsDlcInfo))
1558 #endif
1559 {
1560 DLC_PRINT("MDrv_DLC_SetDlcInfo fail!!!!\n");
1561 return FALSE;
1562 }
1563
1564 #endif
1565 return TRUE;
1566 }
1567
1568 //-------------------------------------------------------------------------------------------------
1569 ///Send BLE Slop Point Change Info to Dlc kernel
1570 /// @param pBLESlopPoint \b IN: the BLE Slop Point Change
1571 /// @return TRUE: DDI call success
1572 /// @attention
1573 /// <b>[MxLib] <em>Flip when vsync interrupt, and the DDI used for set ble info to GFlip. </em></b>
1574 //-------------------------------------------------------------------------------------------------
MDrv_DLC_SendBleChangeInfo(MS_BOOL bBLEPointChange,MS_U16 * pBLESlopPoint)1575 MS_BOOL MDrv_DLC_SendBleChangeInfo(MS_BOOL bBLEPointChange,MS_U16 *pBLESlopPoint)
1576 {
1577
1578 #ifdef MSOS_TYPE_LINUX
1579
1580 MS_U8 i;
1581 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
1582 ST_KDRV_XC_DLC_BLE_INFO stBleInfo;
1583
1584 stBleInfo.bBLEPointChange = bBLEPointChange;
1585
1586 for (i=0; i<6; ++i)
1587 {
1588 stBleInfo.u16BLESlopPoint[i] = pBLESlopPoint[i];
1589 }
1590 #else
1591 MS_BLE_INFO MsBleInfo;
1592
1593 MsBleInfo.bBLEPointChange = bBLEPointChange;
1594
1595 for (i=0; i<6; ++i)
1596 {
1597 MsBleInfo.u16BLESlopPoint[i] = pBLESlopPoint[i];
1598 }
1599 #endif
1600 if(0 > s32FdDlcBle)
1601 {
1602 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
1603 s32FdDlcBle = open("/dev/scaler", O_RDWR);
1604 #else
1605 s32FdDlcBle = open("/dev/gflip", O_RDWR);
1606 #endif
1607
1608 if(0 > s32FdDlcBle)
1609 {
1610 DLC_PRINT("BLE device not opened!!!!\n");
1611 return FALSE;
1612 }
1613 }
1614
1615 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
1616 if (ioctl(s32FdDlcBle, MDRV_XC_IOC_DLCBLECHANGECURVE, &stBleInfo))
1617 #else
1618 if (ioctl(s32FdDlcBle, MDRV_GFLIP_IOC_BLECHANGEPOINT, &MsBleInfo))
1619 #endif
1620 {
1621 DLC_PRINT("MDrv_DLC_SendBleChangeInfo fail!!!!\n");
1622 return FALSE;
1623 }
1624
1625 #endif
1626 return TRUE;
1627 }
1628
1629 //-------------------------------------------------------------------------------------------------
1630 ///Send HDR Init Info to Dlc kernel
1631 /// @param pstDLC_HDRInitData \b IN: the HDR Init Data
1632 /// @return TRUE: DDI call success
1633 /// @attention
1634 /// <b>[MxLib] <em>Flip when vsync interrupt, and the DDI used for set dlc info to GFlip. </em></b>
1635 //-------------------------------------------------------------------------------------------------
MDrv_DLC_SetHDRInit(DLC_HDRinit * pstDLC_HDRInitData)1636 MS_BOOL MDrv_DLC_SetHDRInit(DLC_HDRinit * pstDLC_HDRInitData)
1637 {
1638
1639 #ifdef MSOS_TYPE_LINUX
1640
1641 if(0 > s32FdDlcBle)
1642 {
1643 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
1644 s32FdDlcBle = open("/dev/scaler", O_RDWR);
1645 #else
1646 s32FdDlcBle = open("/dev/gflip", O_RDWR);
1647 #endif
1648
1649 if(0 > s32FdDlcBle)
1650 {
1651 DLC_PRINT("BLE device not opened!!!!\n");
1652 return FALSE;
1653 }
1654 }
1655 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
1656 #else
1657 MS_HDR_INFO_EXTEND MsHDRInfo;
1658 memset(&MsHDRInfo, 0 , sizeof(MS_HDR_INFO_EXTEND));
1659 memcpy(&MsHDRInfo, pstDLC_HDRInitData, sizeof(MS_HDR_INFO_EXTEND));
1660 MsHDRInfo.u16HDRVerInfo = MS_HDR_VERSION;
1661 MsHDRInfo.u16HDRInitLength = sizeof(MS_HDR_INFO_EXTEND);
1662 MsHDRInfo.DLC_HDRCustomerDlcCurve.pucDlcCurve = NULL;
1663 #if !defined (__aarch64__)
1664 MsHDRInfo.DLC_HDRCustomerDlcCurve.pDummy = NULL;
1665 #endif
1666
1667 MS_U16 u16BufSize = sizeof(MS_HDR_INFO_EXTEND) + sizeof(MS_U8)*pstDLC_HDRInitData->DLC_HDRCustomerDlcCurve.u16DlcCurveSize;
1668 MS_U8 *pu8Buf = (MS_U8*)malloc(u16BufSize);
1669 MS_U16 u16Offset = 0;
1670
1671 memset(pu8Buf, 0, u16BufSize);
1672 memcpy(pu8Buf, &MsHDRInfo, sizeof(MS_HDR_INFO_EXTEND));
1673 u16Offset += sizeof(MS_HDR_INFO_EXTEND);
1674
1675 if (pstDLC_HDRInitData->DLC_HDRCustomerDlcCurve.u16DlcCurveSize > 0)
1676 {
1677 memcpy(pu8Buf + u16Offset, pstDLC_HDRInitData->DLC_HDRCustomerDlcCurve.pucDlcCurve, sizeof(MS_U8)*pstDLC_HDRInitData->DLC_HDRCustomerDlcCurve.u16DlcCurveSize);
1678 u16Offset += (sizeof(MS_U8)*pstDLC_HDRInitData->DLC_HDRCustomerDlcCurve.u16DlcCurveSize);
1679 }
1680 #endif
1681
1682 #if defined(UFO_XC_HDR_VERSION) && (UFO_XC_HDR_VERSION == 2)
1683 printf("not support MDrv_DLC_SetHDRInit.\n");
1684 #else
1685 // Send MS_HDR_INFO_EXTEND
1686 if (ioctl(s32FdDlcBle, MDRV_GFLIP_IOC_DLCSETHDRINFO, pu8Buf))
1687 {
1688 DLC_PRINT("MDrv_DLC_SetHDR_Init send MS_HDR_INFO_EXTEND fail!!!!\n");
1689 free(pu8Buf);
1690 return FALSE;
1691 }
1692
1693 free(pu8Buf);
1694 #endif
1695 #endif
1696 return TRUE;
1697 }
1698 #ifdef UFO_XC_HDR
1699 #if (UFO_XC_HDR_VERSION == 2)
1700 #ifdef MSOS_TYPE_LINUX_KERNEL
1701 extern MS_BOOL KDrv_DLC_SetTMOInfo(ST_KDRV_XC_TMO_INFO *pstTMOInfo);
1702 #endif
MDrv_DLC_SetTMOInfo(ST_DLC_TMO_INFO * pstDLCTMOInfo)1703 MS_BOOL MDrv_DLC_SetTMOInfo(ST_DLC_TMO_INFO * pstDLCTMOInfo)
1704 {
1705 ST_KDRV_XC_TMO_INFO *pstKdrvTmoInfo = (ST_KDRV_XC_TMO_INFO*)malloc(sizeof(ST_DLC_TMO_INFO));
1706 pstKdrvTmoInfo->u16SrcMinRatio = pstDLCTMOInfo->u16SrcMinRatio;
1707 pstKdrvTmoInfo->u16SrcMedRatio = pstDLCTMOInfo->u16SrcMedRatio;
1708 pstKdrvTmoInfo->u16SrcMaxRatio = pstDLCTMOInfo->u16SrcMaxRatio;
1709 pstKdrvTmoInfo->u16TgtMin = pstDLCTMOInfo->u16TgtMin;
1710 pstKdrvTmoInfo->u16TgtMed = pstDLCTMOInfo->u16TgtMed;
1711 pstKdrvTmoInfo->u16TgtMax = pstDLCTMOInfo->u16TgtMax;
1712 pstKdrvTmoInfo->u16FrontSlopeMin = pstDLCTMOInfo->u16FrontSlopeMin;
1713 pstKdrvTmoInfo->u16FrontSlopeMax = pstDLCTMOInfo->u16FrontSlopeMax;
1714 pstKdrvTmoInfo->u16BackSlopeMin = pstDLCTMOInfo->u16BackSlopeMin;
1715 pstKdrvTmoInfo->u16BackSlopeMax = pstDLCTMOInfo->u16BackSlopeMax;
1716 pstKdrvTmoInfo->u16SceneChangeThrd = pstDLCTMOInfo->u16SceneChangeThrd;
1717 pstKdrvTmoInfo->u16SceneChangeRatioMax = pstDLCTMOInfo->u16SceneChangeRatioMax;
1718 pstKdrvTmoInfo->u8IIRRatio = pstDLCTMOInfo->u8IIRRatio;
1719 pstKdrvTmoInfo->u8TMOTargetMode = pstDLCTMOInfo->u8TMOTargetMode;
1720 pstKdrvTmoInfo->u16SDRPanelGain = pstDLCTMOInfo->u16SDRPanelGain;
1721 pstKdrvTmoInfo->u16Smin = pstDLCTMOInfo->u16Smin;
1722 pstKdrvTmoInfo->u16Smed = pstDLCTMOInfo->u16Smed;
1723 pstKdrvTmoInfo->u16Smax = pstDLCTMOInfo->u16Smax;
1724 pstKdrvTmoInfo->u16Tmin = pstDLCTMOInfo->u16Tmin;
1725 pstKdrvTmoInfo->u16Tmed = pstDLCTMOInfo->u16Tmed;
1726 pstKdrvTmoInfo->u16Tmax = pstDLCTMOInfo->u16Tmax;
1727 pstKdrvTmoInfo->bRefMode = pstDLCTMOInfo->bRefMode;
1728 pstKdrvTmoInfo->u8TMOUseIniControls = pstDLCTMOInfo->u8TMOUseIniControls;
1729
1730 #ifdef MSOS_TYPE_LINUX
1731 if(0 > s32FdDlcBle)
1732 {
1733 s32FdDlcBle = open("/dev/scaler", O_RDWR);
1734
1735 if(0 > s32FdDlcBle)
1736 {
1737 DLC_PRINT("BLE device not opened!!!!\n");
1738 return FALSE;
1739 }
1740 }
1741
1742 if (ioctl(s32FdDlcBle, MDRV_XC_IOC_DLCSETTMOINFO, pstKdrvTmoInfo))
1743 {
1744 DLC_PRINT("MDrv_DLC_SetTMOInfo send MDRV_XC_IOC_DLCSETTMOINFO fail!!!!\n");
1745 return FALSE;
1746 }
1747 #elif defined(MSOS_TYPE_LINUX_KERNEL)
1748 KDrv_DLC_SetTMOInfo(pstKdrvTmoInfo);
1749 #endif
1750 free(pstKdrvTmoInfo);
1751 return TRUE;
1752
1753 }
1754 #endif
1755 #endif
1756
1757 ////////////////////////////////////////////////////////////////////////////////
1758 //
1759 // DBC library function End
1760 //
1761 ////////////////////////////////////////////////////////////////////////////////
1762
1763 #undef _MDRV_DLC_C_
1764
1765