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