|
1 /* |
|
2 * Copyright (c) 2002-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: Converts basic icon to CFbsBitmap |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <fbs.h> |
|
20 #include <gdi.h> |
|
21 #include "CSatSBasicIconConverter.h" |
|
22 #include "TSatBitOP.h" |
|
23 #include "SatLog.h" |
|
24 |
|
25 // Black&white icon uses 1 bpp. |
|
26 const TUint8 KBpp = 1; |
|
27 |
|
28 // Black&white icon header size is 2. |
|
29 const TUint8 KHeaderSize( 2 ); |
|
30 |
|
31 // Value of icon data, which means that pixel is lit. |
|
32 const TInt KPixelIsLit = 1; |
|
33 const TUint KBitCount( 8 ); |
|
34 |
|
35 // ======== MEMBER FUNCTIONS ======== |
|
36 |
|
37 // ----------------------------------------------------------------------------- |
|
38 // CSatSBasicIconConverter::CSatSBasicIconConverter |
|
39 // C++ default constructor can NOT contain any code, that |
|
40 // might leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 CSatSBasicIconConverter::CSatSBasicIconConverter() : |
|
44 CSatSIconConverter() |
|
45 { |
|
46 LOG( SIMPLE, "SATENGINE: \ |
|
47 CSatSBasicIconConverter::CSatSBasicIconConverter calling - exiting" ) |
|
48 } |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CSatSBasicIconConverter::ConvertL |
|
52 // Converts the basic icon format (ETSI TS 131 102 V4.10.0) to CFbsBitmap |
|
53 // The format of aData has to be following: |
|
54 // 1st byte: Image width |
|
55 // 2nd byte: Image height |
|
56 // 3rd byte to end: Image body. |
|
57 // Image body has to be in following format: |
|
58 // Bit 8: 1st pixel |
|
59 // Bit 7: 2nd pixel |
|
60 // Bit 6: 3rd pixel |
|
61 // etc... |
|
62 // |
|
63 // Clut is not needed for converting basic icon. |
|
64 // (other items were commented in a header). |
|
65 // ----------------------------------------------------------------------------- |
|
66 // |
|
67 CFbsBitmap* CSatSBasicIconConverter::ConvertL( |
|
68 const TDesC8& aData, |
|
69 const TDesC8& /*aClut*/ ) const |
|
70 { |
|
71 LOG( SIMPLE, "SATENGINE: CSatSBasicIconConverter::ConvertL calling" ) |
|
72 |
|
73 CheckDataValidityL( aData ); |
|
74 const TUint8 width( aData[0] ); |
|
75 const TUint8 height( aData[1] ); |
|
76 |
|
77 // Create black and white bitmap. |
|
78 CFbsBitmap* bitmap = CreateBitmapL( width, height, EGray2 ); |
|
79 |
|
80 // Extract the header information away from icon data. |
|
81 const TPtrC8 iconData( |
|
82 aData.Mid( KHeaderSize, aData.Length() - KHeaderSize ) ); |
|
83 |
|
84 TBitmapUtil bitmapUtil( bitmap ); |
|
85 bitmapUtil.Begin( TPoint( 0, 0 ) ); |
|
86 TInt x( 0 ); |
|
87 TInt y( 0 ); |
|
88 // Convert the icon data. |
|
89 for ( y = 0; y < height; y++ ) |
|
90 { |
|
91 bitmapUtil.SetPos( TPoint( 0, y ) ); |
|
92 for ( x = 0; x < width; x++ ) |
|
93 { |
|
94 const TInt startingBit( y * width + x ); |
|
95 const TUint8 color = |
|
96 TSatBitOP::ExtractBits( startingBit, KBpp, iconData ); |
|
97 |
|
98 if ( KPixelIsLit == color ) |
|
99 { |
|
100 // Black is lit pixel. |
|
101 bitmapUtil.SetPixel( KRgbBlack.Value() ); |
|
102 } |
|
103 else |
|
104 { |
|
105 // White means no pixel. |
|
106 bitmapUtil.SetPixel( KRgbWhite.Value() ); |
|
107 } |
|
108 |
|
109 bitmapUtil.IncXPos(); |
|
110 } |
|
111 } |
|
112 |
|
113 bitmapUtil.End(); |
|
114 LOG3( SIMPLE,"SATENGINE: CSatSBasicIconConverter::ConvertL, \ |
|
115 x: %d, y: %d", x, y ) |
|
116 LOG( SIMPLE, "SATENGINE: CSatSBasicIconConverter::ConvertL exiting" ) |
|
117 return bitmap; |
|
118 } |
|
119 |
|
120 // ----------------------------------------------------------------------------- |
|
121 // CSatSBasicIconConverter::CheckDataValidityL |
|
122 // Checks that icon data has valid length. |
|
123 // (other items were commented in a header). |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CSatSBasicIconConverter::CheckDataValidityL( const TDesC8& aData ) const |
|
127 { |
|
128 LOG( SIMPLE, |
|
129 "SATENGINE: CSatSBasicIconConverter::CheckDataValidityL calling" ) |
|
130 |
|
131 TInt err( KErrNone ); |
|
132 |
|
133 // Is there at least width and height in aData. |
|
134 const TInt dataLength( aData.Length() ); |
|
135 |
|
136 if ( dataLength > KHeaderSize ) |
|
137 { |
|
138 LOG( SIMPLE, "SATENGINE: CSatSBasicIconConverter::CheckDataValidityL \ |
|
139 dataLength bigger than KHeaderSize" ) |
|
140 const TUint8 width( aData[0] ); |
|
141 const TUint8 height( aData[1] ); |
|
142 |
|
143 // Width and height does not belong to image body. |
|
144 const TInt imageBodyLength( dataLength - KHeaderSize ); |
|
145 |
|
146 // Check that image body has at least as many |
|
147 // bits than width and height succest. There might |
|
148 // be more bits because the actual size of the image |
|
149 // body may occupie only couple bits from |
|
150 // last byte in image body. |
|
151 const TInt bitsInImageBody( imageBodyLength * KBitCount ); |
|
152 const TInt bitsExpectedInImageBody( width * height ); |
|
153 |
|
154 if ( bitsInImageBody < bitsExpectedInImageBody ) |
|
155 { |
|
156 LOG( SIMPLE, "SATENGINE: CSatSBasicIconConverter::\ |
|
157 CheckDataValidityL bitsInImageBody < bitsExpectedInImageBody" ) |
|
158 err = KErrCorrupt; |
|
159 } |
|
160 } |
|
161 else |
|
162 { |
|
163 LOG( SIMPLE, "SATENGINE: CSatSBasicIconConverter::CheckDataValidityL \ |
|
164 dataLength less than KHeaderSize" ) |
|
165 err = KErrCorrupt; |
|
166 } |
|
167 |
|
168 User::LeaveIfError( err ); |
|
169 LOG( SIMPLE, |
|
170 "SATENGINE: CSatSBasicIconConverter::CheckDataValidityL exiting" ) |
|
171 } |
|
172 |
|
173 // End of File |