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

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

More PE resource changes

File size: 3.9 KB
Line 
1/* $Id: cvtcursor.cpp,v 1.1 1999-08-19 19:50:40 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//******************************************************************************
33void *ConvertCursor(CursorComponent *curHdr, int size, int offsetBits)
34{
35 RGBQUAD *rgb;
36 RGB *os2rgb;
37 WINBITMAPINFOHEADER *bhdr = (WINBITMAPINFOHEADER *)(curHdr+1);
38 BITMAPFILEHEADER *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(BITMAPFILEHEADER) + bmpsize + (1<<bhdr->biBitCount)*sizeof(RGB);
44
45 cursorhdr = (BITMAPFILEHEADER *)malloc(cursorsize);
46 cursorhdr->usType = BFT_POINTER;
47 cursorhdr->cbSize = sizeof(BITMAPFILEHEADER);
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(BITMAPFILEHEADER) + 2*sizeof(RGB) + offsetBits;
58 cursorhdr->bmp.cbFix = sizeof(BITMAPINFOHEADER);
59 cursorhdr->bmp.cx = (USHORT)bhdr->biWidth;
60 cursorhdr->bmp.cy = (USHORT)(bhdr->biHeight);
61 cursorhdr->bmp.cPlanes = bhdr->biPlanes;
62 cursorhdr->bmp.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 = (RGB *)(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//******************************************************************************
Note: See TracBrowser for help on using the repository browser.