1 | /* $Id: cvticon.cpp,v 1.4 1999-09-21 08:24:53 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * PE2LX icons
|
---|
5 | *
|
---|
6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | *
|
---|
8 | *
|
---|
9 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
10 | *
|
---|
11 | */
|
---|
12 | #define INCL_GPIBITMAPS
|
---|
13 | #define INCL_BITMAPFILEFORMAT
|
---|
14 | #define INCL_DOSFILEMGR /* File Manager values */
|
---|
15 | #define INCL_DOSERRORS /* DOS Error values */
|
---|
16 | #define INCL_DOSPROCESS /* DOS Process values */
|
---|
17 | #define INCL_DOSMISC /* DOS Miscellanous values */
|
---|
18 | #define INCL_WIN
|
---|
19 | #include <os2wrap.h>
|
---|
20 | #include <stdio.h>
|
---|
21 | #include <string.h>
|
---|
22 | #include <stdlib.h>
|
---|
23 | #include <string.h>
|
---|
24 | #include <win32type.h>
|
---|
25 | #include <winicon.h>
|
---|
26 | #include <misc.h>
|
---|
27 |
|
---|
28 | //******************************************************************************
|
---|
29 | //******************************************************************************
|
---|
30 | ULONG QueryConvertedIconSize(WINBITMAPINFOHEADER *bmpHdr, int size)
|
---|
31 | {
|
---|
32 | int bwsize, colorsize, rgbsize, iconsize;
|
---|
33 |
|
---|
34 | bwsize = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
|
---|
35 | colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
|
---|
36 | //SvL: 28-09-'98: only for <= 8
|
---|
37 | if(bmpHdr->biBitCount <= 8)
|
---|
38 | rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2);
|
---|
39 | else rgbsize = 0;
|
---|
40 |
|
---|
41 | switch(bmpHdr->biBitCount) {
|
---|
42 | case 1:
|
---|
43 | colorsize /= 8;
|
---|
44 | break;
|
---|
45 | case 4:
|
---|
46 | colorsize /= 2;
|
---|
47 | break;
|
---|
48 | case 8:
|
---|
49 | break;
|
---|
50 | case 16:
|
---|
51 | colorsize *= 2;
|
---|
52 | break;
|
---|
53 | case 24:
|
---|
54 | colorsize *= 3;
|
---|
55 | break;
|
---|
56 | case 32:
|
---|
57 | colorsize *= 4;
|
---|
58 | break;
|
---|
59 | }
|
---|
60 | if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) {
|
---|
61 | bmpHdr->biSizeImage = bwsize + colorsize;
|
---|
62 | }
|
---|
63 |
|
---|
64 | //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header
|
---|
65 | if(bmpHdr->biSizeImage < colorsize) {
|
---|
66 | bmpHdr->biSizeImage = colorsize;
|
---|
67 | }
|
---|
68 | //bitmapfileheader for AndXor mask + 2 RGB structs + bitmapfileheader
|
---|
69 | //for color bitmap + RGB structs for all the colors
|
---|
70 | //SvL, 3-3-98: 2*bwsize
|
---|
71 | iconsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) +
|
---|
72 | rgbsize + 2*bwsize + bmpHdr->biSizeImage;
|
---|
73 |
|
---|
74 | return iconsize;
|
---|
75 | }
|
---|
76 | //******************************************************************************
|
---|
77 | //NOTE: offsetBits is the value added to the offBits bitmap structure members
|
---|
78 | // (handy for converting icon groups)
|
---|
79 | //******************************************************************************
|
---|
80 | void *ConvertIcon(WINBITMAPINFOHEADER *bmpHdr, int size, int *os2size, int offsetBits)
|
---|
81 | {
|
---|
82 | RGBQUAD *rgb;
|
---|
83 | RGB2 *os2rgb;
|
---|
84 | int bwsize, i, colorsize, rgbsize, iconsize;
|
---|
85 | BITMAPFILEHEADER2 *iconhdr;
|
---|
86 | BITMAPFILEHEADER2 *iconhdr2;
|
---|
87 |
|
---|
88 | bwsize = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
|
---|
89 | colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
|
---|
90 | //SvL: 28-09-'98: only for <= 8
|
---|
91 | if(bmpHdr->biBitCount <= 8)
|
---|
92 | rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2);
|
---|
93 | else rgbsize = 0;
|
---|
94 |
|
---|
95 | switch(bmpHdr->biBitCount) {
|
---|
96 | case 1:
|
---|
97 | colorsize /= 8;
|
---|
98 | break;
|
---|
99 | case 4:
|
---|
100 | colorsize /= 2;
|
---|
101 | break;
|
---|
102 | case 8:
|
---|
103 | break;
|
---|
104 | case 16:
|
---|
105 | colorsize *= 2;
|
---|
106 | break;
|
---|
107 | case 24:
|
---|
108 | colorsize *= 3;
|
---|
109 | break;
|
---|
110 | case 32:
|
---|
111 | colorsize *= 4;
|
---|
112 | break;
|
---|
113 | }
|
---|
114 | if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) {
|
---|
115 | bmpHdr->biSizeImage = bwsize + colorsize;
|
---|
116 | }
|
---|
117 | dprintf(("Icon size : %d", bmpHdr->biSizeImage));
|
---|
118 | dprintf(("Icon Width : %d", bmpHdr->biWidth));
|
---|
119 | //height for both the XOR and AND bitmap (color & BW)
|
---|
120 | dprintf(("Height : %d", bmpHdr->biHeight));
|
---|
121 | dprintf(("Icon Bitcount: %d", bmpHdr->biBitCount));
|
---|
122 | dprintf(("Icon Compress: %d", bmpHdr->biCompression));
|
---|
123 |
|
---|
124 | //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header
|
---|
125 | if(bmpHdr->biSizeImage < colorsize) {
|
---|
126 | bmpHdr->biSizeImage = colorsize;
|
---|
127 | }
|
---|
128 | //bitmapfileheader for AndXor mask + 2 RGB structs + bitmapfileheader
|
---|
129 | //for color bitmap + RGB structs for all the colors
|
---|
130 | //SvL, 3-3-98: 2*bwsize
|
---|
131 | iconsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) +
|
---|
132 | rgbsize + 2*bwsize + bmpHdr->biSizeImage;
|
---|
133 |
|
---|
134 | iconhdr = (BITMAPFILEHEADER2 *)malloc(iconsize);
|
---|
135 | memset(iconhdr, 0, iconsize);
|
---|
136 | iconhdr->usType = BFT_COLORICON;
|
---|
137 | iconhdr->cbSize = sizeof(BITMAPFILEHEADER2);
|
---|
138 | iconhdr->xHotspot = 0;
|
---|
139 | iconhdr->yHotspot = 0;
|
---|
140 | iconhdr->offBits = 2*sizeof(BITMAPFILEHEADER2) +
|
---|
141 | 2*sizeof(RGB2) + rgbsize + offsetBits;
|
---|
142 | iconhdr->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
|
---|
143 | iconhdr->bmp2.cx = (USHORT)bmpHdr->biWidth;
|
---|
144 | iconhdr->bmp2.cy = (USHORT)bmpHdr->biHeight;
|
---|
145 | iconhdr->bmp2.cPlanes = 1;
|
---|
146 | iconhdr->bmp2.cBitCount= 1;
|
---|
147 | iconhdr->bmp2.ulCompression = BCA_UNCOMP;
|
---|
148 | iconhdr->bmp2.ulColorEncoding = BCE_RGB;
|
---|
149 | os2rgb = (RGB2 *)(iconhdr+1);
|
---|
150 | memset(os2rgb, 0, sizeof(RGB2));
|
---|
151 | memset(os2rgb+1, 0xff, sizeof(RGB)); //not reserved byte!
|
---|
152 | iconhdr2 = (BITMAPFILEHEADER2 *)(os2rgb+2);
|
---|
153 | iconhdr2->usType = BFT_COLORICON;
|
---|
154 | iconhdr2->cbSize = sizeof(BITMAPFILEHEADER2);
|
---|
155 | iconhdr2->xHotspot = 0;
|
---|
156 | iconhdr2->yHotspot = 0;
|
---|
157 | iconhdr2->offBits = 2*sizeof(BITMAPFILEHEADER2) +
|
---|
158 | 2*sizeof(RGB2) + rgbsize + 2*bwsize + offsetBits;
|
---|
159 | iconhdr2->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
|
---|
160 | iconhdr2->bmp2.cx = (USHORT)bmpHdr->biWidth;
|
---|
161 | iconhdr2->bmp2.cy = (USHORT)(bmpHdr->biHeight/2);
|
---|
162 | iconhdr2->bmp2.cPlanes = bmpHdr->biPlanes;
|
---|
163 | iconhdr2->bmp2.cBitCount= bmpHdr->biBitCount;
|
---|
164 | iconhdr2->bmp2.ulCompression = BCA_UNCOMP;
|
---|
165 | iconhdr2->bmp2.ulColorEncoding = BCE_RGB;
|
---|
166 | os2rgb = (RGB2 *)(iconhdr2+1);
|
---|
167 | rgb = (RGBQUAD *)(bmpHdr+1);
|
---|
168 | if(bmpHdr->biBitCount < 24) {
|
---|
169 | for(i=0;i<(1<<bmpHdr->biBitCount);i++) {
|
---|
170 | os2rgb->bRed = rgb->red;
|
---|
171 | os2rgb->bBlue = rgb->blue;
|
---|
172 | os2rgb->bGreen = rgb->green;
|
---|
173 | os2rgb++;
|
---|
174 | rgb++;
|
---|
175 | }
|
---|
176 | }
|
---|
177 | //write 2*mono pixels + color pixels
|
---|
178 | //There are icons without an AND mask, so check for it
|
---|
179 | if(bmpHdr->biSizeImage == colorsize)
|
---|
180 | {
|
---|
181 | memset((char *)os2rgb, 0, bwsize);
|
---|
182 | memset((char *)os2rgb+bwsize, 0, bwsize);
|
---|
183 | memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
|
---|
184 | }
|
---|
185 | else {
|
---|
186 | memset((char *)os2rgb, 0, bwsize); // windows has no xor mask
|
---|
187 | memcpy((char *)os2rgb+bwsize, (char *)rgb+colorsize, bwsize); // and-mask
|
---|
188 | memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize); // color(xor-mask)
|
---|
189 |
|
---|
190 | // memcpy((char *)os2rgb, (char *)rgb+colorsize, bwsize);
|
---|
191 | // memcpy((char *)os2rgb+bwsize, (char *)rgb+colorsize, bwsize);
|
---|
192 | // memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
|
---|
193 | }
|
---|
194 | *os2size = iconsize;
|
---|
195 | return (void *)iconhdr;
|
---|
196 | }
|
---|
197 | //******************************************************************************
|
---|
198 | //******************************************************************************
|
---|