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 Copyright (c) 2008 MStar Semiconductor, Inc.
80 All rights reserved.
81
82 [Module Name]: MsDLC.c
83 [Date]: 2009-03-20
84 [Comment]:
85 MST DLC subroutines.
86 [Reversion History]:
87 *******************************************************************************/
88
89 #define _MSDLC_C_
90
91 #include "MsDlc_LIB.h"
92 #include "MsDlc.h"
93
94 #ifdef MSOS_TYPE_LINUX
95 #include <sys/ioctl.h>
96 #include <unistd.h>
97 #include <fcntl.h> // O_RDWR
98 #include "../../../graphic/drv/gop/mdrv_gflip_io.h"
99 #endif
100
101 // Compiler option
102 #define DLC_LIB_VERSION 0x3300 //v32.61 // fix bugs of u8_L_H_U & u8_L_H_D
103 //v32.59 // 1. Add guard condition to msDlcOnOff & msDlc_CGC_Init. msDlcOnOff & msDlc_CGC_Init will check DLC On/Off status before execution.
104 //v32.58 // 1. change register data width from WORD -> DWORD 2. Fixs float point issue.
105 //v32.57 // fix bug imgae flick while curve change, fix bug for g_DlcParameters.ucDlcAvgDeltaStill & g_DlcParameters.ucDlcAvgDelta
106 //v32.56 // fix bug for g_DlcParameters.ucDlcAvgDeltaStill
107 //v32.55 // change the resolution of Yavg for g_DlcParameters.ucDlcAvgDeltaStill
108 //v32.54 // add C Gain (CGC) On Off
109 //v32.53 // modify msDlc_AP_ReinitWithoutPara() for debug command
110 //v32.52 // Include DebugTool Command + move g_u8Yth to CGC parameter groups
111 //v32.51 // Modify CGC initial flow
112 //v32.50 // Fix CGC Limit definition
113 //v32.49 // add Cgain control by Jason.Chen, add protect when AvgMax < Avg Min for pure image
114 //v32.48 // reserved for Paulo/Lomeo version number.
115 //v32.47 // fix Yavg threshold problem
116 //v32.46 // rename parameters, add Yavg threshold, g_DlcParameters.ucDlcYAvgThresholdH & g_DlcParameters.ucDlcYAvgThresholdL
117 //v32.45 // fix level[14] over flow issue & unstable when LH2(g_DlcParameters.u8_L_H_D) is high
118 //v32.44 // finetune v32.43
119 //v32.43 // (test) add new parameter for stop curve cgange when Avg Delta <= g_DlcParameters.ucDlcAvgDeltaStill
120 //v32.42 // remove Delay1ms() and replace to a Macro msDlc_Delay1ms
121 //v32.41 // change usage of timeout event, use Delay1ms(n);
122 //v32.40 // add new parameter for WLE/BLE g_DlcParameters.ucDlcBLEPoint, g_DlcParameters.ucDlcWLEPoint, add new parameter for Avg offset (Compal), add timeout in initial stage
123 //v32.39 // modify for get stable pixel count "g_wLumiTotalCount"
124 //v32.38 // fix re-init error in Histogram request bit (bit2)
125 //v32.37 // seperate code msDlcLumiDiffCtrl()
126 //v32.36 // add more overflow/underflow protection
127 //v32.35 // to fix the bug => luma curve (0) is almost "0x00" for all kind of pattern.
128 //v32.34 // add compiler option ENABLE_HISTOGRAM_8 and function msDlcSetVarHistogramRange()
129 //v32.33 // add histogram range of H
130 //v32.32 // add registers initial table
131 //v32.31 // add some definition & add function enter and exit
132 //v32.30 // modify for ATV/DTV are compatible
133 //v32.23 // change definition of g_wAvgDelta => Delta = n * 3 , add function msGetAverageLuminous()
134 //v32.22 // add g_DlcParameters.ucDlcFastAlphaBlending, update g_wAvgDelta
135 //v32.21 // add g_wAvgDelta
136 //v32.20 // add level limit
137 //v32.19 // modify de-flick function, add parameter for pure image "g_DlcParameters.ucDlcPureImageMode", remove msGetHistogramHandler from DLC handler, finetune the process of pure image
138 //v32.18 // modify de-flick function (g_ucUpdateCnt & g_ucDlcFlickAlpha)
139 //v32.17 // fix bug of de-flick function
140 //v32.16 // modify de-flick function
141 //v32.15 // modify alpha belnding & add g_DlcParameters.ucDlcFlickAlphaStart after mode change
142 //v32.14 // Remove garbage (L_L_U...)
143 //v32.13 // Protect Histogram Overflow
144 //v32.12 // modify for tool finetune
145 //v32.11 // modify init static curve & for tool finetune
146 //v32.10 // Lopez & Raphael series 32-seg DLC & version 10
147
148 #define DLC_CGC_LIB_VERSION 0x0104 //v1.04 // add C Gain (CGC) On Off
149 //v1.03 // move g_u8Yth to CGC parameter groups
150 //v1.02 // Modify CGC initial flow
151 //v1.01 // Fix CGC Limit definition
152 //v1.00 // Initial
153
154
155 XDATA StuDlc_FinetuneParamaters g_DlcParameters;
156
157 #define DLC_DEBUG(x) //(x)
158
159 #define DEFAULT_BLE_UPPER_BOND 0x08
160 #define DEFAULT_BLE_LOWER_BOND 0x04
161
162 #define DLC_DEFLICK_PRECISION_SHIFT 64UL
163 #define DLC_DEFLICK_BLEND_FACTOR 32UL
164
165 #define DLC_PURE_IMAGE_DLC_CURVE 0L
166 #define DLC_PURE_IMAGE_LINEAR_CURVE 1L
167 #define DLC_PURE_IMAGE_DO_NOTHING 2L
168
169 #define XC_DLC_ALGORITHM_OLD 0
170 #define XC_DLC_ALGORITHM_NEW 1
171 #define XC_DLC_ALGORITHM_KERNEL 2
172
173 #define XC_DLC_SET_DLC_CURVE_BOTH_SAME 0 // 0:Main and Sub use the same DLC curve
174
175 #ifdef MSOS_TYPE_LINUX
176 XDATA MS_S32 s32FdDlcBle= -1 ;
177 #endif
178
179 XDATA WORD g_wLumaHistogram32H[32];
180 XDATA BYTE g_ucHistogramMax, g_ucHistogramMin;
181 XDATA WORD g_wLumiAverageTemp;
182 XDATA BYTE g_ucHistogramTotal_H;
183 XDATA BYTE g_ucHistogramTotal_L;
184 XDATA BYTE g_ucDlcFlickAlpha;
185 XDATA BYTE g_ucTable[16]; // Final target curve (8 bit)
186 XDATA BYTE g_pre_ucTable[16]; // Final target curve (8 bit)
187 XDATA WORD g_uwTable[16]; // Final target curve (10 bit)
188 XDATA BYTE g_ucCurveYAvg[16];
189 XDATA DWORD g_uwCurveHistogram[16];
190 XDATA WORD g_uwPre_CurveHistogram[16];
191 XDATA WORD g_uwPreTable[16]; // New de-Flick
192 XDATA BYTE g_ucUpdateCnt;
193 XDATA WORD g_wLumiTotalCount;
194 XDATA BYTE g_ucTmpAvgN_1; // Avg value (N-1)
195 XDATA BYTE g_ucTmpAvgN; // Avg value (current N)
196 XDATA WORD g_wTmpAvgN_1_x10; // Avg value (N-1) x 10
197 XDATA WORD g_wTmpAvgN_x10; // Avg value (current N) x 10
198 XDATA BYTE g_ucDlcFastLoop; // for pulse ripple
199
200 #define FLICK_ALPHA_START_COUNTER 40
201
202 XDATA DWORD g_dwFactory;
203 XDATA DWORD g_dwFactory_7;
204 XDATA DWORD g_dwFactory_9;
205 XDATA DWORD g_dwLstep;
206 XDATA DWORD g_dwHstep;
207
208 XDATA BYTE s_Slope[8] = {0x17,0x27,0x47,0x67,0x97,0xB7,0xD7,0xE7};
209
210 static MS_BOOL g_bSetDlcBleOn = TRUE;
211 static WORD g_wPIAlpha=0;
212 static WORD g_wPrePIAlpha=0;
213
214 #define LA1 g_DlcParameters.u8_L_L_U
215 #define LA2 g_DlcParameters.u8_L_L_D
216 #define LB1 g_DlcParameters.u8_L_L_U
217 #define LB2 g_DlcParameters.u8_L_L_D
218 #define LC1 g_DlcParameters.u8_L_L_U
219 #define LC2 g_DlcParameters.u8_L_L_D
220 #define LD1 g_DlcParameters.u8_L_L_U
221 #define LD2 g_DlcParameters.u8_L_L_D
222 #define LE1 g_DlcParameters.u8_L_H_U
223 #define LE2 g_DlcParameters.u8_L_H_D
224 #define LF1 g_DlcParameters.u8_L_H_U
225 #define LF2 g_DlcParameters.u8_L_H_D
226 #define LG1 g_DlcParameters.u8_L_H_U
227 #define LG2 g_DlcParameters.u8_L_H_D
228 #define LH1 g_DlcParameters.u8_L_H_U
229 #define LH2 g_DlcParameters.u8_L_H_D
230
231 #define SA1 g_DlcParameters.u8_S_L_U
232 #define SA2 g_DlcParameters.u8_S_L_D
233 #define SB1 g_DlcParameters.u8_S_L_U
234 #define SB2 g_DlcParameters.u8_S_L_D
235 #define SC1 g_DlcParameters.u8_S_L_U
236 #define SC2 g_DlcParameters.u8_S_L_D
237 #define SD1 g_DlcParameters.u8_S_L_U
238 #define SD2 g_DlcParameters.u8_S_L_D
239 #define SE1 g_DlcParameters.u8_S_H_U
240 #define SE2 g_DlcParameters.u8_S_H_D
241 #define SF1 g_DlcParameters.u8_S_H_U
242 #define SF2 g_DlcParameters.u8_S_H_D
243 #define SG1 g_DlcParameters.u8_S_H_U
244 #define SG2 g_DlcParameters.u8_S_H_D
245 #define SH1 g_DlcParameters.u8_S_H_U
246 #define SH2 g_DlcParameters.u8_S_H_D
247
248 typedef enum
249 {
250 Slope_1,
251 Slope_2,
252 Slope_4,
253 Slope_6,
254 Slope_9,
255 Slope_11,
256 Slope_13,
257 Slope_14,
258 Slope_Max
259 } Slop_Type;
260
261 #define Lstep g_dwLstep
262 #define Hstep g_dwHstep
263
264 //=========================================================
265
266 #define TOTAL_PIXEL ((DWORD)(wVEnd-wVStart)*(wHEnd-wHStart)*7*4/(160*3)) // ((DWORD)(wVEnd-wVStart)*0.04375*4/3*(wHEnd-wHStart))
267
268 void msWriteDLCRegsTbl(DlcRegUnitType code *pTable);
269 void msDlcWriteCurve(BOOL bWindow);
270 void msDlcWriteCurveLSB(BOOL bWindow, BYTE ucIndex, BYTE ucValue);
271 void msDlcLumiDiffCtrl(void);
272 void msDlcSetVarHistogramRange(BYTE *pRangeArray);
273
274 /******************************************************************************/
275 /* CGC */
276 /******************************************************************************/
277 // Constant
278 #define Yvar_Th 4 // Change threshold for DLC luma curve
279 #define Timer_CountU 3 // Increasing Chroma Gain change speed
280 #define Timer_CountD 1 // Decreasing Chroma Gain change speed
281 #define CGain_StepU 1 // Increasing Chroma Gain step
282 #define CGain_StepD 1 // Decreasing Chroma Gain step
283
284 #define Y01_weight 5 // Luma Curve Y[0], Y[1] weighting
285 #define Y23_weight 3 // Luma Curve Y[2], Y[3] weighting
286 #define Y45_weight 1 // Luma Curve Y[4], Y[5] weighting
287 #define Y67_weight 1 // Luma Curve Y[6], Y[7] weighting
288
289 // Local
290 XDATA BYTE g_u8Chroma_OriGain = 0x40;
291 XDATA BYTE g_u8Chroma_target;
292 XDATA WORD g_u16Ydark, g_u16Ydark_pre;
293 XDATA BYTE g_u8TCount = 0;
294 XDATA BYTE g_u8CGC_UpperBond, g_u8CGC_LowerBond;
295 XDATA BOOL g_bSetDLCCurveBoth = 0;//We will set main/sub DLC curve at the same time in 3D side-side ap.
296
297 /******************************************************************************/
298
299 //////////////////////////////////////////////////////////////
300 //
301 //////////////////////////////////////////////////////////////
msDlcInitWithCurve(WORD wHStart,WORD wHEnd,WORD wVStart,WORD wVEnd)302 void msDlcInitWithCurve( WORD wHStart, WORD wHEnd, WORD wVStart, WORD wVEnd )
303 {
304 BYTE ucTmp, ucTimeout;
305
306 msDlc_FunctionEnter();
307
308 g_ucDlcFastLoop = (g_DlcParameters.ucDlcFastAlphaBlending/2) * 16;
309 if (g_DlcParameters.ucDlcFastAlphaBlending == 32) // 32 / 2 * 16 = 0 overflow
310 g_ucDlcFastLoop = 255;
311
312 g_ucHistogramTotal_L = 0;
313 g_ucHistogramTotal_H = 0;
314
315 //putstr("\r\nDLC Initilize use HK MCU");
316
317 g_dwFactory = TOTAL_PIXEL/32/2;
318 g_dwFactory_7 = (g_dwFactory - (g_dwFactory/8));
319 g_dwFactory_9 = (g_dwFactory + (g_dwFactory/8));
320
321 g_dwLstep = g_dwFactory*1/16*12/10;
322 g_dwHstep = g_dwFactory*3/8;
323
324 // Registers Init
325 msWriteDLCRegsTbl(tDLC_Initialize);
326
327 // Set histogram method/dither
328 if (msReadByte(REG_ADDR_DLC_HANDSHAKE) & _BIT2)
329 {
330 ucTimeout = 60;
331 while(!(msReadByte(REG_ADDR_DLC_HANDSHAKE) & _BIT3) && (ucTimeout--))
332 {
333 msDlc_Delay1ms(1);
334 }
335 }
336
337 msWriteByte(REG_ADDR_DLC_HANDSHAKE, msReadByte(REG_ADDR_DLC_HANDSHAKE)|_BIT5|_BIT4 );
338
339 // Set histogram range - H
340 if (REG_ADDR_HISTOGRAM_RANGE_M_HST != REG_NULL)
341 {
342 // Main Window
343 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_M_HST, wHStart/8);
344 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_M_HEN, wHEnd/8);
345 // MWE/Sub Window
346 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_S_HST, wHStart/8);
347 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_S_HEN, wHEnd/8);
348 }
349 // Set histogram range - V
350 // Main Window
351 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_M_VST, wVStart/8);
352 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_M_VEN, wVEnd/8);
353 // MWE/Sub Window
354 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_S_VST, wVStart/8);
355 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_S_VEN, wVEnd/8);
356
357 msWriteByte(REG_ADDR_BLE_UPPER_BOND, DEFAULT_BLE_UPPER_BOND);
358 msWriteByte(REG_ADDR_BLE_LOWER_BOND, DEFAULT_BLE_LOWER_BOND);
359
360 // Enable range for Histogram
361 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_ENABLE, _BIT7|msReadByte(REG_ADDR_HISTOGRAM_RANGE_ENABLE) ); // Enable MAIN_WINDOW histogram
362
363 // Init Luma Curve
364 //putstr("[DLC]: Disable the Burst Write 16 Luma Curve\r\n");
365 for(ucTmp=0; ucTmp<=0x0f; ucTmp++)
366 {
367 g_ucTable[ucTmp] = g_DlcParameters.ucLumaCurve[ucTmp];
368 g_uwPreTable[ucTmp] = (WORD)g_DlcParameters.ucLumaCurve[ucTmp] * DLC_DEFLICK_PRECISION_SHIFT; // New de-Flick
369 msWriteByte((REG_ADDR_DLC_DATA_START_MAIN+ucTmp), g_ucTable[ucTmp]);
370 msDlcWriteCurveLSB(MAIN_WINDOW, ucTmp, 0);
371 msWriteByte((REG_ADDR_DLC_DATA_START_SUB+ucTmp), g_ucTable[ucTmp]);
372 msDlcWriteCurveLSB(SUB_WINDOW, ucTmp, 0);
373 }
374 // init DLC curve index N0 & 16
375 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_MAIN, g_ucTable[0]);
376 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_MAIN + 1, 0x01);
377 msDlcWriteCurveLSB(MAIN_WINDOW, 0xFF, 0);
378 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_MAIN, 255-g_ucTable[15]);
379 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_MAIN + 1, 0x01);
380 msDlcWriteCurveLSB(MAIN_WINDOW, 16, 0);
381 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_SUB, g_ucTable[0]);
382 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_SUB + 1, 0x01);
383 msDlcWriteCurveLSB(SUB_WINDOW, 0xFF, 0);
384 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_SUB, 255-g_ucTable[15]);
385 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_SUB + 1, 0x01);
386 msDlcWriteCurveLSB(SUB_WINDOW, 16, 0);
387
388 // Get Total Pixel Count
389 msWriteByte(REG_ADDR_DLC_HANDSHAKE, msReadByte(REG_ADDR_DLC_HANDSHAKE) & 0xF0);
390 msWriteByte(REG_ADDR_DLC_HANDSHAKE, msReadByte(REG_ADDR_DLC_HANDSHAKE) | _BIT2 | _BIT1);
391
392 g_wLumiTotalCount = msReadByte(REG_ADDR_HISTOGRAM_TOTAL_COUNT_H);
393 g_wLumiTotalCount = (g_wLumiTotalCount << 8) + (WORD)msReadByte(REG_ADDR_HISTOGRAM_TOTAL_COUNT_L);
394
395 g_DlcParameters.ucDlcTimeOut = 0;
396 g_DlcParameters.ucDlcFlickAlphaStart = FLICK_ALPHA_START_COUNTER;
397 g_DlcParameters.ucDlcSlowEvent = 0;
398 g_ucUpdateCnt = 0;
399
400 msDlc_FunctionExit();
401 }
402
msDlc_SetCaptureRange(MS_U16 wHStart,MS_U16 wHEnd,MS_U16 wVStart,MS_U16 wVEnd)403 void msDlc_SetCaptureRange(MS_U16 wHStart,MS_U16 wHEnd, MS_U16 wVStart, MS_U16 wVEnd)
404 {
405 #if 0
406 msDlc_FunctionEnter();
407
408 if (REG_ADDR_HISTOGRAM_RANGE_M_HST != REG_NULL)
409 {
410 if(msReadByte(REG_ADDR_VIP_HISTOGRAM_4K2K_MODE) & BIT(2)||((wHEnd-wHStart)>=3000))
411 {
412 // Set histogram range - H
413 // Main Window
414 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_M_HST, wHStart/8/2);
415 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_M_HEN, wHEnd/8/2);
416
417 // Virtical size need to change by display
418 // Set histogram range - V
419 // Main Window
420 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_M_VST, wVStart/8/2);
421 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_M_VEN, wVEnd/8/2);
422 }
423 else
424 {
425 // Set histogram range - H
426 // Main Window
427 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_M_HST, wHStart/8);
428 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_M_HEN, wHEnd/8);
429
430 // Virtical size need to change by display
431 // Set histogram range - V
432 // Main Window
433 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_M_VST, wVStart/8);
434 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_M_VEN, wVEnd/8);
435 }
436
437 msWriteByte(REG_ADDR_DLC_HANDSHAKE, msReadByte(REG_ADDR_DLC_HANDSHAKE) & 0xF2);
438 msWriteByte(REG_ADDR_DLC_HANDSHAKE, msReadByte(REG_ADDR_DLC_HANDSHAKE) | _BIT2 );
439 }
440 msDlc_FunctionExit();
441 #endif
442 }
443
msDlc_SetCaptureRangeSub(MS_U16 wHStart,MS_U16 wHEnd,MS_U16 wVStart,MS_U16 wVEnd)444 void msDlc_SetCaptureRangeSub(MS_U16 wHStart,MS_U16 wHEnd, MS_U16 wVStart, MS_U16 wVEnd)
445 {
446 msDlc_FunctionEnter();
447
448 if (REG_ADDR_HISTOGRAM_RANGE_S_HST != REG_NULL)
449 {
450 // Set histogram range - H
451 // Sub Window
452 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_S_HST, wHStart/8);
453 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_S_HEN, wHEnd/8);
454
455 // Virtical size need to change by display
456 // Set histogram range - V
457 // Sub Window
458 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_S_VST, wVStart/8);
459 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_S_VEN, wVEnd/8);
460
461 // Enable SUB_WINDOW histogram
462 msWriteByte(REG_ADDR_HISTOGRAM_RANGE_ENABLE, _BIT3|msReadByte(REG_ADDR_HISTOGRAM_RANGE_ENABLE) );
463
464 msWriteByte(REG_ADDR_DLC_HANDSHAKE, msReadByte(REG_ADDR_DLC_HANDSHAKE) & 0xF2);
465 msWriteByte(REG_ADDR_DLC_HANDSHAKE, msReadByte(REG_ADDR_DLC_HANDSHAKE) | _BIT2 );
466 }
467 msDlc_FunctionExit();
468 }
469
msDlcEnableSetDLCCurveBoth(BOOL bEnable)470 void msDlcEnableSetDLCCurveBoth(BOOL bEnable)
471 {
472 g_bSetDLCCurveBoth = bEnable;
473 }
474
475 //////////////////////////////////////////////////////////////
476 //
477 //////////////////////////////////////////////////////////////
msDlcOnOff(BOOL bSwitch,BOOL bWindow)478 void msDlcOnOff(BOOL bSwitch, BOOL bWindow)
479 {
480 BYTE ucCtlBit;
481
482 msDlc_FunctionEnter();
483
484 if( MAIN_WINDOW == bWindow )
485 ucCtlBit = _BIT7;
486 else // Sub window
487 ucCtlBit = _BIT6;
488
489 if( bSwitch ) // Enable
490 {
491 if((msReadByte(REG_ADDR_DLC_HANDSHAKE) & ucCtlBit) )// Shall not turn DLC on when it is on already.
492 {
493 msDlc_FunctionExit();
494 return;
495 }
496
497 msWriteBit(REG_ADDR_DLC_HANDSHAKE, TRUE, ucCtlBit);
498
499 // Request HW to do histogram
500 msWriteByte(REG_ADDR_DLC_HANDSHAKE, msReadByte(REG_ADDR_DLC_HANDSHAKE) & 0xF2);
501
502 msWriteByte(REG_ADDR_DLC_HANDSHAKE, msReadByte(REG_ADDR_DLC_HANDSHAKE) | _BIT2 );
503
504 g_DlcParameters.ucDlcFlickAlphaStart = FLICK_ALPHA_START_COUNTER;
505 g_DlcParameters.ucDlcSlowEvent = 0;
506 }
507 else // Disable
508 {
509 msWriteBit(REG_ADDR_DLC_HANDSHAKE, FALSE, ucCtlBit);
510 }
511
512 msDlc_FunctionExit();
513 }
514
515 //////////////////////////////////////////////////////////////
516 //
517 //////////////////////////////////////////////////////////////
msDlcSetBleOnOff(BOOL bSwitch)518 void msDlcSetBleOnOff(BOOL bSwitch)
519 {
520 g_bSetDlcBleOn= bSwitch ;
521 }
522
523 //////////////////////////////////////////////////////////////
524 //
525 //////////////////////////////////////////////////////////////
msIsBlackVideoEnable(MS_BOOL bWindow)526 MS_BOOL msIsBlackVideoEnable( MS_BOOL bWindow )
527 {
528 MS_BOOL bReturn;
529
530 msVop_FunctionEnter();
531
532 if( MAIN_WINDOW == bWindow)
533 {
534 if(msReadByte(REG_ADDR_VOP_SCREEN_CONTROL) & BIT(1))
535 {
536 bReturn = TRUE;
537 }
538 else
539 {
540 bReturn = FALSE;
541 }
542 }
543 else
544 {
545 if(msReadByte(REG_ADDR_VOP_SCREEN_CONTROL) & BIT(5))
546 {
547 bReturn = TRUE;
548 }
549 else
550 {
551 bReturn = FALSE;
552 }
553 }
554
555 msVop_FunctionExit();
556 return bReturn;
557
558 }
559
560 //////////////////////////////////////////////////////////////
561 //
562 //////////////////////////////////////////////////////////////
msGetAverageLuminous(void)563 BYTE msGetAverageLuminous(void) // = external msGetAverageLuminousValue()
564 {
565 WORD uwTmpAvr;
566
567 // Normalize
568 if (g_wLumiTotalCount!=0)
569 uwTmpAvr = (256 * (DWORD)g_wLumiAverageTemp + (g_wLumiTotalCount/2)) / g_wLumiTotalCount;
570 else
571 uwTmpAvr = 0;
572
573 if (uwTmpAvr >= 255)
574 uwTmpAvr = 255;
575
576 return (BYTE)uwTmpAvr;
577 }
578
579 //////////////////////////////////////////////////////////////
580 //
581 //////////////////////////////////////////////////////////////
msGetAverageLuminous_x4(void)582 WORD msGetAverageLuminous_x4(void) // = external msGetAverageLuminousValue()
583 {
584 WORD uwTmpAvr;
585
586 // Normalize
587 if (g_wLumiTotalCount!=0)
588 uwTmpAvr = (1024 * (DWORD)g_wLumiAverageTemp + (g_wLumiTotalCount/2)) / g_wLumiTotalCount;
589 else
590 uwTmpAvr = 0;
591
592 if (uwTmpAvr >= 1024- 1)
593 uwTmpAvr = 1024- 1;
594
595 return uwTmpAvr;
596 }
597
598 //////////////////////////////////////////////////////////////
599 //
600 //////////////////////////////////////////////////////////////
msGetAverageLuminous_x10(void)601 WORD msGetAverageLuminous_x10(void)
602 {
603 WORD uwTmpAvr;
604
605 // Normalize
606 if (g_wLumiTotalCount!=0)
607 uwTmpAvr = (256 * 10 * (DWORD)g_wLumiAverageTemp + (g_wLumiTotalCount/2)) / g_wLumiTotalCount;
608 else
609 uwTmpAvr = 0;
610
611 if (uwTmpAvr >= (256 * 10 - 1))
612 uwTmpAvr = (256 * 10 - 1);
613
614 return uwTmpAvr;
615 }
616
617 //////////////////////////////////////////////////////////////
618 //
619 //////////////////////////////////////////////////////////////
msGetAverageLuminousSub(void)620 BYTE msGetAverageLuminousSub(void)
621 {
622
623 WORD uwTmpAvr=0, uwLumiTotalCount=0, uwLumiAverageTemp=0 ;
624
625 msDlc_FunctionEnter();
626
627 uwLumiTotalCount = msReadByte(REG_ADDR_HISTOGRAM_SUB_TOTAL_COUNT_H);
628 uwLumiTotalCount = (uwLumiTotalCount << 8) + (WORD)msReadByte(REG_ADDR_HISTOGRAM_SUB_TOTAL_COUNT_L);
629
630 uwLumiAverageTemp = msReadByte(REG_ADDR_HISTOGRAM_SUB_TOTAL_SUM_H);
631 uwLumiAverageTemp = (uwLumiAverageTemp << 8) + (WORD)msReadByte(REG_ADDR_HISTOGRAM_SUB_TOTAL_SUM_L);
632
633 msDlc_FunctionExit();
634
635 // Normalize
636 if (uwLumiTotalCount!=0)
637 uwTmpAvr = (256 * (DWORD)uwLumiAverageTemp + (uwLumiTotalCount/2)) / uwLumiTotalCount;
638 else
639 uwTmpAvr = 0;
640
641 if (uwTmpAvr >= 255)
642 uwTmpAvr = 255;
643
644 return (BYTE)uwTmpAvr;
645 }
646
647 //////////////////////////////////////////////////////////////
648 //
649 //////////////////////////////////////////////////////////////
msGetHistogramHandler(BOOL bWindow)650 BOOL msGetHistogramHandler(BOOL bWindow)
651 {
652 BYTE ucTmp;
653 WORD wTmpHistogramSum; // for protect histogram overflow
654 BYTE ucHistogramOverflowIndex;
655 BYTE ucReturn;
656
657 msDlc_FunctionEnter();
658
659 #if 0 //Have double buffer, does not need to wait.
660 // ENABLE_FAST_HISTOGRAM_CATCH
661 if( !(msReadByte(REG_ADDR_DLC_HANDSHAKE) & _BIT3) ) // Wait until ready
662 {
663 msDlc_FunctionExit();
664 return FALSE;
665 }
666 #endif
667
668 if (g_DlcParameters.ucDlcTimeOut)
669 {
670 // Get histogram 32 data
671 // Total/BW_ref histogram count
672 // putstr("[DLC]: Disable the Burst Read 32-section Histogram\r\n");
673 //dwTotalCount = 0;
674 for (ucTmp = 0, wTmpHistogramSum = 0, ucHistogramOverflowIndex = 0xFF; ucTmp < 32; ucTmp++)
675 {
676 g_wLumaHistogram32H[ucTmp] = msReadByte(REG_ADDR_HISTOGRAM_DATA_32+(2*ucTmp)+1);
677 g_wLumaHistogram32H[ucTmp] <<= 8;
678 g_wLumaHistogram32H[ucTmp] |= msReadByte(REG_ADDR_HISTOGRAM_DATA_32+(2*ucTmp));
679 //printf(" %d",g_wLumaHistogram32H[ucTmp]);
680 //dwTotalCount += g_wLumaHistogram32H[ucTmp];
681
682 // protect histogram overflow
683 if (g_wLumaHistogram32H[ucTmp] >= 65535)
684 {
685 ucHistogramOverflowIndex = ucTmp;
686 //printf("\r\n overflow %d",ucHistogramOverflowIndex);
687 }
688 g_wLumaHistogram32H[ucTmp] >>= 1; // protect histogram overflow
689 wTmpHistogramSum += g_wLumaHistogram32H[ucTmp];
690 }
691
692 //Get the histogram report sum of pixel number .
693 g_wLumiTotalCount = msReadByte(REG_ADDR_HISTOGRAM_TOTAL_COUNT_H);
694 g_wLumiTotalCount = (g_wLumiTotalCount << 8) + (WORD)msReadByte(REG_ADDR_HISTOGRAM_TOTAL_COUNT_L);
695
696 // protect histogram overflow
697 if (ucHistogramOverflowIndex != 0xFF)
698 {
699 if (wTmpHistogramSum > g_wLumiTotalCount)
700 wTmpHistogramSum = g_wLumiTotalCount;
701 g_wLumaHistogram32H[ucHistogramOverflowIndex] += (g_wLumiTotalCount - wTmpHistogramSum);
702 }
703
704 g_ucHistogramTotal_L = msReadByte( REG_ADDR_HISTOGRAM_TOTAL_SUM_L );
705 g_ucHistogramTotal_H = msReadByte( REG_ADDR_HISTOGRAM_TOTAL_SUM_H );
706
707 // Get MIN. & MAX VALUE
708 if( MAIN_WINDOW == bWindow ) // Main window
709 {
710 g_ucHistogramMin = msReadByte(REG_ADDR_MAIN_MIN_VALUE);
711 g_ucHistogramMax = msReadByte(REG_ADDR_MAIN_MAX_VALUE);
712 }
713 else // Sub window
714 {
715 g_ucHistogramMin = msReadByte(REG_ADDR_SUB_MIN_VALUE);
716 g_ucHistogramMax = msReadByte(REG_ADDR_SUB_MAX_VALUE);
717 }
718
719 g_ucTmpAvgN_1 = msGetAverageLuminous();
720 g_wTmpAvgN_1_x10 = msGetAverageLuminous_x10();
721
722 g_wLumiAverageTemp = ((WORD)g_ucHistogramTotal_H<<8) + g_ucHistogramTotal_L;
723 g_ucTmpAvgN = msGetAverageLuminous();
724 g_wTmpAvgN_x10 = msGetAverageLuminous_x10();
725
726 ucReturn = TRUE;
727 }
728 else
729 {
730 ucReturn = FALSE;
731 //putstr("\r\n!!!!! DLC Time Out !!!!!");
732 }
733
734 // After read histogram, request HW to do histogram
735 // Request HW to do histogram
736 msWriteByte(REG_ADDR_DLC_HANDSHAKE, msReadByte(REG_ADDR_DLC_HANDSHAKE) & 0xF2);
737
738 g_DlcParameters.ucDlcTimeOut = 150; // 150ms
739
740 msWriteByte(REG_ADDR_DLC_HANDSHAKE, msReadByte(REG_ADDR_DLC_HANDSHAKE) | _BIT2 );
741
742 msDlc_FunctionExit();
743
744 return ucReturn;
745 }
746
747 //////////////////////////////////////////////////////////////
748 //
749 //////////////////////////////////////////////////////////////
msDlcSetVarHistogramRange(BYTE * pRangeArray)750 void msDlcSetVarHistogramRange(BYTE *pRangeArray)
751 {
752 BYTE ucTmp;
753 DWORD wReg;
754
755 wReg = REG_ADDR_HISTOGRAM_8_RANGE_START;
756 for (ucTmp=0; ucTmp<7 ; ucTmp++)
757 {
758 msWriteByte(wReg, *(pRangeArray + ucTmp));
759 wReg += 1;
760 }
761 }
762
763 //=========================================================
764 //
765 //=========================================================
msDlcLumiDiffCtrl(void)766 void msDlcLumiDiffCtrl(void)
767 {
768 if (g_DlcParameters.ucDlcFlickAlphaStart)
769 {
770 g_DlcParameters.ucDlcFlickAlphaStart--;
771 }
772
773 if (g_DlcParameters.ucDlcSlowEvent)
774 {
775 g_DlcParameters.ucDlcSlowEvent--;
776 g_ucDlcFlickAlpha = 1; // it mean the curve change slowly
777 g_ucDlcFastLoop = 0;
778 }
779 else
780 {
781 if (g_wTmpAvgN_1_x10 >= g_wTmpAvgN_x10)
782 {
783 if ((g_ucDlcFastLoop > 0) || ((g_wTmpAvgN_1_x10 - g_wTmpAvgN_x10 ) >= ((WORD)g_DlcParameters.ucDlcAvgDelta * 10)))
784 {
785 //printf("\r\n1H:Avg = %d",g_ucTmpAvgN_1 - g_ucTmpAvgN);
786 //printf(" g_ucDlcFlickAlpha = %d\r\n",g_ucDlcFlickAlpha);
787
788 g_ucDlcFlickAlpha = g_DlcParameters.ucDlcFastAlphaBlending; // (32/32) = (32/DLC_DEFLICK_BLEND_FACTOR) // it mean the curve change quickly
789 if (g_ucDlcFastLoop == 0)
790 {
791 g_ucDlcFastLoop = (g_DlcParameters.ucDlcFastAlphaBlending/2) * 16;
792 if (g_DlcParameters.ucDlcFastAlphaBlending == 32) // 32 / 2 * 16 = 0 overflow
793 {
794 g_ucDlcFastLoop = 255;
795 }
796 }
797 }
798 else if ((g_DlcParameters.ucDlcAvgDeltaStill <= ((WORD)g_DlcParameters.ucDlcAvgDelta * 10)) && (g_DlcParameters.ucDlcAvgDeltaStill != 0) && ((g_wTmpAvgN_1_x10 - g_wTmpAvgN_x10) <= g_DlcParameters.ucDlcAvgDeltaStill)) // if (Yavg is less than g_DlcParameters.ucDlcAvgDeltaStill) & (Fast change is finish) does NOT do curve change
799 {
800 g_ucDlcFlickAlpha = 0; // (0/32) = (1/DLC_DEFLICK_BLEND_FACTOR) // it mean the curve will be still
801 }
802 else // if ((g_ucTmpAvgN_1 - g_ucTmpAvgN) < g_DlcParameters.ucDlcAvgDelta) // if (Yavg is less than g_DlcParameters.ucDlcAvgDelta) & (Fast change is finish) may do curve change slowly
803 {
804 if ( g_DlcParameters.ucDlcFlickAlphaStart == 0) // chagne source and it's stable
805 {
806 g_ucDlcFlickAlpha = 1; // (1/32) = (1/DLC_DEFLICK_BLEND_FACTOR) // it mean the curve change slowly
807 }
808 else
809 {
810 g_ucDlcFlickAlpha = g_DlcParameters.ucDlcFastAlphaBlending; // (32/32) = (32/DLC_DEFLICK_BLEND_FACTOR) // it mean the curve change quickly
811 }
812 }
813 }
814 else if (g_wTmpAvgN_1_x10 < g_wTmpAvgN_x10)
815 {
816 if ((g_ucDlcFastLoop > 0) || (( g_wTmpAvgN_x10 - g_wTmpAvgN_1_x10 ) >= ((WORD)g_DlcParameters.ucDlcAvgDelta * 10)))
817 {
818 g_ucDlcFlickAlpha = g_DlcParameters.ucDlcFastAlphaBlending; // (32/32) = (32/DLC_DEFLICK_BLEND_FACTOR) // it mean the curve change quickly
819 if (g_ucDlcFastLoop == 0)
820 {
821 g_ucDlcFastLoop = (g_DlcParameters.ucDlcFastAlphaBlending/2) * 16;
822 if (g_DlcParameters.ucDlcFastAlphaBlending == 32) // 32 / 2 * 16 = 0 overflow
823 {
824 g_ucDlcFastLoop = 255;
825 }
826 }
827 }
828 else if ((g_DlcParameters.ucDlcAvgDeltaStill <= ((WORD)g_DlcParameters.ucDlcAvgDelta * 10)) && (g_DlcParameters.ucDlcAvgDeltaStill != 0) && ((g_wTmpAvgN_x10 - g_wTmpAvgN_1_x10) <= g_DlcParameters.ucDlcAvgDeltaStill)) // if (Yavg is less than g_DlcParameters.ucDlcAvgDeltaStill) & (Fast change is finish) does NOT do curve change
829 {
830 g_ucDlcFlickAlpha = 0; // (0/32) = (1/DLC_DEFLICK_BLEND_FACTOR) // it mean the curve will be still
831 }
832 else // if ((g_ucTmpAvgN - g_ucTmpAvgN_1) < g_DlcParameters.ucDlcAvgDelta) // if (Yavg is less than g_DlcParameters.ucDlcAvgDelta) & (Fast change is finish) may do curve change slowly
833 {
834 if (g_DlcParameters.ucDlcFlickAlphaStart == 0) // chagne source and it's stable
835 {
836 g_ucDlcFlickAlpha = 1; // (1/32) = (1/DLC_DEFLICK_BLEND_FACTOR) // it mean the curve change slowly
837 }
838 else
839 {
840 g_ucDlcFlickAlpha = g_DlcParameters.ucDlcFastAlphaBlending; // (32/32) = (32/DLC_DEFLICK_BLEND_FACTOR) // it mean the curve change quickly
841 }
842 }
843 }
844 }
845 }
846
847 //=========================================================
848 //
849 //=========================================================
msDlcHandler(BOOL bWindow)850 void msDlcHandler(BOOL bWindow)
851 {
852 BYTE ucTmp,Tmp,sepPoint =0,sepPoint0 =0,sepPoint1 =0,sepPoint2 =0,ucYAvgNormalize=0,belnging_factor;
853 WORD ucYAvg=0;
854 WORD uwHistogramMax, uwHistogramMax2nd,uwHistogramSlopRatioL, uwHistogramSlopRatioH; // 20110406 Ranma add
855 DWORD uwHistogramAreaSum[32];//,uwPre_Histogram_ShiftR[32],uwPre_Histogram_ShiftL[32]; // 20110406 Ranma add
856 WORD uwHistogramForBleSum=0;
857 WORD uwHistogram_BLE_AreaSum[32];
858 WORD BLE_StartPoint=0,BLE_EndPoint=0,BLE_StartPoint_Correction=0,BLE_EndPoint_Correction=0;
859 WORD BLE_Slop_400,BLE_Slop_480,BLE_Slop_500,BLE_Slop_600,BLE_Slop_800,Dark_BLE_Slop_Min;
860
861 static WORD Pre_BLE_Slop=0x4000;
862 static WORD Pre_g_ucDlcFlickAlpha = 0,Pre_TotalYSum = 0,Pre_BLE_StartPoint_Correction=0xFFF;
863 static BYTE ucPre_YAvg =0x00;
864 static BOOL bPreSubWindowEnable=FALSE;
865 static BYTE ucSubWindowChange=0 ;
866 static WORD uwSubChangeDelayCount=0;
867 BOOL bSubWindowEnable = FALSE;
868 WORD uwBLE_Blend=0,uwBLE_StartPoint_Blend=0,CurveDiff=0,CurveDiff_Coring=0,CurveDiff_base=0,YAvg_base=0;
869 BYTE g_ucDlcFlickAlpha_Max=0,g_ucDlcFlickAlpha_Min=0,YAvg_TH_H,YAvg_TH_L,g_ucDlcFlickAlpha_temp,ucDlcFlickAlpha_Diff=0;
870 DWORD dwSumBelowAvg=0, dwSumAboveAvg=0,dwHistogramDlcSlop[17],BLE_Slop=0x400,BLE_Slop_tmp=0x400;
871 WORD uwArrayComp, uwArraySum, Delta_YAvg=0,coeff0,coeff1,coeff2;
872 DWORD His_ratio_BelowAvg,His_ratio_AboveAvg;
873 DWORD g_uwCurveHistogram0[16],g_uwCurveHistogram1[16],g_uwCurveHistogram2[16];
874 DWORD BLE_sum=0;
875 WORD Pre_YAvg_base,Diff_L,Diff_M,Diff_H,Pre_CurveDiff_base;
876
877 //When DLC algorithm is from kernel, force return.
878 if(g_DlcParameters.ucDlcAlgorithmMode == XC_DLC_ALGORITHM_KERNEL)
879 {
880 return ;
881 }
882
883 msDlc_FunctionEnter();
884
885 msDlcLumiDiffCtrl();
886
887 if(g_DlcParameters.ucDlcAlgorithmMode == XC_DLC_ALGORITHM_OLD)
888 {
889 // If difference is too small, don't do dlc
890 if( ((g_ucHistogramMax-g_ucHistogramMin) < 0x0A) || (g_ucHistogramMin >= g_ucHistogramMax) )
891 {
892 if (g_DlcParameters.ucDlcPureImageMode == DLC_PURE_IMAGE_DO_NOTHING)
893 {
894 msDlc_FunctionExit();
895 return;
896 }
897 else if (g_DlcParameters.ucDlcPureImageMode == DLC_PURE_IMAGE_LINEAR_CURVE)
898 {
899 BYTE ucLuma = 0x07;
900 for( ucTmp = 0; ucTmp < 16; ++ ucTmp )
901 {
902 g_ucTable[ucTmp] = ucLuma;
903 ucLuma += 0x10;
904 }
905
906 g_ucDlcFlickAlpha = g_DlcParameters.ucDlcFastAlphaBlending; // it mean the curve change quickly
907
908 // Write data to luma curve ...
909 msDlcWriteCurve(bWindow);
910 if(g_bSetDLCCurveBoth)
911 {
912 msDlcWriteCurve(SUB_WINDOW);
913 }
914 msDlc_FunctionExit();
915 return;
916 }
917 else // g_DlcParameters.ucDlcPureImageMode == DLC_PURE_IMAGE_DLC_CURVE
918 ;
919 }
920
921 //=========================================================
922 // LC[6] - H0 ~ H12
923 //=========================================================
924 uwArraySum=0;
925 for(ucTmp=0;ucTmp<13;ucTmp++)
926 uwArraySum+= g_wLumaHistogram32H[ucTmp];
927 uwArrayComp = uwArraySum / 13;
928
929 if (uwArrayComp < g_dwFactory_7)
930 {
931 ucTmp = ((g_dwFactory_7 - uwArrayComp) * SD2 / (Lstep*128))+1;
932 if (ucTmp > LD2)
933 ucTmp = LD2;
934 g_ucTable[6] = 0x67 - ucTmp;
935 }
936 else if (uwArrayComp > g_dwFactory_9)
937 {
938 ucTmp = ((uwArrayComp - g_dwFactory_9) * SD1 / (Hstep*128))+1;
939 if (ucTmp > LD1)
940 ucTmp = LD1;
941 g_ucTable[6] = 0x67 + ucTmp;
942 }
943 else
944 g_ucTable[6] = 0x67;
945
946 if ((g_ucTable[6]> s_Slope[Slope_6])&&((g_ucTable[6] - s_Slope[Slope_6])>=2))
947 g_ucTable[6] = g_ucTable[6] - 1;
948 else if ((s_Slope[Slope_6]> g_ucTable[6])&&((s_Slope[Slope_6] - g_ucTable[6])>=2))
949 g_ucTable[6] = g_ucTable[6] + 1;
950 else
951 g_ucTable[6] = s_Slope[Slope_6];
952
953 //=========================================================
954 // LC[4] - H0 ~ H8
955 //=========================================================
956
957 g_ucTable[4] = ((g_ucTable[6] - 0x07) * 2 / 3) + 0x07;
958
959 uwArraySum = uwArraySum - (g_wLumaHistogram32H[12] + g_wLumaHistogram32H[11] + g_wLumaHistogram32H[10] + g_wLumaHistogram32H[9]);
960 uwArrayComp = uwArraySum/9;
961
962 if (uwArrayComp < g_dwFactory_7)
963 {
964 ucTmp = ((g_dwFactory_7 - uwArrayComp) * SC2 / (Lstep*128))+1;
965 if (ucTmp > LC2)
966 ucTmp = LC2;
967 g_ucTable[4] = g_ucTable[4] - ucTmp;
968 }
969 else if (uwArrayComp > g_dwFactory_9)
970 {
971 ucTmp = ((uwArrayComp - g_dwFactory_9) * SC1 / (Hstep*128))+1;
972 if (ucTmp > LC1)
973 ucTmp = LC1;
974 g_ucTable[4] = g_ucTable[4] + ucTmp;
975 }
976
977 if ((g_ucTable[4]> s_Slope[Slope_4])&&((g_ucTable[4]- s_Slope[Slope_4])>=2))
978 g_ucTable[4] = g_ucTable[4] - 1;
979 else if ((s_Slope[Slope_4]> g_ucTable[4])&&((s_Slope[Slope_4]- g_ucTable[4])>=2))
980 g_ucTable[4] = g_ucTable[4] + 1;
981 else
982 g_ucTable[4] = s_Slope[Slope_4];
983
984 //=========================================================
985 // LC[2] - H0 ~ H4
986 //=========================================================
987
988 g_ucTable[2] = ((g_ucTable[4] - 0x07) * 1 / 2) + 0x07;
989 uwArraySum = uwArraySum - (g_wLumaHistogram32H[8] + g_wLumaHistogram32H[7] + g_wLumaHistogram32H[6] + g_wLumaHistogram32H[5]);
990 uwArrayComp = uwArraySum / 5;
991
992 if (uwArrayComp < g_dwFactory_7)
993 {
994 ucTmp = ((g_dwFactory_7 - uwArrayComp) * SB2 / (Lstep*128))+1;
995 if (ucTmp > LB2)
996 ucTmp = LB2;
997 g_ucTable[2] = g_ucTable[2] - ucTmp;
998 }
999 else if (uwArrayComp > g_dwFactory_9)
1000 {
1001 ucTmp = ((uwArrayComp - g_dwFactory_9) * SB1 / (Hstep*128))+1;
1002 if (ucTmp > LB1)
1003 ucTmp = LB1;
1004 g_ucTable[2] = g_ucTable[2] + ucTmp;
1005 }
1006
1007 if ((g_ucTable[2]> s_Slope[Slope_2])&&((g_ucTable[2]- s_Slope[Slope_2])>=2))
1008 g_ucTable[2] = g_ucTable[2] - 1;
1009 else if ((s_Slope[Slope_2]> g_ucTable[2])&&((s_Slope[Slope_2]- g_ucTable[2])>=2))
1010 g_ucTable[2] = g_ucTable[2] + 1;
1011 else
1012 g_ucTable[2] = s_Slope[Slope_2];
1013
1014 //=========================================================
1015 // LC[1] - H0 ~ H2
1016 //=========================================================
1017
1018 g_ucTable[1] = ((g_ucTable[2] - 0x07) * 1 / 2) + 0x07;
1019 uwArraySum = uwArraySum - (g_wLumaHistogram32H[4] + g_wLumaHistogram32H[3]);
1020 uwArrayComp = uwArraySum / 3;
1021
1022 if (uwArrayComp < g_dwFactory_7)
1023 {
1024 ucTmp = ((g_dwFactory_7 - uwArrayComp) * SA2 / (Lstep*128))+1;
1025 if (ucTmp > LA2)
1026 ucTmp = LA2;
1027
1028 if (g_ucTable[1] <= ucTmp)
1029 g_ucTable[1] = 0x00;
1030 else
1031 g_ucTable[1] = g_ucTable[1] - ucTmp;
1032 }
1033 else if (uwArrayComp > g_dwFactory_9)
1034 {
1035 ucTmp = ((uwArrayComp - g_dwFactory_9) * SA1 / (Hstep*128))+1;
1036 if (ucTmp > LA1)
1037 ucTmp = LA1;
1038 g_ucTable[1] = g_ucTable[1] + ucTmp;
1039 }
1040
1041 if ((g_ucTable[1]> s_Slope[Slope_1])&&((g_ucTable[1]- s_Slope[Slope_1])>=1))
1042 g_ucTable[1] = g_ucTable[1] - 1;
1043 else if ((s_Slope[Slope_1]> g_ucTable[1])&&((s_Slope[Slope_1]- g_ucTable[1])>=2))
1044 g_ucTable[1] = g_ucTable[1] + 1;
1045 else
1046 g_ucTable[1] = s_Slope[Slope_1];
1047
1048 //=========================================================
1049 // LC[9] - H19 ~ H31
1050 //=========================================================
1051
1052 uwArraySum=0;
1053 for (ucTmp=19; ucTmp<32; ucTmp++)
1054 uwArraySum+= g_wLumaHistogram32H[ucTmp];
1055
1056 uwArrayComp = uwArraySum / 13;
1057
1058 if (uwArrayComp < g_dwFactory_7)
1059 {
1060 ucTmp = ((g_dwFactory_7 - uwArrayComp) * SE1 / (Lstep*128))+1;
1061 if (ucTmp > LE1)
1062 ucTmp = LE1;
1063 g_ucTable[9] = 0x97 + ucTmp;
1064 }
1065 else if (uwArrayComp > g_dwFactory_9)
1066 {
1067 ucTmp = ((uwArrayComp - g_dwFactory_9) * SE2 / (Hstep*128))+1;
1068 if (ucTmp > LE2)
1069 ucTmp = LE2;
1070 g_ucTable[9] = 0x97 - ucTmp;
1071 }
1072 else
1073 g_ucTable[9] = 0x97;
1074
1075 //=========================================================
1076 // LC[11] - H23 ~ H31
1077 //=========================================================
1078
1079 g_ucTable[11] = 0xF7 - ((0xF7 - g_ucTable[9]) * 2 / 3);
1080 uwArraySum = uwArraySum - (g_wLumaHistogram32H[19] + g_wLumaHistogram32H[20] + g_wLumaHistogram32H[21] + g_wLumaHistogram32H[22]);
1081 uwArrayComp = uwArraySum / 9;
1082
1083 if (uwArrayComp< g_dwFactory_7)
1084 {
1085 ucTmp = ((g_dwFactory_7 - uwArrayComp) * SF1 / (Lstep*128))+1;
1086 if (ucTmp > LF1)
1087 ucTmp = LF1;
1088 g_ucTable[11] = g_ucTable[11] + ucTmp;
1089 }
1090 else if (uwArrayComp > g_dwFactory_9)
1091 {
1092 ucTmp = ((uwArrayComp - g_dwFactory_9) * SF2 / (Hstep*128))+1;
1093 if (ucTmp > LF2)
1094 ucTmp = LF2;
1095 g_ucTable[11] = g_ucTable[11] - ucTmp;
1096 }
1097
1098 //=========================================================
1099 // LC[13] - H27 ~ H31
1100 //=========================================================
1101
1102 g_ucTable[13] = 0xF7 - ((0xF7 - g_ucTable[11]) * 1 / 2);
1103 uwArraySum = uwArraySum - (g_wLumaHistogram32H[23] + g_wLumaHistogram32H[24] + g_wLumaHistogram32H[25] + g_wLumaHistogram32H[26]);
1104 uwArrayComp = uwArraySum / 5;
1105
1106 if (uwArrayComp< g_dwFactory_7)
1107 {
1108 ucTmp = ((g_dwFactory_7 - uwArrayComp) * SG1 / (Lstep*128))+1;
1109 if (ucTmp > LG1)
1110 ucTmp = LG1;
1111
1112 if ((0xFF - g_ucTable[13]) <= ucTmp)
1113 g_ucTable[13] = 0xFF;
1114 else
1115 g_ucTable[13] = g_ucTable[13] + ucTmp;
1116 }
1117 else if (uwArrayComp > g_dwFactory_9)
1118 {
1119 ucTmp = ((uwArrayComp - g_dwFactory_9) * SG2 / (Hstep*128))+1;
1120 if (ucTmp > LG2)
1121 ucTmp = LG2;
1122 g_ucTable[13] = g_ucTable[13] - ucTmp;
1123 }
1124
1125 //=========================================================
1126 // LC[14] - H29 ~ H31
1127 //=========================================================
1128
1129 g_ucTable[14] = 0xF7 - ((0xF7 - g_ucTable[13]) * 1 / 2);
1130 uwArraySum = uwArraySum - (g_wLumaHistogram32H[27] + g_wLumaHistogram32H[28]);
1131 uwArrayComp = uwArraySum / 3;
1132
1133 if (uwArrayComp < g_dwFactory_7)
1134 {
1135 ucTmp = ((g_dwFactory_7 - uwArrayComp) * SH1 / (Lstep*128))+1;
1136 if (ucTmp > LH1)
1137 ucTmp = LH1;
1138
1139 if ((0xFF - g_ucTable[14]) <= ucTmp)
1140 g_ucTable[14] = 0xFF;
1141 else
1142 g_ucTable[14] = g_ucTable[14] + ucTmp;
1143 }
1144 else if (uwArrayComp > g_dwFactory_9)
1145 {
1146 ucTmp = ((uwArrayComp - g_dwFactory_9) * SH2 / (Hstep*128))+1;
1147 if (ucTmp > LH2)
1148 ucTmp = LH2;
1149 g_ucTable[14] =g_ucTable[14] - ucTmp;
1150 }
1151
1152 s_Slope[Slope_1] = g_ucTable[1];
1153 s_Slope[Slope_2] = g_ucTable[2];
1154 s_Slope[Slope_4] = g_ucTable[4];
1155 s_Slope[Slope_6] = g_ucTable[6];
1156
1157 g_ucTable[3] = g_ucTable[2] + ((g_ucTable[4] - g_ucTable[2]) * 1 / 2);
1158 g_ucTable[5] = g_ucTable[4] + ((g_ucTable[6] - g_ucTable[4]) * 1 / 2);
1159 g_ucTable[7] = g_ucTable[6] + ((g_ucTable[9] - g_ucTable[6]) * 1 / 3);
1160 g_ucTable[8] = g_ucTable[6] + ((g_ucTable[9] - g_ucTable[6]) * 2 / 3);
1161 g_ucTable[10] = g_ucTable[9] + ((g_ucTable[11] - g_ucTable[9]) * 1 / 2);
1162 g_ucTable[12] = g_ucTable[11] + ((g_ucTable[13] - g_ucTable[11]) * 1 / 2);
1163 g_ucTable[0] = g_ucTable[1]/3; // Joseph 20081014
1164 g_ucTable[15] = 0xFF - ((0xFF - g_ucTable[14]) / 3);
1165 g_ucTable[15]= ((g_ucTable[15]) / 2) + (0xf7 / 2);
1166
1167 // Get Average Value
1168 ucYAvg = msGetAverageLuminous();
1169
1170 //printf("\r\n ucYAvg = %d",ucYAvg);
1171 if (ucYAvg >= g_DlcParameters.ucDlcYAvgThresholdH)
1172 {
1173 for (ucTmp=0; ucTmp<16; ucTmp++)
1174 {
1175 g_DlcParameters.ucLumaCurve2[ucTmp] = g_DlcParameters.ucLumaCurve2_a[ucTmp];
1176 }
1177 }
1178 else if (ucYAvg <= g_DlcParameters.ucDlcYAvgThresholdL)
1179 {
1180 for (ucTmp=0; ucTmp<16; ucTmp++)
1181 {
1182 g_DlcParameters.ucLumaCurve2[ucTmp] = g_DlcParameters.ucLumaCurve2_b[ucTmp];
1183 }
1184 }
1185 else // (ucYAvg > g_DlcParameters.ucDlcYAvgThresholdL) && (ucYAvg < g_DlcParameters.ucDlcYAvgThresholdH)
1186 {
1187 WORD wYavgW;
1188
1189 wYavgW = ((WORD)(ucYAvg - g_DlcParameters.ucDlcYAvgThresholdL) * 128) / (g_DlcParameters.ucDlcYAvgThresholdH - g_DlcParameters.ucDlcYAvgThresholdL);
1190
1191 for (ucTmp=0; ucTmp<16; ucTmp++)
1192 {
1193 g_DlcParameters.ucLumaCurve2[ucTmp] = ((WORD)(wYavgW * g_DlcParameters.ucLumaCurve2_a[ucTmp]) + (WORD)((128 - wYavgW) * g_DlcParameters.ucLumaCurve2_b[ucTmp])) / 128;
1194 }
1195 }
1196
1197 if (((WORD)g_ucTable[0] + g_DlcParameters.ucLumaCurve[0] + g_DlcParameters.ucLumaCurve2[0]) >= (0x07 + 0x07))
1198 g_ucTable[0] = g_ucTable[0]+(g_DlcParameters.ucLumaCurve[0]-0x07)+(g_DlcParameters.ucLumaCurve2[0]-0x07);
1199 else
1200 g_ucTable[0] = 0;
1201
1202 g_ucTable[1] = g_ucTable[1]+(g_DlcParameters.ucLumaCurve[1]-0x17)+(g_DlcParameters.ucLumaCurve2[1]-0x17);
1203 g_ucTable[2] = g_ucTable[2]+(g_DlcParameters.ucLumaCurve[2]-0x27)+(g_DlcParameters.ucLumaCurve2[2]-0x27);
1204 g_ucTable[3] = g_ucTable[3]+(g_DlcParameters.ucLumaCurve[3]-0x37)+(g_DlcParameters.ucLumaCurve2[3]-0x37);
1205 g_ucTable[4] = g_ucTable[4]+(g_DlcParameters.ucLumaCurve[4]-0x47)+(g_DlcParameters.ucLumaCurve2[4]-0x47);
1206 g_ucTable[5] = g_ucTable[5]+(g_DlcParameters.ucLumaCurve[5]-0x57)+(g_DlcParameters.ucLumaCurve2[5]-0x57);
1207 g_ucTable[6] = g_ucTable[6]+(g_DlcParameters.ucLumaCurve[6]-0x67)+(g_DlcParameters.ucLumaCurve2[6]-0x67);
1208 g_ucTable[7] = g_ucTable[7]+(g_DlcParameters.ucLumaCurve[7]-0x77)+(g_DlcParameters.ucLumaCurve2[7]-0x77);
1209 g_ucTable[8] = g_ucTable[8]+(g_DlcParameters.ucLumaCurve[8]-0x87)+(g_DlcParameters.ucLumaCurve2[8]-0x87);
1210 g_ucTable[9] = g_ucTable[9]+(g_DlcParameters.ucLumaCurve[9]-0x97)+(g_DlcParameters.ucLumaCurve2[9]-0x97);
1211 g_ucTable[10] = g_ucTable[10]+(g_DlcParameters.ucLumaCurve[10]-0xa7)+(g_DlcParameters.ucLumaCurve2[10]-0xa7);
1212 g_ucTable[11] = g_ucTable[11]+(g_DlcParameters.ucLumaCurve[11]-0xb7)+(g_DlcParameters.ucLumaCurve2[11]-0xb7);
1213 g_ucTable[12] = g_ucTable[12]+(g_DlcParameters.ucLumaCurve[12]-0xc7)+(g_DlcParameters.ucLumaCurve2[12]-0xc7);
1214 g_ucTable[13] = g_ucTable[13]+(g_DlcParameters.ucLumaCurve[13]-0xd7)+(g_DlcParameters.ucLumaCurve2[13]-0xd7);
1215 g_ucTable[14] = g_ucTable[14]+(g_DlcParameters.ucLumaCurve[14]-0xe7)+(g_DlcParameters.ucLumaCurve2[14]-0xe7);
1216 if (((WORD)g_ucTable[15] + g_DlcParameters.ucLumaCurve[15] + g_DlcParameters.ucLumaCurve2[15] - 0xF7 - 0xF7) < 0xFF)
1217 g_ucTable[15] = g_ucTable[15]+(g_DlcParameters.ucLumaCurve[15]-0xf7)+(g_DlcParameters.ucLumaCurve2[15]-0xf7);
1218 else
1219 g_ucTable[15] = 0xFF;
1220
1221 // Check Over Flow & Under Flow
1222 if (g_ucTable[15] < 0xD0)
1223 g_ucTable[15] = 0xFF;
1224 if (g_ucTable[14] < 0x90)
1225 g_ucTable[14] = 0xFF;
1226 if (g_ucTable[13] < 0x70)
1227 g_ucTable[13] = 0xFF;
1228 if (g_ucTable[12] < 0x60)
1229 g_ucTable[12] = 0xFF;
1230 if (g_ucTable[11] < 0x50)
1231 g_ucTable[11] = 0xFF;
1232 if (g_ucTable[2] > 0x90)
1233 g_ucTable[2] = 0x0;
1234 if (g_ucTable[1] > 0x60)
1235 g_ucTable[1] = 0x0;
1236 if (g_ucTable[0] > 0x30)
1237 g_ucTable[0] = 0x0;
1238 }
1239 else //New DLC Algorithm
1240 {
1241
1242 #if 0 //For customer require. Run DLC algorithm when static field .
1243 if((g_wLumiAverageTemp-Pre_TotalYSum)==0)
1244 {
1245 return;
1246 }
1247 else
1248 #endif
1249 {
1250 ucYAvg = msGetAverageLuminous();
1251
1252 for (ucTmp=0; ucTmp<32; ucTmp++)
1253 {
1254 if(ucTmp==0)
1255 {
1256 uwHistogramAreaSum[ucTmp]=g_wLumaHistogram32H[ucTmp];
1257 }
1258 else
1259 {
1260 uwHistogramAreaSum[ucTmp] = uwHistogramAreaSum[ucTmp-1] + g_wLumaHistogram32H[ucTmp];
1261 }
1262 }
1263
1264 //Mantis issue of 0232938:Hsense A3 DLC uwHistogramAreaSum[31]=0 will code dump, the divisor can't to be equal to zero .
1265 if(uwHistogramAreaSum[31]==0)
1266 {
1267 DLC_DEBUG(printf("\n Error in [New DLC Algorithm][ %s , %d ] uwHistogramAreaSum[31]=0 !!!\n", __FUNCTION__,__LINE__));
1268 return;
1269 }
1270
1271
1272 // ~~~~~~~~~~~~~~~~~~~~~~~~Pure Image Detect ~~~~~~~~~~~~~~~~~~~~~~~~
1273 if( ((g_ucHistogramMax-g_ucHistogramMin) <= 10) || (g_ucHistogramMin >= g_ucHistogramMax) )
1274 {
1275 g_wPIAlpha = 256;
1276 }
1277 else if ((g_ucHistogramMax-g_ucHistogramMin) >= 26)
1278 {
1279 g_wPIAlpha = 0;
1280 }
1281 else
1282 {
1283 g_wPIAlpha = ((26-(g_ucHistogramMax-g_ucHistogramMin))*256+8)/16;
1284 }
1285
1286 if(g_wPIAlpha <= 0)
1287 {
1288 g_wPIAlpha = 0;
1289 }
1290 else if (g_wPIAlpha >= 256)
1291 {
1292 g_wPIAlpha = 256;
1293 }
1294 else
1295 {
1296 g_wPIAlpha = g_wPIAlpha;
1297 }
1298 // ~~~~~~~~~~~~~~~~~~~~~~~~Pure Image Detect End ~~~~~~~~~~~~~~~~~~~~~~~~
1299
1300 if(ucYAvg >= g_DlcParameters.ucDlcYAvgThresholdH)
1301 {
1302 ucYAvgNormalize=g_DlcParameters.ucDlcSepPointL;
1303 }
1304 else if(ucYAvg <= g_DlcParameters.ucDlcYAvgThresholdL)
1305 {
1306 ucYAvgNormalize=g_DlcParameters.ucDlcSepPointH;
1307 }
1308 else
1309 {
1310 ucYAvgNormalize=((ucYAvg-g_DlcParameters.ucDlcYAvgThresholdL)*g_DlcParameters.ucDlcSepPointL
1311 +(g_DlcParameters.ucDlcYAvgThresholdH-ucYAvg)*g_DlcParameters.ucDlcSepPointH)
1312 /(g_DlcParameters.ucDlcYAvgThresholdH-g_DlcParameters.ucDlcYAvgThresholdL);
1313 }
1314
1315 for (ucTmp=0; ucTmp<31; ucTmp++)
1316 {
1317 if(((ucTmp+1)*8)<ucYAvgNormalize)
1318 {
1319 dwSumBelowAvg = uwHistogramAreaSum[ucTmp]
1320 +((ucYAvgNormalize-(ucTmp+1)*8)*g_wLumaHistogram32H[(ucTmp+1)]+4)/8;
1321 }
1322 }
1323
1324 dwSumAboveAvg = uwHistogramAreaSum[31] - dwSumBelowAvg ;
1325
1326 His_ratio_BelowAvg = (4096*dwSumBelowAvg + (uwHistogramAreaSum[31]/2))/uwHistogramAreaSum[31];
1327 His_ratio_AboveAvg = (4096*dwSumAboveAvg + (uwHistogramAreaSum[31]/2))/uwHistogramAreaSum[31];
1328
1329 if(His_ratio_BelowAvg > 128)
1330 {
1331 His_ratio_BelowAvg = 128;
1332 }
1333 if(His_ratio_AboveAvg > 128)
1334 {
1335 His_ratio_AboveAvg = 128;
1336 }
1337
1338 for (ucTmp=0; ucTmp<32; ucTmp++)
1339 {
1340 uwHistogram_BLE_AreaSum[ucTmp]=((1024*uwHistogramAreaSum[ucTmp])+uwHistogramAreaSum[31]/2)/uwHistogramAreaSum[31];
1341
1342 if(uwHistogram_BLE_AreaSum[ucTmp]>1024)
1343 {
1344 uwHistogram_BLE_AreaSum[ucTmp]=1024;
1345 }
1346 }
1347 //uwHistogram_BLE_AreaSum[ucTmp] = histogram Add to normalize 1024
1348
1349 if ((dwSumBelowAvg == 0)&&(dwSumAboveAvg != 0))
1350 {
1351 for (ucTmp = 0; ucTmp < 32; ucTmp++)
1352 {
1353 if (ucYAvgNormalize >= (((WORD)ucTmp+1)*8))
1354 {
1355 uwHistogramAreaSum[ucTmp] = (ucTmp+1)*8*4;
1356 }
1357 else
1358 {
1359 uwHistogramAreaSum[ucTmp] = ucYAvgNormalize*4 + ((DWORD)uwHistogramAreaSum[ucTmp]*(1024-ucYAvgNormalize*4)+(dwSumAboveAvg/2))/dwSumAboveAvg;
1360 if(uwHistogramAreaSum[ucTmp] >= ((ucTmp+1)*32))
1361 {
1362 uwHistogramAreaSum[ucTmp] = ((ucTmp+1)*32) + (((uwHistogramAreaSum[ucTmp] - ((ucTmp+1)*32))*His_ratio_AboveAvg)/128);
1363 }
1364 else
1365 {
1366 uwHistogramAreaSum[ucTmp] = ((ucTmp+1)*32) - (((((ucTmp+1)*32) - uwHistogramAreaSum[ucTmp])*His_ratio_AboveAvg)/128);
1367 }
1368 }
1369 }
1370 }
1371 else if ((dwSumBelowAvg != 0)&&(dwSumAboveAvg == 0))
1372 {
1373 for (ucTmp = 0; ucTmp < 32; ucTmp++)
1374 {
1375 if (ucYAvgNormalize >= (((WORD)ucTmp+1)*8))
1376 {
1377 uwHistogramAreaSum[ucTmp] = ((DWORD)uwHistogramAreaSum[ucTmp]*ucYAvgNormalize*4+(dwSumBelowAvg/2))/dwSumBelowAvg;
1378 if(uwHistogramAreaSum[ucTmp] >= ((ucTmp+1)*32))
1379 {
1380 uwHistogramAreaSum[ucTmp] = ((ucTmp+1)*32) + (((uwHistogramAreaSum[ucTmp] - ((ucTmp+1)*32))*His_ratio_BelowAvg)/128);
1381 }
1382 else
1383 {
1384 uwHistogramAreaSum[ucTmp] = ((ucTmp+1)*32) - (((((ucTmp+1)*32) - uwHistogramAreaSum[ucTmp])*His_ratio_BelowAvg)/128);
1385 }
1386 }
1387 else
1388 {
1389 uwHistogramAreaSum[ucTmp] = (ucTmp+1)*8*4;
1390 }
1391 }
1392 }
1393 else if((dwSumBelowAvg == 0)&&(dwSumAboveAvg == 0))
1394 {
1395 for (ucTmp = 0; ucTmp < 32; ucTmp++)
1396 {
1397 uwHistogramAreaSum[ucTmp] = (ucTmp+1)*8*4;
1398 }
1399 }
1400 else
1401 {
1402 for (ucTmp = 0; ucTmp < 32; ucTmp++)
1403 {
1404 if (ucYAvgNormalize >= (((WORD)ucTmp+1)*8))
1405 {
1406 uwHistogramAreaSum[ucTmp] = ((DWORD)uwHistogramAreaSum[ucTmp]*ucYAvgNormalize*4+(dwSumBelowAvg/2))/dwSumBelowAvg;
1407 if(uwHistogramAreaSum[ucTmp] >= ((ucTmp+1)*32))
1408 {
1409 uwHistogramAreaSum[ucTmp] = ((ucTmp+1)*32) + (((uwHistogramAreaSum[ucTmp] - ((ucTmp+1)*32))*His_ratio_BelowAvg)/128);
1410 }
1411 else
1412 {
1413 uwHistogramAreaSum[ucTmp] = ((ucTmp+1)*32) - (((((ucTmp+1)*32) - uwHistogramAreaSum[ucTmp])*His_ratio_BelowAvg)/128);
1414 }
1415 }
1416 else
1417 {
1418 uwHistogramAreaSum[ucTmp] = ucYAvgNormalize*4 + ((uwHistogramAreaSum[ucTmp]-dwSumBelowAvg)*(1024-ucYAvgNormalize*4)+(dwSumAboveAvg/2))/dwSumAboveAvg;
1419
1420 if(uwHistogramAreaSum[ucTmp] >= ((ucTmp+1)*32))
1421 {
1422 uwHistogramAreaSum[ucTmp] = ((ucTmp+1)*32) + (((uwHistogramAreaSum[ucTmp] - ((ucTmp+1)*32))*His_ratio_AboveAvg)/128);
1423 }
1424 else
1425 {
1426 uwHistogramAreaSum[ucTmp] = ((ucTmp+1)*32) - (((((ucTmp+1)*32) - uwHistogramAreaSum[ucTmp])*His_ratio_AboveAvg)/128);
1427 }
1428 }
1429 }
1430 }
1431
1432 //down sampling to 16 numbers (store to uwHistogramAreaSum[0~15])
1433
1434 for (ucTmp=0; ucTmp<16; ucTmp++)
1435 {
1436 uwHistogramAreaSum[ucTmp] = uwHistogramAreaSum[ucTmp*2]; //
1437 }
1438
1439 //histogram_DLC limit by slope
1440 uwHistogramMax = 0;
1441
1442 for (ucTmp=0; ucTmp<=16; ucTmp++)
1443 {
1444 if (ucTmp == 0)
1445 {
1446 dwHistogramDlcSlop[ucTmp] = ((uwHistogramAreaSum[ucTmp] - 0) * 256 + 16) / 64;
1447
1448 if (dwHistogramDlcSlop[ucTmp] < 257)
1449 {
1450 dwHistogramDlcSlop[ucTmp] = 257;
1451 }
1452 }
1453 else if (ucTmp == 16)
1454 {
1455 dwHistogramDlcSlop[ucTmp] = ((1024 - uwHistogramAreaSum[ucTmp-1]) * 256 + 16) / 64;
1456
1457 if (dwHistogramDlcSlop[ucTmp] < 257)
1458 {
1459 dwHistogramDlcSlop[ucTmp] = 257;
1460 }
1461 }
1462 else
1463 {
1464 dwHistogramDlcSlop[ucTmp] = ((uwHistogramAreaSum[ucTmp] - uwHistogramAreaSum[ucTmp-1]) * 256 + 32) / 64; //find slop
1465
1466 if (dwHistogramDlcSlop[ucTmp] < 257)
1467 {
1468 dwHistogramDlcSlop[ucTmp] = 257; //(only take the slop > 1)
1469 }
1470 }
1471
1472 dwHistogramDlcSlop[ucTmp] = ((g_DlcParameters.ucDlcHistogramLimitCurve[ucTmp]*512)+((dwHistogramDlcSlop[ucTmp]-256)/2)) / (dwHistogramDlcSlop[ucTmp]-256) ; //SlopRatio 8bit 256=1x
1473
1474 if(dwHistogramDlcSlop[ucTmp] > 0xFFFF)
1475 {
1476 dwHistogramDlcSlop[ucTmp] = 0xFFFF;
1477 }
1478 }
1479
1480 sepPoint = (ucYAvgNormalize-8)/16;
1481 sepPoint0 = sepPoint-1;
1482 sepPoint1 = sepPoint;
1483 sepPoint2 = sepPoint+1;
1484
1485 if(ucYAvgNormalize < (sepPoint2*16))
1486 {
1487 //sepPoint0 = sepPoint;
1488 //sepPoint1 = sepPoint+1;
1489 //sepPoint2 = sepPoint+2;
1490 coeff0 = (((3*((sepPoint2*16)-ucYAvgNormalize)*((sepPoint2*16)-ucYAvgNormalize))+64*((sepPoint2*16)-ucYAvgNormalize)+320));
1491 coeff1 = ((1408-6*((sepPoint2*16)-ucYAvgNormalize)*((sepPoint2*16)-ucYAvgNormalize)));
1492 coeff2 = 2048-coeff0-coeff1;
1493 }
1494 else
1495 {
1496 //sepPoint0 = sepPoint-1;
1497 //sepPoint1 = sepPoint;
1498 //sepPoint2 = sepPoint+1;
1499 coeff0 = (((3*(ucYAvgNormalize-(sepPoint2*16))*(ucYAvgNormalize-(sepPoint2*16)))-64*(ucYAvgNormalize-(sepPoint2*16))+320));
1500 coeff1 = ((1408-6*(ucYAvgNormalize-(sepPoint2*16))*(ucYAvgNormalize-(sepPoint2*16))));
1501 coeff2 = 2048-coeff0-coeff1;
1502 }
1503
1504 //Calculate for sepPoint0~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1505 uwHistogramSlopRatioL = 256;
1506 uwHistogramSlopRatioH = 256;
1507
1508 for (ucTmp = 0; ucTmp<= (sepPoint0+1); ucTmp++)
1509 {
1510 uwHistogramMax2nd = dwHistogramDlcSlop[ucTmp];
1511
1512 if (uwHistogramMax2nd < uwHistogramSlopRatioL)
1513 {
1514 uwHistogramSlopRatioL = uwHistogramMax2nd;
1515 }
1516 }
1517
1518 for (ucTmp = sepPoint0; ucTmp<=16; ucTmp++)
1519 {
1520 uwHistogramMax2nd = dwHistogramDlcSlop[ucTmp];
1521
1522 if (uwHistogramMax2nd < uwHistogramSlopRatioH)
1523 {
1524 uwHistogramSlopRatioH = uwHistogramMax2nd;
1525 }
1526 }
1527
1528 // calcute final target curve for sepPoint0
1529 for (ucTmp = 0; ucTmp < 16; ucTmp++)
1530 {
1531 if (sepPoint0 >= (WORD)ucTmp)
1532 {
1533 if(uwHistogramAreaSum[ucTmp]>(ucTmp * 64 + 32))
1534 {
1535 g_uwCurveHistogram0[ucTmp] = (ucTmp * 64 + 32) + (((uwHistogramAreaSum[ucTmp] - (ucTmp * 64 + 32)) * uwHistogramSlopRatioL + 128) / 256 ) ;
1536 }
1537 else
1538 {
1539 g_uwCurveHistogram0[ucTmp] = (ucTmp * 64 + 32) - ((((ucTmp * 64 + 32)- uwHistogramAreaSum[ucTmp]) * uwHistogramSlopRatioL + 128) / 256);
1540 }
1541 }
1542 else
1543 {
1544 if(uwHistogramAreaSum[ucTmp]>(ucTmp * 64 + 32))
1545 {
1546 g_uwCurveHistogram0[ucTmp] = (ucTmp * 64 + 32) + (((uwHistogramAreaSum[ucTmp] - (ucTmp * 64 + 32)) * uwHistogramSlopRatioH + 128) / 256 ) ;
1547 }
1548 else
1549 {
1550 g_uwCurveHistogram0[ucTmp] = (ucTmp * 64 + 32) - ((((ucTmp * 64 + 32)- uwHistogramAreaSum[ucTmp]) * uwHistogramSlopRatioH + 128) / 256);
1551 }
1552 }
1553 }
1554
1555 //Calculate for sepPoint1~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1556 uwHistogramSlopRatioL = 256;
1557 uwHistogramSlopRatioH = 256;
1558
1559 for (ucTmp = 0; ucTmp<= (sepPoint1+1); ucTmp++)
1560 {
1561 uwHistogramMax2nd = dwHistogramDlcSlop[ucTmp];
1562
1563 if (uwHistogramMax2nd < uwHistogramSlopRatioL)
1564 {
1565 uwHistogramSlopRatioL = uwHistogramMax2nd;
1566 }
1567 }
1568
1569 for (ucTmp = sepPoint1; ucTmp<=16; ucTmp++)
1570 {
1571 uwHistogramMax2nd = dwHistogramDlcSlop[ucTmp];
1572
1573 if (uwHistogramMax2nd < uwHistogramSlopRatioH)
1574 {
1575 uwHistogramSlopRatioH = uwHistogramMax2nd;
1576 }
1577 }
1578
1579 // calcute final target curve for sepPoint1
1580 for (ucTmp = 0; ucTmp < 16; ucTmp++)
1581 {
1582 if (sepPoint1 >= (WORD)ucTmp)
1583 {
1584 if(uwHistogramAreaSum[ucTmp]>(ucTmp * 64 + 32))
1585 {
1586 g_uwCurveHistogram1[ucTmp] = (ucTmp * 64 + 32) + (((uwHistogramAreaSum[ucTmp] - (ucTmp * 64 + 32)) * uwHistogramSlopRatioL + 128) / 256 );
1587 }
1588 else
1589 {
1590 g_uwCurveHistogram1[ucTmp] = (ucTmp * 64 + 32) - ((((ucTmp * 64 + 32)- uwHistogramAreaSum[ucTmp]) * uwHistogramSlopRatioL + 128) / 256 );
1591 }
1592 }
1593 else
1594 {
1595 if(uwHistogramAreaSum[ucTmp]>(ucTmp * 64 + 32))
1596 {
1597 g_uwCurveHistogram1[ucTmp] = (ucTmp * 64 + 32) + (((uwHistogramAreaSum[ucTmp] - (ucTmp * 64 + 32)) * uwHistogramSlopRatioH + 128) / 256 );
1598 }
1599 else
1600 {
1601 g_uwCurveHistogram1[ucTmp] = (ucTmp * 64 + 32) - ((((ucTmp * 64 + 32)- uwHistogramAreaSum[ucTmp]) * uwHistogramSlopRatioH + 128) / 256 );
1602 }
1603 }
1604 }
1605
1606 //Calculate for sepPoint2~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1607 uwHistogramSlopRatioL = 256;
1608 uwHistogramSlopRatioH = 256;
1609
1610 for (ucTmp = 0; ucTmp<= (sepPoint2+1); ucTmp++)
1611 {
1612 uwHistogramMax2nd = dwHistogramDlcSlop[ucTmp];
1613
1614 if (uwHistogramMax2nd < uwHistogramSlopRatioL)
1615 {
1616 uwHistogramSlopRatioL = uwHistogramMax2nd;
1617 }
1618 }
1619
1620 for (ucTmp = sepPoint2; ucTmp<=16; ucTmp++)
1621 {
1622 uwHistogramMax2nd = dwHistogramDlcSlop[ucTmp];
1623
1624 if (uwHistogramMax2nd < uwHistogramSlopRatioH)
1625 {
1626 uwHistogramSlopRatioH = uwHistogramMax2nd;
1627 }
1628 }
1629
1630 // calcute final target curve for sepPoint2
1631 for (ucTmp = 0; ucTmp < 16; ucTmp++)
1632 {
1633 if (sepPoint2 >= (WORD)ucTmp)
1634 {
1635 if(uwHistogramAreaSum[ucTmp]>(ucTmp * 64 + 32))
1636 {
1637 g_uwCurveHistogram2[ucTmp] = (ucTmp * 64 + 32) + (((uwHistogramAreaSum[ucTmp] - (ucTmp * 64 + 32)) * uwHistogramSlopRatioL + 128) / 256 );
1638 }
1639 else
1640 {
1641 g_uwCurveHistogram2[ucTmp] = (ucTmp * 64 + 32) - ((((ucTmp * 64 + 32)- uwHistogramAreaSum[ucTmp]) * uwHistogramSlopRatioL + 128) / 256 );
1642 }
1643 }
1644 else
1645 {
1646 if(uwHistogramAreaSum[ucTmp]>(ucTmp * 64 + 32))
1647 {
1648 g_uwCurveHistogram2[ucTmp] = (ucTmp * 64 + 32) + (((uwHistogramAreaSum[ucTmp] - (ucTmp * 64 + 32)) * uwHistogramSlopRatioH + 128) / 256 );
1649 }
1650 else
1651 {
1652 g_uwCurveHistogram2[ucTmp] = (ucTmp * 64 + 32) - ((((ucTmp * 64 + 32)- uwHistogramAreaSum[ucTmp]) * uwHistogramSlopRatioH + 128) / 256);
1653 }
1654 }
1655 }
1656
1657 for (ucTmp = 0; ucTmp < 16; ucTmp++)
1658 {
1659 g_uwCurveHistogram[ucTmp] = (coeff0*g_uwCurveHistogram0[ucTmp]+coeff1*g_uwCurveHistogram1[ucTmp]+coeff2*g_uwCurveHistogram2[ucTmp]+1024)/2048;
1660 }
1661 ///////////// Histogram_DLC add Low_Pass_filter /////////////
1662
1663 for (ucTmp = 0; ucTmp < 16; ucTmp++)
1664 {
1665 if (ucTmp == 0)
1666 {
1667 g_uwCurveHistogram[ucTmp] = (5*g_uwCurveHistogram[ucTmp] + g_uwCurveHistogram[ucTmp+1]+4)/8;
1668 }
1669 else if (ucTmp == 15)
1670 {
1671 g_uwCurveHistogram[ucTmp] = (g_uwCurveHistogram[ucTmp-1] + 5*g_uwCurveHistogram[ucTmp] + 2048 + 4)/8;
1672 }
1673 else
1674 {
1675 g_uwCurveHistogram[ucTmp] = (g_uwCurveHistogram[ucTmp-1] + 6*g_uwCurveHistogram[ucTmp] + g_uwCurveHistogram[ucTmp+1]+4)/8;
1676 }
1677 }
1678
1679
1680 #if 0 //Ranma Histogram DLC low pass
1681 for (ucTmp = 0; ucTmp < 16; ucTmp++)
1682 {
1683 uwHistogramAreaSum[ucTmp+16] = g_uwCurveHistogram[ucTmp];
1684
1685 if (ucTmp == sepPoint0)
1686 {
1687 uwHistogramAreaSum[ucTmp+16] = (g_uwCurveHistogram[ucTmp-1]+g_uwCurveHistogram[ucTmp]*2+g_uwCurveHistogram[ucTmp+1]+2)/4;
1688 uwHistogramAreaSum[ucTmp] = coeff0*uwHistogramAreaSum[ucTmp+16]+(2048-coeff0)*uwHistogramAreaSum[ucTmp];
1689 }
1690 if (ucTmp == sepPoint1)
1691 {
1692 uwHistogramAreaSum[ucTmp+16] = (g_uwCurveHistogram[ucTmp-2]+g_uwCurveHistogram[ucTmp-1]*2+g_uwCurveHistogram[ucTmp]*2+g_uwCurveHistogram[ucTmp+1]*2+g_uwCurveHistogram[ucTmp+2]+4)/8;
1693 uwHistogramAreaSum[ucTmp] = coeff1*uwHistogramAreaSum[ucTmp+16]+(2048-coeff1)*uwHistogramAreaSum[ucTmp];
1694 }
1695 if (ucTmp == sepPoint2)
1696 {
1697 uwHistogramAreaSum[ucTmp+16] = (g_uwCurveHistogram[ucTmp-1]+g_uwCurveHistogram[ucTmp]*2+g_uwCurveHistogram[ucTmp+1]+2)/4;
1698 uwHistogramAreaSum[ucTmp] = coeff2*uwHistogramAreaSum[ucTmp+16]+(2048-coeff2)*uwHistogramAreaSum[ucTmp];
1699 }
1700 }
1701
1702 LpfBlendAlpha_temp1 = abs(g_uwCurveHistogram[sepPoint0]-g_uwCurveHistogram[sepPoint1]*2+g_uwCurveHistogram[sepPoint2]);
1703 LpfBlendAlpha_temp2 = abs(g_uwCurveHistogram[sepPoint1]-g_uwCurveHistogram[sepPoint2]*2+g_uwCurveHistogram[sepPoint2+1]);
1704
1705 if(LpfBlendAlpha_temp1 > LpfBlendAlpha_temp2)
1706 {
1707 LpfBlendAlpha = LpfBlendAlpha_temp1;
1708 }
1709 else
1710 {
1711 LpfBlendAlpha = LpfBlendAlpha_temp2;
1712 }
1713
1714 if (LpfBlendAlpha >64)
1715 {
1716 LpfBlendAlpha = 64;
1717 }
1718
1719 for (ucTmp = 0; ucTmp < 16; ucTmp++)
1720 {
1721 g_uwCurveHistogram[ucTmp] = (uwHistogramAreaSum[ucTmp+16]*LpfBlendAlpha + (64-LpfBlendAlpha)*g_uwCurveHistogram[ucTmp]+32)/64;
1722
1723 if(g_uwCurveHistogram[ucTmp]>1023)
1724 {
1725 g_uwCurveHistogram[ucTmp]=1023;
1726 }
1727 }
1728
1729 #endif
1730 // Calculate curve by Yavg
1731
1732 //DLC_PRINTF("\r\n ucYAvg = %d",ucYAvg);
1733 if (ucYAvg <= g_DlcParameters.ucDlcYAvgThresholdL)
1734 {
1735 for (ucTmp=0; ucTmp<16; ucTmp++)
1736 {
1737 g_ucCurveYAvg[ucTmp] = g_DlcParameters.ucLumaCurve2_a[ucTmp];
1738 }
1739 }
1740 else if (ucYAvg <= g_DlcParameters.ucDlcYAvgThresholdM)
1741 {
1742 for (ucTmp=0; ucTmp<16; ucTmp++)
1743 {
1744 g_ucCurveYAvg[ucTmp] = (((WORD)g_DlcParameters.ucLumaCurve[ucTmp] * (ucYAvg - g_DlcParameters.ucDlcYAvgThresholdL)) / (g_DlcParameters.ucDlcYAvgThresholdM - g_DlcParameters.ucDlcYAvgThresholdL)) +
1745 (g_DlcParameters.ucLumaCurve2_a[ucTmp] - (((WORD)g_DlcParameters.ucLumaCurve2_a[ucTmp] * (ucYAvg - g_DlcParameters.ucDlcYAvgThresholdL)) / ( g_DlcParameters.ucDlcYAvgThresholdM - g_DlcParameters.ucDlcYAvgThresholdL)));
1746 }
1747 }
1748 else if (ucYAvg <= g_DlcParameters.ucDlcYAvgThresholdH)
1749 {
1750 for (ucTmp=0; ucTmp<16; ucTmp++)
1751 {
1752 g_ucCurveYAvg[ucTmp] = ((WORD)g_DlcParameters.ucLumaCurve2_b[ucTmp] * (ucYAvg - g_DlcParameters.ucDlcYAvgThresholdM) / (g_DlcParameters.ucDlcYAvgThresholdH - g_DlcParameters.ucDlcYAvgThresholdM)) +
1753 (g_DlcParameters.ucLumaCurve[ucTmp] - ((WORD)g_DlcParameters.ucLumaCurve[ucTmp] * (ucYAvg - g_DlcParameters.ucDlcYAvgThresholdM) / (g_DlcParameters.ucDlcYAvgThresholdH - g_DlcParameters.ucDlcYAvgThresholdM)));
1754 }
1755 }
1756 else // if (ucYAvg > g_DlcParameters.ucDlcYAvgThresholdH)
1757 {
1758 for (ucTmp=0; ucTmp<16; ucTmp++)
1759 {
1760 g_ucCurveYAvg[ucTmp] = g_DlcParameters.ucLumaCurve2_b[ucTmp];
1761 }
1762 }
1763
1764 belnging_factor = g_DlcParameters.ucDlcCurveModeMixAlpha;
1765
1766 // Decide Target Curve
1767 Diff_L =g_DlcParameters.ucDlcDiffBase_L;
1768 Diff_M =g_DlcParameters.ucDlcDiffBase_M;
1769 Diff_H =g_DlcParameters.ucDlcDiffBase_H;
1770
1771 if (ucPre_YAvg*4 <= g_DlcParameters.ucDlcYAvgThresholdL*4)
1772 {
1773 Pre_YAvg_base = Diff_L*4;
1774 }
1775 else if (ucPre_YAvg*4 <= g_DlcParameters.ucDlcYAvgThresholdM*4)
1776 {
1777 if(Diff_M >= Diff_L)
1778 {
1779 Pre_YAvg_base = Diff_L*4 + (((Diff_M-Diff_L)*(ucPre_YAvg*4-g_DlcParameters.ucDlcYAvgThresholdL*4))/(g_DlcParameters.ucDlcYAvgThresholdM- g_DlcParameters.ucDlcYAvgThresholdL));
1780 }
1781 else
1782 {
1783 Pre_YAvg_base = Diff_L*4 - (((Diff_L-Diff_M)*(ucPre_YAvg*4-g_DlcParameters.ucDlcYAvgThresholdL*4))/(g_DlcParameters.ucDlcYAvgThresholdM- g_DlcParameters.ucDlcYAvgThresholdL));
1784 }
1785 }
1786 else if (ucPre_YAvg*4 <= g_DlcParameters.ucDlcYAvgThresholdH*4)
1787 {
1788 if(Diff_H >= Diff_M)
1789 {
1790 Pre_YAvg_base = Diff_M*4 + (((Diff_H- Diff_M)*(ucPre_YAvg*4- g_DlcParameters.ucDlcYAvgThresholdM*4))/(g_DlcParameters.ucDlcYAvgThresholdH- g_DlcParameters.ucDlcYAvgThresholdM));
1791 }
1792 else
1793 {
1794 Pre_YAvg_base = Diff_M*4 - (((Diff_M-Diff_H)*(ucPre_YAvg*4-g_DlcParameters.ucDlcYAvgThresholdM*4))/(g_DlcParameters.ucDlcYAvgThresholdH - g_DlcParameters.ucDlcYAvgThresholdM));
1795 }
1796 }
1797 else
1798 {
1799 Pre_YAvg_base = Diff_H*4;
1800 }
1801
1802 if (ucYAvg*4 <= g_DlcParameters.ucDlcYAvgThresholdL*4)
1803 {
1804 YAvg_base = Diff_L*4;
1805 }
1806 else if (ucYAvg*4 <= g_DlcParameters.ucDlcYAvgThresholdM*4)
1807 {
1808 if(Diff_M >= Diff_L)
1809 {
1810 YAvg_base = Diff_L*4 + (((Diff_M-Diff_L)*( ucYAvg*4-g_DlcParameters.ucDlcYAvgThresholdL*4))/(g_DlcParameters.ucDlcYAvgThresholdM- g_DlcParameters.ucDlcYAvgThresholdL));
1811 }
1812 else
1813 {
1814 YAvg_base = Diff_L*4 - (((Diff_L-Diff_M)*( ucYAvg*4-g_DlcParameters.ucDlcYAvgThresholdL*4))/(g_DlcParameters.ucDlcYAvgThresholdM- g_DlcParameters.ucDlcYAvgThresholdL));
1815 }
1816 }
1817 else if (ucYAvg*4 <= g_DlcParameters.ucDlcYAvgThresholdH*4)
1818 {
1819 if(Diff_H >= Diff_M)
1820 {
1821 YAvg_base = Diff_M*4 + (((Diff_H- Diff_M)*( ucYAvg*4- g_DlcParameters.ucDlcYAvgThresholdM*4))/(g_DlcParameters.ucDlcYAvgThresholdH- g_DlcParameters.ucDlcYAvgThresholdM));
1822 }
1823 else
1824 {
1825 YAvg_base = Diff_M*4 - (((Diff_M-Diff_H)*(ucYAvg*4-g_DlcParameters.ucDlcYAvgThresholdM*4))/(g_DlcParameters.ucDlcYAvgThresholdH -g_DlcParameters.ucDlcYAvgThresholdM));
1826 }
1827 }
1828 else
1829 {
1830 YAvg_base = Diff_H*4;
1831 }
1832
1833 YAvg_base = (Pre_YAvg_base + YAvg_base +1)/2;
1834
1835 //Mantis issue of 0232938:Hsense A3 DLC the divisor can't to be equal to zero .
1836 if(YAvg_base==0)
1837 {
1838 DLC_DEBUG(printf("\n Error in [New DLC Algorithm][ %s , %d ] YAvg_base=0 !!!\n", __FUNCTION__,__LINE__));
1839 return;
1840 }
1841
1842 if (g_DlcParameters.ucDlcCurveMode == 0 ) //DLC_CURVE_MODE_BY_YAVG)
1843 {
1844 CurveDiff = g_DlcParameters.ucDlcCurveDiff_H_TH;
1845 for (ucTmp=0; ucTmp<16; ucTmp++)
1846 {
1847 g_uwTable[ucTmp] = (g_ucCurveYAvg[ucTmp]<<2);
1848 }
1849 }
1850 else if (g_DlcParameters.ucDlcCurveMode == 1 ) //DLC_CURVE_MODE_BY_HISTOGRAM)
1851 {
1852 CurveDiff = g_DlcParameters.ucDlcCurveDiff_H_TH;
1853 for (ucTmp=0; ucTmp<16; ucTmp++)
1854 {
1855 g_uwTable[ucTmp] = g_uwCurveHistogram[ucTmp];
1856 }
1857 }
1858 else
1859 {
1860 CurveDiff = 0;
1861 CurveDiff_Coring = 0;
1862 for (ucTmp=0; ucTmp<16; ucTmp++)
1863 {
1864 g_uwTable[ucTmp] = (((WORD)(g_ucCurveYAvg[ucTmp]<<2) * belnging_factor) + ((g_uwCurveHistogram[ucTmp]) * (128 - belnging_factor))) / 128;
1865
1866 if (g_uwPre_CurveHistogram[ucTmp] <= g_DlcParameters.ucDlcYAvgThresholdL*4)
1867 {
1868 Pre_CurveDiff_base = Diff_L*4;
1869 }
1870 else if (g_uwPre_CurveHistogram[ucTmp] <= g_DlcParameters.ucDlcYAvgThresholdM*4)
1871 {
1872 if(Diff_M >= Diff_L)
1873 {
1874 Pre_CurveDiff_base = Diff_L*4 + (((Diff_M-Diff_L)*(g_uwPre_CurveHistogram[ucTmp]-g_DlcParameters.ucDlcYAvgThresholdL*4))/(g_DlcParameters.ucDlcYAvgThresholdM- g_DlcParameters.ucDlcYAvgThresholdL));
1875 }
1876 else
1877 {
1878 Pre_CurveDiff_base = Diff_L*4 - (((Diff_L-Diff_M)*(g_uwPre_CurveHistogram[ucTmp]-g_DlcParameters.ucDlcYAvgThresholdL*4))/(g_DlcParameters.ucDlcYAvgThresholdM- g_DlcParameters.ucDlcYAvgThresholdL));
1879 }
1880 }
1881 else if (g_uwPre_CurveHistogram[ucTmp] <= g_DlcParameters.ucDlcYAvgThresholdH*4)
1882 {
1883 if(Diff_H >= Diff_M)
1884 {
1885 Pre_CurveDiff_base = Diff_M*4 + (((Diff_H- Diff_M)*(g_uwPre_CurveHistogram[ucTmp]- g_DlcParameters.ucDlcYAvgThresholdM*4))/(g_DlcParameters.ucDlcYAvgThresholdH- g_DlcParameters.ucDlcYAvgThresholdM));
1886 }
1887 else
1888 {
1889 Pre_CurveDiff_base = Diff_M*4 -(((Diff_M- Diff_H)*(g_uwPre_CurveHistogram[ucTmp]- g_DlcParameters.ucDlcYAvgThresholdM*4))/(g_DlcParameters.ucDlcYAvgThresholdH- g_DlcParameters.ucDlcYAvgThresholdM));
1890 }
1891 }
1892 else
1893 {
1894 Pre_CurveDiff_base = Diff_H*4;
1895 }
1896
1897 if (g_uwCurveHistogram[ucTmp] <= g_DlcParameters.ucDlcYAvgThresholdL*4)
1898 {
1899 CurveDiff_base = Diff_L*4;
1900 }
1901 else if (g_uwCurveHistogram[ucTmp] <= g_DlcParameters.ucDlcYAvgThresholdM*4)
1902 {
1903 if(Diff_M >= Diff_L)
1904 {
1905 CurveDiff_base = Diff_L*4 + (((Diff_M-Diff_L)*(g_uwCurveHistogram[ucTmp]-g_DlcParameters.ucDlcYAvgThresholdL*4))
1906 /(g_DlcParameters.ucDlcYAvgThresholdM- g_DlcParameters.ucDlcYAvgThresholdL));
1907 }
1908 else
1909 {
1910 CurveDiff_base = Diff_L*4 - (((Diff_L-Diff_M)*(g_uwCurveHistogram[ucTmp]-g_DlcParameters.ucDlcYAvgThresholdL*4))
1911 /(g_DlcParameters.ucDlcYAvgThresholdM- g_DlcParameters.ucDlcYAvgThresholdL));
1912 }
1913 }
1914 else if (g_uwCurveHistogram[ucTmp] <= g_DlcParameters.ucDlcYAvgThresholdH*4)
1915 {
1916 if(Diff_H >= Diff_M)
1917 {
1918 CurveDiff_base = Diff_M*4 + (((Diff_H- Diff_M)*(g_uwCurveHistogram[ucTmp]- g_DlcParameters.ucDlcYAvgThresholdM*4))
1919 /(g_DlcParameters.ucDlcYAvgThresholdH- g_DlcParameters.ucDlcYAvgThresholdM));
1920 }
1921 else
1922 {
1923 CurveDiff_base = Diff_M*4 -(((Diff_M- Diff_H)*(g_uwCurveHistogram[ucTmp]- g_DlcParameters.ucDlcYAvgThresholdM*4))
1924 /(g_DlcParameters.ucDlcYAvgThresholdH- g_DlcParameters.ucDlcYAvgThresholdM));
1925 }
1926 }
1927 else
1928 {
1929 CurveDiff_base = Diff_H*4;
1930 }
1931
1932 CurveDiff_base = (Pre_CurveDiff_base + CurveDiff_base+1)/2;
1933
1934 //Mantis issue of 0232938:Hsense A3 DLC the divisor can't to be equal to zero .
1935 if(CurveDiff_base==0)
1936 {
1937 DLC_DEBUG(printf("\n Error in [New DLC Algorithm][ %s , %d ] CurveDiff_base=0 !!!\n", __FUNCTION__,__LINE__));
1938 return;
1939 }
1940
1941 if(ucTmp*16+8 <= ucYAvgNormalize)
1942 {
1943 if (ucTmp == 0)
1944 {
1945 CurveDiff_Coring = (His_ratio_BelowAvg*(1024-uwHistogram_BLE_AreaSum[1])*abs(g_uwCurveHistogram[ucTmp]-g_uwPre_CurveHistogram[ucTmp]))/(15*CurveDiff_base*128);
1946 }
1947 else
1948 {
1949 CurveDiff_Coring = (His_ratio_BelowAvg*(1024-(uwHistogram_BLE_AreaSum[ucTmp*2+1]- uwHistogram_BLE_AreaSum[ucTmp*2-1]))*abs(g_uwCurveHistogram[ucTmp]-g_uwPre_CurveHistogram[ucTmp]))/(15*CurveDiff_base*128);
1950 }
1951 }
1952 else
1953 {
1954 CurveDiff_Coring = (His_ratio_AboveAvg*(1024-(uwHistogram_BLE_AreaSum[ucTmp*2+1]- uwHistogram_BLE_AreaSum[ucTmp*2-1]))*abs(g_uwCurveHistogram[ucTmp]-g_uwPre_CurveHistogram[ucTmp]))/(15*CurveDiff_base*128);
1955 }
1956
1957 CurveDiff_Coring = CurveDiff_Coring/6;
1958
1959 CurveDiff = CurveDiff + CurveDiff_Coring ;
1960 g_uwPre_CurveHistogram[ucTmp] = g_uwCurveHistogram[ucTmp];
1961 }
1962 }
1963
1964 if(CurveDiff <= g_DlcParameters.ucDlcCurveDiff_L_TH)
1965 {
1966 g_ucDlcFlickAlpha_Max = g_DlcParameters.ucDlcAlphaBlendingMin;
1967 }
1968 else if(CurveDiff >= g_DlcParameters.ucDlcCurveDiff_H_TH)
1969 {
1970 g_ucDlcFlickAlpha_Max = g_DlcParameters.ucDlcAlphaBlendingMax; ;
1971 }
1972 else
1973 {
1974 g_ucDlcFlickAlpha_Max = (((g_DlcParameters.ucDlcAlphaBlendingMax-g_DlcParameters.ucDlcAlphaBlendingMin)*(CurveDiff - g_DlcParameters.ucDlcCurveDiff_L_TH))/
1975 (g_DlcParameters.ucDlcCurveDiff_H_TH - g_DlcParameters.ucDlcCurveDiff_L_TH))+g_DlcParameters.ucDlcAlphaBlendingMin;
1976 }
1977
1978 Delta_YAvg = (96*4*abs(ucYAvg - ucPre_YAvg)+ YAvg_base/2)/YAvg_base;
1979
1980 if(Delta_YAvg > 256)
1981 {
1982 Delta_YAvg = 256;
1983 }
1984 else
1985 {
1986 Delta_YAvg = Delta_YAvg;
1987 }
1988
1989 YAvg_TH_H = g_DlcParameters.ucDlcYAVG_H_TH;
1990 YAvg_TH_L = g_DlcParameters.ucDlcYAVG_L_TH;
1991
1992 if(Delta_YAvg < YAvg_TH_L)
1993 {
1994 g_ucDlcFlickAlpha_Min = g_DlcParameters.ucDlcAlphaBlendingMin;
1995 }
1996 else if(Delta_YAvg >= YAvg_TH_H)
1997 {
1998 g_ucDlcFlickAlpha_Min = g_DlcParameters.ucDlcAlphaBlendingMax;
1999 }
2000 else
2001 {
2002 g_ucDlcFlickAlpha_Min = ((Delta_YAvg- YAvg_TH_L)*( g_DlcParameters.ucDlcAlphaBlendingMax- g_DlcParameters.ucDlcAlphaBlendingMin)
2003 + ( YAvg_TH_H-YAvg_TH_L)/2)/( YAvg_TH_H-YAvg_TH_L)+g_DlcParameters.ucDlcAlphaBlendingMin;
2004 }
2005
2006 ucPre_YAvg = ucYAvg;
2007
2008 if (g_ucDlcFlickAlpha_Max > g_ucDlcFlickAlpha_Min)
2009 {
2010 g_ucDlcFlickAlpha_Max = g_ucDlcFlickAlpha_Max;
2011 g_ucDlcFlickAlpha_Min = g_ucDlcFlickAlpha_Min;
2012 }
2013 else
2014 {
2015 g_ucDlcFlickAlpha_temp = g_ucDlcFlickAlpha_Max;
2016 g_ucDlcFlickAlpha_Max = g_ucDlcFlickAlpha_Min;
2017 g_ucDlcFlickAlpha_Min = g_ucDlcFlickAlpha_temp;
2018 }
2019
2020 g_ucDlcFlickAlpha = ( g_DlcParameters.ucDlcFlicker_alpha*g_ucDlcFlickAlpha_Max + (256- g_DlcParameters.ucDlcFlicker_alpha)*g_ucDlcFlickAlpha_Min+128)/256;
2021
2022 }
2023 }
2024
2025 if( g_DlcParameters.bEnableBLE )
2026 {
2027 BYTE uc_cut,uc_lowbound,uc_highbound,i;
2028
2029 // combine BLE with software
2030 // BLE - get cut point
2031 uc_cut = g_ucHistogramMin;
2032
2033 uc_highbound = msReadByte( REG_ADDR_BLE_UPPER_BOND );
2034 uc_lowbound = msReadByte( REG_ADDR_BLE_LOWER_BOND);
2035
2036 if (uc_cut < uc_lowbound )
2037 {
2038 uc_cut = uc_lowbound;
2039 }
2040 else if ( uc_cut > uc_highbound )
2041 {
2042 uc_cut = uc_highbound;
2043 }
2044 else
2045 {
2046 uc_cut = uc_cut;
2047 }
2048
2049 // BLE - calculation
2050 for(i=0; i<8; ++i)
2051 {
2052 if (g_ucTable[i] < uc_cut)
2053 {
2054 g_ucTable[i] = 0;
2055 }
2056 else if (g_ucTable[i] > (uc_cut+g_DlcParameters.ucDlcBLEPoint))
2057 {
2058 ;
2059 }
2060 else
2061 {
2062 g_ucTable[i] = ((WORD)(g_ucTable[i]-uc_cut))*(uc_cut+g_DlcParameters.ucDlcBLEPoint)/g_DlcParameters.ucDlcBLEPoint;
2063 }
2064 }
2065 }
2066
2067 if( g_DlcParameters.bEnableWLE )
2068 {
2069 BYTE i,uc_wcut,uc_wlowbound,uc_whighbound;
2070 // combine BLE with software
2071 // WLE - get cut point
2072 uc_wcut = g_ucHistogramMax;
2073
2074 uc_whighbound = (msReadByte( REG_ADDR_WLE_UPPER_BOND ) & 0x3F) + 0xC0; // bit offset 0x00~0x3F -> 0xC0~0xFF
2075 uc_wlowbound = (msReadByte( REG_ADDR_WLE_LOWER_BOND) & 0x3F) + 0xC0; // bit offset 0x00~0x3F -> 0xC0~0xFF
2076
2077 if (uc_wcut < uc_wlowbound )
2078 {
2079 uc_wcut = uc_wlowbound;
2080 }
2081 else if ( uc_wcut > uc_whighbound )
2082 {
2083 uc_wcut = uc_whighbound;
2084 }
2085 else
2086 {
2087 uc_wcut = uc_wcut;
2088 }
2089
2090 // WLE - calculation
2091 for(i=0; i<8; ++i)
2092 {
2093 if (g_ucTable[15-i] > uc_wcut)
2094 {
2095 g_ucTable[15-i] = 0xFF;
2096 }
2097 else if (g_ucTable[15-i] < (uc_wcut-g_DlcParameters.ucDlcWLEPoint))
2098 {
2099 ;
2100 }
2101 else
2102 {
2103 g_ucTable[15-i] = 0xFF - (((WORD)(uc_wcut-g_ucTable[15-i]))*(0xFF-uc_wcut+g_DlcParameters.ucDlcWLEPoint)/g_DlcParameters.ucDlcWLEPoint);
2104 }
2105 }
2106 }
2107
2108 // Level Limit
2109 if (g_DlcParameters.ucDlcLevelLimit)
2110 {
2111 if ((g_DlcParameters.ucDlcLevelLimit >= 1) && (g_ucTable[15] >= 0xF7))
2112 {
2113 g_ucTable[15] = 0xF7;
2114 if (g_ucTable[14] > 0xF7)
2115 {
2116 g_ucTable[14] = 0xF7;
2117 }
2118
2119 if (g_ucTable[13] > 0xF7)
2120 {
2121 g_ucTable[13] = 0xF7;
2122 }
2123 }
2124
2125 if ((g_DlcParameters.ucDlcLevelLimit >= 2) && (g_ucTable[14] >= 0xE7))
2126 {
2127 g_ucTable[14] = 0xE7;
2128 if (g_ucTable[13] > 0xE7)
2129 {
2130 g_ucTable[13] = 0xE7;
2131 }
2132
2133 if (g_ucTable[12] > 0xE7)
2134 {
2135 g_ucTable[12] = 0xE7;
2136 }
2137 }
2138
2139 if ((g_DlcParameters.ucDlcLevelLimit >= 3) && (g_ucTable[13] >= 0xD7))
2140 {
2141 g_ucTable[13] = 0xD7;
2142 if (g_ucTable[12] > 0xD7)
2143 {
2144 g_ucTable[12] = 0xD7;
2145 }
2146
2147 if (g_ucTable[11] > 0xD7)
2148 {
2149 g_ucTable[11] = 0xD7;
2150 }
2151 }
2152
2153 if ((g_DlcParameters.ucDlcLevelLimit >= 4) && (g_ucTable[12] >= 0xC7))
2154 {
2155 g_ucTable[12] = 0xC7;
2156 if (g_ucTable[11] > 0xC7)
2157 {
2158 g_ucTable[11] = 0xC7;
2159 }
2160
2161 if (g_ucTable[10] > 0xC7)
2162 {
2163 g_ucTable[10] = 0xC7;
2164 }
2165 }
2166 }
2167 #if 0 //For customer require. Run DLC algorithm when static field .
2168 if((g_wLumiAverageTemp-Pre_TotalYSum)!=0)
2169 #endif
2170 {
2171
2172 if ((g_ucDlcFlickAlpha < (5*Pre_g_ucDlcFlickAlpha /8)) && (ucDlcFlickAlpha_Diff < (g_DlcParameters.ucDlcAlphaBlendingMax- g_DlcParameters.ucDlcAlphaBlendingMin)/2))
2173 {
2174 g_ucDlcFlickAlpha = 2*(ucDlcFlickAlpha_Diff* g_ucDlcFlickAlpha +(( g_DlcParameters.ucDlcAlphaBlendingMax
2175 - g_DlcParameters.ucDlcAlphaBlendingMin)/2- ucDlcFlickAlpha_Diff)* (5*Pre_g_ucDlcFlickAlpha /8))
2176 /( g_DlcParameters.ucDlcAlphaBlendingMax- g_DlcParameters.ucDlcAlphaBlendingMin);
2177 }
2178
2179 Pre_g_ucDlcFlickAlpha = g_ucDlcFlickAlpha;
2180 ucDlcFlickAlpha_Diff = g_ucDlcFlickAlpha_Max-g_ucDlcFlickAlpha_Min;
2181
2182 // ~~~~~~~~~~~~~~~~~~~~~~~~ Sub window open PATCH Start ~~~~~~~~~~~~~~~~~~~~~~~~
2183 bSubWindowEnable = ((msReadByte(REG_ADDR_OP_SW_SUB_ENABLE) & BIT(1)) == BIT(1));
2184
2185 if(bPreSubWindowEnable != bSubWindowEnable)
2186 {
2187 ucSubWindowChange = 1;
2188 bPreSubWindowEnable = bSubWindowEnable;
2189 uwSubChangeDelayCount=0;
2190 }
2191
2192 if(ucSubWindowChange > 0)
2193 {
2194 uwSubChangeDelayCount++;
2195 if(((g_ucDlcFlickAlpha > 48) &&(uwSubChangeDelayCount>=100))
2196 ||((g_ucDlcFlickAlpha > 24) &&(uwSubChangeDelayCount>=200)))
2197 {
2198 ucSubWindowChange = ucSubWindowChange-1;
2199 }
2200
2201 if(ucSubWindowChange == 0)
2202 {
2203 uwSubChangeDelayCount=0;
2204 }
2205 else
2206 {
2207 g_ucDlcFlickAlpha = 0;
2208 }
2209 }
2210 // ~~~~~~~~~~~~~~~~~~~~~~~~ Sub window open PATCH End ~~~~~~~~~~~~~~~~~~~~~~~~
2211
2212 // ~~~~~~~~~~~~~~~~~~~~~~~~ PI_Alpha IIR Start ~~~~~~~~~~~~~~~~~~~~~~~~
2213 if ( g_wPIAlpha >= g_wPrePIAlpha)
2214 {
2215 g_wPIAlpha = ((g_ucDlcFlickAlpha * g_wPIAlpha) +((128-g_ucDlcFlickAlpha)*g_wPrePIAlpha)+127)/128;
2216 }
2217 else
2218 {
2219 g_wPIAlpha = ((g_ucDlcFlickAlpha * g_wPIAlpha) +((128-g_ucDlcFlickAlpha)*g_wPrePIAlpha))/128;
2220 }
2221
2222 g_wPrePIAlpha = g_wPIAlpha;
2223 // ~~~~~~~~~~~~~~~~~~~~~~~~ PI_Alpha IIR End ~~~~~~~~~~~~~~~~~~~~~~~~
2224
2225 // Write data to luma curve ...
2226 msDlcWriteCurve(bWindow);
2227 if(g_bSetDLCCurveBoth)
2228 {
2229 msDlcWriteCurve(SUB_WINDOW);
2230 }
2231
2232 if(g_DlcParameters.ucDlcAlgorithmMode == XC_DLC_ALGORITHM_NEW)
2233 {
2234 //Dyanmic BLE Function
2235 //~~~~~~~~~~~~~~~~~Calculate BLE_StartPoint~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2236 if(((ucYAvg*4) + g_DlcParameters.uwDlcBleStartPointTH)>512)
2237 {
2238 BLE_StartPoint = ((ucYAvg*4) + g_DlcParameters.uwDlcBleStartPointTH - 512);
2239 }
2240 else
2241 {
2242 BLE_StartPoint = 0;
2243 }
2244
2245 BLE_StartPoint_Correction = (BLE_StartPoint+2)/4;
2246
2247 if(BLE_StartPoint_Correction >(Pre_BLE_StartPoint_Correction/16))
2248 {
2249 if(g_ucDlcFlickAlpha==g_DlcParameters.ucDlcAlphaBlendingMin)
2250 {
2251 uwBLE_StartPoint_Blend = (WORD)(((16*(DWORD)BLE_StartPoint_Correction)+(63*(DWORD)Pre_BLE_StartPoint_Correction)+63)/64);
2252 Pre_BLE_StartPoint_Correction = uwBLE_StartPoint_Blend;
2253 uwBLE_StartPoint_Blend = (uwBLE_StartPoint_Blend+8)/16;
2254 }
2255 else
2256 {
2257 uwBLE_StartPoint_Blend = (WORD)((((DWORD) g_ucDlcFlickAlpha * (DWORD)BLE_StartPoint_Correction) +
2258 ((128 - (DWORD)g_ucDlcFlickAlpha) * (DWORD)(Pre_BLE_StartPoint_Correction/16))+127)/128);
2259 Pre_BLE_StartPoint_Correction = uwBLE_StartPoint_Blend*16;
2260 }
2261 }
2262 else
2263 {
2264 if(g_ucDlcFlickAlpha==g_DlcParameters.ucDlcAlphaBlendingMin)
2265 {
2266 uwBLE_StartPoint_Blend = (WORD)(((16*(DWORD)BLE_StartPoint_Correction)+(63*(DWORD)Pre_BLE_StartPoint_Correction))/64);
2267 Pre_BLE_StartPoint_Correction = uwBLE_StartPoint_Blend;
2268 uwBLE_StartPoint_Blend = (uwBLE_StartPoint_Blend+8)/16;
2269 }
2270 else
2271 {
2272 uwBLE_StartPoint_Blend = (WORD)((((DWORD) g_ucDlcFlickAlpha * (DWORD)BLE_StartPoint_Correction) +
2273 ((128 - (DWORD)g_ucDlcFlickAlpha) * (DWORD)(Pre_BLE_StartPoint_Correction/16)))/128);
2274 Pre_BLE_StartPoint_Correction = uwBLE_StartPoint_Blend*16;
2275 }
2276 }
2277
2278 //~~~~~~~~~output = uwBLE_StartPoint_Blend & Pre_BLE_StartPoint_Correction ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2279
2280 //~~~~~~~~~~~~~~~~~Calculate BLE_EndPoint ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2281
2282 for (ucTmp=0; ucTmp<32; ucTmp++)
2283 {
2284 if(ucTmp==0)
2285 {
2286 uwHistogramAreaSum[ucTmp]=g_wLumaHistogram32H[ucTmp];
2287 }
2288 else
2289 {
2290 uwHistogramAreaSum[ucTmp] = uwHistogramAreaSum[ucTmp-1] + g_wLumaHistogram32H[ucTmp];
2291 }
2292 }
2293
2294 ucTmp=0;
2295 while( uwHistogramAreaSum[ucTmp] < uwHistogramAreaSum[31]/8)
2296 {
2297 ucTmp++;
2298 }
2299
2300 if(ucTmp==0)
2301 {
2302 //Mantis issue of 0264631 :[Konka J3] . Use autotest tool control dc on/off. DLC divisor can't to be equal to zero .
2303 if(g_wLumaHistogram32H[0]==0)
2304 {
2305 DLC_DEBUG(printk("\n Error in [New DLC Algorithm][ %s , %d ] g_wLumaHistogram32H[0]=0 !!!\n", __FUNCTION__,__LINE__));
2306 return;
2307 }
2308
2309 BLE_EndPoint = ((g_uwTable[0]*uwHistogramAreaSum[31])/(16*g_wLumaHistogram32H[0]));
2310 }
2311 else
2312 {
2313 uwHistogramForBleSum = (uwHistogramAreaSum[31]/8) - uwHistogramAreaSum[ucTmp-1];
2314
2315 for (Tmp=0; Tmp<30; Tmp++)
2316 {
2317 uwHistogramAreaSum[Tmp] = (g_uwTable[Tmp/2]+g_uwTable[(Tmp+1)/2]+1)/2;
2318 }
2319
2320 for (Tmp=0; Tmp<(ucTmp-1); Tmp++)
2321 {
2322 if(Tmp==0)
2323 {
2324 BLE_sum = g_wLumaHistogram32H[0]*(g_uwTable[0]+1/2);
2325 }
2326 else
2327 {
2328 BLE_sum = BLE_sum + g_wLumaHistogram32H[Tmp] * ((uwHistogramAreaSum[Tmp]+uwHistogramAreaSum[Tmp-1]+1)/2);
2329 }
2330 }
2331
2332 //Mantis issue of 0232938:Hsense A3 DLC the divisor can't to be equal to zero .
2333 if(g_wLumaHistogram32H[ucTmp]==0)
2334 {
2335 DLC_DEBUG(printf("\n Error in [New DLC Algorithm][ %s , %d ] g_wLumaHistogram32H[%d]=0 !!!\n", __FUNCTION__,__LINE__,ucTmp));
2336 return;
2337 }
2338
2339 BLE_sum = BLE_sum + uwHistogramForBleSum *((uwHistogramAreaSum[ucTmp]+uwHistogramAreaSum[ucTmp-1]+1)/2);
2340
2341 BLE_EndPoint = (BLE_sum*8+(uwHistogramAreaSum[31]/2))/uwHistogramAreaSum[31];
2342 }
2343
2344 BLE_EndPoint = (BLE_EndPoint*g_DlcParameters.uwDlcBleEndPointTH+512)/1024;
2345 BLE_EndPoint_Correction = BLE_EndPoint;
2346
2347
2348 //~~~~~~~~~output = BLE_EndPoint Correction ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2349
2350 //~~~~~~~~~Used uwBLE_StartPoint_Blend & BLE_EndPoint_Correction Calculate BLE_Slop ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2351
2352 if(uwBLE_StartPoint_Blend > 0x7F)
2353 {
2354 uwBLE_StartPoint_Blend = 0x7F;
2355 }
2356
2357 if( uwBLE_StartPoint_Blend*4 > BLE_EndPoint_Correction)
2358 {
2359 BLE_Slop = (1024*uwBLE_StartPoint_Blend*4+((uwBLE_StartPoint_Blend*4 - BLE_EndPoint_Correction)/2))
2360 /(uwBLE_StartPoint_Blend*4 - BLE_EndPoint_Correction);
2361 }
2362 else
2363 {
2364 BLE_Slop = 0x7FF;
2365 }
2366
2367 if(BLE_Slop > 0x7FF)
2368 {
2369 BLE_Slop = 0x7FF;
2370 }
2371
2372 if(BLE_Slop < 0x400)
2373 {
2374 BLE_Slop = 0x400;
2375 }
2376
2377 BLE_Slop_400 = g_DlcParameters.uwDlcBLESlopPoint_1;//(msReadByte(L_BK_DLC(0x38)))<<3;
2378 BLE_Slop_480 = g_DlcParameters.uwDlcBLESlopPoint_2;//(msReadByte(H_BK_DLC(0x38)))<<3;
2379 BLE_Slop_500 = g_DlcParameters.uwDlcBLESlopPoint_3;//(msReadByte(L_BK_DLC(0x39)))<<3;
2380 BLE_Slop_600 = g_DlcParameters.uwDlcBLESlopPoint_4;//(msReadByte(H_BK_DLC(0x39)))<<3;
2381 BLE_Slop_800 = g_DlcParameters.uwDlcBLESlopPoint_5;//(msReadByte(L_BK_DLC(0x3A)))<<3;
2382 Dark_BLE_Slop_Min = g_DlcParameters.uwDlcDark_BLE_Slop_Min;//(msReadByte(L_BK_DLC(0x3B)))<<3;
2383
2384 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2385 if(BLE_Slop <= 0x480)
2386 {
2387 BLE_Slop =((BLE_Slop_480-BLE_Slop_400)*(BLE_Slop-0x400)+64)/128+BLE_Slop_400;
2388 }
2389 else if ((BLE_Slop > 0x480) && (BLE_Slop <= 0x500))
2390 {
2391 BLE_Slop =((BLE_Slop_500-BLE_Slop_480)*(BLE_Slop-0x480)+64)/128+BLE_Slop_480;
2392 }
2393 else if ((BLE_Slop > 0x500) && (BLE_Slop <= 0x600))
2394 {
2395 BLE_Slop =((BLE_Slop_600-BLE_Slop_500)*(BLE_Slop-0x500)+128)/256+BLE_Slop_500;
2396 }
2397 else
2398 {
2399 BLE_Slop =((BLE_Slop_800-BLE_Slop_600)*(BLE_Slop-0x600)+256)/512+BLE_Slop_600;
2400 }
2401
2402 if (ucYAvg < ((g_DlcParameters.ucDlcYAvgThresholdL+g_DlcParameters.ucDlcYAvgThresholdM)/2))
2403 {
2404 BLE_Slop_tmp =(((Dark_BLE_Slop_Min - BLE_Slop_400)*(((g_DlcParameters.ucDlcYAvgThresholdL+g_DlcParameters.ucDlcYAvgThresholdM)/2)-ucYAvg)/
2405 ((g_DlcParameters.ucDlcYAvgThresholdL+g_DlcParameters.ucDlcYAvgThresholdM)/2)) + BLE_Slop_400);
2406
2407 if(BLE_Slop > BLE_Slop_tmp)
2408 {
2409 BLE_Slop = BLE_Slop;
2410 }
2411 else
2412 {
2413 BLE_Slop = BLE_Slop_tmp;
2414 }
2415 }
2416 else
2417 {
2418 BLE_Slop = BLE_Slop;
2419 }
2420
2421
2422 // ~~~~~~~~~~~~~~~~~~~~~~~~ Pure Image Patch ~~~~~~~~~~~~~~~~~~~~~~~~
2423 BLE_Slop = (BLE_Slop*(256-g_wPIAlpha)+ 1024*g_wPIAlpha + 128)/256;
2424
2425 //~~~~~~~~~ output = uwBLE_Blend �]with slow approach�^ ~~~~~~~~~~~~~~~~~~~~~
2426
2427 if(BLE_Slop >(Pre_BLE_Slop/16))
2428 {
2429 if(g_ucDlcFlickAlpha==g_DlcParameters.ucDlcAlphaBlendingMin)
2430 {
2431 uwBLE_Blend = (WORD)(((16*(DWORD)BLE_Slop)+(63*(DWORD)Pre_BLE_Slop)+63)/64);
2432 Pre_BLE_Slop = uwBLE_Blend;
2433 uwBLE_Blend = (uwBLE_Blend+8)/16;
2434 }
2435 else
2436 {
2437 uwBLE_Blend = (WORD)((((DWORD) g_ucDlcFlickAlpha * (DWORD)BLE_Slop) +
2438 ((128 - (DWORD)g_ucDlcFlickAlpha) * (DWORD)(Pre_BLE_Slop/16))+127)/128);
2439 Pre_BLE_Slop = uwBLE_Blend*16; //14-bits
2440 }
2441 }
2442 else
2443 {
2444 if(g_ucDlcFlickAlpha==g_DlcParameters.ucDlcAlphaBlendingMin)
2445 {
2446 uwBLE_Blend = (WORD)(((16*(DWORD)BLE_Slop)+(63*(DWORD)Pre_BLE_Slop))/64);
2447 Pre_BLE_Slop = uwBLE_Blend;
2448 uwBLE_Blend = (uwBLE_Blend+8)/16;
2449 }
2450 else
2451 {
2452 uwBLE_Blend = (WORD)((((DWORD) g_ucDlcFlickAlpha * (DWORD)BLE_Slop) +
2453 ((128 - (DWORD)g_ucDlcFlickAlpha) * (DWORD)(Pre_BLE_Slop/16)))/128);
2454 Pre_BLE_Slop = uwBLE_Blend*16;
2455 }
2456 }
2457
2458 if(g_bSetDlcBleOn)
2459 {
2460 msWriteByte(L_BK_DLC(0x10),uwBLE_StartPoint_Blend);
2461 msWriteByte(H_BK_DLC(0x10),uwBLE_Blend>>3);
2462 msWriteByte(L_BK_DLC(0x0D),(msReadByte(L_BK_DLC(0x0D))&0xF8)|(uwBLE_Blend & 0x07));
2463 }
2464 else
2465 {
2466 msWriteByte(L_BK_DLC(0x10),0x00);
2467 msWriteByte(H_BK_DLC(0x10),0x80);
2468 msWriteByte(L_BK_DLC(0x0D),msReadByte(L_BK_DLC(0x0D))&0xF8);
2469 }
2470 }
2471 }
2472 Pre_TotalYSum = g_wLumiAverageTemp;
2473 msDlc_FunctionExit();
2474 }
2475
2476 //////////////////////////////////////////////////////////////
2477 //
2478 //////////////////////////////////////////////////////////////
msDlcWriteCurveLSB(BOOL bWindow,BYTE ucIndex,BYTE ucValue)2479 void msDlcWriteCurveLSB(BOOL bWindow, BYTE ucIndex, BYTE ucValue)
2480 {
2481 DWORD wRegStart;
2482 BYTE ucData;
2483
2484 msDlc_FunctionEnter();
2485
2486 if( MAIN_WINDOW == bWindow )
2487 wRegStart = REG_ADDR_DLC_DATA_LSB_START_MAIN;
2488 else
2489 wRegStart = REG_ADDR_DLC_DATA_LSB_START_SUB;
2490
2491 switch(ucIndex)
2492 {
2493 case 0:
2494 wRegStart += 0;
2495 ucData = (msReadByte(wRegStart) & 0xF3) | (ucValue << 2);
2496 break;
2497 case 1:
2498 wRegStart += 0;
2499 ucData = (msReadByte(wRegStart) & 0xCF) | (ucValue << 4);
2500 break;
2501 case 2:
2502 wRegStart += 0;
2503 ucData = (msReadByte(wRegStart) & 0x3F) | (ucValue << 6);
2504 break;
2505 case 3:
2506 wRegStart += 1;
2507 ucData = (msReadByte(wRegStart) & 0xFC) | (ucValue);
2508 break;
2509 case 4:
2510 wRegStart += 1;
2511 ucData = (msReadByte(wRegStart) & 0xF3) | (ucValue << 2);
2512 break;
2513 case 5:
2514 wRegStart += 1;
2515 ucData = (msReadByte(wRegStart) & 0xCF) | (ucValue << 4);
2516 break;
2517 case 6:
2518 wRegStart += 1;
2519 ucData = (msReadByte(wRegStart) & 0x3F) | (ucValue << 6);
2520 break;
2521 case 7:
2522 wRegStart += 2;
2523 ucData = (msReadByte(wRegStart) & 0xFC) | (ucValue);
2524 break;
2525 case 8:
2526 wRegStart += 2;
2527 ucData = (msReadByte(wRegStart) & 0xF3) | (ucValue << 2);
2528 break;
2529 case 9:
2530 wRegStart += 2;
2531 ucData = (msReadByte(wRegStart) & 0xCF) | (ucValue << 4);
2532 break;
2533 case 10:
2534 wRegStart += 2;
2535 ucData = (msReadByte(wRegStart) & 0x3F) | (ucValue << 6);
2536 break;
2537 case 11:
2538 wRegStart += 3;
2539 ucData = (msReadByte(wRegStart) & 0xFC) | (ucValue);
2540 break;
2541 case 12:
2542 wRegStart += 3;
2543 ucData = (msReadByte(wRegStart) & 0xF3) | (ucValue << 2);
2544 break;
2545 case 13:
2546 wRegStart += 3;
2547 ucData = (msReadByte(wRegStart) & 0xCF) | (ucValue << 4);
2548 break;
2549 case 14:
2550 wRegStart += 3;
2551 ucData = (msReadByte(wRegStart) & 0x3F) | (ucValue << 6);
2552 break;
2553 case 15:
2554 wRegStart += 4;
2555 ucData = (msReadByte(wRegStart) & 0xFC) | (ucValue);
2556 break;
2557 case 16: // index 16
2558 wRegStart += 4;
2559 ucData = (msReadByte(wRegStart) & 0xF3) | (ucValue << 2);
2560 break;
2561 case 0xFF: // index n0
2562 default:
2563 wRegStart += 0;
2564 ucData = (msReadByte(wRegStart) & 0xFC) | (ucValue);
2565 break;
2566 }
2567
2568 msWriteByte(wRegStart, ucData);
2569
2570 msDlc_FunctionExit();
2571 }
2572
msDlcWriteCurve(BOOL bWindow)2573 void msDlcWriteCurve(BOOL bWindow)
2574 {
2575 BYTE ucTmp;
2576 WORD uwBlend;
2577 WORD uwTmp;
2578
2579 msDlc_FunctionEnter();
2580
2581 // Write data to luma curve ...
2582
2583 if(g_DlcParameters.ucDlcAlgorithmMode == XC_DLC_ALGORITHM_OLD)
2584 {
2585
2586 if( MAIN_WINDOW == bWindow )
2587 {
2588 for(ucTmp=0; ucTmp<=0x0f; ucTmp++)
2589 {
2590 if(g_ucDlcFastLoop || (g_ucDlcFlickAlpha >= (DLC_DEFLICK_BLEND_FACTOR >> 1)))
2591 {
2592 if (g_ucDlcFastLoop)
2593 g_ucDlcFastLoop--;
2594
2595 // target value with alpha blending
2596 uwBlend = (WORD)((((DWORD) g_ucDlcFlickAlpha * (DWORD)g_ucTable[ucTmp] * DLC_DEFLICK_PRECISION_SHIFT) +
2597 ((DLC_DEFLICK_BLEND_FACTOR - (DWORD)g_ucDlcFlickAlpha) * (DWORD)g_uwPreTable[ucTmp]))/DLC_DEFLICK_BLEND_FACTOR);
2598
2599 if(uwBlend > g_uwPreTable[ucTmp])
2600 {
2601 uwTmp = (uwBlend - g_uwPreTable[ucTmp]) / (DLC_DEFLICK_BLEND_FACTOR - g_ucDlcFlickAlpha + 1);
2602 uwBlend = g_uwPreTable[ucTmp] + uwTmp;
2603 }
2604 else if(uwBlend < g_uwPreTable[ucTmp])
2605 {
2606 uwTmp = (g_uwPreTable[ucTmp] - uwBlend) / (DLC_DEFLICK_BLEND_FACTOR - g_ucDlcFlickAlpha + 1);
2607 uwBlend = g_uwPreTable[ucTmp] - uwTmp;
2608 }
2609
2610 g_uwPreTable[ucTmp] = uwBlend;
2611
2612 //g_ucTable[ucTmp] = g_uwPreTable[ucTmp] / DLC_DEFLICK_PRECISION_SHIFT;
2613 g_uwTable[ucTmp] = ((DWORD)g_uwPreTable[ucTmp]<<2) / DLC_DEFLICK_PRECISION_SHIFT;
2614 g_ucTable[ucTmp] = g_uwTable[ucTmp]>>2;
2615
2616 msWriteByte((REG_ADDR_DLC_DATA_START_MAIN+ucTmp), g_ucTable[ucTmp]);
2617 msDlcWriteCurveLSB(bWindow, ucTmp, g_uwTable[ucTmp]&0x03);
2618
2619 // set DLC curve index N0 & 16
2620 if (ucTmp == 0)
2621 {
2622 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_MAIN, g_uwTable[0]>>2);
2623 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_MAIN + 1, 0x01);
2624 msDlcWriteCurveLSB(MAIN_WINDOW, 0xFF, g_uwTable[0]&0x03);
2625 }
2626
2627 if (ucTmp == 15)
2628 {
2629 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_MAIN, 255-(g_uwTable[15]>>2));
2630 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_MAIN + 1, 0x01);
2631 msDlcWriteCurveLSB(MAIN_WINDOW, 16, g_uwTable[15]&0x03);
2632 }
2633 }
2634 else if (g_ucDlcFlickAlpha == 0)
2635 {
2636 g_ucTable[ucTmp] = g_uwPreTable[ucTmp] / DLC_DEFLICK_PRECISION_SHIFT;
2637 }
2638 else if ((ucTmp%4) == (g_ucUpdateCnt%4))
2639 {
2640 // target value with alpha blending
2641 uwBlend = (WORD)((((DWORD) g_ucDlcFlickAlpha * (DWORD)g_ucTable[ucTmp] * DLC_DEFLICK_PRECISION_SHIFT) +
2642 ((DLC_DEFLICK_BLEND_FACTOR - (DWORD)g_ucDlcFlickAlpha) * (DWORD)g_uwPreTable[ucTmp]))/DLC_DEFLICK_BLEND_FACTOR);
2643
2644 if(uwBlend > g_uwPreTable[ucTmp])
2645 {
2646 if((uwBlend - g_uwPreTable[ucTmp]) > DLC_DEFLICK_PRECISION_SHIFT)
2647 uwBlend = g_uwPreTable[ucTmp] + DLC_DEFLICK_PRECISION_SHIFT;
2648 }
2649 else if(uwBlend < g_uwPreTable[ucTmp])
2650 {
2651 if((g_uwPreTable[ucTmp] - uwBlend) > DLC_DEFLICK_PRECISION_SHIFT)
2652 uwBlend = g_uwPreTable[ucTmp] - DLC_DEFLICK_PRECISION_SHIFT;
2653 }
2654
2655 g_uwPreTable[ucTmp] = uwBlend;
2656
2657 //g_ucTable[ucTmp] = g_uwPreTable[ucTmp] / DLC_DEFLICK_PRECISION_SHIFT;
2658 g_uwTable[ucTmp] = ((DWORD)g_uwPreTable[ucTmp]<<2) / DLC_DEFLICK_PRECISION_SHIFT;
2659 g_ucTable[ucTmp] = g_uwTable[ucTmp]>>2;
2660
2661 msWriteByte((REG_ADDR_DLC_DATA_START_MAIN+ucTmp), g_ucTable[ucTmp]);
2662 msDlcWriteCurveLSB(bWindow, ucTmp, g_uwTable[ucTmp]&0x03);
2663
2664 // set DLC curve index N0 & 16
2665 if (ucTmp == 0)
2666 {
2667 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_MAIN, g_uwTable[0]>>2);
2668 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_MAIN + 1, 0x01);
2669 msDlcWriteCurveLSB(MAIN_WINDOW, 0xFF, g_uwTable[0]&0x03);
2670 }
2671
2672 if (ucTmp == 15)
2673 {
2674 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_MAIN, 255-(g_uwTable[15]>>2));
2675 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_MAIN + 1, 0x01);
2676 msDlcWriteCurveLSB(MAIN_WINDOW, 16, g_uwTable[15]&0x03);
2677 }
2678 }
2679 }
2680 }
2681 else
2682 {
2683 #if XC_DLC_SET_DLC_CURVE_BOTH_SAME
2684 for(ucTmp=0; ucTmp<=0x0f; ucTmp++)
2685 {
2686 if(g_ucDlcFastLoop || (g_ucDlcFlickAlpha >= (DLC_DEFLICK_BLEND_FACTOR >> 1)))
2687 {
2688 if (g_ucDlcFastLoop)
2689 g_ucDlcFastLoop--;
2690
2691 // target value with alpha blending
2692 uwBlend = (WORD)((((DWORD) g_ucDlcFlickAlpha * (DWORD)g_ucTable[ucTmp] * DLC_DEFLICK_PRECISION_SHIFT) +
2693 ((DLC_DEFLICK_BLEND_FACTOR - (DWORD)g_ucDlcFlickAlpha) * (DWORD)g_uwPreTable[ucTmp]))/DLC_DEFLICK_BLEND_FACTOR);
2694
2695 if(uwBlend > g_uwPreTable[ucTmp])
2696 {
2697 uwTmp = (uwBlend - g_uwPreTable[ucTmp]) / (DLC_DEFLICK_BLEND_FACTOR - g_ucDlcFlickAlpha + 1);
2698 uwBlend = g_uwPreTable[ucTmp] + uwTmp;
2699 }
2700 else if(uwBlend < g_uwPreTable[ucTmp])
2701 {
2702 uwTmp = (g_uwPreTable[ucTmp] - uwBlend) / (DLC_DEFLICK_BLEND_FACTOR - g_ucDlcFlickAlpha + 1);
2703 uwBlend = g_uwPreTable[ucTmp] - uwTmp;
2704 }
2705
2706 g_uwPreTable[ucTmp] = uwBlend;
2707
2708 //g_ucTable[ucTmp] = g_uwPreTable[ucTmp] / DLC_DEFLICK_PRECISION_SHIFT;
2709 g_uwTable[ucTmp] = ((DWORD)g_uwPreTable[ucTmp]<<2) / DLC_DEFLICK_PRECISION_SHIFT;
2710 g_ucTable[ucTmp] = g_uwTable[ucTmp]>>2;
2711
2712 msWriteByte((REG_ADDR_DLC_DATA_START_SUB+ucTmp), g_ucTable[ucTmp]);
2713 msDlcWriteCurveLSB(bWindow, ucTmp, g_uwTable[ucTmp]&0x03);
2714
2715 // set DLC curve index N0 & 16
2716 if (ucTmp == 0)
2717 {
2718 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_SUB, g_uwTable[0]>>2);
2719 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_SUB + 1, 0x01);
2720 msDlcWriteCurveLSB(SUB_WINDOW, 0xFF, g_uwTable[0]&0x03);
2721 }
2722
2723 if (ucTmp == 15)
2724 {
2725 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_SUB, 255-(g_uwTable[15]>>2));
2726 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_SUB + 1, 0x01);
2727 msDlcWriteCurveLSB(SUB_WINDOW, 16, g_uwTable[15]&0x03);
2728 }
2729 }
2730 else if (g_ucDlcFlickAlpha == 0)
2731 {
2732 g_ucTable[ucTmp] = g_uwPreTable[ucTmp] / DLC_DEFLICK_PRECISION_SHIFT;
2733 }
2734 else if ((ucTmp%4) == (g_ucUpdateCnt%4))
2735 {
2736 // target value with alpha blending
2737 uwBlend = (WORD)((((DWORD) g_ucDlcFlickAlpha * (DWORD)g_ucTable[ucTmp] * DLC_DEFLICK_PRECISION_SHIFT) +
2738 ((DLC_DEFLICK_BLEND_FACTOR - (DWORD)g_ucDlcFlickAlpha) * (DWORD)g_uwPreTable[ucTmp]))/DLC_DEFLICK_BLEND_FACTOR);
2739
2740 if(uwBlend > g_uwPreTable[ucTmp])
2741 {
2742 if((uwBlend - g_uwPreTable[ucTmp]) > DLC_DEFLICK_PRECISION_SHIFT)
2743 uwBlend = g_uwPreTable[ucTmp] + DLC_DEFLICK_PRECISION_SHIFT;
2744 }
2745 else if(uwBlend < g_uwPreTable[ucTmp])
2746 {
2747 if((g_uwPreTable[ucTmp] - uwBlend) > DLC_DEFLICK_PRECISION_SHIFT)
2748 uwBlend = g_uwPreTable[ucTmp] - DLC_DEFLICK_PRECISION_SHIFT;
2749 }
2750
2751 g_uwPreTable[ucTmp] = uwBlend;
2752
2753 //g_ucTable[ucTmp] = g_uwPreTable[ucTmp] / DLC_DEFLICK_PRECISION_SHIFT;
2754 g_uwTable[ucTmp] = ((DWORD)g_uwPreTable[ucTmp]<<2) / DLC_DEFLICK_PRECISION_SHIFT;
2755 g_ucTable[ucTmp] = g_uwTable[ucTmp]>>2;
2756
2757 msWriteByte((REG_ADDR_DLC_DATA_START_SUB+ucTmp), g_ucTable[ucTmp]);
2758 msDlcWriteCurveLSB(bWindow, ucTmp, g_uwTable[ucTmp]&0x03);
2759
2760 // set DLC curve index N0 & 16
2761 if (ucTmp == 0)
2762 {
2763 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_SUB, g_uwTable[0]>>2);
2764 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_SUB + 1, 0x01);
2765 msDlcWriteCurveLSB(SUB_WINDOW, 0xFF, g_uwTable[0]&0x03);
2766 }
2767
2768 if (ucTmp == 15)
2769 {
2770 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_SUB, 255-(g_uwTable[15]>>2));
2771 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_SUB + 1, 0x01);
2772 msDlcWriteCurveLSB(SUB_WINDOW, 16, g_uwTable[15]&0x03);
2773 }
2774 }
2775 }
2776 #else
2777 for(ucTmp=0; ucTmp<=0x0f; ucTmp++)
2778 {
2779 msWriteByte((REG_ADDR_DLC_DATA_START_SUB+ucTmp), g_ucTable[ucTmp]);
2780 msDlcWriteCurveLSB(bWindow, ucTmp, g_uwTable[ucTmp]&0x03);
2781
2782 // set DLC curve index N0 & 16
2783 if (ucTmp == 0)
2784 {
2785 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_SUB, g_uwTable[0]>>2);
2786 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_SUB + 1, 0x01);
2787 msDlcWriteCurveLSB(SUB_WINDOW, 0xFF, g_uwTable[0]&0x03);
2788 }
2789
2790 if (ucTmp == 15)
2791 {
2792 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_SUB, 255-(g_uwTable[15]>>2));
2793 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_SUB + 1, 0x01);
2794 msDlcWriteCurveLSB(SUB_WINDOW, 16, g_uwTable[15]&0x03);
2795 }
2796 }
2797 #endif
2798 }
2799 }
2800 else
2801 {
2802
2803 if( MAIN_WINDOW == bWindow )
2804 {
2805 for(ucTmp=0; ucTmp<=0x0f; ucTmp++)
2806 {
2807 g_uwTable[ucTmp] = (g_wPIAlpha*(ucTmp*64 + 32)+(256-g_wPIAlpha)*g_uwTable[ucTmp]+128)/256;
2808
2809 if(g_uwTable[ucTmp]>(g_uwPreTable[ucTmp]/16))
2810 {
2811 if(g_ucDlcFlickAlpha==g_DlcParameters.ucDlcAlphaBlendingMin)
2812 {
2813 uwBlend = (WORD)(((16*(DWORD)g_uwTable[ucTmp])+(63*(DWORD)g_uwPreTable[ucTmp])+63)/64); //14-bits
2814 g_uwPreTable[ucTmp] = uwBlend; //14-bits
2815 uwBlend = (uwBlend+8)/16; //10-bits
2816 }
2817 else
2818 {
2819 uwBlend = (WORD)((((DWORD) g_ucDlcFlickAlpha * (DWORD)g_uwTable[ucTmp]) +
2820 ((128 - (DWORD)g_ucDlcFlickAlpha) * (DWORD)(g_uwPreTable[ucTmp]/16))+127)/128); //10-bits
2821 g_uwPreTable[ucTmp] = uwBlend*16; //14-bits
2822 uwBlend = uwBlend;
2823 }
2824 }
2825 else
2826 {
2827 if(g_ucDlcFlickAlpha==g_DlcParameters.ucDlcAlphaBlendingMin)
2828 {
2829 uwBlend = (WORD)(((16*(DWORD)g_uwTable[ucTmp])+(63*(DWORD)g_uwPreTable[ucTmp]))/64); //14-bits
2830 g_uwPreTable[ucTmp] = uwBlend; //14-bits
2831 uwBlend = (uwBlend+8)/16; //10-bits
2832 }
2833 else
2834 {
2835 uwBlend = (WORD)((((DWORD) g_ucDlcFlickAlpha * (DWORD)g_uwTable[ucTmp]) +
2836 ((128 - (DWORD)g_ucDlcFlickAlpha) * (DWORD)(g_uwPreTable[ucTmp]/16)))/128); //10-bits
2837 g_uwPreTable[ucTmp] = uwBlend*16; //14-bits
2838 uwBlend = uwBlend;
2839 }
2840 }
2841
2842 g_uwTable[ucTmp] = uwBlend;
2843 g_ucTable[ucTmp] = g_uwTable[ucTmp]>>2;
2844
2845 msWriteByte((REG_ADDR_DLC_DATA_START_MAIN+ucTmp), g_ucTable[ucTmp]);
2846 msDlcWriteCurveLSB(bWindow, ucTmp, g_uwTable[ucTmp]&0x03);
2847
2848 // set DLC curve index N0 & 16
2849 if (ucTmp == 0)
2850 {
2851 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_MAIN, g_uwTable[0]>>2);
2852 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_MAIN + 1, 0x01);
2853 msDlcWriteCurveLSB(MAIN_WINDOW, 0xFF, g_uwTable[0]&0x03);
2854 }
2855
2856 if (ucTmp == 15)
2857 {
2858 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_MAIN, 255-(g_uwTable[15]>>2));
2859 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_MAIN + 1, 0x01);
2860 msDlcWriteCurveLSB(MAIN_WINDOW, 16, g_uwTable[15]&0x03);
2861 }
2862 }
2863 }
2864 else
2865 {
2866 #if XC_DLC_SET_DLC_CURVE_BOTH_SAME
2867 //Mantis issue of 0232938:Hsense A3 DLC the divisor can't to be equal to zero .
2868 if((DLC_DEFLICK_BLEND_FACTOR - g_ucDlcFlickAlpha + 1)==0)
2869 {
2870 DLC_DEBUG(printf("\n Error in [New DLC Algorithm][ %s , %d ] (DLC_DEFLICK_BLEND_FACTOR - g_ucDlcFlickAlpha + 1)=0 !!!\n", __FUNCTION__,__LINE__));
2871 return;
2872 }
2873
2874 for(ucTmp=0; ucTmp<=0x0f; ucTmp++)
2875 {
2876 if(g_ucDlcFastLoop || (g_ucDlcFlickAlpha >= (DLC_DEFLICK_BLEND_FACTOR >> 1)))
2877 {
2878 if (g_ucDlcFastLoop)
2879 {
2880 g_ucDlcFastLoop--;
2881 }
2882
2883 // target value with alpha blending
2884
2885 uwBlend = (WORD)((((DWORD) g_ucDlcFlickAlpha * (DWORD)g_ucTable[ucTmp] * 4) +
2886 ((32 - (DWORD)g_ucDlcFlickAlpha) * (DWORD)g_uwPreTable[ucTmp])+16)/32);
2887
2888 if(uwBlend > g_uwPreTable[ucTmp])
2889 {
2890 uwTmp = (uwBlend - g_uwPreTable[ucTmp]) / (DLC_DEFLICK_BLEND_FACTOR - g_ucDlcFlickAlpha + 1);
2891 uwBlend = g_uwPreTable[ucTmp] + uwTmp;
2892 }
2893 else if(uwBlend < g_uwPreTable[ucTmp])
2894 {
2895 uwTmp = (g_uwPreTable[ucTmp] - uwBlend) / (DLC_DEFLICK_BLEND_FACTOR - g_ucDlcFlickAlpha + 1);
2896 uwBlend = g_uwPreTable[ucTmp] - uwTmp;
2897 }
2898
2899 g_uwPreTable[ucTmp] = uwBlend;
2900
2901 g_uwTable[ucTmp] = g_uwPreTable[ucTmp];
2902 g_ucTable[ucTmp] = g_uwTable[ucTmp]>>2;
2903
2904 msWriteByte((REG_ADDR_DLC_DATA_START_SUB+ucTmp), g_ucTable[ucTmp]);
2905 msDlcWriteCurveLSB(bWindow, ucTmp, g_uwTable[ucTmp]&0x03);
2906
2907 // set DLC curve index N0 & 16
2908 if (ucTmp == 0)
2909 {
2910 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_SUB, g_uwTable[0]>>2);
2911 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_SUB + 1, 0x01);
2912 msDlcWriteCurveLSB(SUB_WINDOW, 0xFF, g_uwTable[0]&0x03);
2913 }
2914
2915 if (ucTmp == 15)
2916 {
2917 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_SUB, 255-(g_uwTable[15]>>2));
2918 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_SUB + 1, 0x01);
2919 msDlcWriteCurveLSB(SUB_WINDOW, 16, g_uwTable[15]&0x03);
2920 }
2921 }
2922 else if (g_ucDlcFlickAlpha == 0)
2923 {
2924 g_ucTable[ucTmp] = g_uwPreTable[ucTmp] / 4;
2925 }
2926 else if ((ucTmp%4) == (g_ucUpdateCnt%4))
2927 {
2928 // target value with alpha blending
2929
2930 uwBlend = (WORD)((((DWORD) g_ucDlcFlickAlpha * (DWORD)g_ucTable[ucTmp] * 4) +
2931 ((32 - (DWORD)g_ucDlcFlickAlpha) * (DWORD)g_uwPreTable[ucTmp])+16)/32);
2932
2933 if(uwBlend > g_uwPreTable[ucTmp])
2934 {
2935 if((uwBlend - g_uwPreTable[ucTmp]) > 4)
2936 {
2937 uwBlend = g_uwPreTable[ucTmp] + 4;
2938 }
2939 }
2940 else if(uwBlend < g_uwPreTable[ucTmp])
2941 {
2942 if((g_uwPreTable[ucTmp] - uwBlend) > 4)
2943 {
2944 uwBlend = g_uwPreTable[ucTmp] - 4;
2945 }
2946 }
2947
2948 g_uwPreTable[ucTmp] = uwBlend;
2949
2950 g_uwTable[ucTmp] = g_uwPreTable[ucTmp];
2951 g_ucTable[ucTmp] = g_uwTable[ucTmp]>>2;
2952
2953 msWriteByte((REG_ADDR_DLC_DATA_START_SUB+ucTmp), g_ucTable[ucTmp]);
2954 msDlcWriteCurveLSB(bWindow, ucTmp, g_uwTable[ucTmp]&0x03);
2955
2956 // set DLC curve index N0 & 16
2957 if (ucTmp == 0)
2958 {
2959 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_SUB, g_uwTable[0]>>2);
2960 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_SUB + 1, 0x01);
2961 msDlcWriteCurveLSB(SUB_WINDOW, 0xFF, g_uwTable[0]&0x03);
2962 }
2963
2964 if (ucTmp == 15)
2965 {
2966 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_SUB, 255-(g_uwTable[15]>>2));
2967 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_SUB + 1, 0x01);
2968 msDlcWriteCurveLSB(SUB_WINDOW, 16, g_uwTable[15]&0x03);
2969 }
2970 }
2971 }
2972 #else
2973 for(ucTmp=0; ucTmp<=0x0f; ucTmp++)
2974 {
2975 msWriteByte((REG_ADDR_DLC_DATA_START_SUB+ucTmp), g_ucTable[ucTmp]);
2976 msDlcWriteCurveLSB(bWindow, ucTmp, g_uwTable[ucTmp]&0x03);
2977
2978 // set DLC curve index N0 & 16
2979 if (ucTmp == 0)
2980 {
2981 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_SUB, g_uwTable[0]>>2);
2982 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_N0_SUB + 1, 0x01);
2983 msDlcWriteCurveLSB(SUB_WINDOW, 0xFF, g_uwTable[0]&0x03);
2984 }
2985
2986 if (ucTmp == 15)
2987 {
2988 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_SUB, 255-(g_uwTable[15]>>2));
2989 msWriteByte(REG_ADDR_DLC_DATA_EXTEND_16_SUB + 1, 0x01);
2990 msDlcWriteCurveLSB(SUB_WINDOW, 16, g_uwTable[15]&0x03);
2991 }
2992 }
2993 #endif
2994 }
2995 }
2996
2997 g_ucUpdateCnt++;
2998
2999 msDlc_FunctionExit();
3000 }
3001
3002 //////////////////////////////////////////////////////////////
3003 // Program register bytes to MST chip.
3004 //
3005 // Arguments: pTable - pointer of registers table
3006 //////////////////////////////////////////////////////////////
msWriteDLCRegsTbl(DlcRegUnitType code * pTable)3007 void msWriteDLCRegsTbl(DlcRegUnitType code *pTable)
3008 {
3009 WORD wReg; // register index
3010
3011 while (1)
3012 {
3013 wReg = pTable->wReg; // get register index
3014 if (wReg == _END_OF_TBL_) // check end of table
3015 break;
3016
3017 msWriteByte(wReg, pTable->ucValue); // write register
3018
3019 pTable++; // next
3020 } // while
3021 }
3022
msDlcSpeedupTrigger(BYTE ucLoop)3023 void msDlcSpeedupTrigger(BYTE ucLoop)
3024 {
3025 g_DlcParameters.ucDlcFlickAlphaStart = ucLoop;
3026 }
3027
3028 /******************************************************************************/
3029 /* CGC */
3030 /******************************************************************************/
3031
msDlc_CGC_Init(void)3032 void msDlc_CGC_Init(void)
3033 {
3034 msDlc_FunctionEnter();
3035
3036 if((msReadByte(REG_ADDR_DLC_HANDSHAKE) & _BIT7) )// Shall not Init CGC again while DLC is On.
3037 {
3038 msDlc_FunctionExit();
3039 return;
3040 }
3041
3042 g_u8Chroma_OriGain = msReadByte(REG_ADDR_DLC_C_GAIN);
3043 msDlc_CGC_ReInit();
3044
3045 msDlc_FunctionExit();
3046 }
3047
msDlc_CGC_ReInit(void)3048 void msDlc_CGC_ReInit(void) // For CGC Init & Tool change parameter value dynamicly
3049 {
3050 if ((0xFF-g_u8Chroma_OriGain)>g_DlcParameters.ucCGCChroma_GainLimitH)
3051 g_u8CGC_UpperBond = (g_u8Chroma_OriGain+g_DlcParameters.ucCGCChroma_GainLimitH);
3052 else
3053 g_u8CGC_UpperBond = 0xFF;
3054
3055 if (g_DlcParameters.ucCGCChroma_GainLimitL<g_u8Chroma_OriGain)
3056 g_u8CGC_LowerBond = (g_u8Chroma_OriGain-g_DlcParameters.ucCGCChroma_GainLimitL);
3057 else
3058 g_u8CGC_LowerBond = 0x00;
3059
3060 g_u16Ydark = (Y01_weight*(g_ucTable[0]+g_ucTable[1])+Y23_weight*(g_ucTable[2]+g_ucTable[3]))/(2*(Y01_weight+Y23_weight));
3061 g_u16Ydark = g_u16Ydark+((Y45_weight*(g_ucTable[4]+g_ucTable[5])+Y67_weight*(g_ucTable[6]+g_ucTable[7])))/(2*(Y45_weight+Y67_weight));
3062
3063 if (g_DlcParameters.ucCGCCGain_offset & _BIT7)
3064 g_u16Ydark = (g_u16Ydark-(g_DlcParameters.ucCGCCGain_offset&0x7F));
3065 else
3066 g_u16Ydark = (g_u16Ydark+g_DlcParameters.ucCGCCGain_offset);
3067
3068 g_u16Ydark_pre = g_u16Ydark;
3069
3070 //printf("\r\n[1]. g_ucTable[0] = %d \n", g_ucTable[0]);
3071 //printf("\r\n[2]. g_ucTable[1] = %d \n", g_ucTable[1]);
3072 //printf("\r\n[3]. g_ucTable[2] = %d \n", g_ucTable[2]);
3073 //printf("\r\n[4]. g_ucTable[3] = %d \n", g_ucTable[3]);
3074 //printf("\r\n[5]. g_ucTable[4] = %d \n", g_ucTable[4]);
3075
3076
3077 //printf("\r\ng_u8CGC_UpperBond = %d \n", g_u8CGC_UpperBond);
3078 //printf("\r\ng_u8CGC_LowerBond = %d \n", g_u8CGC_LowerBond);
3079
3080 //printf("\r\ng_u16Ydark(std) = %d \n", g_u16Ydark);
3081 }
3082
msDlc_CGC_SetGain(BYTE u8CGain)3083 void msDlc_CGC_SetGain(BYTE u8CGain)
3084 {
3085 msDlc_FunctionEnter();
3086
3087 if (g_DlcParameters.bCGCCGainCtrl && (REG_ADDR_DLC_C_GAIN != REG_NULL))
3088 msWriteByte(REG_ADDR_DLC_C_GAIN, u8CGain);
3089
3090 msDlc_FunctionExit();
3091 }
3092
msDlc_CGC_Handler(void)3093 void msDlc_CGC_Handler(void)
3094 {
3095 BYTE u8TmpVal;
3096
3097 WORD u16Ytemp, u16Ydiff;
3098
3099 msDlc_FunctionEnter();
3100
3101 //printf("\r\n g_u8CGC_UpperBond = %d \n", g_u8CGC_UpperBond);
3102 //printf("\r\n g_u8CGC_LowerBond = %d \n", g_u8CGC_LowerBond);
3103
3104 u16Ytemp = (DWORD) (Y01_weight*(g_ucTable[0]+g_ucTable[1])+
3105 Y23_weight*(g_ucTable[2]+g_ucTable[3]))/
3106 (Y01_weight+Y23_weight);
3107
3108 u16Ytemp = u16Ytemp/2+(DWORD)(Y45_weight*(g_ucTable[4]+g_ucTable[5])+
3109 Y67_weight*(g_ucTable[6]+g_ucTable[7]))/
3110 (2*(Y45_weight+Y67_weight));
3111
3112 //printf("\r\nu16Ytemp = %d", u16Ytemp);
3113 //printf("\r\ng_u16Ydark_pre = %d", g_u16Ydark_pre);
3114
3115 if (abs(u16Ytemp-g_u16Ydark_pre)>=Yvar_Th)
3116 {
3117 g_u8TCount++;
3118
3119 if ((u16Ytemp>g_u16Ydark)&&(g_u8TCount>=Timer_CountU))
3120 {
3121 //printf("\r\ng_u8TCountU = %d", g_u8TCount);
3122 g_u8TCount = 0;
3123
3124 u16Ydiff=(u16Ytemp-g_u16Ydark);
3125
3126 if (u16Ydiff>g_DlcParameters.ucCGCYth)
3127 {
3128 g_u8Chroma_target = g_u8Chroma_OriGain+(WORD)((u16Ydiff-g_DlcParameters.ucCGCYth)*g_DlcParameters.ucCGCYCslope)/(0x20);
3129
3130 if (g_u8Chroma_target > g_u8CGC_UpperBond)
3131 g_u8Chroma_target = g_u8CGC_UpperBond;
3132 }
3133 else
3134 g_u8Chroma_target = g_u8Chroma_OriGain;
3135 }
3136 else if ((u16Ytemp<=g_u16Ydark)&&(g_u8TCount>=Timer_CountD))
3137 {
3138 //printf("\r\ng_u8TCountD = %d", g_u8TCount);
3139 g_u8TCount = 0;
3140
3141 u16Ydiff=(g_u16Ydark-u16Ytemp);
3142
3143 if (u16Ydiff>g_DlcParameters.ucCGCYth)
3144 {
3145 g_u8Chroma_target = g_u8Chroma_OriGain-(WORD)((u16Ydiff-g_DlcParameters.ucCGCYth)*g_DlcParameters.ucCGCYCslope)/(0x20);
3146
3147 if (g_u8Chroma_target < g_u8CGC_LowerBond)
3148 g_u8Chroma_target = g_u8CGC_LowerBond;
3149 }
3150 else
3151 g_u8Chroma_target = g_u8Chroma_OriGain;
3152 }
3153
3154 //printf("\r\ng_u8Chroma_target = %d", g_u8Chroma_target);
3155
3156 u8TmpVal = msReadByte(REG_ADDR_DLC_C_GAIN);
3157
3158 if (g_u8Chroma_target>u8TmpVal)
3159 msDlc_CGC_SetGain(u8TmpVal+CGain_StepU);
3160 else if (g_u8Chroma_target<u8TmpVal)
3161 msDlc_CGC_SetGain(u8TmpVal-CGain_StepD);
3162 }
3163
3164 g_u16Ydark_pre = (DWORD)(31*g_u16Ydark_pre+u16Ytemp)/32;
3165
3166 msDlc_FunctionExit();
3167 }
3168
3169 //////////////////////////////////////////////////////////////
3170 // Debug Protocol
3171 //////////////////////////////////////////////////////////////
3172
3173 // Debug Command Paser
3174 #define URCMD_MST_DLC_TEST_FORCE_PAUSE 0
3175 #define URCMD_MST_DLC_TEST_FORCE_RUN 1
3176 #define URCMD_MST_DLC_TEST_READ 2 // old mode
3177 #define URCMD_MST_DLC_TEST_WRITE_1 3
3178 #define URCMD_MST_DLC_TEST_WRITE_2 4
3179 #define URCMD_MST_DLC_TEST_REINIT 5
3180 #define URCMD_MST_DLC_TEST_READ_BOUNDARY 6
3181 #define URCMD_MST_DLC_TEST_WRITE_BOUNDARY 7
3182 #define URCMD_MST_DLC_TEST_READ_CV1 8
3183 #define URCMD_MST_DLC_TEST_READ_CV2A 9
3184 #define URCMD_MST_DLC_TEST_READ_CV2B 10
3185 #define URCMD_MST_DLC_TEST_WRITE_CV1 11
3186 #define URCMD_MST_DLC_TEST_WRITE_CV2A 12
3187 #define URCMD_MST_DLC_TEST_WRITE_CV2B 13
3188 #define URCMD_MST_DLC_TEST_READ_INFO 14
3189 #define URCMD_MST_DLC_TEST_WRITE_INFO 15
3190 #define URCMD_MST_DLC_TEST_CGC_REINIT 16
3191 #define URCMD_MST_DLC_TEST_READ_Sloplimit 17
3192 #define URCMD_MST_DLC_TEST_WRITE_Sloplimit 18
3193
msDLC_ParametersTool(BYTE * pCmdBuff)3194 void msDLC_ParametersTool(BYTE *pCmdBuff)
3195 {
3196 BYTE ucTmpLen;
3197
3198 ucTmpLen = *(pCmdBuff+1); //ucTmpLen
3199
3200 switch(*(pCmdBuff+3)) //UART_EXT_CMD
3201 {
3202 case URCMD_MST_DLC_TEST_FORCE_PAUSE:
3203
3204 break;
3205 case URCMD_MST_DLC_TEST_FORCE_RUN:
3206
3207 break;
3208 case URCMD_MST_DLC_TEST_READ:
3209 {
3210 BYTE i;
3211 for (i=0; i<16; i+=2)
3212 {
3213 putchar(0xF3);
3214 putchar(g_DlcParameters.ucLumaCurve[i]);
3215 putchar(g_DlcParameters.ucLumaCurve[i+1]);
3216 Delay1ms(150);
3217 }
3218 }
3219 break;
3220 case URCMD_MST_DLC_TEST_WRITE_1:
3221 {
3222 BYTE i;
3223 #if 1//( ENABLE_UART_CHECKSUM )
3224 ucTmpLen--; // remove checksum byte
3225 #endif
3226 for (i=0; i<(ucTmpLen-4); i++)
3227 g_DlcParameters.ucLumaCurve[i] = *(pCmdBuff+4 + i);
3228 }
3229 break;
3230 case URCMD_MST_DLC_TEST_WRITE_2:
3231 {
3232 BYTE i;
3233 #if 1//( ENABLE_UART_CHECKSUM )
3234 ucTmpLen--; // remove checksum byte
3235 #endif
3236 for (i=0; i<(ucTmpLen-4); i++)
3237 g_DlcParameters.ucLumaCurve[8 + i] = *(pCmdBuff+4 + i);
3238 }
3239 break;
3240 case URCMD_MST_DLC_TEST_READ_CV1:
3241 {
3242 putchar(0xF2);
3243 putchar(g_DlcParameters.ucLumaCurve[*(pCmdBuff+4)]);
3244 }
3245 break;
3246 case URCMD_MST_DLC_TEST_READ_CV2A:
3247 {
3248 putchar(0xF2);
3249 putchar(g_DlcParameters.ucLumaCurve2_a[*(pCmdBuff+4)]);
3250 }
3251 break;
3252 case URCMD_MST_DLC_TEST_READ_CV2B:
3253 {
3254 putchar(0xF2);
3255 putchar(g_DlcParameters.ucLumaCurve2_b[*(pCmdBuff+4)]);
3256 }
3257 break;
3258 case URCMD_MST_DLC_TEST_WRITE_CV1:
3259 {
3260 BYTE i;
3261 #if 1//( ENABLE_UART_CHECKSUM )
3262 ucTmpLen--; // remove checksum byte
3263 #endif
3264 for (i=0; i<(ucTmpLen-4-1); i++)
3265 g_DlcParameters.ucLumaCurve[*(pCmdBuff+4) + i] = *(pCmdBuff+5 + i);
3266 }
3267 break;
3268 case URCMD_MST_DLC_TEST_WRITE_CV2A:
3269 {
3270 BYTE i;
3271 #if 1//( ENABLE_UART_CHECKSUM )
3272 ucTmpLen--; // remove checksum byte
3273 #endif
3274 for (i=0; i<(ucTmpLen-4-1); i++)
3275 g_DlcParameters.ucLumaCurve2_a[*(pCmdBuff+4) + i] = *(pCmdBuff+5 + i);
3276 }
3277 break;
3278 case URCMD_MST_DLC_TEST_WRITE_CV2B:
3279 {
3280 BYTE i;
3281 #if 1//( ENABLE_UART_CHECKSUM )
3282 ucTmpLen--; // remove checksum byte
3283 #endif
3284 for (i=0; i<(ucTmpLen-4-1); i++)
3285 g_DlcParameters.ucLumaCurve2_b[*(pCmdBuff+4) + i] = *(pCmdBuff+5 + i);
3286 }
3287 break;
3288 case URCMD_MST_DLC_TEST_READ_INFO:
3289 {
3290 if (*(pCmdBuff+4) == 1) // DLC curve
3291 {
3292 putchar(0xF2);
3293 putchar(g_ucTable[*(pCmdBuff+5)]);
3294 }
3295 else if (*(pCmdBuff+4) == 2) // DLC other
3296 {
3297 if (*(pCmdBuff+5) < 64)
3298 {
3299 putchar(0xF2);
3300 if (*(pCmdBuff+5)%2)
3301 putchar(g_wLumaHistogram32H[*(pCmdBuff+5)/2] & 0xFF);
3302 else
3303 putchar(g_wLumaHistogram32H[*(pCmdBuff+5)/2] >> 8);
3304 }
3305 else if (*(pCmdBuff+5) == 200)
3306 {
3307 WORD wVer;
3308 wVer = msDlcLibVersionCheck();
3309 putchar(0xF3);
3310 putchar(wVer >> 8);
3311 putchar(wVer & 0xFF);
3312 }
3313 else if (*(pCmdBuff+5) == 201)
3314 {
3315 putchar(0xF3);
3316 putchar(g_DlcParameters.uwDlcBleStartPointTH >> 8);
3317 putchar(g_DlcParameters.uwDlcBleStartPointTH & 0xFF);
3318 }
3319 else if (*(pCmdBuff+5) == 202)
3320 {
3321 putchar(0xF3);
3322 putchar(g_DlcParameters.uwDlcBleEndPointTH >> 8);
3323 putchar(g_DlcParameters.uwDlcBleEndPointTH & 0xFF);
3324 }
3325 else if (*(pCmdBuff+5) == 203)
3326 {
3327 putchar(0xF3);
3328 putchar(g_DlcParameters.uwDlcBLESlopPoint_1 >> 8);
3329 putchar(g_DlcParameters.uwDlcBLESlopPoint_1 & 0xFF);
3330 }
3331 else if (*(pCmdBuff+5) == 204)
3332 {
3333 putchar(0xF3);
3334 putchar(g_DlcParameters.uwDlcBLESlopPoint_2 >> 8);
3335 putchar(g_DlcParameters.uwDlcBLESlopPoint_2 & 0xFF);
3336 }
3337 else if (*(pCmdBuff+5) == 205)
3338 {
3339 putchar(0xF3);
3340 putchar(g_DlcParameters.uwDlcBLESlopPoint_3 >> 8);
3341 putchar(g_DlcParameters.uwDlcBLESlopPoint_3 & 0xFF);
3342 }
3343 else if (*(pCmdBuff+5) == 206)
3344 {
3345 putchar(0xF3);
3346 putchar(g_DlcParameters.uwDlcBLESlopPoint_4 >> 8);
3347 putchar(g_DlcParameters.uwDlcBLESlopPoint_4 & 0xFF);
3348 }
3349 else if (*(pCmdBuff+5) == 207)
3350 {
3351 putchar(0xF3);
3352 putchar(g_DlcParameters.uwDlcBLESlopPoint_5 >> 8);
3353 putchar(g_DlcParameters.uwDlcBLESlopPoint_5 & 0xFF);
3354 }
3355 else if (*(pCmdBuff+5) == 208)
3356 {
3357 putchar(0xF3);
3358 putchar(g_DlcParameters.uwDlcDark_BLE_Slop_Min >> 8);
3359 putchar(g_DlcParameters.uwDlcDark_BLE_Slop_Min & 0xFF);
3360 }
3361 else if (*(pCmdBuff+5) >= 64)
3362 {
3363 putchar(0xF2);
3364 if (*(pCmdBuff+5) == 64)
3365 putchar(g_wLumiAverageTemp & 0xFF);
3366 else if (*(pCmdBuff+5) == 65)
3367 putchar(g_wLumiAverageTemp >> 8);
3368 else if (*(pCmdBuff+5) == 66)
3369 putchar(g_wLumiTotalCount & 0xFF);
3370 else if (*(pCmdBuff+5) == 67)
3371 putchar(g_wLumiTotalCount >> 8);
3372 else if (*(pCmdBuff+5) == 68)
3373 putchar(g_DlcParameters.u8_L_L_U);
3374 else if (*(pCmdBuff+5) == 69)
3375 putchar(g_DlcParameters.u8_L_L_D);
3376 else if (*(pCmdBuff+5) == 70)
3377 putchar(g_DlcParameters.u8_L_H_U);
3378 else if (*(pCmdBuff+5) == 71)
3379 putchar(g_DlcParameters.u8_L_H_D);
3380 else if (*(pCmdBuff+5) == 72)
3381 putchar(g_DlcParameters.u8_S_L_U);
3382 else if (*(pCmdBuff+5) == 73)
3383 putchar(g_DlcParameters.u8_S_L_D);
3384 else if (*(pCmdBuff+5) == 74)
3385 putchar(g_DlcParameters.u8_S_H_U);
3386 else if (*(pCmdBuff+5) == 75)
3387 putchar(g_DlcParameters.u8_S_H_D);
3388 else if (*(pCmdBuff+5) == 76)
3389 putchar(g_ucHistogramMin);
3390 else if (*(pCmdBuff+5) == 77)
3391 putchar(g_ucHistogramMax);
3392 else if (*(pCmdBuff+5) == 78)
3393 putchar(g_DlcParameters.ucDlcPureImageMode);
3394 else if (*(pCmdBuff+5) == 79)
3395 putchar(g_DlcParameters.ucDlcLevelLimit);
3396 else if (*(pCmdBuff+5) == 80)
3397 putchar(g_DlcParameters.ucDlcAvgDelta);
3398 else if (*(pCmdBuff+5) == 81)
3399 putchar(g_DlcParameters.ucDlcFastAlphaBlending);
3400 else if (*(pCmdBuff+5) == 82)
3401 putchar(g_DlcParameters.bEnableBLE);
3402 else if (*(pCmdBuff+5) == 83)
3403 putchar(g_DlcParameters.bEnableWLE);
3404 else if (*(pCmdBuff+5) == 84)
3405 putchar(g_DlcParameters.ucDlcBLEPoint);
3406 else if (*(pCmdBuff+5) == 85)
3407 putchar(g_DlcParameters.ucDlcWLEPoint);
3408 else if (*(pCmdBuff+5) == 86)
3409 putchar(g_DlcParameters.ucDlcAvgDeltaStill);
3410 else if (*(pCmdBuff+5) == 87)
3411 putchar(g_DlcParameters.ucDlcYAvgThresholdL);
3412 else if (*(pCmdBuff+5) == 88)
3413 putchar(g_DlcParameters.ucDlcYAvgThresholdH);
3414 else if (*(pCmdBuff+5) == 89)
3415 putchar(g_DlcParameters.ucCGCCGain_offset);
3416 else if (*(pCmdBuff+5) == 90)
3417 putchar(g_DlcParameters.ucCGCChroma_GainLimitH);
3418 else if (*(pCmdBuff+5) == 91)
3419 putchar(g_DlcParameters.ucCGCChroma_GainLimitL);
3420 else if (*(pCmdBuff+5) == 92)
3421 putchar(g_DlcParameters.ucCGCYCslope);
3422 else if (*(pCmdBuff+5) == 93)
3423 putchar(g_DlcParameters.ucCGCYth);
3424 else if (*(pCmdBuff+5) == 94)
3425 putchar(g_DlcParameters.bCGCCGainCtrl);
3426 else if (*(pCmdBuff+5) == 95)
3427 putchar(g_DlcParameters.ucDlcYAvgThresholdM);
3428 else if (*(pCmdBuff+5) == 96)
3429 putchar(g_DlcParameters.ucDlcCurveMode);
3430 else if (*(pCmdBuff+5) == 97)
3431 putchar(g_DlcParameters.ucDlcCurveModeMixAlpha);
3432 else if (*(pCmdBuff+5) == 98)
3433 putchar(g_DlcParameters.ucDlcAlgorithmMode);
3434 else if (*(pCmdBuff+5) == 99)
3435 putchar(g_DlcParameters.ucDlcSepPointH);
3436 else if (*(pCmdBuff+5) == 100)
3437 putchar(g_DlcParameters.ucDlcSepPointL);
3438 else if (*(pCmdBuff+5) == 101)
3439 putchar(g_DlcParameters.ucDlcCurveDiff_L_TH);
3440 else if (*(pCmdBuff+5) == 102)
3441 putchar(g_DlcParameters.ucDlcCurveDiff_H_TH);
3442 else if (*(pCmdBuff+5) == 103)
3443 putchar(g_DlcParameters.ucDlcCurveDiffCoringTH);
3444 else if (*(pCmdBuff+5) == 104)
3445 putchar(g_DlcParameters.ucDlcAlphaBlendingMin);
3446 else if (*(pCmdBuff+5) == 105)
3447 putchar(g_DlcParameters.ucDlcAlphaBlendingMax);
3448 else if (*(pCmdBuff+5) == 106)
3449 putchar(g_DlcParameters.ucDlcFlicker_alpha);
3450 else if (*(pCmdBuff+5) == 107)
3451 putchar(g_DlcParameters.ucDlcYAVG_L_TH);
3452 else if (*(pCmdBuff+5) == 108)
3453 putchar(g_DlcParameters.ucDlcYAVG_H_TH);
3454 else if (*(pCmdBuff+5) == 109)
3455 putchar(g_DlcParameters.ucDlcDiffBase_L);
3456 else if (*(pCmdBuff+5) == 110)
3457 putchar(g_DlcParameters.ucDlcDiffBase_M);
3458 else if (*(pCmdBuff+5) == 111)
3459 putchar(g_DlcParameters.ucDlcDiffBase_H);
3460 else
3461 putchar(0);
3462 }
3463 else
3464 {
3465 putchar(0xF2);
3466 putchar(0);
3467 }
3468 }
3469 }
3470 break;
3471 case URCMD_MST_DLC_TEST_WRITE_INFO:
3472 {
3473 if (*(pCmdBuff+4) == 0)
3474 {
3475 g_DlcParameters.u8_L_L_U = *(pCmdBuff+5);
3476 }
3477 else if (*(pCmdBuff+4) == 1)
3478 {
3479 g_DlcParameters.u8_L_L_D = *(pCmdBuff+5);
3480 }
3481 else if (*(pCmdBuff+4) == 2)
3482 {
3483 g_DlcParameters.u8_L_H_U = *(pCmdBuff+5);
3484 }
3485 else if (*(pCmdBuff+4) == 3)
3486 {
3487 g_DlcParameters.u8_L_H_D = *(pCmdBuff+5);
3488 }
3489 else if (*(pCmdBuff+4) == 4)
3490 {
3491 g_DlcParameters.u8_S_L_U = *(pCmdBuff+5);
3492 }
3493 else if (*(pCmdBuff+4) == 5)
3494 {
3495 g_DlcParameters.u8_S_L_D = *(pCmdBuff+5);
3496 }
3497 else if (*(pCmdBuff+4) == 6)
3498 {
3499 g_DlcParameters.u8_S_H_U = *(pCmdBuff+5);
3500 }
3501 else if (*(pCmdBuff+4) == 7)
3502 {
3503 g_DlcParameters.u8_S_H_D = *(pCmdBuff+5);
3504 }
3505 else if (*(pCmdBuff+4) == 8)
3506 {
3507 g_DlcParameters.ucDlcPureImageMode = *(pCmdBuff+5);
3508 }
3509 else if (*(pCmdBuff+4) == 9)
3510 {
3511 g_DlcParameters.ucDlcLevelLimit = *(pCmdBuff+5);
3512 }
3513 else if (*(pCmdBuff+4) == 10)
3514 {
3515 g_DlcParameters.ucDlcAvgDelta = *(pCmdBuff+5);
3516 }
3517 else if (*(pCmdBuff+4) == 11)
3518 {
3519 g_DlcParameters.ucDlcFastAlphaBlending = *(pCmdBuff+5);
3520 }
3521 else if (*(pCmdBuff+4) == 12)
3522 {
3523 g_DlcParameters.bEnableBLE = *(pCmdBuff+5);
3524 }
3525 else if (*(pCmdBuff+4) == 13)
3526 {
3527 g_DlcParameters.bEnableWLE = *(pCmdBuff+5);
3528 }
3529 else if (*(pCmdBuff+4) == 14)
3530 {
3531 g_DlcParameters.ucDlcBLEPoint = *(pCmdBuff+5);
3532 }
3533 else if (*(pCmdBuff+4) == 15)
3534 {
3535 g_DlcParameters.ucDlcWLEPoint = *(pCmdBuff+5);
3536 }
3537 else if (*(pCmdBuff+4) == 16)
3538 {
3539 g_DlcParameters.ucDlcAvgDeltaStill= *(pCmdBuff+5);
3540 }
3541 else if (*(pCmdBuff+4) == 17)
3542 {
3543 g_DlcParameters.ucDlcYAvgThresholdL = *(pCmdBuff+5);
3544 }
3545 else if (*(pCmdBuff+4) == 18)
3546 {
3547 g_DlcParameters.ucDlcYAvgThresholdH = *(pCmdBuff+5);
3548 }
3549 else if (*(pCmdBuff+4) == 19)
3550 {
3551 g_DlcParameters.ucCGCCGain_offset = *(pCmdBuff+5);
3552 }
3553 else if (*(pCmdBuff+4) == 20)
3554 {
3555 g_DlcParameters.ucCGCChroma_GainLimitH = *(pCmdBuff+5);
3556 }
3557 else if (*(pCmdBuff+4) == 21)
3558 {
3559 g_DlcParameters.ucCGCChroma_GainLimitL = *(pCmdBuff+5);
3560 }
3561 else if (*(pCmdBuff+4) == 22)
3562 {
3563 g_DlcParameters.ucCGCYCslope = *(pCmdBuff+5);
3564 }
3565 else if (*(pCmdBuff+4) == 23)
3566 {
3567 g_DlcParameters.ucCGCYth = *(pCmdBuff+5);
3568 }
3569 else if (*(pCmdBuff+4) == 24)
3570 {
3571 g_DlcParameters.bCGCCGainCtrl = *(pCmdBuff+5);
3572 }
3573 else if (*(pCmdBuff+4) == 25)
3574 {
3575 g_DlcParameters.ucDlcYAvgThresholdM = *(pCmdBuff+5);
3576 }
3577 else if (*(pCmdBuff+4) == 26)
3578 {
3579 g_DlcParameters.ucDlcCurveMode = *(pCmdBuff+5);
3580 }
3581 else if (*(pCmdBuff+4) == 27)
3582 {
3583 g_DlcParameters.ucDlcCurveModeMixAlpha = *(pCmdBuff+5);
3584 }
3585 else if (*(pCmdBuff+4) == 28)
3586 {
3587 g_DlcParameters.ucDlcAlgorithmMode = *(pCmdBuff+5);
3588 }
3589 else if (*(pCmdBuff+4) == 29)
3590 {
3591 g_DlcParameters.ucDlcSepPointH = *(pCmdBuff+5);
3592 }
3593 else if (*(pCmdBuff+4) == 30)
3594 {
3595 g_DlcParameters.ucDlcSepPointL = *(pCmdBuff+5);
3596 }
3597 else if (*(pCmdBuff+4) == 31)
3598 {
3599 g_DlcParameters.uwDlcBleStartPointTH = (WORD)((*(pCmdBuff+6)<<8)+(*(pCmdBuff+5)));
3600 }
3601 else if (*(pCmdBuff+4) == 32)
3602 {
3603 g_DlcParameters.uwDlcBleEndPointTH = (WORD)((*(pCmdBuff+6)<<8)+(*(pCmdBuff+5)));
3604 }
3605 else if (*(pCmdBuff+4) == 33)
3606 {
3607 g_DlcParameters.ucDlcCurveDiff_L_TH = *(pCmdBuff+5);
3608 }
3609 else if (*(pCmdBuff+4) == 34)
3610 {
3611 g_DlcParameters.ucDlcCurveDiff_H_TH = *(pCmdBuff+5);
3612 }
3613 else if (*(pCmdBuff+4) == 35)
3614 {
3615 g_DlcParameters.uwDlcBLESlopPoint_1 = (WORD)((*(pCmdBuff+6)<<8)+(*(pCmdBuff+5)));
3616 }
3617 else if (*(pCmdBuff+4) == 36)
3618 {
3619 g_DlcParameters.uwDlcBLESlopPoint_2 = (WORD)((*(pCmdBuff+6)<<8)+(*(pCmdBuff+5)));
3620 }
3621 else if (*(pCmdBuff+4) == 37)
3622 {
3623 g_DlcParameters.uwDlcBLESlopPoint_3 = (WORD)((*(pCmdBuff+6)<<8)+(*(pCmdBuff+5)));
3624 }
3625 else if (*(pCmdBuff+4) == 38)
3626 {
3627 g_DlcParameters.uwDlcBLESlopPoint_4 = (WORD)((*(pCmdBuff+6)<<8)+(*(pCmdBuff+5)));
3628 }
3629 else if (*(pCmdBuff+4) == 39)
3630 {
3631 g_DlcParameters.uwDlcBLESlopPoint_5 = (WORD)((*(pCmdBuff+6)<<8)+(*(pCmdBuff+5)));
3632 }
3633 else if (*(pCmdBuff+4) == 40)
3634 {
3635 g_DlcParameters.uwDlcDark_BLE_Slop_Min = (WORD)((*(pCmdBuff+6)<<8)+(*(pCmdBuff+5)));
3636 }
3637 else if (*(pCmdBuff+4) == 41)
3638 {
3639 g_DlcParameters.ucDlcCurveDiffCoringTH = *(pCmdBuff+5);
3640 }
3641 else if (*(pCmdBuff+4) == 42)
3642 {
3643 g_DlcParameters.ucDlcAlphaBlendingMin = *(pCmdBuff+5);
3644 }
3645 else if (*(pCmdBuff+4) == 43)
3646 {
3647 g_DlcParameters.ucDlcAlphaBlendingMax = *(pCmdBuff+5);
3648 }
3649 else if (*(pCmdBuff+4) == 44)
3650 {
3651 g_DlcParameters.ucDlcFlicker_alpha= *(pCmdBuff+5);
3652 }
3653 else if (*(pCmdBuff+4) == 45)
3654 {
3655 g_DlcParameters.ucDlcYAVG_L_TH = *(pCmdBuff+5);
3656 }
3657 else if (*(pCmdBuff+4) == 46)
3658 {
3659 g_DlcParameters.ucDlcYAVG_H_TH = *(pCmdBuff+5);
3660 }
3661 else if (*(pCmdBuff+4) == 47)
3662 {
3663 g_DlcParameters.ucDlcDiffBase_L= *(pCmdBuff+5);
3664 }
3665 else if (*(pCmdBuff+4) == 48)
3666 {
3667 g_DlcParameters.ucDlcDiffBase_M = *(pCmdBuff+5);
3668 }
3669 else if (*(pCmdBuff+4) == 49)
3670 {
3671 g_DlcParameters.ucDlcDiffBase_H = *(pCmdBuff+5);
3672 }
3673 msDlcSpeedupTrigger(16);
3674 }
3675 break;
3676 case URCMD_MST_DLC_TEST_REINIT:
3677 msDlc_AP_ReinitWithoutPara();
3678 msDlcOnOff( _ENABLE, MAIN_WINDOW);
3679 break;
3680 case URCMD_MST_DLC_TEST_CGC_REINIT:
3681 msDlc_CGC_ReInit();
3682 break;
3683 case URCMD_MST_DLC_TEST_READ_Sloplimit:
3684 {
3685 putchar(0xF2);
3686 putchar(g_DlcParameters.ucDlcHistogramLimitCurve[*(pCmdBuff+4)]);
3687 }
3688 break;
3689 case URCMD_MST_DLC_TEST_WRITE_Sloplimit:
3690 {
3691 BYTE i;
3692 #if 1//( ENABLE_UART_CHECKSUM )
3693 ucTmpLen--; // remove checksum byte
3694 #endif
3695 for (i=0; i<(ucTmpLen-4-1); i++)
3696 g_DlcParameters.ucDlcHistogramLimitCurve[*(pCmdBuff+4) + i] = *(pCmdBuff+5 + i);
3697 }
3698 break;
3699 }
3700 }
3701
3702 //////////////////////////////////////////////////////////////
3703 //
3704 //////////////////////////////////////////////////////////////
msDlcLibVersionCheck(void)3705 WORD msDlcLibVersionCheck(void)
3706 {
3707 return DLC_LIB_VERSION;
3708 }
3709
msDlcCGCLibVersionCheck(void)3710 WORD msDlcCGCLibVersionCheck(void)
3711 {
3712 return DLC_CGC_LIB_VERSION;
3713 }
3714
3715 #undef _MSDLC_C_
3716