First public contribution.
1 // Copyright (c) 2003-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.
18 #include "CompressionBookmark.h"
19 #include "BitmapCompr.h"
21 #include "bitmapconst.h"
23 GLREF_C void Panic(TFbsPanic aPanic);
26 The method recalculates aLineScanPos which is used for quick search of the
27 nearest "length" byte before aStartPos.
28 Note: The method should be used only for compressed in RAM bitmaps for which
31 @post aLineScanPos might be updated
33 GLDEF_C void AdjustLineScanningPosition(TLineScanningPosition& aLineScanPos,
37 TInt aCompressedDataBytes)
39 TInt difference = ::Abs(aStartPos - aLineScanPos.iCursorPos);
40 if(difference > aBitmapWidth && aCompressedDataBytes > KCompressionBookMarkThreshold)
42 const TCompressionBookMark* bookMarkPtr =
43 (const TCompressionBookMark*)((const TUint8*)aBase +
44 (aCompressedDataBytes + 3) / 4 * 4 + 4);
45 if(bookMarkPtr->iSrcDataOffset && bookMarkPtr->IsCheckSumOk())
47 TInt difference2 = ::Abs(aStartPos - bookMarkPtr->iCursorPos);
48 if(difference2 < difference)
50 aLineScanPos.iCursorPos = bookMarkPtr->iCursorPos;
51 aLineScanPos.iSrcDataPtr = ((TUint8*)aBase) + bookMarkPtr->iSrcDataOffset;
58 The method gets the first 16 bpp pixel value pointed by aSrcPtr and copies it aCount times
62 @param aSrcPtr It points to the source pixel
63 @param aDestPtr It points to the destination buffer where the pixel should be copied aCount times
64 @param aCount How many times the pixel value should be copied
65 @return The updated aDestPtr
68 TUint8* TScanLineDecompressor<E2bpp, E2bpp>::CopyPixel(TUint8* aDestPtr,
69 const TUint8* aSrcPtr,
72 //We can't access directly the 16 bits data chunk, because it may be located at an odd address and
73 //THUMB build will fail with "KERNEL EXEC-3".
74 TUint8 lsb = *aSrcPtr;
75 TUint8 msb = *(aSrcPtr + 1);
76 TUint16 data = TUint16(lsb | (TUint16(msb) << 8));
77 TUint32 data32 = TUint32(data | (TUint32(data) << 16));
78 if((TUint32(aDestPtr) & 0x2) && aCount)
80 *(TUint16*)aDestPtr = data;
81 aDestPtr += 2;//+= 2 - the pixel color is coded into 16 bits - 2 bytes
86 *(TUint32*)aDestPtr = data32;
87 aDestPtr += 4;//+= 4 - the pixel color is coded into 16 bits - 2 x 2 bytes
92 *(TUint16*)aDestPtr = data;
93 aDestPtr += 2;//+= 2 - the pixel color is coded into 16 bits - 2 bytes
99 The method gets the first 24 bpp pixel value pointed by aSrcPtr and copies it aCount times
103 @param aSrcPtr It points to the source pixel
104 @param aDestPtr It points to the destination buffer where the pixel should be copied aCount times
105 @param aCount How many times the pixel value should be copied
106 @return The updated aDestPtr
109 TUint8* TScanLineDecompressor<E3bpp, E3bpp>::CopyPixel(TUint8* aDestPtr,
110 const TUint8* aSrcPtr,
113 const TUint8 b1 = *aSrcPtr;
114 const TUint8 b2 = *(aSrcPtr + 1);
115 const TUint8 b3 = *(aSrcPtr + 2);
126 The method gets the first 32 bpp pixel value pointed by aSrcPtr and copies it aCount times
130 @param aSrcPtr It points to the source pixel
131 @param aDestPtr It points to the destination buffer where the pixel should be copied aCount times
132 @param aCount How many times the pixel value should be copied
133 @return The updated aDestPtr
136 TUint8* TScanLineDecompressor<E4bpp, E4bpp>::CopyPixel(TUint8* aDestPtr,
137 const TUint8* aSrcPtr,
140 __ASSERT_DEBUG((reinterpret_cast<TUint32>(aDestPtr) & 0x3)==0,Panic(EFbsBitmapDecompressionError)); // make sure the start address is word aligned
142 const TUint8 b1 = *aSrcPtr;
143 const TUint8 b2 = *(aSrcPtr + 1);
144 const TUint8 b3 = *(aSrcPtr + 2);
145 const TUint8 b4 = *(aSrcPtr + 3);
147 if((reinterpret_cast<TUint32>(aDestPtr) & 0x3)== 0) // the start address is word aligned
149 const TUint32 pixel = (b4 << 24) | (b3 << 16) | (b2 << 8) | b1;
150 TUint32* destPtr32 = reinterpret_cast <TUint32*>(aDestPtr);
151 TInt blocksOf16 = ((aCount + 0x0f) >> 4); // number of blocks of upto 16 words to write
152 // the first iteration writes 1 to 15 words
153 switch (aCount & 0x0f)
154 { // note that case statements intentionally cascade
156 do { // second and subsequent iterations always write 16 words
157 *destPtr32++ = pixel;
159 *destPtr32++ = pixel;
161 *destPtr32++ = pixel;
163 *destPtr32++ = pixel;
165 *destPtr32++ = pixel;
167 *destPtr32++ = pixel;
169 *destPtr32++ = pixel;
171 *destPtr32++ = pixel;
173 *destPtr32++ = pixel;
175 *destPtr32++ = pixel;
177 *destPtr32++ = pixel;
179 *destPtr32++ = pixel;
181 *destPtr32++ = pixel;
183 *destPtr32++ = pixel;
185 *destPtr32++ = pixel;
187 *destPtr32++ = pixel;
188 } while(--blocksOf16 > 0);
191 return reinterpret_cast <TUint8*>(destPtr32);
205 The method gets the first 24 bpp pixel value pointed by aSrcPtr and copies it aCount times
206 to aDestPtr 32 bpp buffer.
209 @param aSrcPtr It points to the source pixel
210 @param aDestPtr It points to the destination buffer where the pixel should be copied aCount times
211 @param aCount How many times the pixel value should be copied
212 @return The updated aDestPtr
215 TUint8* TScanLineDecompressor<E3bpp, E4bpp>::CopyPixel(TUint8* aDestPtr,
216 const TUint8* aSrcPtr,
219 const TUint8 b1 = *aSrcPtr;
220 const TUint8 b2 = *(aSrcPtr + 1);
221 const TUint8 b3 = *(aSrcPtr + 2);
223 if((reinterpret_cast<TUint32>(aDestPtr) & 0x3)== 0) // the start address is word aligned
225 const TUint32 pixel = 0xFF000000 | (b3 << 16) | (b2 << 8) | b1; //it is more accurate to equalize to 0xff,
226 //as top byte could correspond an alpha channel
227 TUint32* destPtr32 = reinterpret_cast <TUint32*>(aDestPtr);
228 TInt blocksOf16 = ((aCount + 0x0f) >> 4); // number of blocks of upto 16 words to write
229 // the first iteration writes 1 to 15 words
230 switch (aCount & 0x0f)
231 { // note that case statements intentionally cascade
233 do { // second and subsequent iterations always write 16 words
234 *destPtr32++ = pixel;
236 *destPtr32++ = pixel;
238 *destPtr32++ = pixel;
240 *destPtr32++ = pixel;
242 *destPtr32++ = pixel;
244 *destPtr32++ = pixel;
246 *destPtr32++ = pixel;
248 *destPtr32++ = pixel;
250 *destPtr32++ = pixel;
252 *destPtr32++ = pixel;
254 *destPtr32++ = pixel;
256 *destPtr32++ = pixel;
258 *destPtr32++ = pixel;
260 *destPtr32++ = pixel;
262 *destPtr32++ = pixel;
264 *destPtr32++ = pixel;
265 } while(--blocksOf16 > 0);
268 return reinterpret_cast <TUint8*>(destPtr32);
276 *aDestPtr++ = 0xff; //it is more accurate to equalize to 0xff, as top byte
277 //could correspond an alpha channel
283 The method gets the 24 bpp pixel value pointed by aSrcPtr and copies it aCount times
284 to aDestPtr 32 bpp buffer.
287 @param aSrcPtr It points to the source pixel
288 @param aDestPtr It points to the destination buffer where the pixel should be copied aCount times
289 @param aCount How many times the pixel value should be copied
290 @return The updated aDestPtr
293 TUint8* TScanLineDecompressor<E3bpp, E4bpp>::CopyBlockPixel(TUint8* aDestPtr,
294 const TUint8* aSrcPtr,
299 *aDestPtr++ = *aSrcPtr++;
300 *aDestPtr++ = *aSrcPtr++;
301 *aDestPtr++ = *aSrcPtr++;
302 *aDestPtr++ = 0xff; //it is more accurate to equalize to 0xff, as top byte
303 //could correspond an alpha channel
309 The method should never be executed.
310 Introduced to prevent CCover compiler from failing.
312 @return The unchanged aDestPtr
315 TUint8* TScanLineDecompressor<E2bpp, E2bpp>::CopyBlockPixel(TUint8* aDestPtr,
316 const TUint8* /*aSrcPtr*/,
317 TInt /*aCount*/) const
323 The method should never be executed.
324 Introduced to prevent CCover compiler from failing.
326 @return The unchanged aDestPtr
329 TUint8* TScanLineDecompressor<E3bpp, E3bpp>::CopyBlockPixel(TUint8* aDestPtr,
330 const TUint8* /*aSrcPtr*/,
331 TInt /*aCount*/) const
337 The method should never be executed.
338 Introduced to prevent CCover compiler from failing.
340 @return The unchanged aDestPtr
343 TUint8* TScanLineDecompressor<E4bpp, E4bpp>::CopyBlockPixel(TUint8* aDestPtr,
344 const TUint8* /*aSrcPtr*/,
345 TInt /*aCount*/) const