|
1 /* |
|
2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * CDisplayChain |
|
16 * Image processing class implementing |
|
17 * display specific image processing: |
|
18 * - Scaling to display size with pan support |
|
19 * - IETD - display specific color contrast enhancement |
|
20 * - Sharpening |
|
21 * - Display feature compensation by simple color management |
|
22 * - Dithering |
|
23 * |
|
24 */ |
|
25 |
|
26 |
|
27 |
|
28 #include <fbs.h> |
|
29 #include "DisplayChain.h" |
|
30 |
|
31 |
|
32 /* |
|
33 ----------------------------------------------------------------------------- |
|
34 |
|
35 Constructor |
|
36 |
|
37 Default constructor, initializes member variables to initial values |
|
38 |
|
39 Return Values: none |
|
40 |
|
41 ----------------------------------------------------------------------------- |
|
42 */ |
|
43 CDisplayChain::CDisplayChain() |
|
44 { |
|
45 // This function is intentionally left blank. |
|
46 } |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 /* |
|
52 ----------------------------------------------------------------------------- |
|
53 |
|
54 NewLC |
|
55 |
|
56 Factory function to instantiate the class. |
|
57 This function leaves the class pointer to the cleanup stack |
|
58 May leave with KErrNoMemory if no memory available |
|
59 |
|
60 Return Values: CDisplayChain* self: pointer to the class instance |
|
61 |
|
62 ----------------------------------------------------------------------------- |
|
63 */ |
|
64 CDisplayChain* CDisplayChain::NewLC() |
|
65 { |
|
66 CDisplayChain* self = new (ELeave) CDisplayChain(); |
|
67 CleanupStack::PushL(self); |
|
68 self->ConstructL(); |
|
69 return self; |
|
70 } |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 /* |
|
76 ----------------------------------------------------------------------------- |
|
77 |
|
78 CDCIetd |
|
79 |
|
80 NewL |
|
81 |
|
82 Factory function to instantiate the class. |
|
83 May leave with KErrNoMemory if no memory available |
|
84 |
|
85 Return Values: CDisplayChain* self: pointer to the class instance |
|
86 |
|
87 ----------------------------------------------------------------------------- |
|
88 */ |
|
89 CDisplayChain* CDisplayChain::NewL() |
|
90 { |
|
91 CDisplayChain* self = CDisplayChain::NewLC(); |
|
92 CleanupStack::Pop(); |
|
93 return self; |
|
94 } |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 /* |
|
101 ----------------------------------------------------------------------------- |
|
102 |
|
103 CDCIetd |
|
104 |
|
105 ConstructL |
|
106 |
|
107 Second phase constructor. Does nothing at the moment |
|
108 |
|
109 Return Values: none |
|
110 |
|
111 ----------------------------------------------------------------------------- |
|
112 */ |
|
113 void CDisplayChain::ConstructL() |
|
114 { |
|
115 // Create objects for ImaamiImageChain |
|
116 DigitalZoomPtr = CDCDigitalZoom::NewL(); |
|
117 CleanupStack::PushL(DigitalZoomPtr); |
|
118 |
|
119 SharpeningPtr = DCSharpening::NewL(); |
|
120 CleanupStack::PushL(SharpeningPtr); |
|
121 |
|
122 DitheringPtr = CDCDithering::NewL(); |
|
123 CleanupStack::PushL(DitheringPtr); |
|
124 |
|
125 IetdPtr = CDCIetd::NewL(); |
|
126 CleanupStack::PushL(IetdPtr); |
|
127 |
|
128 ColorManagementPtr = CDCColorManagement::NewL(); |
|
129 CleanupStack::PushL(ColorManagementPtr); |
|
130 |
|
131 |
|
132 TInt i; //Index |
|
133 |
|
134 //As default image is just opened to be processed |
|
135 Parameters.FirstOpening = ETrue; |
|
136 |
|
137 //Get current processing parameters from processing objects |
|
138 DigitalZoomPtr->GetParameters(&Parameters.DZParameters); |
|
139 IetdPtr->GetParams(&Parameters.IETDParameters); |
|
140 SharpeningPtr->GetParameters(&Parameters.SharpeningParameters); |
|
141 ColorManagementPtr->GetParameters(&Parameters.ColorManagementParameters); |
|
142 |
|
143 //Here the parameters can be read for example from a text file or from the registers, etc. |
|
144 //if (!ReadFileL()) |
|
145 { |
|
146 //Set default parameter values |
|
147 //(Defined in DCInit.h) |
|
148 //---------------------------- |
|
149 |
|
150 //Set each processing ON/OFF |
|
151 Parameters.DigitalZoomON = DZ; |
|
152 Parameters.DitheringON = DITHER; |
|
153 Parameters.ColorManagementON = ETrue; //CM; |
|
154 Parameters.IetdON = IETD; |
|
155 Parameters.SharpeningON = SHARP; |
|
156 |
|
157 //DigitalZoom |
|
158 DigitalZoomPtr->GetParameters(&Parameters.DZParameters); |
|
159 Parameters.DZParameters.sizeX = DZsizeX; |
|
160 Parameters.DZParameters.sizeY = DZsizeY; |
|
161 Parameters.DZParameters.scaleX = DZscaleX; |
|
162 Parameters.DZParameters.scaleY = DZscaleY; |
|
163 Parameters.DZParameters.allShiftX = DZallX; |
|
164 Parameters.DZParameters.allShiftY = DZallY; |
|
165 Parameters.DZParameters.newShiftX = DZnewX; |
|
166 Parameters.DZParameters.newShiftY = DZnewY; |
|
167 |
|
168 //IETD |
|
169 Parameters.IETDParameters.aStretchLimit = StretchLimit; |
|
170 Parameters.IETDParameters.aBlackPixels = BlackPixels; |
|
171 Parameters.IETDParameters.aWhitePixels = WhitePixels; |
|
172 Parameters.IETDParameters.aSaturationGain = SaturationGain; |
|
173 Parameters.IETDParameters.aBitLimit = BitLimit; |
|
174 Parameters.IETDParameters.aWBC = WBC; |
|
175 Parameters.IETDParameters.aDBC = DBC; |
|
176 |
|
177 //Sharpening |
|
178 Parameters.SharpeningParameters.SHARP_GAIN = SharpGain; |
|
179 Parameters.SharpeningParameters.SHARP_DZONE = SharpDZone; |
|
180 Parameters.SharpeningParameters.SHARP_OVER = SharpOver; |
|
181 |
|
182 //Color Management (fill LUTs and matrix) |
|
183 for(i=0;i<256;i++) |
|
184 { |
|
185 Parameters.ColorManagementParameters.GammaR[i] = CMGammaR[i]; |
|
186 } |
|
187 |
|
188 for(i=0;i<256;i++) |
|
189 { |
|
190 Parameters.ColorManagementParameters.GammaG[i] = CMGammaG[i]; |
|
191 } |
|
192 |
|
193 for(i=0;i<256;i++) |
|
194 { |
|
195 Parameters.ColorManagementParameters.GammaB[i] = CMGammaB[i]; |
|
196 } |
|
197 |
|
198 for(i=0;i<256;i++) |
|
199 { |
|
200 Parameters.ColorManagementParameters.TRCR[i] = CMTRCR[i]; |
|
201 } |
|
202 |
|
203 for(i=0;i<256;i++) |
|
204 { |
|
205 Parameters.ColorManagementParameters.TRCG[i] = CMTRCG[i]; |
|
206 } |
|
207 |
|
208 for(i=0;i<256;i++) |
|
209 { |
|
210 Parameters.ColorManagementParameters.TRCB[i] = CMTRCB[i]; |
|
211 } |
|
212 |
|
213 for(i=0;i<9;i++) |
|
214 { |
|
215 Parameters.ColorManagementParameters.Matrix[i] = CMMatrix[i]; |
|
216 } |
|
217 |
|
218 } |
|
219 |
|
220 //Set the default parameters |
|
221 IetdPtr->SetParams(&Parameters.IETDParameters); |
|
222 SharpeningPtr->SetParameters(&Parameters.SharpeningParameters); |
|
223 ColorManagementPtr->SetParameters(&Parameters.ColorManagementParameters); |
|
224 |
|
225 CleanupStack::Pop(5); //Processing objects |
|
226 } |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 /* |
|
232 ----------------------------------------------------------------------------- |
|
233 |
|
234 CDCIetd |
|
235 |
|
236 Destructor |
|
237 |
|
238 Deletes the allocated memory |
|
239 |
|
240 Return Values: none |
|
241 |
|
242 ----------------------------------------------------------------------------- |
|
243 */ |
|
244 CDisplayChain::~CDisplayChain() |
|
245 { |
|
246 //Delete processing objects |
|
247 delete DigitalZoomPtr; |
|
248 delete SharpeningPtr; |
|
249 delete DitheringPtr; |
|
250 delete IetdPtr; |
|
251 delete ColorManagementPtr; |
|
252 } |
|
253 |
|
254 |
|
255 |
|
256 /* |
|
257 ----------------------------------------------------------------------------- |
|
258 |
|
259 ProcessL |
|
260 |
|
261 Process image referenced by InBitmap (modify aTargetBitmap). |
|
262 If scaling is not used aTargetBitmap is processed directly. |
|
263 |
|
264 May leave with KErrNoMemory if no memory available |
|
265 |
|
266 Return Values: none |
|
267 |
|
268 ----------------------------------------------------------------------------- |
|
269 */ |
|
270 void CDisplayChain::ProcessL(const CFbsBitmap* InBitmap, CFbsBitmap* aTargetBitmap) |
|
271 { |
|
272 |
|
273 //CHECK! pan check needed only when DZ is ON |
|
274 //Scaling |
|
275 if (Parameters.DigitalZoomON) |
|
276 { |
|
277 // refine the zooming parameters based on input data |
|
278 TSize inSize = InBitmap->SizeInPixels(); |
|
279 TSize outSize = aTargetBitmap->SizeInPixels(); |
|
280 Parameters.DZParameters.sizeX = outSize.iWidth; |
|
281 Parameters.DZParameters.sizeY = outSize.iHeight; |
|
282 Parameters.DZParameters.scaleX = (TReal)outSize.iWidth/(TReal)inSize.iWidth; |
|
283 Parameters.DZParameters.scaleY = (TReal)outSize.iHeight/(TReal)inSize.iHeight; |
|
284 |
|
285 //If the image is tried to pan over the image borders, bound to the borders |
|
286 if (Parameters.DZParameters.allShiftX < (-InBitmap->SizeInPixels().iWidth/2 * Parameters.DZParameters.scaleX + aTargetBitmap->SizeInPixels().iWidth/2)) |
|
287 { |
|
288 Parameters.DZParameters.allShiftX = (TInt)((-InBitmap->SizeInPixels().iWidth/2)*Parameters.DZParameters.scaleX + aTargetBitmap->SizeInPixels().iWidth/2); |
|
289 } |
|
290 |
|
291 if (Parameters.DZParameters.allShiftX > (InBitmap->SizeInPixels().iWidth/2 * Parameters.DZParameters.scaleX - aTargetBitmap->SizeInPixels().iWidth/2)) |
|
292 { |
|
293 Parameters.DZParameters.allShiftX = (TInt)((InBitmap->SizeInPixels().iWidth/2)*Parameters.DZParameters.scaleX - aTargetBitmap->SizeInPixels().iWidth/2); |
|
294 } |
|
295 |
|
296 if (Parameters.DZParameters.allShiftY < (-InBitmap->SizeInPixels().iHeight/2 * Parameters.DZParameters.scaleY + aTargetBitmap->SizeInPixels().iHeight/2)) |
|
297 { |
|
298 Parameters.DZParameters.allShiftY = (TInt)((-InBitmap->SizeInPixels().iHeight/2)*Parameters.DZParameters.scaleY + aTargetBitmap->SizeInPixels().iHeight/2); |
|
299 } |
|
300 |
|
301 if (Parameters.DZParameters.allShiftY > (InBitmap->SizeInPixels().iHeight/2 * Parameters.DZParameters.scaleY - aTargetBitmap->SizeInPixels().iHeight/2)) |
|
302 { |
|
303 Parameters.DZParameters.allShiftY = (TInt)((InBitmap->SizeInPixels().iHeight/2)*Parameters.DZParameters.scaleY - aTargetBitmap->SizeInPixels().iHeight/2); |
|
304 } |
|
305 |
|
306 DigitalZoomPtr->SetParameters(&Parameters.DZParameters); |
|
307 DigitalZoomPtr->ProcessL(InBitmap, aTargetBitmap); |
|
308 } |
|
309 |
|
310 //IETD |
|
311 if (Parameters.IetdON) |
|
312 { |
|
313 if (Parameters.FirstOpening) |
|
314 { |
|
315 IetdPtr->Analyze(*aTargetBitmap); |
|
316 Parameters.FirstOpening = EFalse; |
|
317 } |
|
318 //Set parameters is needed if default values can change (read from file etc.) |
|
319 //IetdPtr->SetParams(&Parameters.IETDParameters); |
|
320 IetdPtr->ProcessL(*aTargetBitmap); |
|
321 } |
|
322 |
|
323 //Sharpening |
|
324 if (Parameters.SharpeningON) |
|
325 { |
|
326 //Set parameters is needed if default values can change (read from file etc.) |
|
327 //SharpeningPtr->SetParameters(&Parameters.SharpeningParameters); |
|
328 SharpeningPtr->ProcessL(aTargetBitmap); |
|
329 } |
|
330 |
|
331 //ColorManagement |
|
332 if (Parameters.ColorManagementON) |
|
333 { |
|
334 //Set parameters is needed if default values can change (read from file etc.) |
|
335 //ColorManagementPtr->SetParameters(&Parameters.ColorManagementParameters); |
|
336 ColorManagementPtr->ProcessL(aTargetBitmap); |
|
337 } |
|
338 |
|
339 //Dithering |
|
340 if (Parameters.DitheringON) |
|
341 { |
|
342 DitheringPtr->ProcessL(*aTargetBitmap); |
|
343 } |
|
344 } |
|
345 |
|
346 |
|
347 |
|
348 |
|
349 /* |
|
350 ----------------------------------------------------------------------------- |
|
351 |
|
352 SetParams |
|
353 |
|
354 Set processing parameters |
|
355 |
|
356 Return Values: none |
|
357 |
|
358 ----------------------------------------------------------------------------- |
|
359 */ |
|
360 void CDisplayChain::SetParameters(DisplayChainParams* params) |
|
361 { |
|
362 //Copy parameter struct |
|
363 Parameters = *params; |
|
364 } |
|
365 |
|
366 |
|
367 |
|
368 /* |
|
369 ----------------------------------------------------------------------------- |
|
370 |
|
371 GetParams |
|
372 |
|
373 Get current processing parameters |
|
374 |
|
375 Return Values: none |
|
376 |
|
377 ----------------------------------------------------------------------------- |
|
378 */ |
|
379 void CDisplayChain::GetParameters(DisplayChainParams* params) |
|
380 { |
|
381 //Copy parameter struct |
|
382 *params = Parameters; |
|
383 } |
|
384 |
|
385 |
|
386 /* |
|
387 ----------------------------------------------------------------------------- |
|
388 |
|
389 ReadFileL |
|
390 |
|
391 Example function for reading processing parameters from file |
|
392 |
|
393 Return Values: none |
|
394 |
|
395 ----------------------------------------------------------------------------- |
|
396 TBool CDisplayChain::ReadFileL() |
|
397 { |
|
398 |
|
399 FILE *fp; |
|
400 TInt i,j,data; |
|
401 TUint8 data_uchar; |
|
402 TReal data_real; |
|
403 |
|
404 // Open for read (will fail if file does not exist) |
|
405 if((fp = fopen("e:\\DisplayChain.txt","r"))==NULL ) |
|
406 { |
|
407 if((fp = fopen("c:\\DisplayChain.txt","r"))==NULL ) |
|
408 { |
|
409 //AfxMessageBox("CMData.txt was not opened"); |
|
410 return EFalse; |
|
411 } |
|
412 } |
|
413 |
|
414 //Digital Zoom |
|
415 fscanf(fp,"%d",&data); |
|
416 Parameters.DigitalZoomON = data; |
|
417 |
|
418 //Ietd |
|
419 fscanf(fp,"%d",&data); |
|
420 Parameters.IetdON = data; |
|
421 |
|
422 fscanf(fp,"%d",&data_uchar); |
|
423 Parameters.IETDParameters.aWhitePixels = data_uchar; |
|
424 |
|
425 fscanf(fp,"%d",&data_uchar); |
|
426 Parameters.IETDParameters.aBlackPixels = data_uchar; |
|
427 |
|
428 fscanf(fp,"%d",&data_uchar); |
|
429 Parameters.IETDParameters.aStretchLimit = data_uchar; |
|
430 |
|
431 fscanf(fp,"%d",&data_uchar); |
|
432 Parameters.IETDParameters.aSaturationGain = data_uchar; |
|
433 |
|
434 fscanf(fp,"%d",&data_uchar); |
|
435 Parameters.IETDParameters.aBitLimit = data_uchar; |
|
436 |
|
437 fscanf(fp,"%d",&data_uchar); |
|
438 Parameters.IETDParameters.aWBC = data_uchar; |
|
439 |
|
440 fscanf(fp,"%d",&data_uchar); |
|
441 Parameters.IETDParameters.aDBC = data_uchar; |
|
442 |
|
443 //Sharpening |
|
444 fscanf(fp,"%d",&data); |
|
445 Parameters.SharpeningON = data; |
|
446 |
|
447 fscanf(fp,"%d",&data); |
|
448 Parameters.SharpeningParameters.SHARP_OVER = data; |
|
449 |
|
450 fscanf(fp,"%d",&data); |
|
451 Parameters.SharpeningParameters.SHARP_DZONE = data; |
|
452 |
|
453 //fscanf(fp,"%f",&data_real); |
|
454 fscanf(fp,"%d",&data); |
|
455 data_real = ((TReal)data)/65536; |
|
456 Parameters.SharpeningParameters.SHARP_GAIN = data_real; |
|
457 |
|
458 //Dithering |
|
459 fscanf(fp,"%d",&data); |
|
460 Parameters.DitheringON = data; |
|
461 |
|
462 //ColorManagement |
|
463 fscanf(fp,"%d",&data); |
|
464 Parameters.ColorManagementON = data; |
|
465 |
|
466 for(i=0;i<256;i++) |
|
467 { |
|
468 fscanf(fp,"%d",&data); |
|
469 Parameters.ColorManagementParameters.GammaR[i]=data; |
|
470 } |
|
471 |
|
472 for(i=0;i<256;i++) |
|
473 { |
|
474 fscanf(fp,"%d",&data); |
|
475 Parameters.ColorManagementParameters.GammaG[i]=data; |
|
476 } |
|
477 |
|
478 for(i=0;i<256;i++) |
|
479 { |
|
480 fscanf(fp,"%d",&data); |
|
481 Parameters.ColorManagementParameters.GammaB[i]=data; |
|
482 } |
|
483 |
|
484 for(i=0;i<256;i++) |
|
485 { |
|
486 fscanf(fp,"%d",&data); |
|
487 Parameters.ColorManagementParameters.TRCR[i]=data; |
|
488 } |
|
489 |
|
490 for(i=0;i<256;i++) |
|
491 { |
|
492 fscanf(fp,"%d",&data); |
|
493 Parameters.ColorManagementParameters.TRCG[i]=data; |
|
494 } |
|
495 |
|
496 for(i=0;i<256;i++) |
|
497 { |
|
498 fscanf(fp,"%d",&data); |
|
499 Parameters.ColorManagementParameters.TRCB[i]=data; |
|
500 } |
|
501 |
|
502 |
|
503 for(i=0;i<3;i++) |
|
504 { |
|
505 for(j=0;j<3;j++) |
|
506 { |
|
507 fscanf(fp,"%d",&data); |
|
508 Parameters.ColorManagementParameters.Matrix [3*i+j]=data; |
|
509 } |
|
510 } |
|
511 |
|
512 |
|
513 // Close stream |
|
514 fclose(fp); |
|
515 |
|
516 return ETrue; |
|
517 } |
|
518 */ |
|
519 //----IMAAMI---- |