|
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 * CDCDithering |
|
16 * Dithering by H263 algorithm developed in NMP/Oulu. |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 // Include Files |
|
23 #include <e32std.h> // The basic definitions |
|
24 #include <fbs.h> // For FBS bitmap |
|
25 #include "DCDithering.h" // The DCDithering class |
|
26 |
|
27 |
|
28 |
|
29 // MEMBER FUNCTIONS |
|
30 //============================================================================= |
|
31 |
|
32 |
|
33 |
|
34 /* |
|
35 ----------------------------------------------------------------------------- |
|
36 |
|
37 CDCDithering |
|
38 |
|
39 Constructor |
|
40 |
|
41 Default constructor |
|
42 |
|
43 Return Values: none |
|
44 |
|
45 ----------------------------------------------------------------------------- |
|
46 */ |
|
47 CDCDithering::CDCDithering() |
|
48 { |
|
49 // This function is intentionally left blank. |
|
50 } |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 /* |
|
56 ----------------------------------------------------------------------------- |
|
57 |
|
58 CDCDithering |
|
59 |
|
60 NewLC |
|
61 |
|
62 Factory function to instantiate the class. |
|
63 This function leaves the class pointer to the cleanup stack |
|
64 May leave with KErrNoMemory if no memory available |
|
65 |
|
66 Return Values: CDCDithering* self: pointer to the class instance |
|
67 |
|
68 ----------------------------------------------------------------------------- |
|
69 */ |
|
70 CDCDithering* CDCDithering::NewLC() |
|
71 { |
|
72 CDCDithering* self = new (ELeave) CDCDithering(); |
|
73 CleanupStack::PushL(self); |
|
74 self->ConstructL(); |
|
75 return self; |
|
76 } |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 /* |
|
82 ----------------------------------------------------------------------------- |
|
83 |
|
84 CDCDithering |
|
85 |
|
86 NewL |
|
87 |
|
88 Factory function to instantiate the class. |
|
89 May leave with KErrNoMemory if no memory available |
|
90 |
|
91 Return Values: CDCDithering* self: pointer to the class instance |
|
92 |
|
93 ----------------------------------------------------------------------------- |
|
94 */ |
|
95 CDCDithering* CDCDithering::NewL() |
|
96 { |
|
97 CDCDithering* self = CDCDithering::NewLC(); |
|
98 CleanupStack::Pop(); |
|
99 return self; |
|
100 } |
|
101 |
|
102 |
|
103 |
|
104 /* |
|
105 ----------------------------------------------------------------------------- |
|
106 |
|
107 CDCDithering |
|
108 |
|
109 ConstructL |
|
110 |
|
111 Second phase constructor. Does nothing at the moment |
|
112 |
|
113 Return Values: none |
|
114 |
|
115 ----------------------------------------------------------------------------- |
|
116 */ |
|
117 void CDCDithering::ConstructL() |
|
118 { |
|
119 // This function is intentionally left blank. |
|
120 } |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 /* |
|
126 ----------------------------------------------------------------------------- |
|
127 |
|
128 CDCDithering |
|
129 |
|
130 Destructor |
|
131 |
|
132 Return Values: none |
|
133 |
|
134 ----------------------------------------------------------------------------- |
|
135 */ |
|
136 CDCDithering::~CDCDithering() |
|
137 { |
|
138 // This function is intentionally left blank. |
|
139 } |
|
140 |
|
141 |
|
142 |
|
143 /* |
|
144 ----------------------------------------------------------------------------- |
|
145 |
|
146 ProcessL |
|
147 |
|
148 Process image referenced by aImage (modify aImage). |
|
149 May leave with KErrNoMemory if no memory available |
|
150 |
|
151 Return Values: none |
|
152 |
|
153 ----------------------------------------------------------------------------- |
|
154 */ |
|
155 void CDCDithering::ProcessL(CFbsBitmap& aImage) |
|
156 { |
|
157 TUint r, g, b; // Color components |
|
158 TUint8* dataPtr; // Pointer to data |
|
159 |
|
160 //Dithering variables, init to 0 |
|
161 TInt count=0; |
|
162 TInt16 dither=0; |
|
163 |
|
164 //EColor16M image is needed |
|
165 if (aImage.DisplayMode() != EColor16M || aImage.DisplayMode() != EColor16M) |
|
166 return; |
|
167 |
|
168 // Line Buffer and pointer to the data |
|
169 TUint imageWidth = aImage.SizeInPixels().iWidth; |
|
170 TUint scanLineLengthInBytes = aImage.ScanLineLength(imageWidth, aImage.DisplayMode()); |
|
171 |
|
172 //Allocate buffer for scanline |
|
173 iScanLineBuffer = HBufC8::NewMaxL(scanLineLengthInBytes); |
|
174 //Pointer to scanline |
|
175 TPtr8 linePtr = iScanLineBuffer->Des(); |
|
176 |
|
177 //Step through image lines |
|
178 for (TInt lineNo=0; lineNo<aImage.SizeInPixels().iHeight; ++lineNo) |
|
179 { |
|
180 //Get line |
|
181 aImage.GetScanLine(linePtr, TPoint(0, lineNo), imageWidth, aImage.DisplayMode()); |
|
182 //CHECK! CONST_CAST not used in every algorithm which way is better? |
|
183 dataPtr = CONST_CAST(TUint8*, linePtr.Ptr()); |
|
184 |
|
185 //Step through image pixels |
|
186 for (TUint x=0; x < imageWidth; ++x) |
|
187 { |
|
188 // Get original values |
|
189 b = *dataPtr++; |
|
190 g = *dataPtr++; |
|
191 r = *dataPtr++; |
|
192 |
|
193 //Compute DCDithering factor from base count |
|
194 switch (count&1) |
|
195 { |
|
196 case 0: |
|
197 dither = (TInt16)(dither*0x7ffd); |
|
198 break; |
|
199 case 1: |
|
200 dither = (TInt16)(dither+0x7f21); |
|
201 break; |
|
202 } |
|
203 |
|
204 //Add DCDithering factor, adjust gain according to quantization factors. |
|
205 r = Limit255((TInt)r + (dither>>13)); |
|
206 g = Limit255((TInt)g - (dither>>14)); |
|
207 b = Limit255((TInt)b + (dither>>13)); |
|
208 |
|
209 //Move to the previous pixel |
|
210 dataPtr -= 3; |
|
211 |
|
212 /* Set the result */ |
|
213 *dataPtr++ = (TUint8)b; |
|
214 *dataPtr++ = (TUint8)g; |
|
215 *dataPtr++ = (TUint8)r; |
|
216 |
|
217 //Increase bae count |
|
218 count++; |
|
219 } |
|
220 |
|
221 //Set scan line |
|
222 aImage.SetScanLine(linePtr, lineNo); |
|
223 } |
|
224 |
|
225 //Free allocated memory |
|
226 delete(iScanLineBuffer); |
|
227 iScanLineBuffer = 0; |
|
228 } |
|
229 // End of File |
|
230 //----IMAAMI---- |