|
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 //DCColorManagement.cpp |
|
23 // |
|
24 //Version 1.00 |
|
25 // |
|
26 //Contains: |
|
27 // CDCCDM |
|
28 // Simple color management approach consisting |
|
29 // of 3xLUT + 3x3 Matrix + 3xLUT for compensating |
|
30 // display specific features. |
|
31 // |
|
32 //History: |
|
33 // 19.08.2003 version 1.00 created using existing IMAAMI algorithms |
|
34 //************************************************************************* |
|
35 |
|
36 #include <fbs.h> |
|
37 #include <s32file.h> |
|
38 #include <stdio.h> |
|
39 #include "DCColorManagement.h" |
|
40 |
|
41 |
|
42 |
|
43 /* |
|
44 ----------------------------------------------------------------------------- |
|
45 |
|
46 CDCColorManagement |
|
47 |
|
48 Constructor |
|
49 |
|
50 Default constructor, initializes member variables to initial values |
|
51 |
|
52 Return Values: none |
|
53 |
|
54 ----------------------------------------------------------------------------- |
|
55 */ |
|
56 CDCColorManagement::CDCColorManagement() |
|
57 { |
|
58 //Set default values for parameters |
|
59 //Set pointer to internal data (LUTs and matrix memory locations) |
|
60 iParams.GammaR = iGammaR; |
|
61 iParams.GammaG = iGammaG; |
|
62 iParams.GammaB = iGammaB; |
|
63 iParams.Matrix = iMatrix; |
|
64 iParams.TRCR = iTRCR; |
|
65 iParams.TRCG = iTRCG; |
|
66 iParams.TRCB = iTRCB; |
|
67 } |
|
68 |
|
69 |
|
70 |
|
71 /* |
|
72 ----------------------------------------------------------------------------- |
|
73 |
|
74 NewLC |
|
75 |
|
76 Factory function to instantiate the class. |
|
77 This function leaves the class pointer to the cleanup stack |
|
78 May leave with KErrNoMemory if no memory available |
|
79 |
|
80 Return Values: CDCColorManagement* self: pointer to the class instance |
|
81 |
|
82 ----------------------------------------------------------------------------- |
|
83 */ |
|
84 CDCColorManagement* CDCColorManagement::NewLC() |
|
85 { |
|
86 CDCColorManagement* self = new (ELeave) CDCColorManagement(); |
|
87 CleanupStack::PushL(self); |
|
88 self->ConstructL(); |
|
89 return self; |
|
90 } |
|
91 |
|
92 |
|
93 |
|
94 /* |
|
95 ----------------------------------------------------------------------------- |
|
96 |
|
97 NewL |
|
98 |
|
99 Factory function to instantiate the class. |
|
100 May leave with KErrNoMemory if no memory available |
|
101 |
|
102 Return Values: CDCColorManagement* self: pointer to the class instance |
|
103 |
|
104 ----------------------------------------------------------------------------- |
|
105 */ |
|
106 CDCColorManagement* CDCColorManagement::NewL() |
|
107 { |
|
108 CDCColorManagement* self = CDCColorManagement::NewLC(); |
|
109 CleanupStack::Pop(); |
|
110 return self; |
|
111 } |
|
112 |
|
113 |
|
114 |
|
115 |
|
116 /* |
|
117 ----------------------------------------------------------------------------- |
|
118 |
|
119 ConstructL |
|
120 |
|
121 Second phase constructor. Does nothing at the moment |
|
122 |
|
123 Return Values: none |
|
124 |
|
125 ----------------------------------------------------------------------------- |
|
126 */ |
|
127 void CDCColorManagement::ConstructL() |
|
128 { |
|
129 // This function is intentionally left blank. |
|
130 } |
|
131 |
|
132 |
|
133 |
|
134 /* |
|
135 ----------------------------------------------------------------------------- |
|
136 |
|
137 Destructor |
|
138 |
|
139 Deletes the scanline buffer |
|
140 |
|
141 Return Values: none |
|
142 |
|
143 ----------------------------------------------------------------------------- |
|
144 */ |
|
145 CDCColorManagement::~CDCColorManagement() |
|
146 { |
|
147 // This function is intentionally left blank. |
|
148 } |
|
149 |
|
150 |
|
151 |
|
152 |
|
153 /* |
|
154 ----------------------------------------------------------------------------- |
|
155 |
|
156 ProcessL |
|
157 |
|
158 Process image referenced by aBPtr (modify aBPtr). |
|
159 May leave with KErrNoMemory if no memory available |
|
160 |
|
161 Return Values: none |
|
162 |
|
163 ----------------------------------------------------------------------------- |
|
164 */ |
|
165 void CDCColorManagement::ProcessL(CFbsBitmap* aBPtr) |
|
166 { |
|
167 |
|
168 TInt r, g, b, rr, gg, bb; // Color components |
|
169 TUint8* DataPtr; // Pointer to image data |
|
170 |
|
171 //Check image mode |
|
172 if (aBPtr->DisplayMode() != EColor16M) |
|
173 return; |
|
174 |
|
175 // Line Buffer and pointer to the data |
|
176 TUint LineLength = aBPtr->SizeInPixels().iWidth; |
|
177 iScanLine = HBufC8::NewMaxL(LineLength*3); |
|
178 TPtr8 LinePtr((TUint8*)iScanLine->Des().Ptr(), LineLength*3); |
|
179 |
|
180 // Step through image lines |
|
181 for (TInt LineNo=0; LineNo<aBPtr->SizeInPixels().iHeight; ++LineNo) |
|
182 { |
|
183 //Get line from image and set data pointer |
|
184 aBPtr->GetScanLine(LinePtr, TPoint(0, LineNo), aBPtr->SizeInPixels().iWidth, aBPtr->DisplayMode()); |
|
185 DataPtr = (TUint8 *)iScanLine->Des().Ptr(); |
|
186 |
|
187 //Step through image pixels |
|
188 for (TUint x=aBPtr->SizeInPixels().iWidth; x != 0; --x) |
|
189 { |
|
190 //Get the color components and map them using linearization LUTs |
|
191 b=iParams.GammaR[*DataPtr]; |
|
192 g=iParams.GammaG[*(DataPtr+1)]; |
|
193 r=iParams.GammaB[*(DataPtr+2)]; |
|
194 |
|
195 //Process with 3x3 matrix |
|
196 rr=(r*iParams.Matrix[0] + g*iParams.Matrix[3*0+1] + b*iParams.Matrix[3*0+2])>>16; |
|
197 gg=(r*iParams.Matrix[3*1+0] + g*iParams.Matrix[3*1+1] + b*iParams.Matrix[3*1+2])>>16; |
|
198 bb=(r*iParams.Matrix[3*2+0] + g*iParams.Matrix[3*2+1] + b*iParams.Matrix[3*2+2])>>16; |
|
199 |
|
200 //Limit between 0...255 |
|
201 if (rr<0) rr=0; if (rr>255) rr=255; |
|
202 if (gg<0) gg=0; if (gg>255) gg=255; |
|
203 if (bb<0) bb=0; if (bb>255) bb=255; |
|
204 |
|
205 //Process with TRC LUTs |
|
206 rr=iParams.TRCR[rr]; |
|
207 gg=iParams.TRCG[gg]; |
|
208 bb=iParams.TRCB[bb]; |
|
209 |
|
210 //Set color components |
|
211 *DataPtr = (TUint8)bb; |
|
212 ++DataPtr; |
|
213 *DataPtr = (TUint8)gg; |
|
214 ++DataPtr; |
|
215 *DataPtr = (TUint8)rr; |
|
216 ++DataPtr; |
|
217 } |
|
218 |
|
219 //Set processed line |
|
220 aBPtr->SetScanLine(LinePtr, LineNo); |
|
221 } |
|
222 |
|
223 //Free memory |
|
224 delete(iScanLine); |
|
225 iScanLine = 0; |
|
226 } |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 /* |
|
232 ----------------------------------------------------------------------------- |
|
233 |
|
234 SetParams |
|
235 |
|
236 Set processing parameters |
|
237 |
|
238 Return Values: none |
|
239 |
|
240 ----------------------------------------------------------------------------- |
|
241 */ |
|
242 void CDCColorManagement::SetParameters(DCColorManagementParams* params) |
|
243 { |
|
244 iParams = *params; |
|
245 } |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 /* |
|
251 ----------------------------------------------------------------------------- |
|
252 |
|
253 GetParams |
|
254 |
|
255 Get current processing parameters |
|
256 |
|
257 Return Values: none |
|
258 |
|
259 ----------------------------------------------------------------------------- |
|
260 */ |
|
261 void CDCColorManagement::GetParameters(DCColorManagementParams* params) |
|
262 { |
|
263 *params = iParams; |
|
264 } |
|
265 //----IMAAMI---- |