1 | /* $Id: cvtcursor.cpp,v 1.2 1999-08-22 22:11:21 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * PE2LX cursor conversion code
|
---|
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 <wincursor.h>
|
---|
27 | #include <misc.h>
|
---|
28 |
|
---|
29 | //******************************************************************************
|
---|
30 | //NOTE: offsetBits is the value added to the offBits bitmap structure members
|
---|
31 | // (handy for converting cursor groups)
|
---|
32 | //******************************************************************************
|
---|
33 | void *ConvertCursor(CursorComponent *curHdr, int size, int offsetBits)
|
---|
34 | {
|
---|
35 | RGBQUAD *rgb;
|
---|
36 | RGB2 *os2rgb;
|
---|
37 | WINBITMAPINFOHEADER *bhdr = (WINBITMAPINFOHEADER *)(curHdr+1);
|
---|
38 | BITMAPFILEHEADER2 *cursorhdr;
|
---|
39 | int i, bwsize, bmpsize, cursorsize;
|
---|
40 |
|
---|
41 | dprintf(("ConvertCursor: Cursor size %d", size));
|
---|
42 | bmpsize = size - sizeof(CursorComponent) - (1<<bhdr->biBitCount)*sizeof(RGBQUAD);
|
---|
43 | cursorsize = sizeof(BITMAPFILEHEADER2) + bmpsize + (1<<bhdr->biBitCount)*sizeof(RGB2);
|
---|
44 |
|
---|
45 | cursorhdr = (BITMAPFILEHEADER2 *)malloc(cursorsize);
|
---|
46 | cursorhdr->usType = BFT_POINTER;
|
---|
47 | cursorhdr->cbSize = sizeof(BITMAPFILEHEADER2);
|
---|
48 | cursorhdr->xHotspot = curHdr->xHotspot;
|
---|
49 |
|
---|
50 | /* @@@PH y-hotspot is upside down ! */
|
---|
51 | cursorhdr->yHotspot = (bhdr->biHeight >> 1) - 1 /* height div 2 */
|
---|
52 | - curHdr->yHotspot; /* subtract hot.y */
|
---|
53 |
|
---|
54 | dprintf(("Cursor Hot.x : %d", curHdr->xHotspot));
|
---|
55 | dprintf(("Cursor Hot.y : %d", curHdr->yHotspot));
|
---|
56 |
|
---|
57 | cursorhdr->offBits = sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) + offsetBits;
|
---|
58 | cursorhdr->bmp2.cbFix = sizeof(BITMAPINFOHEADER);
|
---|
59 | cursorhdr->bmp2.cx = (USHORT)bhdr->biWidth;
|
---|
60 | cursorhdr->bmp2.cy = (USHORT)(bhdr->biHeight);
|
---|
61 | cursorhdr->bmp2.cPlanes = bhdr->biPlanes;
|
---|
62 | cursorhdr->bmp2.cBitCount = bhdr->biBitCount;
|
---|
63 | dprintf(("Cursor size : %d", bhdr->biSizeImage));
|
---|
64 | dprintf(("Cursor Width : %d", bhdr->biWidth));
|
---|
65 | //height for both the XOR and AND bitmap (color & BW)
|
---|
66 | dprintf(("Height : %d", bhdr->biHeight));
|
---|
67 | dprintf(("Cursor Bitcount: %d", bhdr->biBitCount));
|
---|
68 | dprintf(("Cursor Compress: %d", bhdr->biCompression));
|
---|
69 |
|
---|
70 | os2rgb = (RGB2 *)(cursorhdr+1);
|
---|
71 | rgb = (RGBQUAD *)(bhdr+1);
|
---|
72 | for(i=0;i<(1<<bhdr->biBitCount);i++) {
|
---|
73 | os2rgb->bRed = rgb->red;
|
---|
74 | os2rgb->bBlue = rgb->blue;
|
---|
75 | os2rgb->bGreen = rgb->green;
|
---|
76 | os2rgb++;
|
---|
77 | rgb++;
|
---|
78 | }
|
---|
79 |
|
---|
80 | if(bhdr->biSizeImage > bmpsize || bhdr->biSizeImage == 0) {
|
---|
81 | bwsize = bhdr->biWidth*(bhdr->biHeight);
|
---|
82 |
|
---|
83 | switch(bhdr->biBitCount) {
|
---|
84 | case 1:
|
---|
85 | bwsize /= 8;
|
---|
86 | break;
|
---|
87 | case 4:
|
---|
88 | bwsize /= 2;
|
---|
89 | break;
|
---|
90 | case 8:
|
---|
91 | break;
|
---|
92 | case 16:
|
---|
93 | bwsize *= 2;
|
---|
94 | break;
|
---|
95 | case 24:
|
---|
96 | bwsize *= 3;
|
---|
97 | break;
|
---|
98 | case 32:
|
---|
99 | bwsize *= 4;
|
---|
100 | break;
|
---|
101 | }
|
---|
102 | }
|
---|
103 | else bwsize = bhdr->biSizeImage;
|
---|
104 |
|
---|
105 | //write XOR and AND mask
|
---|
106 | memcpy((char *)os2rgb, (char *)rgb, bwsize);
|
---|
107 |
|
---|
108 | return cursorhdr;
|
---|
109 | }
|
---|
110 | //******************************************************************************
|
---|
111 | //******************************************************************************
|
---|