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

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

Dani's cursor conversion fix

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