|
1 /* |
|
2 * Copyright (c) 2005-2009 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #include "stdafx.h" |
|
23 #include "CSTATDataFormatConverter.h" |
|
24 #include "statbitmap.h" |
|
25 |
|
26 extern TRgb* color256Palette; |
|
27 extern char* color256InversePalette; |
|
28 |
|
29 TRgb* color256Palette = NULL; |
|
30 char* color256InversePalette = NULL; |
|
31 |
|
32 TRgb::TRgb() |
|
33 : iRed(255),iGreen(255),iBlue(255),iSpare(0) |
|
34 {} |
|
35 |
|
36 TRgb::TRgb(long unsigned int val) |
|
37 : iRed((unsigned char)(val&0xff)),iGreen((unsigned char)((val>>8)&0xff)),iBlue((unsigned char)((val>>16)&0xff)),iSpare(0) |
|
38 {} |
|
39 |
|
40 TRgb::TRgb(int r,int g,int b) |
|
41 : iRed((unsigned char)r),iGreen((unsigned char)g),iBlue((unsigned char)b),iSpare(0) |
|
42 {} |
|
43 |
|
44 TRgb &TRgb::operator=(const TRgb &col) |
|
45 { |
|
46 iRed=col.iRed; |
|
47 iGreen=col.iGreen; |
|
48 iBlue=col.iBlue; |
|
49 return(*this); |
|
50 } |
|
51 |
|
52 int TRgb::operator==(const TRgb &col) |
|
53 { |
|
54 return(iRed==col.iRed && iGreen==col.iGreen && iBlue==col.iBlue); |
|
55 } |
|
56 |
|
57 int TRgb::Difference(const TRgb& col) const |
|
58 { |
|
59 return abs(iRed-col.iRed) + abs(iGreen-col.iGreen) + abs(iBlue-col.iBlue); |
|
60 } |
|
61 |
|
62 int TRgb::Gray2() const |
|
63 { |
|
64 return Gray256() / 128; |
|
65 } |
|
66 |
|
67 int TRgb::Gray4() const |
|
68 { |
|
69 return Gray256() / 64; |
|
70 } |
|
71 |
|
72 int TRgb::Gray16() const |
|
73 { |
|
74 return Gray256() / 16; |
|
75 } |
|
76 |
|
77 int TRgb::Gray256() const |
|
78 { |
|
79 return((2*iRed+5*iGreen+iBlue)/8); |
|
80 } |
|
81 |
|
82 int TRgb::Color16() const |
|
83 { |
|
84 int index = (iRed >> 5) & 0x007; |
|
85 index |= (iGreen >> 2) & 0x038; |
|
86 index |= (iBlue << 1) & 0x1c0; |
|
87 return color16inverse[index]; |
|
88 } |
|
89 |
|
90 int TRgb::Color256() const |
|
91 { |
|
92 int index = (iRed >> 4) & 0x00f; |
|
93 index |= iGreen & 0x0f0; |
|
94 index |= (iBlue << 4) & 0xf00; |
|
95 |
|
96 if (color256InversePalette) |
|
97 return color256InversePalette[index]; |
|
98 else |
|
99 return color256inverse[index]; |
|
100 } |
|
101 |
|
102 int TRgb::Color4K() const |
|
103 { |
|
104 return(((iRed&0xf0)<<4)|(iGreen&0xf0)|((iBlue&0xf0)>>4)); |
|
105 } |
|
106 |
|
107 int TRgb::Color64K() const |
|
108 { |
|
109 return(((iRed&0xf8)<<8)|((iGreen&0xfc)<<3)|((iBlue&0xf8)>>3)); |
|
110 } |
|
111 |
|
112 long int TRgb::Color16M() const |
|
113 { |
|
114 return((iRed<<16)|(iGreen<<8)|iBlue); |
|
115 } |
|
116 |
|
117 TRgb TRgb::Gray2(int aGray2) |
|
118 { |
|
119 aGray2 *= 255; |
|
120 return TRgb(aGray2,aGray2,aGray2); |
|
121 } |
|
122 |
|
123 TRgb TRgb::Gray4(int aGray4) |
|
124 { |
|
125 aGray4 *= 85; |
|
126 return TRgb(aGray4,aGray4,aGray4); |
|
127 } |
|
128 |
|
129 TRgb TRgb::Gray16(int aGray16) |
|
130 { |
|
131 aGray16 *= 17; |
|
132 return TRgb(aGray16,aGray16,aGray16); |
|
133 } |
|
134 |
|
135 TRgb TRgb::Gray256(int aGray256) |
|
136 { |
|
137 return TRgb(aGray256,aGray256,aGray256); |
|
138 } |
|
139 |
|
140 TRgb TRgb::Color16(int aColor16) |
|
141 { |
|
142 return TRgb(color16array[aColor16&0xf]); |
|
143 } |
|
144 |
|
145 TRgb TRgb::Color256(int aColor256) |
|
146 { |
|
147 if (color256Palette) |
|
148 return color256Palette[aColor256&0xff]; |
|
149 else |
|
150 return TRgb(color256array[aColor256&0xff]); |
|
151 } |
|
152 |
|
153 TRgb TRgb::Color4K(int aColor4K) |
|
154 { |
|
155 return TRgb(((aColor4K>>8)&0xf)*17,((aColor4K>>4)&0xf)*17,(aColor4K&0xf)*17); |
|
156 } |
|
157 |
|
158 TRgb TRgb::Color64K(int aColor64K) |
|
159 { |
|
160 return TRgb(((aColor64K>>11)&0x1f)*255/31,((aColor64K>>5)&0x3f)*255/63,(aColor64K&0x1f)*255/31); |
|
161 } |
|
162 |
|
163 TRgb TRgb::Color16M(long int aColor16M) |
|
164 { |
|
165 return TRgb(((aColor16M>>16)&0xff),(aColor16M>>8)&0xff,aColor16M&0xff); |
|
166 } |
|
167 |