| 1 | /* $Id: cvtcursor.cpp,v 1.6 1999-09-25 14:31:00 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 | memset(cursorhdr, 0, cursorsize);
|
|---|
| 59 | cursorhdr->usType = BFT_POINTER;
|
|---|
| 60 | cursorhdr->cbSize = sizeof(BITMAPFILEHEADER2);
|
|---|
| 61 | cursorhdr->xHotspot = curHdr->xHotspot;
|
|---|
| 62 |
|
|---|
| 63 | /* @@@PH y-hotspot is upside down ! */
|
|---|
| 64 | cursorhdr->yHotspot = (bhdr->biHeight >> 1) /* height div 2 */
|
|---|
| 65 | - curHdr->yHotspot; /* subtract hot.y */
|
|---|
| 66 |
|
|---|
| 67 | dprintf(("Cursor Hot.x : %d", curHdr->xHotspot));
|
|---|
| 68 | dprintf(("Cursor Hot.y : %d", curHdr->yHotspot));
|
|---|
| 69 |
|
|---|
| 70 | cursorhdr->offBits = sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) + offsetBits;
|
|---|
| 71 | cursorhdr->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
|
|---|
| 72 | cursorhdr->bmp2.cx = (USHORT)bhdr->biWidth;
|
|---|
| 73 | cursorhdr->bmp2.cy = (USHORT)(bhdr->biHeight);
|
|---|
| 74 | cursorhdr->bmp2.cPlanes = bhdr->biPlanes;
|
|---|
| 75 | cursorhdr->bmp2.cBitCount = bhdr->biBitCount;
|
|---|
| 76 | cursorhdr->bmp2.ulCompression = BCA_UNCOMP;
|
|---|
| 77 | cursorhdr->bmp2.ulColorEncoding = BCE_RGB;
|
|---|
| 78 | dprintf(("Cursor size : %d", bhdr->biSizeImage));
|
|---|
| 79 | dprintf(("Cursor Width : %d", bhdr->biWidth));
|
|---|
| 80 | //height for both the XOR and AND bitmap (color & BW)
|
|---|
| 81 | dprintf(("Height : %d", bhdr->biHeight));
|
|---|
| 82 | dprintf(("Cursor Bitcount: %d", bhdr->biBitCount));
|
|---|
| 83 | dprintf(("Cursor Compress: %d", bhdr->biCompression));
|
|---|
| 84 |
|
|---|
| 85 | os2rgb = (RGB2 *)(cursorhdr+1);
|
|---|
| 86 | rgb = (RGBQUAD *)(bhdr+1);
|
|---|
| 87 | for(i=0;i<(1<<bhdr->biBitCount);i++) {
|
|---|
| 88 | os2rgb->bRed = rgb->red;
|
|---|
| 89 | os2rgb->bBlue = rgb->blue;
|
|---|
| 90 | os2rgb->bGreen = rgb->green;
|
|---|
| 91 | os2rgb++;
|
|---|
| 92 | rgb++;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | if(bhdr->biSizeImage > bmpsize || bhdr->biSizeImage == 0) {
|
|---|
| 96 | bwsize = bhdr->biWidth*(bhdr->biHeight);
|
|---|
| 97 |
|
|---|
| 98 | switch(bhdr->biBitCount) {
|
|---|
| 99 | case 1:
|
|---|
| 100 | bwsize /= 8;
|
|---|
| 101 | break;
|
|---|
| 102 | case 4:
|
|---|
| 103 | bwsize /= 2;
|
|---|
| 104 | break;
|
|---|
| 105 | case 8:
|
|---|
| 106 | break;
|
|---|
| 107 | case 16:
|
|---|
| 108 | bwsize *= 2;
|
|---|
| 109 | break;
|
|---|
| 110 | case 24:
|
|---|
| 111 | bwsize *= 3;
|
|---|
| 112 | break;
|
|---|
| 113 | case 32:
|
|---|
| 114 | bwsize *= 4;
|
|---|
| 115 | break;
|
|---|
| 116 | }
|
|---|
| 117 | }
|
|---|
| 118 | else bwsize = bhdr->biSizeImage;
|
|---|
| 119 |
|
|---|
| 120 | //write XOR and AND mask
|
|---|
| 121 | memcpy((char *)os2rgb, (char *)rgb, bwsize);
|
|---|
| 122 |
|
|---|
| 123 | *os2size = cursorsize;
|
|---|
| 124 | return cursorhdr;
|
|---|
| 125 | }
|
|---|
| 126 | //******************************************************************************
|
|---|
| 127 | //******************************************************************************
|
|---|