-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIcon.cpp
193 lines (170 loc) · 5.24 KB
/
Icon.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#include <cstdlib>
#include <cstring>
#include "Icon.hpp"
int Os2Icon::ipow(int b, int e){
int p=b;
while(--e)
p*=b;
return p;
}
void Os2Icon::setDataImage(PBYTE datos, int tamanio){
pImgData = (PBYTE)malloc(tamanio);
memcpy(pImgData, datos, tamanio);
}
void Os2Icon::setMaskData(PBYTE datos){
maskSize = getSizeMaskImage();
pMaskData = (PBYTE)calloc(maskSize*2,1);
memset(pMaskData,0,maskSize);
memcpy(pMaskData+maskSize,datos,maskSize);
}
ULONG Os2Icon::getSizeImage(){
return calcImageSize(ibih->getCx(), ibih->getCy(), ibih->getCBitCount());
}
ULONG Os2Icon::getSizeMaskImage(){
// Mask image is square and 1 bpp.
return calcImageSize(Mibih->getCx(), Mibih->getCx(), 1);
}
ULONG Os2Icon::sizePaleta(){
ULONG buffer;
int porte;
int numbits = getIbih()->getCPlanes()*getIbih()->getCBitCount();
if(numbits != 24)
porte = ipow(2,numbits);
else
porte = 0;
buffer = porte*sizeof(RGB);
return buffer;
}
void Os2Icon12::convPal(RgbQuad *bpaleta, int colores){
int i;
pPaletaColor = (RGB*)malloc(colores*sizeof(RGB));
for(i=0;i<colores;i++){
pPaletaColor[i].bRed = bpaleta[i].getBlue();
pPaletaColor[i].bGreen = bpaleta[i].getGreen();
pPaletaColor[i].bBlue = bpaleta[i].getRed();
}
}
IconBIH* Os2Icon::getIbih(){
return ibih;
}
int Os2Icon12::setPalBW(){
pPaletaBW = (RGB*)malloc(sizeof(RGB)*2);
pPaletaBW[0].bBlue = 0x00;
pPaletaBW[0].bGreen = 0x00;
pPaletaBW[0].bRed = 0x00;
pPaletaBW[1].bBlue = 0xff;
pPaletaBW[1].bGreen = 0xff;
pPaletaBW[1].bRed = 0xff;
return 0;
}
Os2Icon12::Os2Icon12(IconImage *imagenWin){
bih = new BITMAPINFOHEADER;
pArray = new BITMAPARRAYFILEHEADER;
pHead = new BITMAPFILEHEADER;
int winBpp = imagenWin->getBitsXPixel();
//No configuro la paleta de colores si es un icono de 24 bits
if(winBpp < 24)
convPal(imagenWin->getIcColors(),imagenWin->getNumColores());
setNumBitsColores(winBpp < 24 ? winBpp : 24);
setPalBW();
PBYTE dataImage = imagenWin->getIcXor();
int numBytes = imagenWin->getNumBytes();
// 32 bpp ? Then convert to 24 bpp
if(winBpp == 32)
{
PBYTE src;
PBYTE dst;
int w = imagenWin->getBitmapHeader()->getBiWidth();
int h = imagenWin->getBitmapHeader()->getBiHeight() / 2;
int srcStride = calcStride(w, 32);
int dstStride = calcStride(w, 24);
int x;
int y;
src = dataImage;
numBytes = dstStride * h;
dataImage = (PBYTE)calloc(numBytes, 1);
dst = dataImage;
for(y = 0; y < h; y++)
{
for(x = 0; x < w; x++)
{
// Consider AND map
if (imagenWin->getIcAndPixel(x, y))
{
*dst++ = 0; src++;
*dst++ = 0; src++;
*dst++ = 0; src++;
}
else
{
*dst++ = *src++;
*dst++ = *src++;
*dst++ = *src++;
}
// skip alpha value
src++;
}
// skip remains bytes
src += srcStride - w * 4; // 32 bpp
dst += dstStride - w * 3; // 24 bpp
}
}
setDataImage(dataImage, numBytes);
if(winBpp == 32)
free(dataImage);
setArray();
setDatos(imagenWin);
setXorAnd(imagenWin);
setMaskData(imagenWin->getIcAnd());
}
ULONG Os2Icon12::getSizePicture(){
ULONG size;
int n1 = sizeof(BITMAPARRAYFILEHEADER);
int n2 = sizeof(BITMAPFILEHEADER);
int n3 = sizeof(RGB);
size = n1+n2+(n3*2)+sizePaleta();
return size;
}
int Os2Icon12::setXorAnd(IconImage *datos){
// BITMAPFILEHEADER xheader = pArray->bfh;
pArray->bfh.usType = BFT_COLORICON;
pArray->bfh.cbSize = sizeof(BITMAPFILEHEADER);
pArray->bfh.xHotspot = datos->getBitmapHeader()->getBiWidth()/2;
pArray->bfh.yHotspot = datos->getBitmapHeader()->getBiHeight()/4;
pArray->bfh.offBits = 0;
pArray->bfh.bmp.cbFix = sizeof(BITMAPINFOHEADER);
pArray->bfh.bmp.cx = datos->getBitmapHeader()->getBiWidth();
pArray->bfh.bmp.cy = datos->getBitmapHeader()->getBiHeight();
pArray->bfh.bmp.cPlanes = datos->getBitmapHeader()->getBiPlanes();
pArray->bfh.bmp.cBitCount = 1;
Mibih->setIBIH(&pArray->bfh.bmp);
return 0;
}
int Os2Icon12::setDatos(IconImage *datos){
pHead->usType =0x4943;
pHead->cbSize =sizeof(BITMAPFILEHEADER);
pHead->xHotspot =datos->getBitmapHeader()->getBiWidth()/2;
pHead->yHotspot =datos->getBitmapHeader()->getBiHeight()/4;
pHead->offBits =0;
pHead->bmp.cbFix =sizeof(BITMAPINFOHEADER);
pHead->bmp.cx =datos->getBitmapHeader()->getBiWidth();
pHead->bmp.cy =datos->getBitmapHeader()->getBiHeight()/2;
pHead->bmp.cPlanes =datos->getBitmapHeader()->getBiPlanes();
// pHead->bmp.cBitCount =datos->getBitmapHeader()->getBiBitCount();
pHead->bmp.cBitCount =datos->getBitsXPixel();
if (pHead->bmp.cBitCount == 32)
pHead->bmp.cBitCount = 24;
ibih->setIBIH(&pHead->bmp);
return 0;
}
int Os2Icon12::setArray(){
pArray->usType =0x4142;
pArray->cbSize =sizeof(BITMAPARRAYFILEHEADER);
pArray->offNext =1;
pArray->cxDisplay =0;
pArray->cyDisplay =0;
return 0;
}
int Os2Icon12::getAlto(){
return pHead->bmp.cy;
}