1 // Copyright (c) 1995-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #if !defined(__BITMAP_H__)
18 #if !defined(__E32STD_H__)
21 #if !defined(__F32FILE_H__)
24 #if !defined(__GDI_H__)
28 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
29 #include <graphics/bitmapuid.h>
33 #define SYMBIAN_DEBUG_FBS_LOCKHEAP
36 //Forward declarations
38 class TCompressionBookMark;
42 Defines the types of file compression.
46 enum TBitmapfileCompression
48 /** Bitmap file is not compressed. */
50 /** File is compressed using run-length encoding compression. */
52 /** File is compressed using twelve bit run-length encoding compression. */
53 ETwelveBitRLECompression,
54 /** File is compressed using sixteen bit run-length encoding compression. */
55 ESixteenBitRLECompression,
56 /** File is compressed using twenty four bit run-length encoding compression. */
57 ETwentyFourBitRLECompression,
58 /** File is compressed using twenty four bit run-length encoding compression from 32-bit bitmap buffer. */
59 EThirtyTwoUBitRLECompression,
60 /** File is compressed using thirty two bit run-length encoding compression from 32-bit bitmap buffer. */
61 EThirtyTwoABitRLECompression,
62 /** File is compressed as a palette plus reduced bit-per-pixel. Only applicable to bitmaps already loaded in RAM. */
63 EGenericPaletteCompression,
64 /** Extended bitmap. Data format is proprietary to licensee. */
65 EProprietaryCompression,
66 //Insert new enum items here!
67 ERLECompressionLast = 255
71 Defines the available file compression schemes.
75 enum TBitmapfileCompressionScheme
77 /** File is compressed using run-length encoding compression. */
79 /** File is compressed as a palette plus reduced bit-per-pixel. */
81 /** File is compressed as a palette plus reduced bit-per-pixel, with automatic fallback to RLE if bitmap is not suitable*/
82 EPaletteCompressionWithRLEFallback
86 WARNING: Typedef for internal use ONLY. Compatibility is not guaranteed in future releases.
90 typedef void (*TAssignFunction)(TUint8*& aDestPtr, TUint32 aColor);
92 WARNING: Typedef for internal use ONLY. Compatibility is not guaranteed in future releases.
96 typedef void (*TDecodeFunction)(TUint8* aDataPtr, TUint32* aPalettePtr, TUint8*& aDestPtr, TAssignFunction aAssignFunction);
99 Contains information about the bitmap when streaming bitmaps to stores.
103 class SEpocBitmapHeader
106 inline SEpocBitmapHeader() :
107 iBitmapSize(sizeof(SEpocBitmapHeader)),
108 iStructSize(sizeof(SEpocBitmapHeader)),
114 iCompression(ENoBitmapCompression)
118 /** Defines whether bitmap is colour and if it comprises an alpha channel. */
121 /** Bitmap doesn't comprise color */
123 /** Bitmap comprises color */
125 /** Bitmap comprises color with alpha channel */
127 /** Bitmap comprises pre-multiplied colors with alpha channel */
129 /** Unknown format */
133 /** The size of the bitmap data, in bytes. */
135 /** The size of the structure in which the bitmap data is stored. */
137 /** The size of the bitmap, in pixels. */
139 /** The size of the bitmap, in twips. */
141 /** The bitmap's number of bits per pixel */
143 /** Whether or not the bitmap is colour and comprises an alpha value. */
145 /** The number of entries in the bitmap's palette. */
146 TInt iPaletteEntries;
147 /** The type of compression used to store the bitmap. */
148 TBitmapfileCompression iCompression;
152 WARNING: Class for internal use ONLY. Compatibility is not guaranteed in future releases.
157 class TLineScanningPosition
160 inline TLineScanningPosition(TUint32* aSrcDataPtr);
164 HBufC8* iScanLineBuffer;
165 CFbsRasterizer* const iRasterizer;
168 class CShiftedFileStore;
171 BitGdi bitmap class (pseudo-CXxx class).
172 WARNING: Class for internal use ONLY. Compatibility is not guaranteed in future releases.
178 friend class CFbClient;
179 friend class CFbsBitmap;
180 friend class CBitmapObject;
181 friend class CFbsBitmapAsyncStreamer;
182 friend class CFbsBackgroundCompression;
183 friend class CleanupDelete<CBitwiseBitmap>;
185 IMPORT_C TUid Uid() const;
186 IMPORT_C void ExternalizeL(RWriteStream& aStream,const CFbsBitmap& aHandleBitmap) const;
187 IMPORT_C void ExternalizeRectangleL(RWriteStream& aStream,const TRect& aRect,const CFbsBitmap& aHandleBitmap) const;
188 IMPORT_C void InternalizeL(RReadStream& aStream);
189 IMPORT_C static void InternalizeHeaderL(RReadStream& aStream,SEpocBitmapHeader& aHeader);
190 IMPORT_C TSize SizeInPixels() const;
191 IMPORT_C TSize SizeInTwips() const;
192 IMPORT_C TDisplayMode DisplayMode() const;
193 IMPORT_C TInt HorizontalTwipsToPixels(TInt aTwips) const;
194 IMPORT_C TInt VerticalTwipsToPixels(TInt aTwips) const;
195 IMPORT_C TInt HorizontalPixelsToTwips(TInt aPixels) const;
196 IMPORT_C TInt VerticalPixelsToTwips(TInt aPixels) const;
197 IMPORT_C void GetPixel(TRgb& aColor,const TPoint& aPos,TUint32* aBase, CFbsRasterizer* aRasterizer) const;
198 IMPORT_C TInt GetScanLinePtr(TUint32*& aSlptr, TPoint& aPixel,TInt aLength, TUint32* aBase, TLineScanningPosition& aLineScanningPosition) const;
199 IMPORT_C TInt GetScanLinePtr(TUint32*& aSlptr, TInt& aLength, TPoint& aPixel,TUint32* aBase, TLineScanningPosition& aLineScanningPosition) const;
200 IMPORT_C void GetScanLine(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TBool aDither,const TPoint& aDitherOffset,TDisplayMode aDispMode,TUint32* aBase, TLineScanningPosition& aLineScanningPosition) const;
201 IMPORT_C void GetScanLine(TUint32*& aSlptr, TDes8& aBuf,const TPoint& aPixel,TInt aLength,TBool aDither,const TPoint& aDitherOffset,TDisplayMode aDispMode) const;
202 IMPORT_C void GetScanLine(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TBool aDither,const TPoint& aDitherOffset,TDisplayMode aDispMode,TUint32* aBase) const;
203 IMPORT_C void GetVerticalScanLine(TDes8& aBuf,TInt aX,TBool aDither,const TPoint& aDitherOffset,TDisplayMode aDispMode,TUint32* aBase, CFbsRasterizer* aRasterizer) const;
204 IMPORT_C void StretchScanLine(TDes8& aBuf,const TPoint& aPixel,TInt aClipStrchX,TInt aClipStrchLen,TInt aStretchLength,TInt aOrgX,TInt aOrgLen,const TPoint& aDitherOffset,TDisplayMode aDispMode,TUint32* aBase) const;
205 IMPORT_C void StretchScanLine(TDes8& aBuf,const TPoint& aPixel,TInt aClipStrchX,TInt aClipStrchLen,TInt aStretchLength,TInt aOrgX,TInt aOrgLen,const TPoint& aDitherOffset,TDisplayMode aDispMode,TUint32* aBase, TLineScanningPosition& aLineScanningPosition) const;
206 IMPORT_C TUint32* ScanLineAddress(TUint32* aBase,TUint aY) const;
207 IMPORT_C TBool IsMonochrome(TUint32* aBase) const;
208 IMPORT_C TBool IsLargeBitmap() const;
209 IMPORT_C TInt CompressData();
210 IMPORT_C TInt CompressData(TBitmapfileCompressionScheme aScheme);
211 IMPORT_C TInt CheckBackgroundCompressData();
212 IMPORT_C void SetCompressionBookmark(TLineScanningPosition& aLineScanningPosition, TUint32* aBase, const CFbsBitmap* aFbsBitmap);
213 IMPORT_C TInt HardwareBitmapHandle() const;
214 IMPORT_C TBool IsCompressedInRAM() const;
215 IMPORT_C TBool IsCompressed() const;
216 IMPORT_C TInt DataStride() const;
217 IMPORT_C SEpocBitmapHeader Header() const;
219 IMPORT_C void operator delete(TAny*);
220 void operator delete(TAny*, TAny*) {} // This function exists only to prevent a compiler warning
221 IMPORT_C CBitwiseBitmap(RHeap* aHeap,CChunkPile* aPile);
222 IMPORT_C ~CBitwiseBitmap();
223 IMPORT_C void Reset();
224 IMPORT_C TInt Construct(const TSize& aSize,TDisplayMode aDispMode,TUid aCreatorUid);
225 IMPORT_C TInt ConstructExtended(const TSize& aSize, TDisplayMode aDispMode, TUid aType, TInt aDataSize);
226 IMPORT_C void ConstructL(RFs& aFs,const TDesC& aFilename,TInt32 aId,TUint aFileOffset);
227 IMPORT_C void ConstructL(RFile& aFile,TInt32 aId,TUint aFileOffset);
228 IMPORT_C void ConstructL(CShiftedFileStore* aFileStore,TStreamId aStreamId);
229 IMPORT_C TInt CopyData(const CBitwiseBitmap& aSourceBitmap);
231 void GenerateLineFromCompressedTwelveBitData(TUint8* aDestBuffer, const TPoint& aPixel,TInt aLength,TUint32* aBase, TLineScanningPosition& aLineScanningPosition) const;
232 void GenerateLineFromCompressedEightBitData(TUint8* aDestBuffer, const TPoint& aPixel,TInt aLength,TUint32* aBase, TLineScanningPosition& aLineScanningPosition) const;
233 TUint8 GetGrayPixelEx(TInt aX,TUint32* aScanLineAddress) const;
234 TRgb GetRgbPixelEx(TInt aX,TUint32* aScanLineAddress) const;
235 void GetRgbPixelExMany(TInt aX,TUint32* aScanlinePtr,TUint32* aDest,TInt aLength) const;
236 void GetRgbPixelExMany16M(TInt aX,TUint32* aScanlinePtr,TUint8* aDest,TInt aLength) const;
237 void GetRgbPixelExMany16MAP(TInt aX,TUint32* aScanlinePtr,TUint32* aDest,TInt aLength) const;
238 void GetScanLineGray2(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TBool aDither,const TPoint& aDitherOffset,TUint32* aScanlinePtr) const;
239 void GetScanLineGray4(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TBool aDither,const TPoint& aDitherOffset,TUint32* aScanlinePtr) const;
240 void GetScanLineGray16(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TUint32* aScanlinePtr) const;
241 void GetScanLineGray256(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TUint32* aScanlinePtr) const;
242 void GetScanLineColor16(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TUint32* aScanlinePtr) const;
243 void GetScanLineColor256(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TUint32* aScanlinePtr) const;
244 void GetScanLineColor4K(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TUint32* aScanlinePtr) const;
245 void GetScanLineColor64K(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TUint32* aScanlinePtr) const;
246 void GetScanLineColor16M(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TUint32* aScanlinePtr) const;
247 void GetScanLineColor16MU(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TUint32* aScanlinePtr) const;
248 void GetScanLineColorRgb(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TUint32* aScanlinePtr) const;
249 void GetScanLineExBits(TDes8& aBuf,TInt aX,TInt aLength,TUint32* aScanlinePtr) const;
250 void GetScanLineExBytes(TDes8& aBuf,TInt aX,TInt aLength,TUint32* aScanlinePtr) const;
251 void DoExternalizeDataCompressedL(RWriteStream& aStream,TUint8* aData,TInt aSizeInBytes) const;
252 void DoExternalizeByteDataCompressedL(RWriteStream& aStream,TUint8* aData,TInt aSizeInBytes) const;
253 void DoExternalizeTwelveBitDataCompressedL(RWriteStream& aStream,TUint8* aData,TInt aSizeInBytes) const;
254 void DoExternalizeSixteenBitDataCompressedL(RWriteStream& aStream,TUint8* aData,TInt aSizeInBytes) const;
255 void DoExternalizeTwentyFourBitDataCompressedL(RWriteStream& aStream,TUint8* aData,TInt aSizeInBytes) const;
256 void DoExternalizeThirtyTwoUBitDataCompressedL(RWriteStream& aStream,TUint8* aData,TInt aSizeInBytes) const;
257 void DoExternalizeThirtyTwoABitDataCompressedL(RWriteStream& aStream,TUint8* aData,TInt aSizeInBytes) const;
258 TInt SizeOfDataCompressed(TUint8* aData,TInt aSizeInBytes) const;
259 TInt SizeOfByteDataCompressed(TUint8* aData,TInt aSizeInBytes) const;
260 TInt SizeOfTwelveBitDataCompressed(TUint8* aData,TInt aSizeInBytes) const;
261 TInt SizeOfSixteenBitDataCompressed(TUint8* aData,TInt aSizeInBytes) const;
262 TInt SizeOfTwentyFourBitDataCompressed(TUint8* aData,TInt aSizeInBytes) const;
263 TInt SizeOfThirtyTwoUBitDataCompressed(TUint8* aData,TInt aSizeInBytes) const;
264 TInt SizeOfThirtyTwoABitDataCompressed(TUint8* aData,TInt aSizeInBytes) const;
265 TBool TrueColorPointerCompare(TUint8* aColorPointer,TUint8 aComponent1,TUint8 aComponent2,TUint8 aComponent3) const;
266 TBool ColorAlphaPointerCompare(TUint8* aColorPointer,TUint8 aComponent1,TUint8 aComponent2,TUint8 aComponent3,TUint8 aComponent4) const;
267 void DoInternalizeL(RReadStream& aStream,TInt aSrceSize,TUint32* aBase);
268 void DoInternalizeCompressedDataL(RReadStream& aStream,TInt aSrceSize,TUint32* aBase,TBitmapfileCompression aCompression);
269 void DoDecompressByteData(TUint8* aDestBuffer,TInt aDestSize,TUint8* aSrceBuffer,TInt aSrceSize);
271 void DoDecompressByteDataAltL(RReadStream& aStream,TInt aSrceSizeInBytes,TUint32* aBase);
272 void DoDecompressTwelveBitData(TUint8* aDestBuffer,TInt aDestSize,TUint8* aSrceBuffer,TInt aSrceSize);
273 void DoDecompressTwelveBitDataAltL(RReadStream& aStream,TInt aSrceSizeInBytes,TUint32* aBase);
274 void DoDecompressSixteenBitData(TUint8* aDestBuffer,TInt aDestSize,TUint8* aSrceBuffer,TInt aSrceSize);
275 void DoDecompressSixteenBitDataAltL(RReadStream& aStream,TInt aSrceSizeInBytes,TUint32* aBase);
276 void DoDecompressTwentyFourBitData(TUint8* aDestBuffer,TInt aDestSize,TUint8* aSrceBuffer,TInt aSrceSize);
277 void DoDecompressTwentyFourBitDataAltL(RReadStream& aStream,TInt aSrceSizeInBytes,TUint32* aBase);
278 void DoDecompressThirtyTwoUBitData(TUint8* aDestBuffer,TInt aDestSize,TUint8* aSrceBuffer,TInt aSrceSize);
279 void DoDecompressThirtyTwoUBitDataAltL(RReadStream& aStream,TInt aSrceSizeInBytes,TUint32* aBase);
280 void DoDecompressThirtyTwoABitData(TUint8* aDestBuffer,TInt aDestSize,TUint8* aSrceBuffer,TInt aSrceSize);
281 void DoDecompressThirtyTwoABitDataAltL(RReadStream& aStream,TInt aSrceSizeInBytes,TUint32* aBase);
282 void DoStretchScanLine(TDes8& aBuf,TInt x,TInt y,TInt aClipStrchX,TInt aClipStrchLen,TInt aStretchLength,TInt aOrgX,TInt aOrgLen,const TPoint& aDitherOffset,TDisplayMode aDispMode,TUint32* aBase,TLineScanningPosition& aLineScanningPosition) const;
283 void DoCompressScanLine(TDes8& aBuf,TInt x,TInt y,TInt aClipStrchX,TInt aClipStrchLen,TInt aStretchLength,TInt aOrgX,TInt aOrgLen,const TPoint& aDitherOffset,TDisplayMode aDispMode,TUint32* aBase,TLineScanningPosition& aLineScanningPosition) const;
284 TUint32 HashTo1bpp(TUint32 aGray256,TBool aOddX,TBool aOddY) const;
285 TUint32 HashTo2bpp(TUint32 aGray256,TInt aDitherIndex) const;
286 TBool IsWordMonochrome(TUint32 aWord) const;
287 TUint32* DataAddress() const;
288 static void WhiteFill(TUint8* aData,TInt aDataSize,TDisplayMode aDispMode);
289 static TInt ByteWidth(TInt aPixelWidth,TDisplayMode aDispMode);
290 static TInt Bpp(TDisplayMode aDispMode);
291 static TInt IsColor(TDisplayMode aDispMode);
292 static TDisplayMode DisplayMode(TInt aBpp,TInt aColor);
293 static TBitmapfileCompression CompressionType(TInt aBpp, TInt aColor);
294 TInt DoGetScanLinePtr(TUint32*& aSlptr, TPoint& aPixel,TInt aLength, TUint32* aBase, TLineScanningPosition& aLineScanningPosition) const;
295 void GenerateLineFromCompressedSixteenBitData(TUint8* aDestBuffer, const TPoint& aPixel,TInt aLength, TUint32* aBase, TLineScanningPosition& aLineScanningPosition) const;
296 TDisplayMode InitialDisplayMode() const;
297 TInt SetDisplayMode(TDisplayMode aDisplayMode, TUint32* aDataAddress);
298 TInt DisplayModeArgCheck(TDisplayMode aDisplayMode, TUint32* aDataAddress) const;
299 void ChangeDisplayMode( TDisplayMode aNewDisplayMode,
300 TInt aScanLineWidthNew,
301 TUint8* aDataAddrNew,
302 TUint32* aDataAddress,
306 void UpdateBitmapProperties(TDisplayMode aNewDisplayMode);
307 TInt SwapWidthAndHeight(TUint32* aDataAddress);
308 void GenerateLineFromCompressed24BitData(TUint8* aDestBuffer, const TPoint& aPixel,TInt aLength, TUint32* aBase, TLineScanningPosition& aLineScanningPosition) const;
309 void GenerateLineFromCompressed32UBitData(TUint8* aDestBuffer, const TPoint& aPixel,TInt aLength, TUint32* aBase, TLineScanningPosition& aLineScanningPosition) const;
310 void GenerateLineFromCompressed32ABitData(TUint8* aDestBuffer, const TPoint& aPixel,TInt aLength, TUint32* aBase, TLineScanningPosition& aLineScanningPosition) const;
311 void AdjustXCoord(TInt& aX) const;
312 void GetLineScanPos(TLineScanningPosition& aLineScanPos,
313 const TCompressionBookMark*& aComprBookMark,
314 const TUint8* aBase) const;
315 void UpdateBookMark(const TLineScanningPosition& aLineScanPos,
316 TCompressionBookMark* aComprBookMark,
317 const TUint8* aBase) const;
318 void GetScanLineColor16MA(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TUint32* aScanlinePtr) const;
319 void GetScanLineColor16MAP(TDes8& aBuf,const TPoint& aPixel,TInt aLength,TUint32* aScanlinePtr) const;
320 TInt PaletteCompress();
321 void GenerateLineFromPaletteCompressedData(TUint8* aDestBuffer, const TPoint& aPixel,TInt aLength, TUint32* aBase, TLineScanningPosition& aLineScanningPosition) const;
322 TUint PaletteBitsPerPixel(TInt aNumColors) const;
323 TUint PaletteBytesPerPixel(TInt aBitsPerPixel) const;
324 void PaletteDecodeAndAssignGeneric(TUint8* aDataPtr, TUint32* aPalettePtr, TUint8*& aDestPtr, TUint aStartPixel, TUint aEndPixel, TUint aCompressedPixelsPerByte, TUint aCompressedBitsPerPixel) const;
325 static void PaletteDecode1PixelPerByte(TUint8* aDataPtr, TUint32* aPalettePtr, TUint8*& aDestPtr, TAssignFunction aAssignFunction);
326 static void PaletteDecode2PixelPerByte(TUint8* aDataPtr, TUint32* aPalettePtr, TUint8*& aDestPtr, TAssignFunction aAssignFunction);
327 static void PaletteDecode4PixelPerByte(TUint8* aDataPtr, TUint32* aPalettePtr, TUint8*& aDestPtr, TAssignFunction aAssignFunction);
328 static void PaletteDecode8PixelPerByte(TUint8* aDataPtr, TUint32* aPalettePtr, TUint8*& aDestPtr, TAssignFunction aAssignFunction);
329 static void PaletteAssign16BitColor(TUint8*& aDestPtr, TUint32 aColor);
330 static void PaletteAssign24BitColor(TUint8*& aDestPtr, TUint32 aColor);
331 static void PaletteAssign32BitColor(TUint8*& aDestPtr, TUint32 aColor);
332 void UpdatePaddingData(TUint32* aData);
333 static void CheckHeaderIsValidL(const SEpocBitmapHeader& aHeader);
334 static TInt CompressedFormatInfo(TDisplayMode aDispMode, TInt& aBytesPerPack, TInt& aBytesPerCompressed);
335 static void BitmapFill32(TUint32* aDestPtr32, TInt aCount, TUint32 aValue32);
336 static inline void BitmapFill16(TUint16* aDestPtr16, TInt aCount, TUint16 aValue16);
340 #ifdef SYMBIAN_DEBUG_FBS_LOCKHEAP
341 TInt iLockCount; // number of calls to CFbsBitmap::LockHeap() not balanced by calls to CFbsBitmap::UnlockHeap()
342 TThreadId iThreadId; // id of thread that called CFbsBitmap::LockHeap() if any
344 TInt64 iSerialNumber; // serial number of bitmap which is unique to the whole FBServ
345 TInt iTouchCount; // number of calls to TouchBitmap()i.e. number of times bitmap has been changed
347 inline TExtra* Extra() const; // only for bitmaps created in RAM
352 TSettings(TDisplayMode aDisplayMode);
353 void SetDisplayModes(TDisplayMode aDisplayMode);
354 void SetCurrentDisplayMode(TDisplayMode aDisplayMode);
355 TDisplayMode CurrentDisplayMode() const;
356 TDisplayMode InitialDisplayMode() const;
357 inline void SetDirtyBitmap();
358 inline TBool IsDirtyBitmap() const;
359 inline void SetVolatileBitmap();
360 inline TBool IsVolatileBitmap() const;
363 EBitmapFlagDirty = 0x00010000, // set in the old bitmap when a re-allocating operation has created a new bitmap
364 EBitmapFlagVolatile = 0x00020000, // set when DataAddress() has been called but BeginDataAccess() has not
371 SEpocBitmapHeader iHeader;
373 TInt iDataOffset; // offset in bytes from "this" or from base of bitmap chunk, or hardware bitmap handle
374 TBool iIsCompressedInRAM; //flag indicating whether CompressData has been called