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