source: trunk/src/kernel32/cvtcursor.cpp@ 1570

Last change on this file since 1570 was 1475, checked in by sandervl, 26 years ago

Color cursor changes + dll loading fixes

File size: 7.8 KB
Line 
1/* $Id: cvtcursor.cpp,v 1.8 1999-10-27 10:35:41 sandervl Exp $ */
2
3/*
4 * PE2LX cursor conversion code
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
7 * Copyright 1999 Daniela Engert (dani@ngrt.de)
8 *
9 *
10 * Project Odin Software License can be found in LICENSE.TXT
11 *
12 */
13#define INCL_GPIBITMAPS
14#define INCL_BITMAPFILEFORMAT
15#define INCL_DOSFILEMGR /* File Manager values */
16#define INCL_DOSERRORS /* DOS Error values */
17#define INCL_DOSPROCESS /* DOS Process values */
18#define INCL_DOSMISC /* DOS Miscellanous values */
19#define INCL_WIN
20#include <os2wrap.h>
21#include <stdio.h>
22#include <string.h>
23#include <stdlib.h>
24#include <string.h>
25#include <win32type.h>
26#include <winicon.h>
27#include <wincursor.h>
28#include <misc.h>
29
30//******************************************************************************
31//******************************************************************************
32ULONG QueryConvertedCursorSize(CursorComponent *curHdr, int size)
33{
34 WINBITMAPINFOHEADER *bmpHdr = (WINBITMAPINFOHEADER *)(curHdr+1);
35 int bwsize, colorsize, rgbsize, cursorsize;
36
37 bwsize = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
38 colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
39
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 if(bmpHdr->biBitCount > 1) {
72 //And mask, xor mask (0) + color image
73 cursorsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) +
74 rgbsize + 2*bwsize + bmpHdr->biSizeImage;
75 }
76 else {
77 //And + xor mask
78 cursorsize = sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) + 2*bwsize;
79 }
80
81 return cursorsize;
82}
83//******************************************************************************
84//NOTE: offsetBits is the value added to the offBits bitmap structure members
85// (handy for converting cursor groups)
86//******************************************************************************
87void *ConvertCursor(CursorComponent *curHdr, int size, int *os2size, int offsetBits)
88{
89 RGBQUAD *rgb;
90 RGB2 *os2rgb;
91 WINBITMAPINFOHEADER *bmpHdr = (WINBITMAPINFOHEADER *)(curHdr+1);
92 BITMAPFILEHEADER2 *cursorhdr, *cursorhdr2;
93 int i, bwsize, bmpsize, cursorsize, rgbsize, colorsize;
94
95 dprintf(("ConvertCursor: Cursor size %d", size));
96 bwsize = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
97 colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
98
99 if(bmpHdr->biBitCount <= 8)
100 rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2);
101 else rgbsize = 0;
102
103 switch(bmpHdr->biBitCount) {
104 case 1:
105 colorsize /= 8;
106 break;
107 case 4:
108 colorsize /= 2;
109 break;
110 case 8:
111 break;
112 case 16:
113 colorsize *= 2;
114 break;
115 case 24:
116 colorsize *= 3;
117 break;
118 case 32:
119 colorsize *= 4;
120 break;
121 }
122 if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) {
123 bmpHdr->biSizeImage = bwsize + colorsize;
124 }
125
126 //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header
127 if(bmpHdr->biSizeImage < colorsize) {
128 bmpHdr->biSizeImage = colorsize;
129 }
130 if(bmpHdr->biBitCount == 1) {
131 //And + xor mask
132 cursorsize = sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) + 2*bwsize;
133 }
134 else {
135 //And mask, xor mask (0) + color image
136 cursorsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) +
137 rgbsize + 2*bwsize + bmpHdr->biSizeImage;
138 }
139
140 cursorhdr = (BITMAPFILEHEADER2 *)malloc(cursorsize);
141 memset(cursorhdr, 0, cursorsize);
142 cursorhdr->usType = BFT_POINTER;
143 cursorhdr->cbSize = sizeof(BITMAPFILEHEADER2);
144 cursorhdr->xHotspot = curHdr->xHotspot;
145
146 /* @@@PH y-hotspot is upside down ! */
147 cursorhdr->yHotspot = (bmpHdr->biHeight >> 1) /* height div 2 */
148 - curHdr->yHotspot; /* subtract hot.y */
149
150 dprintf(("Cursor Hot.x : %d", curHdr->xHotspot));
151 dprintf(("Cursor Hot.y : %d", curHdr->yHotspot));
152
153 if(bmpHdr->biBitCount == 1) {
154 cursorhdr->offBits = sizeof(BITMAPFILEHEADER2) +
155 2*sizeof(RGB2) + offsetBits;
156 }
157 else {
158 cursorhdr->offBits = 2*sizeof(BITMAPFILEHEADER2) +
159 2*sizeof(RGB2) + rgbsize + offsetBits;
160 }
161
162 cursorhdr->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
163 cursorhdr->bmp2.cx = (USHORT)bmpHdr->biWidth;
164 cursorhdr->bmp2.cy = (USHORT)(bmpHdr->biHeight);
165 cursorhdr->bmp2.cPlanes = bmpHdr->biPlanes;
166 cursorhdr->bmp2.cBitCount = 1;
167 cursorhdr->bmp2.ulCompression = BCA_UNCOMP;
168 cursorhdr->bmp2.ulColorEncoding = BCE_RGB;
169 dprintf(("Cursor size : %d", bmpHdr->biSizeImage));
170 dprintf(("Cursor Width : %d", bmpHdr->biWidth));
171 //height for both the XOR and AND bitmap (color & BW)
172 dprintf(("Height : %d", bmpHdr->biHeight));
173 dprintf(("Cursor Bitcount: %d", bmpHdr->biBitCount));
174 dprintf(("Cursor Compress: %d", bmpHdr->biCompression));
175
176 os2rgb = (RGB2 *)(cursorhdr+1);
177 rgb = (RGBQUAD *)(bmpHdr+1);
178 if(bmpHdr->biBitCount == 1) {
179 for(i=0;i<2;i++) {
180 os2rgb->bRed = rgb->red;
181 os2rgb->bBlue = rgb->blue;
182 os2rgb->bGreen = rgb->green;
183 os2rgb++;
184 rgb++;
185 }
186 //write XOR and AND mask
187 memcpy((char *)os2rgb, (char *)rgb, bwsize*2);
188 }
189 else {
190 memset(os2rgb, 0, sizeof(RGB2));
191 memset(os2rgb+1, 0xff, sizeof(RGB)); //not reserved byte!
192 cursorhdr2 = (BITMAPFILEHEADER2 *)(os2rgb+2);
193 cursorhdr2->usType = BFT_COLORICON;
194 cursorhdr2->cbSize = sizeof(BITMAPFILEHEADER2);
195 cursorhdr2->xHotspot = curHdr->xHotspot;
196 cursorhdr2->yHotspot = (bmpHdr->biHeight >> 1) /* height div 2 */
197 - curHdr->yHotspot; /* subtract hot.y */
198 cursorhdr2->offBits = 2*sizeof(BITMAPFILEHEADER2) +
199 2*sizeof(RGB2) + rgbsize + 2*bwsize + offsetBits;
200 cursorhdr2->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
201 cursorhdr2->bmp2.cx = (USHORT)bmpHdr->biWidth;
202 cursorhdr2->bmp2.cy = (USHORT)(bmpHdr->biHeight/2);
203 cursorhdr2->bmp2.cPlanes = bmpHdr->biPlanes;
204 cursorhdr2->bmp2.cBitCount= bmpHdr->biBitCount;
205 cursorhdr2->bmp2.ulCompression = BCA_UNCOMP;
206 cursorhdr2->bmp2.ulColorEncoding = BCE_RGB;
207 os2rgb = (RGB2 *)(cursorhdr2+1);
208 rgb = (RGBQUAD *)(bmpHdr+1);
209 if(bmpHdr->biBitCount <= 8) {
210 for(i=0;i<(1<<bmpHdr->biBitCount);i++) {
211 os2rgb->bRed = rgb->red;
212 os2rgb->bBlue = rgb->blue;
213 os2rgb->bGreen = rgb->green;
214 os2rgb++;
215 rgb++;
216 }
217 }
218 //write XOR and AND mask
219 char *pXor = (char *)os2rgb;
220 char *pAnd = (char *)os2rgb + bwsize;
221
222 memcpy (pAnd, (char *)rgb + colorsize, bwsize);
223 memset (pXor, 0, bwsize);
224 memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
225 }
226
227 *os2size = cursorsize;
228 return cursorhdr;
229}
230//******************************************************************************
231//******************************************************************************
Note: See TracBrowser for help on using the repository browser.