williamr@4: // Copyright (c) 1998-2009 Nokia Corporation and/or its subsidiary(-ies). williamr@4: // All rights reserved. williamr@4: // This component and the accompanying materials are made available williamr@4: // under the terms of "Eclipse Public License v1.0" williamr@4: // which accompanies this distribution, and is available williamr@4: // at the URL "http://www.eclipse.org/legal/epl-v10.html". williamr@4: // williamr@4: // Initial Contributors: williamr@4: // Nokia Corporation - initial contribution. williamr@4: // williamr@4: // Contributors: williamr@4: // williamr@4: // Description: williamr@4: // williamr@4: williamr@4: #ifndef ___IMAGEPROCESSOR_H__ williamr@4: #define ___IMAGEPROCESSOR_H__ williamr@4: williamr@4: #include williamr@4: #include williamr@4: williamr@4: /** williamr@4: @publishedAll williamr@4: */ williamr@4: enum TImageBitmapUtilPanic williamr@4: { williamr@4: ECorrupt williamr@4: }; williamr@4: williamr@4: /** williamr@4: @publishedAll williamr@4: @released williamr@4: williamr@4: Interface to colour conversion classes for various display modes. williamr@4: Manages the mapping between RGB/Greyscale values and the index williamr@4: into the color palette for the given display mode. williamr@4: */ williamr@4: class TColorConvertor williamr@4: { williamr@4: public: williamr@4: IMPORT_C static TColorConvertor* NewL(TDisplayMode aDisplayMode); williamr@4: williamr@4: /** williamr@4: Returns the colour index corresponding to the supplied RGB value. williamr@4: Operates in the context of the current display mode. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @param aColor williamr@4: The colour in RGB format. williamr@4: williamr@4: @return The colour index. williamr@4: */ williamr@4: virtual TInt ColorIndex(TRgb aColor) const = 0; williamr@4: williamr@4: /** williamr@4: Returns the RGB value corresponding to the supplied colour index. williamr@4: Operates in the context of the current display mode. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @param aColorIndex williamr@4: The colour in RGB format. williamr@4: williamr@4: @return The RGB value. williamr@4: */ williamr@4: virtual TRgb Color(TInt aColorIndex) const = 0; williamr@4: williamr@4: /** williamr@4: Gets an array of colour indices from a corresponding array of RGB values. williamr@4: Operates in the context of the current display mode. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @param aIndexBuffer williamr@4: A pointer to the first element in destination array. williamr@4: @param aColorBuffer williamr@4: A pointer to the first element in the source array. williamr@4: @param aCount williamr@4: The number of elements to get. williamr@4: */ williamr@4: virtual void ColorToIndex(TInt* aIndexBuffer,TRgb* aColorBuffer,TInt aCount) const = 0; williamr@4: williamr@4: inline static TInt RgbToMonochrome(TRgb aRgb); williamr@4: }; williamr@4: williamr@4: williamr@4: /** williamr@4: @publishedAll williamr@4: @released williamr@4: williamr@4: Bitmap utility class. williamr@4: */ williamr@4: class TImageBitmapUtil williamr@4: { williamr@4: public: williamr@4: IMPORT_C TImageBitmapUtil(); williamr@4: IMPORT_C void Begin(); williamr@4: IMPORT_C TBool Begin(const TPoint& aPosition); williamr@4: IMPORT_C void End(); williamr@4: IMPORT_C void SetBitmapL(CFbsBitmap* aBitmap); williamr@4: IMPORT_C void SetPixel(TUint32 aPixelIndex); williamr@4: IMPORT_C void SetPixels(TUint32* aPixelIndex,TInt aNumberOfPixels); williamr@4: IMPORT_C TBool SetPos(const TPoint& aPosition); williamr@4: williamr@4: private: williamr@4: union TDataPointer williamr@4: { williamr@4: TUint32* iWordPos; williamr@4: TUint8* iBytePos; williamr@4: }; williamr@4: private: williamr@4: CFbsBitmap* iBitmap; williamr@4: TSize iSize; williamr@4: TPoint iPosition; williamr@4: TDataPointer iData; williamr@4: TDataPointer iBase; williamr@4: TInt iBpp; williamr@4: TInt iBppShift; williamr@4: TInt iPixelShift; williamr@4: TInt iPixelsPerWord; williamr@4: TInt iBitShift; williamr@4: TInt iScanlineWordLength; williamr@4: TUint32 iMask; williamr@4: TBool iWordAccess; williamr@4: }; williamr@4: williamr@4: williamr@4: class CImageProcessor; williamr@4: class CImageProcessorExtension; williamr@4: williamr@4: /** williamr@4: @publishedAll williamr@4: @released williamr@4: williamr@4: Utility class providing static factory functions for creating instances of williamr@4: CImageProcessor derived classes. williamr@4: */ williamr@4: class ImageProcessorUtility williamr@4: { williamr@4: public: williamr@4: IMPORT_C static TInt ReductionFactor(const TSize& aOriginalSize,const TSize& aReducedSize); williamr@4: IMPORT_C static CImageProcessor* NewImageProcessorL(const CFbsBitmap& aBitmap,const TSize& aImageSize,TDisplayMode aImageDisplayMode, TBool aDisableErrorDiffusion); williamr@4: IMPORT_C static CImageProcessor* NewImageProcessorL(const CFbsBitmap& aBitmap,TInt aReductionFactor,TDisplayMode aImageDisplayMode, TBool aDisableErrorDiffusion); williamr@4: IMPORT_C static CImageProcessorExtension* NewImageProcessorExtensionL(const CFbsBitmap& aBitmap,TInt aReductionFactor,TDisplayMode aImageDisplayMode, TBool aDisableErrorDiffusion); williamr@4: williamr@4: private: williamr@4: TBool static UseErrorDiffuser(const TDisplayMode& aBitmapDisplayMode, const TDisplayMode& aImageDisplayMode); williamr@4: TBool static IsMonochrome(const TDisplayMode& aBitmapDisplayMode, const TDisplayMode& aImageDisplayMode); williamr@4: }; williamr@4: williamr@4: williamr@4: williamr@4: /** williamr@4: @publishedAll williamr@4: @released williamr@4: williamr@4: Interface to image processing classes used by CImageDecoder plugins. This is not a application client API. williamr@4: */ williamr@4: class CImageProcessor : public CBase williamr@4: { williamr@4: public: williamr@4: // Setup williamr@4: williamr@4: /** williamr@4: Initialises internal data structures prior to conversion. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @param aBitmap williamr@4: A reference to a fully constucted bitmap with the required williamr@4: display mode and size. williamr@4: @param aImageRect williamr@4: The region of the image to convert. williamr@4: */ williamr@4: virtual void PrepareL(CFbsBitmap& aBitmap,const TRect& aImageRect) = 0; williamr@4: williamr@4: /** williamr@4: Initialises internal data structures prior to the manipulation of the specified pixel block. williamr@4: williamr@4: This overloaded version allows specification of a block size williamr@4: for those formats which support blocked pixel data eg. JPEG williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @param aBitmap williamr@4: A reference to a fully constucted bitmap with the required williamr@4: display mode and size. williamr@4: @param aImageRect williamr@4: The region of the image to convert. williamr@4: @param aRgbBlockSize williamr@4: The size of the block to use. williamr@4: */ williamr@4: virtual void PrepareL(CFbsBitmap& aBitmap,const TRect& aImageRect,const TSize& aRgbBlockSize) = 0; williamr@4: williamr@4: /** williamr@4: Sets the number of pixels by which to increment the current position in williamr@4: the Y-axis. This is used when rendering images supporting interlacing. williamr@4: eg GIF williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @param aYInc williamr@4: The number of pixels. williamr@4: */ williamr@4: virtual void SetYPosIncrement(TInt aYInc) = 0; williamr@4: williamr@4: /** williamr@4: Sets the number times the current line should be repeated. The lines williamr@4: are repeated in the same direction as set by SetYPosIncrement(). This williamr@4: is used to fill blank lines when rendering interlaced images. eg GIF. williamr@4: @param aLineRepeat The number of times the current line should be repeated williamr@4: */ williamr@4: virtual void SetLineRepeat(TInt aLineRepeat) = 0; williamr@4: williamr@4: /** williamr@4: Sets the pixel padding to the value specified by aNumberOfPixels. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @param aNumberOfPixels williamr@4: The number of pixels to use for padding. williamr@4: */ williamr@4: virtual void SetPixelPadding(TInt aNumberOfPixels) = 0; williamr@4: williamr@4: // Color pixel writing williamr@4: williamr@4: /** williamr@4: Sets the pixel at the current position to aColor. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @post williamr@4: The current position is updated. williamr@4: williamr@4: @param aColor williamr@4: The RGB value to set the current pixel to. williamr@4: williamr@4: @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, williamr@4: otherwise EFalse. williamr@4: */ williamr@4: virtual TBool SetPixel(TRgb aColor) = 0; williamr@4: williamr@4: /** williamr@4: Sets aCount number of pixels to the value given by aColor, starting at williamr@4: the current position. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @post williamr@4: On success, the current position is updated. williamr@4: williamr@4: @param aColor williamr@4: The RGB value to set the pixels to. williamr@4: @param aCount williamr@4: The number of pixels to set. williamr@4: williamr@4: @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, williamr@4: otherwise EFalse. williamr@4: */ williamr@4: virtual TBool SetPixelRun(TRgb aColor,TInt aCount) = 0; williamr@4: williamr@4: /** williamr@4: Updates the bitmap with colour information from the array of colour values. williamr@4: williamr@4: Uses the array of colour values supplied by aColorBuffer, whose length williamr@4: is specified by aBufferLength, to update successive pixels with values in the williamr@4: buffer, starting at the current position. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @post williamr@4: The current position is updated. williamr@4: williamr@4: @param aColorBuffer williamr@4: A pointer to the first element in the array. williamr@4: @param aBufferLength williamr@4: The number of elements in the array. williamr@4: williamr@4: @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, williamr@4: otherwise EFalse. williamr@4: */ williamr@4: virtual TBool SetPixels(TRgb* aColorBuffer,TInt aBufferLength) = 0; williamr@4: williamr@4: /** williamr@4: Sets the current pixel block using the data supplied in aColorBuffer. williamr@4: williamr@4: Note: williamr@4: For use with image types that support blocking of pixels eg JPEG. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @param aColorBuffer williamr@4: A pointer to a buffer representing a block of pixel color values. williamr@4: williamr@4: @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, williamr@4: otherwise EFalse. williamr@4: */ williamr@4: virtual TBool SetPixelBlock(TRgb* aColorBuffer) = 0; williamr@4: williamr@4: // Monochrome pixel writing williamr@4: williamr@4: /** williamr@4: Sets the pixel at the current position to aGray256. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @post williamr@4: The current position is updated. williamr@4: williamr@4: @param aGray256 williamr@4: The greyscale value to set the current pixel to. williamr@4: williamr@4: @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, williamr@4: otherwise EFalse. williamr@4: */ williamr@4: virtual TBool SetMonoPixel(TInt aGray256) = 0; williamr@4: williamr@4: /** williamr@4: Sets the number of pixels specified by aCount to the value given by aGray256, starting at williamr@4: the current position. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @post williamr@4: The current position is updated. williamr@4: williamr@4: @param aGray256 williamr@4: The greyscale value to set the pixels to. williamr@4: @param aCount williamr@4: The number of pixels to set. williamr@4: williamr@4: @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, williamr@4: otherwise EFalse. williamr@4: */ williamr@4: virtual TBool SetMonoPixelRun(TInt aGray256,TInt aCount) = 0; williamr@4: williamr@4: /** williamr@4: Updates the bitmap with greyscale information from the array of greyscale values. williamr@4: williamr@4: The array of values supplied by aGray256Buffer, whose length williamr@4: is specified in aBufferLength, is used to update successive pixels with the williamr@4: greyscales values. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @post williamr@4: The current position is updated. williamr@4: williamr@4: @param aGray256Buffer williamr@4: A pointer to the first element in the array of greyscale values. williamr@4: @param aBufferLength williamr@4: The number of elements in the array. williamr@4: williamr@4: @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, williamr@4: otherwise EFalse. williamr@4: */ williamr@4: virtual TBool SetMonoPixels(TUint32* aGray256Buffer,TInt aBufferLength) = 0; williamr@4: williamr@4: /** williamr@4: Sets a specified number of pixels to the specified greyscale value. williamr@4: williamr@4: For image types which support blocking of pixels eg JPEG, the current williamr@4: pixel block is set using the data supplied in aGray256Buffer. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @param aGray256Buffer williamr@4: A pointer to a buffer representing a block of pixel color values. williamr@4: williamr@4: @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, williamr@4: otherwise EFalse. williamr@4: */ williamr@4: virtual TBool SetMonoPixelBlock(TUint32* aGray256Buffer) = 0; williamr@4: williamr@4: // Processor flow control williamr@4: williamr@4: /** williamr@4: Sets the current position in the bitmap to aPosition. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @param aPosition williamr@4: A reference to TPoint object defining the position to move to. williamr@4: williamr@4: @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, williamr@4: otherwise EFalse. williamr@4: */ williamr@4: virtual TBool SetPos(const TPoint& aPosition) = 0; williamr@4: williamr@4: /** williamr@4: Commits the changes made to the current bitmap by flushing the buffer. williamr@4: williamr@4: This is a virtual function that each derived class must implement. williamr@4: williamr@4: @post williamr@4: The current position is updated. williamr@4: williamr@4: @return A boolean indicating if the operation was successful. ETrue if the operation succeeded, williamr@4: otherwise EFalse. williamr@4: */ williamr@4: virtual TBool FlushPixels() = 0; williamr@4: williamr@4: private: williamr@4: // Future proofing williamr@4: IMPORT_C virtual void ReservedVirtual1(); williamr@4: IMPORT_C virtual void ReservedVirtual2(); williamr@4: IMPORT_C virtual void ReservedVirtual3(); williamr@4: IMPORT_C virtual void ReservedVirtual4(); williamr@4: }; williamr@4: williamr@4: /** williamr@4: @publishedAll williamr@4: @released williamr@4: williamr@4: Flag used to determine the type of transformation which is the result of williamr@4: single or multiple transformation operations requested via calls to williamr@4: COperationExtension::AddOperationL. williamr@4: williamr@4: 8 unique orientations: williamr@4: williamr@4: @code williamr@4: normal 90 180 270 williamr@4: 00 10 01 00 11 01 10 11 williamr@4: 01 11 11 10 10 00 00 01 williamr@4: williamr@4: V flip 90 180 270 williamr@4: 10 00 11 10 =Hflip =Hflip+90 williamr@4: 11 01 01 00 williamr@4: williamr@4: H flip 90 180 270 williamr@4: 01 11 00 01 =Vflip =Vflip+90 williamr@4: 00 10 10 11 williamr@4: @endcode williamr@4: williamr@4: @see COperationExtension::AddOperationL williamr@4: */ williamr@4: enum TTransformOptions williamr@4: { williamr@4: /** Normal Decode williamr@4: */ williamr@4: EDecodeNormal = 0x11011000, williamr@4: williamr@4: /** Rotate 90 degrees. williamr@4: */ williamr@4: EDecodeRotate90 = 0x10110001, williamr@4: williamr@4: /** Rotate 180 degrees. williamr@4: */ williamr@4: EDecodeRotate180 = 0x00100111, williamr@4: williamr@4: /** Rotate 270 degrees. williamr@4: */ williamr@4: EDecodeRotate270 = 0x01001110, williamr@4: williamr@4: /** Horizontal flip. williamr@4: */ williamr@4: EDecodeHorizontalFlip = 0x10001101, williamr@4: williamr@4: /** Horizontal flip and rotate 90 degrees. williamr@4: */ williamr@4: EDecodeHorizontalFlipRotate90 = 0x11100100, williamr@4: williamr@4: /** Vertical flip. williamr@4: */ williamr@4: EDecodeVerticalFlip = 0x01110010, williamr@4: williamr@4: /** Vertical flip and rotate 90 degrees. williamr@4: */ williamr@4: EDecodeVerticalFlipRotate90 = 0x00011011 williamr@4: }; williamr@4: williamr@4: williamr@4: /** williamr@4: @publishedAll williamr@4: @released williamr@4: williamr@4: Class that provides support for Framework Extensions. williamr@4: williamr@4: @see CImageProcessor williamr@4: @see CImageReadCodec williamr@4: @see CImageDecoderPlugin williamr@4: */ williamr@4: class CImageProcessorExtension : public CImageProcessor williamr@4: { williamr@4: public: williamr@4: IMPORT_C virtual ~CImageProcessorExtension(); williamr@4: IMPORT_C void SetClippingRect(const TRect& aRect); williamr@4: IMPORT_C void SetScaling(TInt aScalingCoeff); williamr@4: IMPORT_C void SetScaling(const TSize& aDesiredSize); williamr@4: IMPORT_C void SetOperation(TTransformOptions aOperation); williamr@4: IMPORT_C void SetInitialScanlineSkipPadding(TInt aNumberOfScanlines); williamr@4: williamr@4: protected: williamr@4: IMPORT_C CImageProcessorExtension(); williamr@4: williamr@4: protected: williamr@4: /** Clipping rectangle */ williamr@4: TRect iClippingRect; williamr@4: /** Scaling coefficient */ williamr@4: TInt iScalingCoeff; williamr@4: /** Desired size after scaling */ williamr@4: TSize iDesiredSize; williamr@4: /** Operations to apply to image */ williamr@4: TTransformOptions iOperation; williamr@4: /** Position in destination at which start rendering */ williamr@4: TPoint iStartPosition; williamr@4: /** Position in destination at which rendering is complete */ williamr@4: TPoint iEndPosition; williamr@4: /** An initial one-off number of scanlines to be skipped */ williamr@4: TInt iNumberOfScanlinesToSkip; williamr@4: }; williamr@4: williamr@4: inline TInt TColorConvertor::RgbToMonochrome(TRgb aRgb) williamr@4: { williamr@4: TInt value = aRgb.Internal(); williamr@4: TInt r = value&0xFF0000; williamr@4: TInt g = value&0xFF00; williamr@4: value = (value&0xFF)<<16; // blue<<16 williamr@4: value += r<<1; // + (red<<16)*2 williamr@4: value += g<<(16+2-8); // + (green<<16)*4 williamr@4: value += g<<(16+0-8); // + (green<<16) williamr@4: return value>>(16+3); // total/8 williamr@4: } williamr@4: williamr@4: #endif //___IMAGEPROCESSOR_H__ williamr@4: