|
1 // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #ifndef ___IMAGEPROCESSOR_H__ |
|
17 #define ___IMAGEPROCESSOR_H__ |
|
18 |
|
19 #include <gdi.h> |
|
20 #include <fbs.h> |
|
21 |
|
22 /** |
|
23 @publishedAll |
|
24 */ |
|
25 enum TImageBitmapUtilPanic |
|
26 { |
|
27 ECorrupt |
|
28 }; |
|
29 |
|
30 /** |
|
31 @publishedAll |
|
32 @released |
|
33 |
|
34 Interface to colour conversion classes for various display modes. |
|
35 Manages the mapping between RGB/Greyscale values and the index |
|
36 into the color palette for the given display mode. |
|
37 */ |
|
38 class TColorConvertor |
|
39 { |
|
40 public: |
|
41 IMPORT_C static TColorConvertor* NewL(TDisplayMode aDisplayMode); |
|
42 |
|
43 /** |
|
44 Returns the colour index corresponding to the supplied RGB value. |
|
45 Operates in the context of the current display mode. |
|
46 |
|
47 This is a virtual function that each derived class must implement. |
|
48 |
|
49 @param aColor |
|
50 The colour in RGB format. |
|
51 |
|
52 @return The colour index. |
|
53 */ |
|
54 virtual TInt ColorIndex(TRgb aColor) const = 0; |
|
55 |
|
56 /** |
|
57 Returns the RGB value corresponding to the supplied colour index. |
|
58 Operates in the context of the current display mode. |
|
59 |
|
60 This is a virtual function that each derived class must implement. |
|
61 |
|
62 @param aColorIndex |
|
63 The colour in RGB format. |
|
64 |
|
65 @return The RGB value. |
|
66 */ |
|
67 virtual TRgb Color(TInt aColorIndex) const = 0; |
|
68 |
|
69 /** |
|
70 Gets an array of colour indices from a corresponding array of RGB values. |
|
71 Operates in the context of the current display mode. |
|
72 |
|
73 This is a virtual function that each derived class must implement. |
|
74 |
|
75 @param aIndexBuffer |
|
76 A pointer to the first element in destination array. |
|
77 @param aColorBuffer |
|
78 A pointer to the first element in the source array. |
|
79 @param aCount |
|
80 The number of elements to get. |
|
81 */ |
|
82 virtual void ColorToIndex(TInt* aIndexBuffer,TRgb* aColorBuffer,TInt aCount) const = 0; |
|
83 |
|
84 inline static TInt RgbToMonochrome(TRgb aRgb); |
|
85 }; |
|
86 |
|
87 |
|
88 /** |
|
89 @publishedAll |
|
90 @released |
|
91 |
|
92 Bitmap utility class. |
|
93 */ |
|
94 class TImageBitmapUtil |
|
95 { |
|
96 public: |
|
97 IMPORT_C TImageBitmapUtil(); |
|
98 IMPORT_C void Begin(); |
|
99 IMPORT_C TBool Begin(const TPoint& aPosition); |
|
100 IMPORT_C void End(); |
|
101 IMPORT_C void SetBitmapL(CFbsBitmap* aBitmap); |
|
102 IMPORT_C void SetPixel(TUint32 aPixelIndex); |
|
103 IMPORT_C void SetPixels(TUint32* aPixelIndex,TInt aNumberOfPixels); |
|
104 IMPORT_C TBool SetPos(const TPoint& aPosition); |
|
105 |
|
106 private: |
|
107 union TDataPointer |
|
108 { |
|
109 TUint32* iWordPos; |
|
110 TUint8* iBytePos; |
|
111 }; |
|
112 private: |
|
113 CFbsBitmap* iBitmap; |
|
114 TSize iSize; |
|
115 TPoint iPosition; |
|
116 TDataPointer iData; |
|
117 TDataPointer iBase; |
|
118 TInt iBpp; |
|
119 TInt iBppShift; |
|
120 TInt iPixelShift; |
|
121 TInt iPixelsPerWord; |
|
122 TInt iBitShift; |
|
123 TInt iScanlineWordLength; |
|
124 TUint32 iMask; |
|
125 TBool iWordAccess; |
|
126 }; |
|
127 |
|
128 |
|
129 class CImageProcessor; |
|
130 class CImageProcessorExtension; |
|
131 |
|
132 /** |
|
133 @publishedAll |
|
134 @released |
|
135 |
|
136 Utility class providing static factory functions for creating instances of |
|
137 CImageProcessor derived classes. |
|
138 */ |
|
139 class ImageProcessorUtility |
|
140 { |
|
141 public: |
|
142 IMPORT_C static TInt ReductionFactor(const TSize& aOriginalSize,const TSize& aReducedSize); |
|
143 IMPORT_C static CImageProcessor* NewImageProcessorL(const CFbsBitmap& aBitmap,const TSize& aImageSize,TDisplayMode aImageDisplayMode, TBool aDisableErrorDiffusion); |
|
144 IMPORT_C static CImageProcessor* NewImageProcessorL(const CFbsBitmap& aBitmap,TInt aReductionFactor,TDisplayMode aImageDisplayMode, TBool aDisableErrorDiffusion); |
|
145 IMPORT_C static CImageProcessorExtension* NewImageProcessorExtensionL(const CFbsBitmap& aBitmap,TInt aReductionFactor,TDisplayMode aImageDisplayMode, TBool aDisableErrorDiffusion); |
|
146 |
|
147 private: |
|
148 TBool static UseErrorDiffuser(const TDisplayMode& aBitmapDisplayMode, const TDisplayMode& aImageDisplayMode); |
|
149 TBool static IsMonochrome(const TDisplayMode& aBitmapDisplayMode, const TDisplayMode& aImageDisplayMode); |
|
150 }; |
|
151 |
|
152 |
|
153 |
|
154 /** |
|
155 @publishedAll |
|
156 @released |
|
157 |
|
158 Interface to image processing classes used by CImageDecoder plugins. This is not a application client API. |
|
159 */ |
|
160 class CImageProcessor : public CBase |
|
161 { |
|
162 public: |
|
163 // Setup |
|
164 |
|
165 /** |
|
166 Initialises internal data structures prior to conversion. |
|
167 |
|
168 This is a virtual function that each derived class must implement. |
|
169 |
|
170 @param aBitmap |
|
171 A reference to a fully constucted bitmap with the required |
|
172 display mode and size. |
|
173 @param aImageRect |
|
174 The region of the image to convert. |
|
175 */ |
|
176 virtual void PrepareL(CFbsBitmap& aBitmap,const TRect& aImageRect) = 0; |
|
177 |
|
178 /** |
|
179 Initialises internal data structures prior to the manipulation of the specified pixel block. |
|
180 |
|
181 This overloaded version allows specification of a block size |
|
182 for those formats which support blocked pixel data eg. JPEG |
|
183 |
|
184 This is a virtual function that each derived class must implement. |
|
185 |
|
186 @param aBitmap |
|
187 A reference to a fully constucted bitmap with the required |
|
188 display mode and size. |
|
189 @param aImageRect |
|
190 The region of the image to convert. |
|
191 @param aRgbBlockSize |
|
192 The size of the block to use. |
|
193 */ |
|
194 virtual void PrepareL(CFbsBitmap& aBitmap,const TRect& aImageRect,const TSize& aRgbBlockSize) = 0; |
|
195 |
|
196 /** |
|
197 Sets the number of pixels by which to increment the current position in |
|
198 the Y-axis. This is used when rendering images supporting interlacing. |
|
199 eg GIF |
|
200 |
|
201 This is a virtual function that each derived class must implement. |
|
202 |
|
203 @param aYInc |
|
204 The number of pixels. |
|
205 */ |
|
206 virtual void SetYPosIncrement(TInt aYInc) = 0; |
|
207 |
|
208 /** |
|
209 Sets the number times the current line should be repeated. The lines |
|
210 are repeated in the same direction as set by SetYPosIncrement(). This |
|
211 is used to fill blank lines when rendering interlaced images. eg GIF. |
|
212 @param aLineRepeat The number of times the current line should be repeated |
|
213 */ |
|
214 virtual void SetLineRepeat(TInt aLineRepeat) = 0; |
|
215 |
|
216 /** |
|
217 Sets the pixel padding to the value specified by aNumberOfPixels. |
|
218 |
|
219 This is a virtual function that each derived class must implement. |
|
220 |
|
221 @param aNumberOfPixels |
|
222 The number of pixels to use for padding. |
|
223 */ |
|
224 virtual void SetPixelPadding(TInt aNumberOfPixels) = 0; |
|
225 |
|
226 // Color pixel writing |
|
227 |
|
228 /** |
|
229 Sets the pixel at the current position to aColor. |
|
230 |
|
231 This is a virtual function that each derived class must implement. |
|
232 |
|
233 @post |
|
234 The current position is updated. |
|
235 |
|
236 @param aColor |
|
237 The RGB value to set the current pixel to. |
|
238 |
|
239 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, |
|
240 otherwise EFalse. |
|
241 */ |
|
242 virtual TBool SetPixel(TRgb aColor) = 0; |
|
243 |
|
244 /** |
|
245 Sets aCount number of pixels to the value given by aColor, starting at |
|
246 the current position. |
|
247 |
|
248 This is a virtual function that each derived class must implement. |
|
249 |
|
250 @post |
|
251 On success, the current position is updated. |
|
252 |
|
253 @param aColor |
|
254 The RGB value to set the pixels to. |
|
255 @param aCount |
|
256 The number of pixels to set. |
|
257 |
|
258 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, |
|
259 otherwise EFalse. |
|
260 */ |
|
261 virtual TBool SetPixelRun(TRgb aColor,TInt aCount) = 0; |
|
262 |
|
263 /** |
|
264 Updates the bitmap with colour information from the array of colour values. |
|
265 |
|
266 Uses the array of colour values supplied by aColorBuffer, whose length |
|
267 is specified by aBufferLength, to update successive pixels with values in the |
|
268 buffer, starting at the current position. |
|
269 |
|
270 This is a virtual function that each derived class must implement. |
|
271 |
|
272 @post |
|
273 The current position is updated. |
|
274 |
|
275 @param aColorBuffer |
|
276 A pointer to the first element in the array. |
|
277 @param aBufferLength |
|
278 The number of elements in the array. |
|
279 |
|
280 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, |
|
281 otherwise EFalse. |
|
282 */ |
|
283 virtual TBool SetPixels(TRgb* aColorBuffer,TInt aBufferLength) = 0; |
|
284 |
|
285 /** |
|
286 Sets the current pixel block using the data supplied in aColorBuffer. |
|
287 |
|
288 Note: |
|
289 For use with image types that support blocking of pixels eg JPEG. |
|
290 |
|
291 This is a virtual function that each derived class must implement. |
|
292 |
|
293 @param aColorBuffer |
|
294 A pointer to a buffer representing a block of pixel color values. |
|
295 |
|
296 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, |
|
297 otherwise EFalse. |
|
298 */ |
|
299 virtual TBool SetPixelBlock(TRgb* aColorBuffer) = 0; |
|
300 |
|
301 // Monochrome pixel writing |
|
302 |
|
303 /** |
|
304 Sets the pixel at the current position to aGray256. |
|
305 |
|
306 This is a virtual function that each derived class must implement. |
|
307 |
|
308 @post |
|
309 The current position is updated. |
|
310 |
|
311 @param aGray256 |
|
312 The greyscale value to set the current pixel to. |
|
313 |
|
314 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, |
|
315 otherwise EFalse. |
|
316 */ |
|
317 virtual TBool SetMonoPixel(TInt aGray256) = 0; |
|
318 |
|
319 /** |
|
320 Sets the number of pixels specified by aCount to the value given by aGray256, starting at |
|
321 the current position. |
|
322 |
|
323 This is a virtual function that each derived class must implement. |
|
324 |
|
325 @post |
|
326 The current position is updated. |
|
327 |
|
328 @param aGray256 |
|
329 The greyscale value to set the pixels to. |
|
330 @param aCount |
|
331 The number of pixels to set. |
|
332 |
|
333 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, |
|
334 otherwise EFalse. |
|
335 */ |
|
336 virtual TBool SetMonoPixelRun(TInt aGray256,TInt aCount) = 0; |
|
337 |
|
338 /** |
|
339 Updates the bitmap with greyscale information from the array of greyscale values. |
|
340 |
|
341 The array of values supplied by aGray256Buffer, whose length |
|
342 is specified in aBufferLength, is used to update successive pixels with the |
|
343 greyscales values. |
|
344 |
|
345 This is a virtual function that each derived class must implement. |
|
346 |
|
347 @post |
|
348 The current position is updated. |
|
349 |
|
350 @param aGray256Buffer |
|
351 A pointer to the first element in the array of greyscale values. |
|
352 @param aBufferLength |
|
353 The number of elements in the array. |
|
354 |
|
355 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, |
|
356 otherwise EFalse. |
|
357 */ |
|
358 virtual TBool SetMonoPixels(TUint32* aGray256Buffer,TInt aBufferLength) = 0; |
|
359 |
|
360 /** |
|
361 Sets a specified number of pixels to the specified greyscale value. |
|
362 |
|
363 For image types which support blocking of pixels eg JPEG, the current |
|
364 pixel block is set using the data supplied in aGray256Buffer. |
|
365 |
|
366 This is a virtual function that each derived class must implement. |
|
367 |
|
368 @param aGray256Buffer |
|
369 A pointer to a buffer representing a block of pixel color values. |
|
370 |
|
371 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, |
|
372 otherwise EFalse. |
|
373 */ |
|
374 virtual TBool SetMonoPixelBlock(TUint32* aGray256Buffer) = 0; |
|
375 |
|
376 // Processor flow control |
|
377 |
|
378 /** |
|
379 Sets the current position in the bitmap to aPosition. |
|
380 |
|
381 This is a virtual function that each derived class must implement. |
|
382 |
|
383 @param aPosition |
|
384 A reference to TPoint object defining the position to move to. |
|
385 |
|
386 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, |
|
387 otherwise EFalse. |
|
388 */ |
|
389 virtual TBool SetPos(const TPoint& aPosition) = 0; |
|
390 |
|
391 /** |
|
392 Commits the changes made to the current bitmap by flushing the buffer. |
|
393 |
|
394 This is a virtual function that each derived class must implement. |
|
395 |
|
396 @post |
|
397 The current position is updated. |
|
398 |
|
399 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, |
|
400 otherwise EFalse. |
|
401 */ |
|
402 virtual TBool FlushPixels() = 0; |
|
403 |
|
404 private: |
|
405 // Future proofing |
|
406 IMPORT_C virtual void ReservedVirtual1(); |
|
407 IMPORT_C virtual void ReservedVirtual2(); |
|
408 IMPORT_C virtual void ReservedVirtual3(); |
|
409 IMPORT_C virtual void ReservedVirtual4(); |
|
410 }; |
|
411 |
|
412 /** |
|
413 @publishedAll |
|
414 @released |
|
415 |
|
416 Flag used to determine the type of transformation which is the result of |
|
417 single or multiple transformation operations requested via calls to |
|
418 COperationExtension::AddOperationL. |
|
419 |
|
420 8 unique orientations: |
|
421 |
|
422 @code |
|
423 normal 90 180 270 |
|
424 00 10 01 00 11 01 10 11 |
|
425 01 11 11 10 10 00 00 01 |
|
426 |
|
427 V flip 90 180 270 |
|
428 10 00 11 10 =Hflip =Hflip+90 |
|
429 11 01 01 00 |
|
430 |
|
431 H flip 90 180 270 |
|
432 01 11 00 01 =Vflip =Vflip+90 |
|
433 00 10 10 11 |
|
434 @endcode |
|
435 |
|
436 @see COperationExtension::AddOperationL |
|
437 */ |
|
438 enum TTransformOptions |
|
439 { |
|
440 /** Normal Decode |
|
441 */ |
|
442 EDecodeNormal = 0x11011000, |
|
443 |
|
444 /** Rotate 90 degrees. |
|
445 */ |
|
446 EDecodeRotate90 = 0x10110001, |
|
447 |
|
448 /** Rotate 180 degrees. |
|
449 */ |
|
450 EDecodeRotate180 = 0x00100111, |
|
451 |
|
452 /** Rotate 270 degrees. |
|
453 */ |
|
454 EDecodeRotate270 = 0x01001110, |
|
455 |
|
456 /** Horizontal flip. |
|
457 */ |
|
458 EDecodeHorizontalFlip = 0x10001101, |
|
459 |
|
460 /** Horizontal flip and rotate 90 degrees. |
|
461 */ |
|
462 EDecodeHorizontalFlipRotate90 = 0x11100100, |
|
463 |
|
464 /** Vertical flip. |
|
465 */ |
|
466 EDecodeVerticalFlip = 0x01110010, |
|
467 |
|
468 /** Vertical flip and rotate 90 degrees. |
|
469 */ |
|
470 EDecodeVerticalFlipRotate90 = 0x00011011 |
|
471 }; |
|
472 |
|
473 |
|
474 /** |
|
475 @publishedAll |
|
476 @released |
|
477 |
|
478 Class that provides support for Framework Extensions. |
|
479 |
|
480 @see CImageProcessor |
|
481 @see CImageReadCodec |
|
482 @see CImageDecoderPlugin |
|
483 */ |
|
484 class CImageProcessorExtension : public CImageProcessor |
|
485 { |
|
486 public: |
|
487 IMPORT_C virtual ~CImageProcessorExtension(); |
|
488 IMPORT_C void SetClippingRect(const TRect& aRect); |
|
489 IMPORT_C void SetScaling(TInt aScalingCoeff); |
|
490 IMPORT_C void SetScaling(const TSize& aDesiredSize); |
|
491 IMPORT_C void SetOperation(TTransformOptions aOperation); |
|
492 IMPORT_C void SetInitialScanlineSkipPadding(TInt aNumberOfScanlines); |
|
493 |
|
494 protected: |
|
495 IMPORT_C CImageProcessorExtension(); |
|
496 |
|
497 protected: |
|
498 /** Clipping rectangle */ |
|
499 TRect iClippingRect; |
|
500 /** Scaling coefficient */ |
|
501 TInt iScalingCoeff; |
|
502 /** Desired size after scaling */ |
|
503 TSize iDesiredSize; |
|
504 /** Operations to apply to image */ |
|
505 TTransformOptions iOperation; |
|
506 /** Position in destination at which start rendering */ |
|
507 TPoint iStartPosition; |
|
508 /** Position in destination at which rendering is complete */ |
|
509 TPoint iEndPosition; |
|
510 /** An initial one-off number of scanlines to be skipped */ |
|
511 TInt iNumberOfScanlinesToSkip; |
|
512 }; |
|
513 |
|
514 inline TInt TColorConvertor::RgbToMonochrome(TRgb aRgb) |
|
515 { |
|
516 TInt value = aRgb.Internal(); |
|
517 TInt r = value&0xFF0000; |
|
518 TInt g = value&0xFF00; |
|
519 value = (value&0xFF)<<16; // blue<<16 |
|
520 value += r<<1; // + (red<<16)*2 |
|
521 value += g<<(16+2-8); // + (green<<16)*4 |
|
522 value += g<<(16+0-8); // + (green<<16) |
|
523 return value>>(16+3); // total/8 |
|
524 } |
|
525 |
|
526 #endif //___IMAGEPROCESSOR_H__ |
|
527 |