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

Last change on this file since 5386 was 5386, checked in by sandervl, 24 years ago

removed cursor(group) conversion code

File size: 7.9 KB
Line 
1/* $Id: cvtcursor.cpp,v 1.11 2001-03-27 16:18:26 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#define DBG_LOCALLOG DBG_cvtcursor
31#include "dbglocal.h"
32
33//******************************************************************************
34//******************************************************************************
35ULONG QueryConvertedCursorSize(CursorComponent *curHdr, int size)
36{
37 WINBITMAPINFOHEADER *bmpHdr = (WINBITMAPINFOHEADER *)(curHdr+1);
38 int bwsize, colorsize, rgbsize, cursorsize;
39 ULONG biSizeImage;
40
41 bwsize = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
42 colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
43
44 if(bmpHdr->biBitCount <= 8)
45 rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2);
46 else rgbsize = 0;
47
48 switch(bmpHdr->biBitCount) {
49 case 1:
50 colorsize /= 8;
51 break;
52 case 4:
53 colorsize /= 2;
54 break;
55 case 8:
56 break;
57 case 16:
58 colorsize *= 2;
59 break;
60 case 24:
61 colorsize *= 3;
62 break;
63 case 32:
64 colorsize *= 4;
65 break;
66 }
67 if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) {
68 biSizeImage = bwsize + colorsize;
69 }
70 else biSizeImage = bmpHdr->biSizeImage;
71
72 //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header
73 if(biSizeImage < colorsize) {
74 biSizeImage = colorsize;
75 }
76
77 if(bmpHdr->biBitCount > 1) {
78 //And mask, xor mask (0) + color image
79 cursorsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) +
80 rgbsize + 2*bwsize + biSizeImage;
81 }
82 else {
83 //And + xor mask
84 cursorsize = sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) + 2*bwsize;
85 }
86
87 return cursorsize;
88}
89//******************************************************************************
90//NOTE: offsetBits is the value added to the offBits bitmap structure members
91// (handy for converting cursor groups)
92//******************************************************************************
93void *ConvertCursor(CursorComponent *curHdr, int size, int *os2size, int offsetBits)
94{
95 RGBQUAD *rgb;
96 RGB2 *os2rgb;
97 WINBITMAPINFOHEADER *bmpHdr = (WINBITMAPINFOHEADER *)(curHdr+1);
98 BITMAPFILEHEADER2 *cursorhdr, *cursorhdr2;
99 int i, bwsize, bmpsize, cursorsize, rgbsize, colorsize;
100 ULONG biSizeImage;
101
102 dprintf(("ConvertCursor: Cursor size %d", size));
103 bwsize = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
104 colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
105
106 if(bmpHdr->biBitCount <= 8)
107 rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2);
108 else rgbsize = 0;
109
110 switch(bmpHdr->biBitCount) {
111 case 1:
112 colorsize /= 8;
113 break;
114 case 4:
115 colorsize /= 2;
116 break;
117 case 8:
118 break;
119 case 16:
120 colorsize *= 2;
121 break;
122 case 24:
123 colorsize *= 3;
124 break;
125 case 32:
126 colorsize *= 4;
127 break;
128 }
129 if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) {
130 biSizeImage = bwsize + colorsize;
131 }
132 else biSizeImage = bmpHdr->biSizeImage;
133
134 //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header
135 if(biSizeImage < colorsize) {
136 biSizeImage = colorsize;
137 }
138
139 if(bmpHdr->biBitCount == 1) {
140 //And + xor mask
141 cursorsize = sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) + 2*bwsize;
142 }
143 else {
144 //And mask, xor mask (0) + color image
145 cursorsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) +
146 rgbsize + 2*bwsize + biSizeImage;
147 }
148
149 cursorhdr = (BITMAPFILEHEADER2 *)malloc(cursorsize);
150 memset(cursorhdr, 0, cursorsize);
151 cursorhdr->usType = BFT_POINTER;
152 cursorhdr->cbSize = sizeof(BITMAPFILEHEADER2);
153 cursorhdr->xHotspot = curHdr->xHotspot;
154
155 /* @@@PH y-hotspot is upside down ! */
156 cursorhdr->yHotspot = (bmpHdr->biHeight >> 1) /* height div 2 */
157 - curHdr->yHotspot; /* subtract hot.y */
158
159 dprintf2(("Cursor Hot.x : %d", curHdr->xHotspot));
160 dprintf2(("Cursor Hot.y : %d", curHdr->yHotspot));
161
162 if(bmpHdr->biBitCount == 1) {
163 cursorhdr->offBits = sizeof(BITMAPFILEHEADER2) +
164 2*sizeof(RGB2) + offsetBits;
165 }
166 else {
167 cursorhdr->offBits = 2*sizeof(BITMAPFILEHEADER2) +
168 2*sizeof(RGB2) + rgbsize + offsetBits;
169 }
170
171 cursorhdr->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
172 cursorhdr->bmp2.cx = (USHORT)bmpHdr->biWidth;
173 cursorhdr->bmp2.cy = (USHORT)(bmpHdr->biHeight);
174 cursorhdr->bmp2.cPlanes = bmpHdr->biPlanes;
175 cursorhdr->bmp2.cBitCount = 1;
176 cursorhdr->bmp2.ulCompression = BCA_UNCOMP;
177 cursorhdr->bmp2.ulColorEncoding = BCE_RGB;
178 dprintf2(("Cursor size : %d", biSizeImage));
179 dprintf2(("Cursor Width : %d", bmpHdr->biWidth));
180 //height for both the XOR and AND bitmap (color & BW)
181 dprintf2(("Height : %d", bmpHdr->biHeight));
182 dprintf2(("Cursor Bitcount: %d", bmpHdr->biBitCount));
183 dprintf2(("Cursor Compress: %d", bmpHdr->biCompression));
184
185 os2rgb = (RGB2 *)(cursorhdr+1);
186 rgb = (RGBQUAD *)(bmpHdr+1);
187 if(bmpHdr->biBitCount == 1) {
188 for(i=0;i<2;i++) {
189 os2rgb->bRed = rgb->red;
190 os2rgb->bBlue = rgb->blue;
191 os2rgb->bGreen = rgb->green;
192 os2rgb++;
193 rgb++;
194 }
195 //write XOR and AND mask
196 memcpy((char *)os2rgb, (char *)rgb, bwsize*2);
197 }
198 else {
199 memset(os2rgb, 0, sizeof(RGB2));
200 memset(os2rgb+1, 0xff, sizeof(RGB)); //not reserved byte!
201 cursorhdr2 = (BITMAPFILEHEADER2 *)(os2rgb+2);
202 cursorhdr2->usType = BFT_COLORICON;
203 cursorhdr2->cbSize = sizeof(BITMAPFILEHEADER2);
204 cursorhdr2->xHotspot = curHdr->xHotspot;
205 cursorhdr2->yHotspot = (bmpHdr->biHeight >> 1) /* height div 2 */
206 - curHdr->yHotspot; /* subtract hot.y */
207 cursorhdr2->offBits = 2*sizeof(BITMAPFILEHEADER2) +
208 2*sizeof(RGB2) + rgbsize + 2*bwsize + offsetBits;
209 cursorhdr2->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
210 cursorhdr2->bmp2.cx = (USHORT)bmpHdr->biWidth;
211 cursorhdr2->bmp2.cy = (USHORT)(bmpHdr->biHeight/2);
212 cursorhdr2->bmp2.cPlanes = bmpHdr->biPlanes;
213 cursorhdr2->bmp2.cBitCount= bmpHdr->biBitCount;
214 cursorhdr2->bmp2.ulCompression = BCA_UNCOMP;
215 cursorhdr2->bmp2.ulColorEncoding = BCE_RGB;
216 os2rgb = (RGB2 *)(cursorhdr2+1);
217 rgb = (RGBQUAD *)(bmpHdr+1);
218 if(bmpHdr->biBitCount <= 8) {
219 for(i=0;i<(1<<bmpHdr->biBitCount);i++) {
220 os2rgb->bRed = rgb->red;
221 os2rgb->bBlue = rgb->blue;
222 os2rgb->bGreen = rgb->green;
223 os2rgb++;
224 rgb++;
225 }
226 }
227 //write XOR and AND mask
228 char *pXor = (char *)os2rgb;
229 char *pAnd = (char *)os2rgb + bwsize;
230
231 memcpy (pAnd, (char *)rgb + colorsize, bwsize);
232 memset (pXor, 0, bwsize);
233 memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
234 }
235
236 *os2size = cursorsize;
237 return cursorhdr;
238}
239//******************************************************************************
240//******************************************************************************
Note: See TracBrowser for help on using the repository browser.