|
1 /* |
|
2 * Copyright (c) 2006-2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: 1 bit format, 2 distinct color values, stored as a byte. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include "TMIDGray1Vertical.h" |
|
21 |
|
22 namespace |
|
23 { |
|
24 const TUint8 KWhite = 0; |
|
25 const TUint8 KBlack = 1; |
|
26 const TInt KBitOffset = 7; |
|
27 } |
|
28 |
|
29 void TMIDGray1Vertical::InitializeL(const TMIDBitmapParameters& aParameters) |
|
30 { |
|
31 TMIDFormatConverter::InitializeL(aParameters); |
|
32 iOffset += iTransformer.iPoint.iX + iTransformer.iPoint.iY * iScanlength; |
|
33 iBitmap = (TUint8*)aParameters.iPixels; |
|
34 } |
|
35 |
|
36 TUint32 TMIDGray1Vertical::ConvertInternal(const TMIDInternalARGB& aInternal) |
|
37 { |
|
38 if ((aInternal.iR + aInternal.iG + aInternal.iB) < |
|
39 KWhiteBlackSumRGBMidValue) |
|
40 { |
|
41 // return 'on' (black) |
|
42 return KBlack; |
|
43 } |
|
44 else |
|
45 { |
|
46 // return 'off' (white) |
|
47 return KWhite; |
|
48 } |
|
49 } |
|
50 |
|
51 void TMIDGray1Vertical::Convert(TMIDInternalARGB& aResult, TUint32 aColor) const |
|
52 { |
|
53 aResult.iA = KAlphaFullOpaque; |
|
54 if (aColor == KWhite) |
|
55 { |
|
56 aResult.iR = KAlphaFullOpaque; |
|
57 aResult.iG = KAlphaFullOpaque; |
|
58 aResult.iB = KAlphaFullOpaque; |
|
59 } |
|
60 else |
|
61 { |
|
62 aResult.iR = 0; |
|
63 aResult.iG = 0; |
|
64 aResult.iB = 0; |
|
65 } |
|
66 } |
|
67 |
|
68 void TMIDGray1Vertical::GetPixel(TMIDInternalARGB& aResult) const |
|
69 { |
|
70 // calculate byte, which contains pixel bit |
|
71 TInt y((iOffset - iOffset % iScanlength) / (iScanlength << KGray1VerticalShift)); |
|
72 |
|
73 TUint8 bit = (TUint8)((iOffset / iScanlength) & KGray1VerticalAnd); |
|
74 |
|
75 TInt position(y * iScanlength + iOffset % iScanlength); |
|
76 |
|
77 Convert(aResult, (iBitmap[ position ] >> bit) & 1); // CSI: 2 Wrong index means implementation error # |
|
78 } |
|
79 |
|
80 |
|
81 TUint8 TMIDGray1Vertical::GetAlpha() const |
|
82 { |
|
83 // calculate byte, which contains pixel bit |
|
84 TInt y((iOffset - iOffset % iScanlength) / (iScanlength << KGray1VerticalShift)); |
|
85 |
|
86 TUint8 bit = (TUint8)((iOffset / iScanlength) & KGray1VerticalAnd); |
|
87 |
|
88 TInt position(y * iScanlength + iOffset % iScanlength); |
|
89 |
|
90 return (TUint8)(((((TUint8*)iAlphaBitmap)[ position ] >> bit) & 1) * KAlphaFullOpaque); // CSI: 2 Wrong index means implementation error # |
|
91 } |
|
92 |
|
93 void TMIDGray1Vertical::PlotPixel(const TMIDInternalARGB& aInternal) |
|
94 { |
|
95 |
|
96 TInt y((iOffset - iOffset % iScanlength) / |
|
97 (iScanlength << KGray1VerticalShift)); |
|
98 |
|
99 TUint8 bit = (TUint8)(KBitOffset - |
|
100 ((iOffset / iScanlength) & KGray1VerticalAnd)); |
|
101 |
|
102 TInt position(y * iScanlength + iOffset % iScanlength); |
|
103 if (ConvertInternal(aInternal) == KBlack) |
|
104 { |
|
105 // black |
|
106 iBitmap[ position ] = (TUint8)(iBitmap[ position ] | KBits[ bit ]); // CSI: 2 Wrong index means implementation error # |
|
107 } |
|
108 else |
|
109 { |
|
110 // white |
|
111 iBitmap[ position ] = (TUint8)(iBitmap[ position ] & ~KBits[ bit ]); // CSI: 2 Wrong index means implementation error # |
|
112 } |
|
113 } |
|
114 |
|
115 void TMIDGray1Vertical::PlotPixelWithAlpha(const TMIDInternalARGB& aInternal) |
|
116 { |
|
117 PlotPixel(aInternal); |
|
118 |
|
119 // modifying alpha channel |
|
120 if (iAlphaBitmap) |
|
121 { |
|
122 if (iAlphaMode == EGray256) |
|
123 { |
|
124 ((TUint8*)iAlphaBitmap)[ iOffset ] = aInternal.iA; // CSI: 2 Wrong index means implementation error # |
|
125 } |
|
126 else |
|
127 { |
|
128 // otherwise we have same format as normal bitmap |
|
129 // getting real bitmap from converter |
|
130 TUint32* tempBitmap = Bitmap(); |
|
131 SetBitmap(iAlphaBitmap); |
|
132 |
|
133 // It must be either white or black |
|
134 // NOTE: This is just opposite way than |
|
135 // normal alpha since 0 (black) is 'on' |
|
136 // and 1 (white) is 'off' |
|
137 TMIDInternalARGB alphaIn; |
|
138 if (aInternal.iA != KAlphaFullOpaque) |
|
139 { |
|
140 alphaIn = KOpaque; |
|
141 } |
|
142 PlotPixel(alphaIn); |
|
143 |
|
144 // reverting to original bitmap |
|
145 SetBitmap(tempBitmap); |
|
146 } |
|
147 } |
|
148 } |
|
149 |
|
150 TBool TMIDGray1Vertical::CheckSize(TInt aPixelSize, TInt aLastDrawnPixelOffset) |
|
151 { |
|
152 if (aLastDrawnPixelOffset <= aPixelSize * KPixelsInByteGray1Vertical) |
|
153 { |
|
154 return ETrue; // there's enough space |
|
155 } |
|
156 return EFalse; // there's not enough space |
|
157 } |