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 the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #ifndef ___IMAGEPROCESSOR_H__
17 #define ___IMAGEPROCESSOR_H__
25 enum TImageBitmapUtilPanic
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.
41 IMPORT_C static TColorConvertor* NewL(TDisplayMode aDisplayMode);
44 Returns the colour index corresponding to the supplied RGB value.
45 Operates in the context of the current display mode.
47 This is a virtual function that each derived class must implement.
50 The colour in RGB format.
52 @return The colour index.
54 virtual TInt ColorIndex(TRgb aColor) const = 0;
57 Returns the RGB value corresponding to the supplied colour index.
58 Operates in the context of the current display mode.
60 This is a virtual function that each derived class must implement.
63 The colour in RGB format.
65 @return The RGB value.
67 virtual TRgb Color(TInt aColorIndex) const = 0;
70 Gets an array of colour indices from a corresponding array of RGB values.
71 Operates in the context of the current display mode.
73 This is a virtual function that each derived class must implement.
76 A pointer to the first element in destination array.
78 A pointer to the first element in the source array.
80 The number of elements to get.
82 virtual void ColorToIndex(TInt* aIndexBuffer,TRgb* aColorBuffer,TInt aCount) const = 0;
84 inline static TInt RgbToMonochrome(TRgb aRgb);
94 class TImageBitmapUtil
97 IMPORT_C TImageBitmapUtil();
98 IMPORT_C void Begin();
99 IMPORT_C TBool Begin(const TPoint& aPosition);
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);
123 TInt iScanlineWordLength;
129 class CImageProcessor;
130 class CImageProcessorExtension;
136 Utility class providing static factory functions for creating instances of
137 CImageProcessor derived classes.
139 class ImageProcessorUtility
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* ImageProcessorUtility::NewImageProcessorExtensionL(const CFbsBitmap& aBitmap,TInt aReductionFactor,TDisplayMode aImageDisplayMode, TBool aDisableErrorDiffusion);
148 TBool static UseErrorDiffuser(const TDisplayMode& aBitmapDisplayMode, const TDisplayMode& aImageDisplayMode);
149 TBool static IsMonochrome(const TDisplayMode& aBitmapDisplayMode, const TDisplayMode& aImageDisplayMode);
158 Interface to image processing classes.
160 class CImageProcessor : public CBase
166 Initialises internal data structures prior to conversion.
168 This is a virtual function that each derived class must implement.
171 A reference to a fully constucted bitmap with the required
172 display mode and size.
174 The region of the image to convert.
176 virtual void PrepareL(CFbsBitmap& aBitmap,const TRect& aImageRect) = 0;
179 Initialises internal data structures prior to the manipulation of the specified pixel block.
181 This overloaded version allows specification of a block size
182 for those formats which support blocked pixel data eg. JPEG
184 This is a virtual function that each derived class must implement.
187 A reference to a fully constucted bitmap with the required
188 display mode and size.
190 The region of the image to convert.
192 The size of the block to use.
194 virtual void PrepareL(CFbsBitmap& aBitmap,const TRect& aImageRect,const TSize& aRgbBlockSize) = 0;
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.
201 This is a virtual function that each derived class must implement.
204 The number of pixels.
206 virtual void SetYPosIncrement(TInt aYInc) = 0;
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
214 virtual void SetLineRepeat(TInt aLineRepeat) = 0;
217 Sets the pixel padding to the value specified by aNumberOfPixels.
219 This is a virtual function that each derived class must implement.
221 @param aNumberOfPixels
222 The number of pixels to use for padding.
224 virtual void SetPixelPadding(TInt aNumberOfPixels) = 0;
226 // Color pixel writing
229 Sets the pixel at the current position to aColor.
231 This is a virtual function that each derived class must implement.
234 The current position is updated.
237 The RGB value to set the current pixel to.
239 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded,
242 virtual TBool SetPixel(TRgb aColor) = 0;
245 Sets aCount number of pixels to the value given by aColor, starting at
246 the current position.
248 This is a virtual function that each derived class must implement.
251 On success, the current position is updated.
254 The RGB value to set the pixels to.
256 The number of pixels to set.
258 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded,
261 virtual TBool SetPixelRun(TRgb aColor,TInt aCount) = 0;
264 Updates the bitmap with colour information from the array of colour values.
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.
270 This is a virtual function that each derived class must implement.
273 The current position is updated.
276 A pointer to the first element in the array.
278 The number of elements in the array.
280 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded,
283 virtual TBool SetPixels(TRgb* aColorBuffer,TInt aBufferLength) = 0;
286 Sets the current pixel block using the data supplied in aColorBuffer.
289 For use with image types that support blocking of pixels eg JPEG.
291 This is a virtual function that each derived class must implement.
294 A pointer to a buffer representing a block of pixel color values.
296 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded,
299 virtual TBool SetPixelBlock(TRgb* aColorBuffer) = 0;
301 // Monochrome pixel writing
304 Sets the pixel at the current position to aGray256.
306 This is a virtual function that each derived class must implement.
309 The current position is updated.
312 The greyscale value to set the current pixel to.
314 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded,
317 virtual TBool SetMonoPixel(TInt aGray256) = 0;
320 Sets the number of pixels specified by aCount to the value given by aGray256, starting at
321 the current position.
323 This is a virtual function that each derived class must implement.
326 The current position is updated.
329 The greyscale value to set the pixels to.
331 The number of pixels to set.
333 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded,
336 virtual TBool SetMonoPixelRun(TInt aGray256,TInt aCount) = 0;
339 Updates the bitmap with greyscale information from the array of greyscale values.
341 The array of values supplied by aGray256Buffer, whose length
342 is specified in aBufferLength, is used to update successive pixels with the
345 This is a virtual function that each derived class must implement.
348 The current position is updated.
350 @param aGray256Buffer
351 A pointer to the first element in the array of greyscale values.
353 The number of elements in the array.
355 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded,
358 virtual TBool SetMonoPixels(TUint32* aGray256Buffer,TInt aBufferLength) = 0;
361 Sets a specified number of pixels to the specified greyscale value.
363 For image types which support blocking of pixels eg JPEG, the current
364 pixel block is set using the data supplied in aGray256Buffer.
366 This is a virtual function that each derived class must implement.
368 @param aGray256Buffer
369 A pointer to a buffer representing a block of pixel color values.
371 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded,
374 virtual TBool SetMonoPixelBlock(TUint32* aGray256Buffer) = 0;
376 // Processor flow control
379 Sets the current position in the bitmap to aPosition.
381 This is a virtual function that each derived class must implement.
384 A reference to TPoint object defining the position to move to.
386 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded,
389 virtual TBool SetPos(const TPoint& aPosition) = 0;
392 Commits the changes made to the current bitmap by flushing the buffer.
394 This is a virtual function that each derived class must implement.
397 The current position is updated.
399 @return A boolean indicating if the operation was successful. ETrue if the operation succeeded,
402 virtual TBool FlushPixels() = 0;
406 IMPORT_C virtual void ReservedVirtual1();
407 IMPORT_C virtual void ReservedVirtual2();
408 IMPORT_C virtual void ReservedVirtual3();
409 IMPORT_C virtual void ReservedVirtual4();
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.
420 8 unique orientations:
424 00 10 01 00 11 01 10 11
425 01 11 11 10 10 00 00 01
428 10 00 11 10 =Hflip =Hflip+90
432 01 11 00 01 =Vflip =Vflip+90
436 @see COperationExtension::AddOperationL
438 enum TTransformOptions
442 EDecodeNormal = 0x11011000,
444 /** Rotate 90 degrees.
446 EDecodeRotate90 = 0x10110001,
448 /** Rotate 180 degrees.
450 EDecodeRotate180 = 0x00100111,
452 /** Rotate 270 degrees.
454 EDecodeRotate270 = 0x01001110,
458 EDecodeHorizontalFlip = 0x10001101,
460 /** Horizontal flip and rotate 90 degrees.
462 EDecodeHorizontalFlipRotate90 = 0x11100100,
466 EDecodeVerticalFlip = 0x01110010,
468 /** Vertical flip and rotate 90 degrees.
470 EDecodeVerticalFlipRotate90 = 0x00011011
478 Class that provides support for Framework Extensions.
482 @see CImageDecoderPlugin
484 class CImageProcessorExtension : public CImageProcessor
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);
495 IMPORT_C CImageProcessorExtension();
498 /** Clipping rectangle */
500 /** Scaling coefficient */
502 /** Desired size after scaling */
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 */
510 /** An initial one-off number of scanlines to be skipped */
511 TInt iNumberOfScanlinesToSkip;
514 inline TInt TColorConvertor::RgbToMonochrome(TRgb aRgb)
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
526 #endif //___IMAGEPROCESSOR_H__