First public contribution.
1 // Copyright (c) 2007-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 #include <graphics/lookuptable.h>
17 #include <graphics/blendingalgorithms.h>
19 #include "pixelutil.h"
20 #include "directgdiadapter.h"
21 #include "directgditypes.h"
23 TBool PixelFormatUtil::HasAlpha(TUidPixelFormat aPixelFormat)
25 const TBool hasAlpha =
26 // short circuit format equivalent to legacy TDisplayMode with alpha channel
27 aPixelFormat == EUidPixelFormatARGB_8888 ||
28 aPixelFormat == EUidPixelFormatARGB_8888_PRE ||
30 aPixelFormat == EUidPixelFormatBGRA_8888 ||
31 aPixelFormat == EUidPixelFormatABGR_8888 ||
32 aPixelFormat == EUidPixelFormatABGR_8888_PRE ||
33 aPixelFormat == EUidPixelFormatBGRA_8888_PRE ||
34 aPixelFormat == EUidPixelFormatARGB_2101010 ||
35 aPixelFormat == EUidPixelFormatABGR_2101010 ||
36 aPixelFormat == EUidPixelFormatARGB_1555 ||
37 aPixelFormat == EUidPixelFormatARGB_4444 ||
38 aPixelFormat == EUidPixelFormatARGB_8332 ||
39 aPixelFormat == EUidPixelFormatBGRA_5551 ||
40 aPixelFormat == EUidPixelFormatBGRA_4444 ||
41 aPixelFormat == EUidPixelFormatAP_88 ||
42 aPixelFormat == EUidPixelFormatA_8;
47 TUidPixelFormat PixelFormatUtil::ConvertToPixelFormat(TDisplayMode aDisplayMode)
52 return EUidPixelFormatL_1;
54 return EUidPixelFormatL_2;
56 return EUidPixelFormatL_4;
58 return EUidPixelFormatL_8;
60 return EUidPixelFormatP_4;
62 return EUidPixelFormatP_8;
64 return EUidPixelFormatXRGB_4444;
66 return EUidPixelFormatRGB_565;
68 return EUidPixelFormatRGB_888;
70 return EUidPixelFormatXRGB_8888;
72 return EUidPixelFormatARGB_8888;
74 return EUidPixelFormatARGB_8888_PRE;
76 return EUidPixelFormatUnknown;
80 TDisplayMode PixelFormatUtil::ConvertToDisplayMode(TUidPixelFormat aPixelFormat)
84 case EUidPixelFormatL_1:
86 case EUidPixelFormatL_2:
88 case EUidPixelFormatL_4:
90 case EUidPixelFormatL_8:
92 case EUidPixelFormatP_4:
94 case EUidPixelFormatP_8:
96 case EUidPixelFormatXRGB_4444:
98 case EUidPixelFormatRGB_565:
100 case EUidPixelFormatRGB_888:
102 case EUidPixelFormatXRGB_8888:
104 case EUidPixelFormatARGB_8888:
106 case EUidPixelFormatARGB_8888_PRE:
113 TInt PixelFormatUtil::BitsPerPixel(TUidPixelFormat aPixelFormat)
115 switch (aPixelFormat)
117 case EUidPixelFormatP_1:
118 case EUidPixelFormatL_1:
120 case EUidPixelFormatP_2:
121 case EUidPixelFormatL_2:
123 case EUidPixelFormatP_4:
124 case EUidPixelFormatL_4:
126 case EUidPixelFormatRGB_332:
127 case EUidPixelFormatA_8:
128 case EUidPixelFormatBGR_332:
129 case EUidPixelFormatP_8:
130 case EUidPixelFormatL_8:
132 case EUidPixelFormatRGB_565:
133 case EUidPixelFormatBGR_565:
134 case EUidPixelFormatARGB_1555:
135 case EUidPixelFormatXRGB_1555:
136 case EUidPixelFormatARGB_4444:
137 case EUidPixelFormatARGB_8332:
138 case EUidPixelFormatBGRX_5551:
139 case EUidPixelFormatBGRA_5551:
140 case EUidPixelFormatBGRA_4444:
141 case EUidPixelFormatBGRX_4444:
142 case EUidPixelFormatAP_88:
143 case EUidPixelFormatXRGB_4444:
144 case EUidPixelFormatXBGR_4444:
146 case EUidPixelFormatBGR_888:
147 case EUidPixelFormatRGB_888:
149 case EUidPixelFormatXRGB_8888:
150 case EUidPixelFormatBGRX_8888:
151 case EUidPixelFormatXBGR_8888:
152 case EUidPixelFormatBGRA_8888:
153 case EUidPixelFormatARGB_8888:
154 case EUidPixelFormatABGR_8888:
155 case EUidPixelFormatARGB_8888_PRE:
156 case EUidPixelFormatABGR_8888_PRE:
157 case EUidPixelFormatBGRA_8888_PRE:
158 case EUidPixelFormatARGB_2101010:
159 case EUidPixelFormatABGR_2101010:
162 GRAPHICS_ASSERT_DEBUG(EFalse, EDirectGdiPanicInvalidDisplayMode);
168 Create pixel buffer reader from a given pixel buffer by specifying its buffer addres and properties.
169 Supported format are:
170 -EUidPixelFormatRGB_565
171 -EUidPixelFormatXRGB_8888
172 -EUidPixelFormatARGB_8888
173 -EUidPixelFormatARGB_8888_PRE
175 TPixelBufferReader::TPixelBufferReader(const TUint32* aPixelBuffer, const TSize& aSize, TInt aStride, TUidPixelFormat aFormat):
176 iBuffer(aPixelBuffer),
181 GRAPHICS_ASSERT_DEBUG(iBuffer && iStride!=0, EDirectGdiPanicInvalidBitmap);
182 GRAPHICS_ASSERT_DEBUG(iSize.iWidth!=0 && iSize.iHeight!=0, EDirectGdiPanicOutOfBounds);
183 GRAPHICS_ASSERT_DEBUG(
184 iFormat==EUidPixelFormatRGB_565 ||
185 iFormat==EUidPixelFormatXRGB_8888 ||
186 iFormat==EUidPixelFormatARGB_8888 ||
187 iFormat==EUidPixelFormatARGB_8888_PRE,
188 EDirectGdiPanicInvalidDisplayMode);
192 Copies pixels into user buffer starting and ending based on the given read position and
193 read length (in pixels). Convert data into user pixel format if requested.
194 Copying will be done forward or backward (from a given read position) based on read direction parameter.
196 @pre TPixelBufferReader object was constructed with valid pixel buffer and its properties.
197 Starting and ending read position is within the pixel buffer area.
198 Supported read format:
200 XRGB_8888, ARGB_8888 or ARGB_8888_PRE.
201 @post Pixels copied into user buffer.
203 void TPixelBufferReader::GetScanLine(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
204 TUidPixelFormat aReadFormat, TReadDirection aReadDir) const
206 GRAPHICS_ASSERT_DEBUG(aReadPos.iX>=0 && aReadPos.iX<iSize.iWidth &&
207 aReadPos.iY>=0 && aReadPos.iY<iSize.iHeight, EDirectGdiPanicOutOfBounds);
208 GRAPHICS_ASSERT_DEBUG(
209 aReadFormat==EUidPixelFormatRGB_565 ||
210 aReadFormat==EUidPixelFormatXRGB_8888 ||
211 aReadFormat==EUidPixelFormatARGB_8888 ||
212 aReadFormat==EUidPixelFormatARGB_8888_PRE,
213 EDirectGdiPanicInvalidDisplayMode);
218 case EReadHorizontal:
219 GRAPHICS_ASSERT_DEBUG(aReadPos.iX+aReadLen<=iSize.iWidth, EDirectGdiPanicOutOfBounds);
222 case EReadHorizontalReverse:
223 GRAPHICS_ASSERT_DEBUG(aReadPos.iX-aReadLen+1>=0, EDirectGdiPanicOutOfBounds);
227 GRAPHICS_ASSERT_DEBUG(aReadPos.iY+aReadLen<=iSize.iHeight, EDirectGdiPanicOutOfBounds);
230 case EReadVerticalReverse:
231 GRAPHICS_ASSERT_DEBUG(aReadPos.iY-aReadLen+1>=0, EDirectGdiPanicOutOfBounds);
238 case EUidPixelFormatRGB_565:
239 GetScanLineRGB_565(aReadBuf, aReadPos, aReadLen, aReadDir);
241 case EUidPixelFormatXRGB_8888:
242 GetScanLineXRGB_8888(aReadBuf, aReadPos, aReadLen, aReadDir);
244 case EUidPixelFormatARGB_8888:
245 GetScanLineARGB_8888(aReadBuf, aReadPos, aReadLen, aReadDir);
247 case EUidPixelFormatARGB_8888_PRE:
248 GetScanLineARGB_8888_PRE(aReadBuf, aReadPos, aReadLen, aReadDir);
251 aReadBuf.SetLength(0);
257 Copies pixels into user buffer starting and ending based on the given read position and
258 read length (in pixels). Converts data into user pixel format and scales up or down depending
259 on the specified parameters. Copying will be done forward or backward (from a given read position)
260 based on read direction parameter.
262 @pre TPixelBufferReader object was constructed with valid pixel buffer and its properties.
263 Starting and ending read position is within the pixel buffer area.
264 Supported read format:
266 XRGB_8888, ARGB_8888 or ARGB_8888_PRE.
267 @post Pixels copied into user buffer.
269 void TPixelBufferReader::GetScaledScanLine(TDes8& aReadBuf, const TPoint& aReadPos, TInt aClipPos,
270 TInt aClipLen, TInt aDestLen, TInt aSrcLen, TUidPixelFormat aReadFormat,
271 TReadDirection aReadDir) const
273 GRAPHICS_ASSERT_DEBUG(aReadPos.iX>=0 && aReadPos.iX<iSize.iWidth &&
274 aReadPos.iY>=0 && aReadPos.iY<iSize.iHeight, EDirectGdiPanicOutOfBounds);
276 GRAPHICS_ASSERT_DEBUG(
277 aReadFormat==EUidPixelFormatRGB_565 ||
278 aReadFormat==EUidPixelFormatXRGB_8888 ||
279 aReadFormat==EUidPixelFormatARGB_8888 ||
280 aReadFormat==EUidPixelFormatARGB_8888_PRE,
281 EDirectGdiPanicInvalidDisplayMode);
283 if (aReadDir == EReadHorizontal || aReadDir == EReadHorizontalReverse)
285 GetScaledScanLineH(aReadBuf, aReadPos, aClipPos, aClipLen, aDestLen, aSrcLen, aReadFormat, aReadDir);
289 GetScaledScanLineV(aReadBuf, aReadPos, aClipPos, aClipLen, aDestLen, aSrcLen, aReadFormat, aReadDir);
294 Gets pixel address in arbitrary position within the buffer
296 const TUint32* TPixelBufferReader::GetPixelAddr(const TPoint& aPos) const
298 const TUint32* slptr = GetScanLineAddr(aPos.iY);
299 return PixelFormatUtil::BitsPerPixel(iFormat)==32? slptr+aPos.iX : (TUint32*)((TUint16*)slptr+aPos.iX);
303 Gets scanline address for a give row poisition
305 const TUint32* TPixelBufferReader::GetScanLineAddr(TInt aRow) const
307 return (iBuffer + (aRow * iStride >> 2));
311 Copies from 16-bit src to 32-bit dest
313 void TPixelBufferReader::CopyFromRGB_565(TUint32* aDstPtr, const TUint16* aSrcPtr,
314 TInt aNumOfPixels, TInt aAdvance) const
316 const TUint16* lowAdd = Convert16to32bppLow();
317 const TUint32* highAdd = Convert16to32bppHigh();
319 while (aNumOfPixels--)
321 const TUint8 low = *aSrcPtr & 0xff;
322 const TUint8 high = *aSrcPtr >> 8;
323 *aDstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
330 Calculates pixel position increment based on a given read direction and buffer pixel format.
332 TInt TPixelBufferReader::GetAdvance(TReadDirection aReadDir) const
335 // supported pixel buffer is either 16-bit or 32-bit
339 case EReadHorizontal:
342 case EReadHorizontalReverse:
346 advance = PixelFormatUtil::BitsPerPixel(iFormat)==16? iStride >> 1 : iStride >> 2;
348 case EReadVerticalReverse:
349 advance = PixelFormatUtil::BitsPerPixel(iFormat)==16? -(iStride >> 1) : -(iStride >> 2);
357 Reads and converts scanline into RGB_565.
359 void TPixelBufferReader::GetScanLineRGB_565(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
360 TReadDirection aReadDir) const
362 // read as much as buffer can hold
363 aReadLen = Min(aReadLen, aReadBuf.MaxLength() >> 1);
364 aReadBuf.SetLength(aReadLen << 1);
366 TUint16* dstPtr = (TUint16*)aReadBuf.Ptr();
367 const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
368 TInt posX = aReadPos.iX;
369 const TInt advance = GetAdvance(aReadDir);
371 // supported pixel buffer:
379 case EUidPixelFormatRGB_565:
381 const TUint16* srcPtr = (TUint16*)scanLinePtr + posX;
390 case EUidPixelFormatXRGB_8888:
392 const TUint32* srcPtr = scanLinePtr + posX;
395 *dstPtr++ = TUint16(TRgb::Color16MU(*srcPtr).Color64K());
401 case EUidPixelFormatARGB_8888:
403 const TUint32* srcPtr = scanLinePtr + posX;
406 *dstPtr++ = TUint16(TRgb::Color16MA(*srcPtr).Color64K());
412 case EUidPixelFormatARGB_8888_PRE:
414 const TUint32* srcPtr = scanLinePtr + posX;
417 *dstPtr++ = TUint16(TRgb::Color16MAP(*srcPtr).Color64K());
426 Reads and converts scanline into XRGB_8888.
428 void TPixelBufferReader::GetScanLineXRGB_8888(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
429 TReadDirection aReadDir) const
431 // read as much as buffer can hold
432 aReadLen = Min(aReadLen, aReadBuf.MaxLength() >> 2);
433 aReadBuf.SetLength(aReadLen << 2);
435 TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
436 const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
437 TInt posX = aReadPos.iX;
438 const TInt advance = GetAdvance(aReadDir);
440 // supported pixel buffer:
448 case EUidPixelFormatRGB_565:
450 const TUint16* srcPtr = (TUint16*)scanLinePtr + posX;
451 CopyFromRGB_565(dstPtr, srcPtr, aReadLen, advance);
455 case EUidPixelFormatXRGB_8888:
456 case EUidPixelFormatARGB_8888:
458 const TUint32* srcPtr = scanLinePtr + posX;
467 case EUidPixelFormatARGB_8888_PRE:
469 const TUint32* srcPtr = scanLinePtr + posX;
470 const TUint16* normTable = PtrTo16BitNormalisationTable();
473 *dstPtr++ = PMA2NonPMAPixel(*srcPtr, normTable);
482 Reads and converts scanline into ARGB_8888.
484 void TPixelBufferReader::GetScanLineARGB_8888(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
485 TReadDirection aReadDir) const
487 // read as much as buffer can hold
488 aReadLen = Min(aReadLen, aReadBuf.MaxLength() >> 2);
489 aReadBuf.SetLength(aReadLen << 2);
491 TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
492 const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
493 TInt posX = aReadPos.iX;
494 const TInt advance = GetAdvance(aReadDir);
496 // supported pixel buffer:
504 case EUidPixelFormatRGB_565:
506 const TUint16* srcPtr = (TUint16*)scanLinePtr + posX;
507 CopyFromRGB_565(dstPtr, srcPtr, aReadLen, advance);
511 case EUidPixelFormatXRGB_8888:
513 const TUint32* srcPtr = scanLinePtr + posX;
516 *dstPtr++ = 0xff000000 | *srcPtr;
522 case EUidPixelFormatARGB_8888:
524 const TUint32* srcPtr = scanLinePtr + posX;
533 case EUidPixelFormatARGB_8888_PRE:
535 const TUint32* srcPtr = scanLinePtr + posX;
536 const TUint16* normTable = PtrTo16BitNormalisationTable();
539 *dstPtr++ = PMA2NonPMAPixel(*srcPtr, normTable);
548 Read and convert scanline into ARGB_8888_PRE.
550 void TPixelBufferReader::GetScanLineARGB_8888_PRE(TDes8& aReadBuf, const TPoint& aReadPos, TInt aReadLen,
551 TReadDirection aReadDir) const
553 // read as much as buffer can hold
554 aReadLen = Min(aReadLen, aReadBuf.MaxLength() >> 2);
555 aReadBuf.SetLength(aReadLen << 2);
557 TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
558 const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
559 TInt posX = aReadPos.iX;
560 const TInt advance = GetAdvance(aReadDir);
562 // supported pixel buffer:
570 case EUidPixelFormatRGB_565:
572 const TUint16* srcPtr = (TUint16*)scanLinePtr + posX;
573 CopyFromRGB_565(dstPtr, srcPtr, aReadLen, advance);
577 case EUidPixelFormatXRGB_8888:
579 const TUint32* srcPtr = scanLinePtr + posX;
582 *dstPtr++ = 0xff000000 | *srcPtr;
588 case EUidPixelFormatARGB_8888:
590 const TUint32* srcPtr = scanLinePtr + posX;
593 TUint32 argb = *srcPtr;
602 case EUidPixelFormatARGB_8888_PRE:
604 const TUint32* srcPtr = scanLinePtr + posX;
616 Reads and scales pixels horizontally from either left or right. Converts to other pixel format if
619 void TPixelBufferReader::GetScaledScanLineH(TDes8& aReadBuf, const TPoint& aReadPos, TInt aClipDestPos,
620 TInt aClipDestLen, TInt aDestLen, TInt aSrcLen, TUidPixelFormat aReadFormat,
621 TReadDirection aReadDir) const
623 // setup DDA for scaling in X direction, use read pos as starting point and move right or left
624 // depending on the read direction
627 TPoint xPos(aReadPos.iX, 0);
628 const TPoint delta = aReadDir==EReadHorizontal? TPoint(aSrcLen, aDestLen) : TPoint(-aSrcLen, aDestLen);
629 xScaler.Construct(xPos, xPos + delta, TLinearDDA::ELeft);
631 // jump to dest X position and return the corresponding src X position
632 xPos.iY = aClipDestPos;
633 if (aClipDestPos > 0)
635 xScaler.JumpToYCoord(xPos.iX, xPos.iY);
639 xScaler.NextStep(xPos);
642 const TUint32* scanLinePtr = GetScanLineAddr(aReadPos.iY);
644 // supported pixel buffer:
650 // supported read format
658 case EUidPixelFormatRGB_565:
660 aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 1);
661 aReadBuf.SetLength(aClipDestLen << 1);
663 TUint16* dstPtr = (TUint16*)aReadBuf.Ptr();
664 TUint16* dstLimit = dstPtr + aClipDestLen;
668 case EUidPixelFormatRGB_565:
670 const TUint16* srcPtr = (TUint16*) scanLinePtr;
671 while(dstPtr < dstLimit)
673 *dstPtr++ = *(srcPtr + xPos.iX);
674 xScaler.NextStep(xPos);
679 case EUidPixelFormatXRGB_8888:
681 const TUint32* srcPtr = scanLinePtr;
682 while (dstPtr < dstLimit)
684 *dstPtr++ = TUint16(TRgb::Color16MU(*(srcPtr + xPos.iX)).Color64K());
685 xScaler.NextStep(xPos);
690 case EUidPixelFormatARGB_8888:
692 const TUint32* srcPtr = scanLinePtr;
693 while (dstPtr < dstLimit)
695 *dstPtr++ = TUint16(TRgb::Color16MA(*(srcPtr + xPos.iX)).Color64K());
696 xScaler.NextStep(xPos);
701 case EUidPixelFormatARGB_8888_PRE:
703 const TUint32* srcPtr = scanLinePtr;
704 while (dstPtr < dstLimit)
706 *dstPtr++ = TUint16(TRgb::Color16MAP(*(srcPtr + xPos.iX)).Color64K());
707 xScaler.NextStep(xPos);
715 case EUidPixelFormatXRGB_8888:
717 aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
718 aReadBuf.SetLength(aClipDestLen << 2);
720 TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
721 TUint32* dstLimit = dstPtr + aClipDestLen;
725 case EUidPixelFormatRGB_565:
727 const TUint16* srcPtr = (TUint16*)scanLinePtr;
729 const TUint16* lowAdd = Convert16to32bppLow();
730 const TUint32* highAdd = Convert16to32bppHigh();
732 while (dstPtr < dstLimit)
734 TUint16 c = *(srcPtr + xPos.iX);
735 const TUint8 low = c & 0xff;
736 const TUint8 high = c >> 8;
737 *dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
739 xScaler.NextStep(xPos);
744 case EUidPixelFormatXRGB_8888:
745 case EUidPixelFormatARGB_8888:
747 const TUint32* srcPtr = scanLinePtr;
748 while(dstPtr < dstLimit)
750 *dstPtr++ = *(srcPtr + xPos.iX);
751 xScaler.NextStep(xPos);
756 case EUidPixelFormatARGB_8888_PRE:
758 const TUint32* srcPtr = scanLinePtr;
759 const TUint16* normTable = PtrTo16BitNormalisationTable();
760 while(dstPtr < dstLimit)
762 *dstPtr++ = PMA2NonPMAPixel(*(srcPtr + xPos.iX), normTable);
763 xScaler.NextStep(xPos);
771 case EUidPixelFormatARGB_8888:
773 aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
774 aReadBuf.SetLength(aClipDestLen << 2);
776 TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
777 TUint32* dstLimit = dstPtr + aClipDestLen;
781 case EUidPixelFormatRGB_565:
783 const TUint16* srcPtr = (TUint16*)scanLinePtr;
785 const TUint16* lowAdd = Convert16to32bppLow();
786 const TUint32* highAdd = Convert16to32bppHigh();
788 while (dstPtr < dstLimit)
790 TUint16 c = *(srcPtr + xPos.iX);
791 const TUint8 low = c & 0xff;
792 const TUint8 high = c >> 8;
793 *dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
795 xScaler.NextStep(xPos);
800 case EUidPixelFormatXRGB_8888:
802 const TUint32* srcPtr = scanLinePtr;
803 while(dstPtr < dstLimit)
805 *dstPtr++ = 0xff000000 | *(srcPtr + xPos.iX);
806 xScaler.NextStep(xPos);
811 case EUidPixelFormatARGB_8888:
813 const TUint32* srcPtr = scanLinePtr;
814 while(dstPtr < dstLimit)
816 *dstPtr++ = *(srcPtr + xPos.iX);
817 xScaler.NextStep(xPos);
822 case EUidPixelFormatARGB_8888_PRE:
824 const TUint32* srcPtr = scanLinePtr;
825 const TUint16* normTable = PtrTo16BitNormalisationTable();
826 while(dstPtr < dstLimit)
828 *dstPtr++ = PMA2NonPMAPixel(*(srcPtr + xPos.iX), normTable);
829 xScaler.NextStep(xPos);
837 case EUidPixelFormatARGB_8888_PRE:
839 aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
840 aReadBuf.SetLength(aClipDestLen << 2);
842 TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
843 TUint32* dstLimit = dstPtr + aClipDestLen;
847 case EUidPixelFormatRGB_565:
849 const TUint16* srcPtr = (TUint16*)scanLinePtr;
851 const TUint16* lowAdd = Convert16to32bppLow();
852 const TUint32* highAdd = Convert16to32bppHigh();
854 while (dstPtr < dstLimit)
856 TUint16 c = *(srcPtr + xPos.iX);
857 const TUint8 low = c & 0xff;
858 const TUint8 high = c >> 8;
859 *dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
861 xScaler.NextStep(xPos);
866 case EUidPixelFormatXRGB_8888:
868 const TUint32* srcPtr = scanLinePtr;
869 while(dstPtr < dstLimit)
871 *dstPtr++ = 0xff000000 | *(srcPtr + xPos.iX);
872 xScaler.NextStep(xPos);
877 case EUidPixelFormatARGB_8888_PRE:
879 const TUint32* srcPtr = scanLinePtr;
880 while(dstPtr < dstLimit)
882 *dstPtr++ = *(srcPtr + xPos.iX);
883 xScaler.NextStep(xPos);
888 case EUidPixelFormatARGB_8888:
890 const TUint32* srcPtr = scanLinePtr;
891 while (dstPtr < dstLimit)
893 TUint32 argb = *(srcPtr + xPos.iX);
897 xScaler.NextStep(xPos);
908 Reads and scales pixels vertically from either top or bottom. Converts to other pixel format
911 void TPixelBufferReader::GetScaledScanLineV(TDes8& aReadBuf, const TPoint& aReadPos, TInt aClipDestPos,
912 TInt aClipDestLen, TInt aDestLen, TInt aSrcLen, TUidPixelFormat aReadFormat,
913 TReadDirection aReadDir) const
915 // setup DDA for scaling in Y direction, use read pos as starting point and move up or down
916 // depending on the read direction
919 TPoint yPos(aReadPos.iY, 0);
920 const TPoint delta = aReadDir==EReadVertical? TPoint(aSrcLen, aDestLen) : TPoint(-aSrcLen, aDestLen);
921 yScaler.Construct(yPos, yPos + delta, TLinearDDA::ELeft);
923 // jump to dest Y position and return the corresponding src Y position
924 yPos.iY = aClipDestPos;
925 if (aClipDestPos > 0)
927 yScaler.JumpToYCoord(yPos.iX, yPos.iY);
931 yScaler.NextStep(yPos);
934 // supported pixel buffer:
940 // supported read format
948 case EUidPixelFormatRGB_565:
950 aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 1);
951 aReadBuf.SetLength(aClipDestLen << 1);
953 TUint16* dstPtr = (TUint16*)aReadBuf.Ptr();
954 TUint16* dstLimit = dstPtr + aClipDestLen;
958 case EUidPixelFormatRGB_565:
960 const TUint16* srcPtr = (TUint16*) iBuffer + aReadPos.iX;
961 const TInt offset = iStride >> 1;
963 while(dstPtr < dstLimit)
965 *dstPtr++ = *(srcPtr + yPos.iX * offset);
966 yScaler.NextStep(yPos);
971 case EUidPixelFormatXRGB_8888:
973 const TUint32* srcPtr = iBuffer + aReadPos.iX;
974 const TInt offset = iStride >> 2;
976 while (dstPtr < dstLimit)
978 *dstPtr++ = TUint16(TRgb::Color16MU(*(srcPtr + yPos.iX * offset)).Color64K());
979 yScaler.NextStep(yPos);
984 case EUidPixelFormatARGB_8888:
986 const TUint32* srcPtr = iBuffer + aReadPos.iX;
987 const TInt offset = iStride >> 2;
989 while (dstPtr < dstLimit)
991 *dstPtr++ = TUint16(TRgb::Color16MA(*(srcPtr + yPos.iX * offset)).Color64K());
992 yScaler.NextStep(yPos);
997 case EUidPixelFormatARGB_8888_PRE:
999 const TUint32* srcPtr = iBuffer + aReadPos.iX;
1000 const TInt offset = iStride >> 2;
1002 while (dstPtr < dstLimit)
1004 *dstPtr++ = TUint16(TRgb::Color16MAP(*(srcPtr + yPos.iX * offset)).Color64K());
1005 yScaler.NextStep(yPos);
1013 case EUidPixelFormatXRGB_8888:
1015 aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
1016 aReadBuf.SetLength(aClipDestLen << 2);
1018 TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
1019 TUint32* dstLimit = dstPtr + aClipDestLen;
1023 case EUidPixelFormatRGB_565:
1025 const TUint16* srcPtr = (TUint16*)iBuffer + aReadPos.iX;
1026 const TInt offset = iStride >> 1;
1028 const TUint16* lowAdd = Convert16to32bppLow();
1029 const TUint32* highAdd = Convert16to32bppHigh();
1031 while (dstPtr < dstLimit)
1033 TUint16 c = *(srcPtr + yPos.iX * offset);
1034 const TUint8 low = c & 0xff;
1035 const TUint8 high = c >> 8;
1036 *dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
1038 yScaler.NextStep(yPos);
1043 case EUidPixelFormatXRGB_8888:
1044 case EUidPixelFormatARGB_8888:
1046 const TUint32* srcPtr = iBuffer + aReadPos.iX;
1047 const TInt offset = iStride >> 2;
1049 while(dstPtr < dstLimit)
1051 *dstPtr++ = *(srcPtr + yPos.iX * offset);
1052 yScaler.NextStep(yPos);
1057 case EUidPixelFormatARGB_8888_PRE:
1059 const TUint32* srcPtr = iBuffer + aReadPos.iX;
1060 const TInt offset = iStride >> 2;
1061 const TUint16* normTable = PtrTo16BitNormalisationTable();
1063 while(dstPtr < dstLimit)
1065 *dstPtr++ = PMA2NonPMAPixel(*(srcPtr + yPos.iX * offset), normTable);
1066 yScaler.NextStep(yPos);
1074 case EUidPixelFormatARGB_8888:
1076 aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
1077 aReadBuf.SetLength(aClipDestLen << 2);
1079 TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
1080 TUint32* dstLimit = dstPtr + aClipDestLen;
1084 case EUidPixelFormatRGB_565:
1086 const TUint16* srcPtr = (TUint16*)iBuffer + aReadPos.iX;
1087 const TInt offset = iStride >> 1;
1089 const TUint16* lowAdd = Convert16to32bppLow();
1090 const TUint32* highAdd = Convert16to32bppHigh();
1092 while (dstPtr < dstLimit)
1094 TUint16 c = *(srcPtr + yPos.iX * offset);
1095 const TUint8 low = c & 0xff;
1096 const TUint8 high = c >> 8;
1097 *dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
1099 yScaler.NextStep(yPos);
1104 case EUidPixelFormatXRGB_8888:
1106 const TUint32* srcPtr = iBuffer + aReadPos.iX;
1107 const TInt offset = iStride >> 2;
1109 while(dstPtr < dstLimit)
1111 *dstPtr++ = 0xff000000 | *(srcPtr + yPos.iX * offset);
1112 yScaler.NextStep(yPos);
1117 case EUidPixelFormatARGB_8888:
1119 const TUint32* srcPtr = iBuffer + aReadPos.iX;
1120 const TInt offset = iStride >> 2;
1122 while(dstPtr < dstLimit)
1124 *dstPtr++ = *(srcPtr + yPos.iX * offset);
1125 yScaler.NextStep(yPos);
1130 case EUidPixelFormatARGB_8888_PRE:
1132 const TUint32* srcPtr = iBuffer + aReadPos.iX;
1133 const TInt offset = iStride >> 2;
1134 const TUint16* normTable = PtrTo16BitNormalisationTable();
1136 while(dstPtr < dstLimit)
1138 *dstPtr++ = PMA2NonPMAPixel(*(srcPtr + yPos.iX * offset), normTable);
1139 yScaler.NextStep(yPos);
1147 case EUidPixelFormatARGB_8888_PRE:
1149 aClipDestLen = Min(aClipDestLen, aReadBuf.MaxLength() >> 2);
1150 aReadBuf.SetLength(aClipDestLen << 2);
1152 TUint32* dstPtr = (TUint32*)aReadBuf.Ptr();
1153 TUint32* dstLimit = dstPtr + aClipDestLen;
1157 case EUidPixelFormatRGB_565:
1159 const TUint16* srcPtr = (TUint16*)iBuffer + aReadPos.iX;
1160 const TInt offset = iStride >> 1;
1162 const TUint16* lowAdd = Convert16to32bppLow();
1163 const TUint32* highAdd = Convert16to32bppHigh();
1165 while (dstPtr < dstLimit)
1167 TUint16 c = *(srcPtr + yPos.iX * offset);
1168 const TUint8 low = c & 0xff;
1169 const TUint8 high = c >> 8;
1170 *dstPtr++ = (*(highAdd+high)) | (*(lowAdd+low));
1172 yScaler.NextStep(yPos);
1177 case EUidPixelFormatXRGB_8888:
1179 const TUint32* srcPtr = iBuffer + aReadPos.iX;
1180 const TInt offset = iStride >> 2;
1182 while(dstPtr < dstLimit)
1184 *dstPtr++ = 0xff000000 | *(srcPtr + yPos.iX * offset);
1185 yScaler.NextStep(yPos);
1190 case EUidPixelFormatARGB_8888_PRE:
1192 const TUint32* srcPtr = iBuffer + aReadPos.iX;
1193 const TInt offset = iStride >> 2;
1195 while(dstPtr < dstLimit)
1197 *dstPtr++ = *(srcPtr + yPos.iX * offset);
1198 yScaler.NextStep(yPos);
1203 case EUidPixelFormatARGB_8888:
1205 const TUint32* srcPtr = iBuffer + aReadPos.iX;
1206 const TInt offset = iStride >> 2;
1208 while (dstPtr < dstLimit)
1210 TUint32 argb = *(srcPtr + yPos.iX * offset);
1214 yScaler.NextStep(yPos);