source: trunk/src/kernel32/cvticon.cpp@ 3721

Last change on this file since 3721 was 2802, checked in by sandervl, 26 years ago

Added new logging feature

File size: 6.9 KB
Line 
1/* $Id: cvticon.cpp,v 1.8 2000-02-16 14:25:37 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#define DBG_LOCALLOG DBG_cvticon
29#include "dbglocal.h"
30
31//******************************************************************************
32//******************************************************************************
33ULONG QueryConvertedIconSize(WINBITMAPINFOHEADER *bmpHdr, int size)
34{
35 int bwsize, colorsize, rgbsize, iconsize;
36
37 bwsize = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
38 colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
39 //SvL: 28-09-'98: only for <= 8
40 if(bmpHdr->biBitCount <= 8)
41 rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2);
42 else rgbsize = 0;
43
44 switch(bmpHdr->biBitCount) {
45 case 1:
46 colorsize /= 8;
47 break;
48 case 4:
49 colorsize /= 2;
50 break;
51 case 8:
52 break;
53 case 16:
54 colorsize *= 2;
55 break;
56 case 24:
57 colorsize *= 3;
58 break;
59 case 32:
60 colorsize *= 4;
61 break;
62 }
63 if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) {
64 bmpHdr->biSizeImage = bwsize + colorsize;
65 }
66
67 //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header
68 if(bmpHdr->biSizeImage < colorsize) {
69 bmpHdr->biSizeImage = colorsize;
70 }
71 //bitmapfileheader for AndXor mask + 2 RGB structs + bitmapfileheader
72 //for color bitmap + RGB structs for all the colors
73 //SvL, 3-3-98: 2*bwsize
74 iconsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) +
75 rgbsize + 2*bwsize + bmpHdr->biSizeImage;
76
77 return iconsize;
78}
79//******************************************************************************
80//NOTE: offsetBits is the value added to the offBits bitmap structure members
81// (handy for converting icon groups)
82//******************************************************************************
83void *ConvertIcon(WINBITMAPINFOHEADER *bmpHdr, int size, int *os2size, int offsetBits)
84{
85 RGBQUAD *rgb;
86 RGB2 *os2rgb;
87 int bwsize, i, colorsize, rgbsize, iconsize;
88 BITMAPFILEHEADER2 *iconhdr;
89 BITMAPFILEHEADER2 *iconhdr2;
90 char *pAnd, *pXor;
91
92 bwsize = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
93 colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
94 //SvL: 28-09-'98: only for <= 8
95 if(bmpHdr->biBitCount <= 8)
96 rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2);
97 else rgbsize = 0;
98
99 switch(bmpHdr->biBitCount) {
100 case 1:
101 colorsize /= 8;
102 break;
103 case 4:
104 colorsize /= 2;
105 break;
106 case 8:
107 break;
108 case 16:
109 colorsize *= 2;
110 break;
111 case 24:
112 colorsize *= 3;
113 break;
114 case 32:
115 colorsize *= 4;
116 break;
117 }
118 if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) {
119 bmpHdr->biSizeImage = bwsize + colorsize;
120 }
121 dprintf2(("Icon size : %d", bmpHdr->biSizeImage));
122 dprintf2(("Icon Width : %d", bmpHdr->biWidth));
123 //height for both the XOR and AND bitmap (color & BW)
124 dprintf2(("Height : %d", bmpHdr->biHeight));
125 dprintf2(("Icon Bitcount: %d", bmpHdr->biBitCount));
126 dprintf2(("Icon Compress: %d", bmpHdr->biCompression));
127
128 //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header
129 if(bmpHdr->biSizeImage < colorsize) {
130 bmpHdr->biSizeImage = colorsize;
131 }
132 //bitmapfileheader for AndXor mask + 2 RGB structs + bitmapfileheader
133 //for color bitmap + RGB structs for all the colors
134 //SvL, 3-3-98: 2*bwsize
135 iconsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) +
136 rgbsize + 2*bwsize + bmpHdr->biSizeImage;
137
138 iconhdr = (BITMAPFILEHEADER2 *)malloc(iconsize);
139 memset(iconhdr, 0, iconsize);
140 iconhdr->usType = BFT_COLORICON;
141 iconhdr->cbSize = sizeof(BITMAPFILEHEADER2);
142 iconhdr->xHotspot = 0;
143 iconhdr->yHotspot = 0;
144 iconhdr->offBits = 2*sizeof(BITMAPFILEHEADER2) +
145 2*sizeof(RGB2) + rgbsize + offsetBits;
146 iconhdr->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
147 iconhdr->bmp2.cx = (USHORT)bmpHdr->biWidth;
148 iconhdr->bmp2.cy = (USHORT)bmpHdr->biHeight;
149 iconhdr->bmp2.cPlanes = 1;
150 iconhdr->bmp2.cBitCount= 1;
151 iconhdr->bmp2.ulCompression = BCA_UNCOMP;
152 iconhdr->bmp2.ulColorEncoding = BCE_RGB;
153 os2rgb = (RGB2 *)(iconhdr+1);
154 memset(os2rgb, 0, sizeof(RGB2));
155 memset(os2rgb+1, 0xff, sizeof(RGB)); //not reserved byte!
156 iconhdr2 = (BITMAPFILEHEADER2 *)(os2rgb+2);
157 iconhdr2->usType = BFT_COLORICON;
158 iconhdr2->cbSize = sizeof(BITMAPFILEHEADER2);
159 iconhdr2->xHotspot = 0;
160 iconhdr2->yHotspot = 0;
161 iconhdr2->offBits = 2*sizeof(BITMAPFILEHEADER2) +
162 2*sizeof(RGB2) + rgbsize + 2*bwsize + offsetBits;
163 iconhdr2->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
164 iconhdr2->bmp2.cx = (USHORT)bmpHdr->biWidth;
165 iconhdr2->bmp2.cy = (USHORT)(bmpHdr->biHeight/2);
166 iconhdr2->bmp2.cPlanes = bmpHdr->biPlanes;
167 iconhdr2->bmp2.cBitCount= bmpHdr->biBitCount;
168 iconhdr2->bmp2.ulCompression = BCA_UNCOMP;
169 iconhdr2->bmp2.ulColorEncoding = BCE_RGB;
170 os2rgb = (RGB2 *)(iconhdr2+1);
171 rgb = (RGBQUAD *)(bmpHdr+1);
172 if(bmpHdr->biBitCount <= 8) {
173 for(i=0;i<(1<<bmpHdr->biBitCount);i++) {
174 os2rgb->bRed = rgb->red;
175 os2rgb->bBlue = rgb->blue;
176 os2rgb->bGreen = rgb->green;
177 os2rgb++;
178 rgb++;
179 }
180 }
181
182 pXor = (char *)os2rgb;
183 pAnd = (char *)os2rgb + bwsize;
184
185 if ((size - (bmpHdr->biSize - rgbsize - colorsize)) == bwsize) {
186 char *q;
187 int i, linesize;
188
189 linesize = bmpHdr->biWidth / 8;
190 q = (char *)rgb + colorsize;
191 for (i = 0; i < (bmpHdr->biHeight/2); i++) {
192 memcpy (pAnd, q, linesize);
193 pAnd += linesize;
194 q += linesize;
195
196 memcpy (pXor, q, linesize);
197 pXor += linesize;
198 q += linesize;
199 }
200 } else {
201 memcpy (pAnd, (char *)rgb + colorsize, bwsize);
202 memset (pXor, 0, bwsize);
203 }
204 memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
205
206 *os2size = iconsize;
207 return (void *)iconhdr;
208}
209//******************************************************************************
210//******************************************************************************
Note: See TracBrowser for help on using the repository browser.