|
1 // Copyright (c) 1999-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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 #include <fbs.h> |
|
17 #include "WBMPCodec.h" |
|
18 |
|
19 |
|
20 // CWbmpReadCodec |
|
21 CWbmpReadCodec::CWbmpReadCodec(const TSize& aWbmpSize): |
|
22 iOriginalSize(aWbmpSize) |
|
23 {} |
|
24 |
|
25 CWbmpReadCodec::~CWbmpReadCodec() |
|
26 { |
|
27 } |
|
28 |
|
29 CWbmpReadCodec* CWbmpReadCodec::NewL(const TSize& aWbmpSize) |
|
30 { |
|
31 CWbmpReadCodec* self = new(ELeave) CWbmpReadCodec(aWbmpSize); |
|
32 CleanupStack::PushL(self); |
|
33 self->ConstructL(); |
|
34 CleanupStack::Pop(self); |
|
35 return self; |
|
36 } |
|
37 |
|
38 |
|
39 TFrameState CWbmpReadCodec::ProcessFrameL(TBufPtr8& aSrc) |
|
40 { |
|
41 const TUint8* srcStart = aSrc.Ptr(); |
|
42 iDataPtr = srcStart; |
|
43 iDataPtrLimit = srcStart + aSrc.Length(); |
|
44 |
|
45 DoProcessL(); |
|
46 |
|
47 TInt bytesUsed = iDataPtr - srcStart; |
|
48 aSrc.Shift(bytesUsed); |
|
49 |
|
50 iBytesProcessed += bytesUsed; |
|
51 if (iBytesProcessed >= iBytesExpected) |
|
52 { |
|
53 ImageProcessor()->FlushPixels(); |
|
54 return EFrameComplete; |
|
55 } |
|
56 |
|
57 return EFrameIncomplete; |
|
58 } |
|
59 |
|
60 void CWbmpReadCodec::DoProcessL() |
|
61 { |
|
62 CImageProcessor*const imageProc = ImageProcessor(); |
|
63 while (iDataPtr < iDataPtrLimit) |
|
64 { |
|
65 TUint8 value = *iDataPtr++; |
|
66 |
|
67 // code will compare value with successive masks 0x80, 0x40 etc downto but not including 0 |
|
68 for (TUint mask=0x80; mask!=0; mask >>= 1) |
|
69 imageProc->SetPixel((value & mask) ? KRgbWhite : KRgbBlack); |
|
70 } |
|
71 } |
|
72 |
|
73 void CWbmpReadCodec::InitFrameL(TFrameInfo& /*aFrameInfo*/, CFrameImageData& /*aFrameImageData*/, TBool aDisableErrorDiffusion, CFbsBitmap& aFrame, CFbsBitmap* /*aDestinationMask*/) |
|
74 { |
|
75 Pos().SetXY(0,0); |
|
76 |
|
77 const TSize destinationSize(aFrame.SizeInPixels()); |
|
78 TInt reductionFactor = ReductionFactor(iOriginalSize, destinationSize); |
|
79 CImageProcessor* imageProc = ImageProcessorUtility::NewImageProcessorL(aFrame, reductionFactor, EGray2, aDisableErrorDiffusion); |
|
80 SetImageProcessor(imageProc); |
|
81 imageProc->PrepareL(aFrame,iOriginalSize); |
|
82 |
|
83 iBytesProcessed = 0; |
|
84 |
|
85 // clear bitmap so partial decodes don't produce rubbish on screen |
|
86 ClearBitmapL(aFrame, KRgbWhite); |
|
87 |
|
88 TInt actualWidth = (iOriginalSize.iWidth + 7) & ~7; |
|
89 imageProc->SetPixelPadding(actualWidth - iOriginalSize.iWidth); |
|
90 iBytesExpected = (actualWidth >> 3) * iOriginalSize.iHeight; |
|
91 } |
|
92 |