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