| 1 | /* $Id: icon.cpp,v 1.10 2000-02-16 14:34:19 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * Win32 icon conversion functions for OS/2
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1998 Sander van Leeuwen
|
|---|
| 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> //Odin32 OS/2 api wrappers
|
|---|
| 20 | #include <stdio.h>
|
|---|
| 21 | #include <string.h>
|
|---|
| 22 | #include <stdlib.h>
|
|---|
| 23 | #include <iostream.h>
|
|---|
| 24 | #include <string.h>
|
|---|
| 25 |
|
|---|
| 26 | #include <win32type.h>
|
|---|
| 27 |
|
|---|
| 28 | #include <winicon.h>
|
|---|
| 29 | #include <misc.h>
|
|---|
| 30 |
|
|---|
| 31 | #define DBG_LOCALLOG DBG_icon
|
|---|
| 32 | #include "dbglocal.h"
|
|---|
| 33 |
|
|---|
| 34 | //******************************************************************************
|
|---|
| 35 | //******************************************************************************
|
|---|
| 36 | PBYTE ConvertWin32Icon(PBYTE presbits, DWORD dwResSize, DWORD *OS2ResSize)
|
|---|
| 37 | {
|
|---|
| 38 | WINBITMAPINFOHEADER *bmpHdr = (WINBITMAPINFOHEADER *)presbits;
|
|---|
| 39 | BITMAPFILEHEADER *iconhdr;
|
|---|
| 40 | BITMAPFILEHEADER *iconhdr2;
|
|---|
| 41 | RGBQUAD *rgb;
|
|---|
| 42 | RGB *os2rgb;
|
|---|
| 43 | int bwsize, i, colorsize, rgbsize, iconsize;
|
|---|
| 44 |
|
|---|
| 45 | bwsize = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
|
|---|
| 46 | colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
|
|---|
| 47 | if(bmpHdr->biBitCount < 24)
|
|---|
| 48 | rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB);
|
|---|
| 49 | else rgbsize = 0;
|
|---|
| 50 |
|
|---|
| 51 | switch(bmpHdr->biBitCount) {
|
|---|
| 52 | case 1:
|
|---|
| 53 | colorsize /= 8;
|
|---|
| 54 | break;
|
|---|
| 55 | case 4:
|
|---|
| 56 | colorsize /= 2;
|
|---|
| 57 | break;
|
|---|
| 58 | case 8:
|
|---|
| 59 | break;
|
|---|
| 60 | case 16:
|
|---|
| 61 | colorsize *= 2;
|
|---|
| 62 | break;
|
|---|
| 63 | case 24:
|
|---|
| 64 | colorsize *= 3;
|
|---|
| 65 | break;
|
|---|
| 66 | case 32:
|
|---|
| 67 | colorsize *= 4;
|
|---|
| 68 | break;
|
|---|
| 69 | }
|
|---|
| 70 | if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) {
|
|---|
| 71 | bmpHdr->biSizeImage = bwsize + colorsize;
|
|---|
| 72 | }
|
|---|
| 73 | #if 0
|
|---|
| 74 | cout << "Icon size : " << bmpHdr->biSizeImage << endl;
|
|---|
| 75 | cout << "Icon Width : " << bmpHdr->biWidth << endl;
|
|---|
| 76 | //height for both the XOR and AND bitmap (color & BW)
|
|---|
| 77 | cout << "Height : " << bmpHdr->biHeight << endl;
|
|---|
| 78 | cout << "Icon Bitcount: " << bmpHdr->biBitCount << endl;
|
|---|
| 79 | cout << "Icon Compress: " << bmpHdr->biCompression << endl;
|
|---|
| 80 | #endif
|
|---|
| 81 |
|
|---|
| 82 | //bitmapfileheader for AndXor mask + 2 RGB structs + bitmapfileheader
|
|---|
| 83 | //for color bitmap + RGB structs for all the colors
|
|---|
| 84 | //SvL, 15-3-98: 2*bwsize
|
|---|
| 85 | iconsize = 2*sizeof(BITMAPFILEHEADER) + 2*sizeof(RGB) +
|
|---|
| 86 | rgbsize + 2*bwsize + bmpHdr->biSizeImage;
|
|---|
| 87 | //There are icons without an XOR mask, so check for it
|
|---|
| 88 | if(bmpHdr->biSizeImage == colorsize) {
|
|---|
| 89 | iconsize += bwsize;
|
|---|
| 90 | }
|
|---|
| 91 | iconhdr = (BITMAPFILEHEADER *)malloc(iconsize);
|
|---|
| 92 | iconhdr->usType = BFT_COLORICON;
|
|---|
| 93 | iconhdr->cbSize = sizeof(BITMAPFILEHEADER);
|
|---|
| 94 | iconhdr->xHotspot = 0;
|
|---|
| 95 | iconhdr->yHotspot = 0;
|
|---|
| 96 | iconhdr->offBits = 2*sizeof(BITMAPFILEHEADER) +
|
|---|
| 97 | 2*sizeof(RGB) + rgbsize;
|
|---|
| 98 | iconhdr->bmp.cbFix = sizeof(BITMAPINFOHEADER);
|
|---|
| 99 | iconhdr->bmp.cx = (USHORT)bmpHdr->biWidth;
|
|---|
| 100 | iconhdr->bmp.cy = (USHORT)bmpHdr->biHeight;
|
|---|
| 101 | iconhdr->bmp.cPlanes = 1;
|
|---|
| 102 | iconhdr->bmp.cBitCount = 1;
|
|---|
| 103 | os2rgb = (RGB *)(iconhdr+1);
|
|---|
| 104 | memset(os2rgb, 0, sizeof(RGB));
|
|---|
| 105 | memset(os2rgb+1, 0xff, sizeof(RGB));
|
|---|
| 106 | iconhdr2 = (BITMAPFILEHEADER *)(os2rgb+2);
|
|---|
| 107 | iconhdr2->usType = BFT_COLORICON;
|
|---|
| 108 | iconhdr2->cbSize = sizeof(BITMAPFILEHEADER);
|
|---|
| 109 | iconhdr2->xHotspot = 0;
|
|---|
| 110 | iconhdr2->yHotspot = 0;
|
|---|
| 111 | iconhdr2->offBits = 2*sizeof(BITMAPFILEHEADER) +
|
|---|
| 112 | 2*sizeof(RGB) + rgbsize + 2*bwsize;
|
|---|
| 113 | iconhdr2->bmp.cbFix = sizeof(BITMAPINFOHEADER);
|
|---|
| 114 | iconhdr2->bmp.cx = (USHORT)bmpHdr->biWidth;
|
|---|
| 115 | iconhdr2->bmp.cy = (USHORT)(bmpHdr->biHeight/2);
|
|---|
| 116 | iconhdr2->bmp.cPlanes = bmpHdr->biPlanes;
|
|---|
| 117 | iconhdr2->bmp.cBitCount= bmpHdr->biBitCount;
|
|---|
| 118 | os2rgb = (RGB *)(iconhdr2+1);
|
|---|
| 119 | rgb = (RGBQUAD *)(bmpHdr+1);
|
|---|
| 120 | if(bmpHdr->biBitCount < 24) {
|
|---|
| 121 | for(i=0;i<(1<<bmpHdr->biBitCount);i++) {
|
|---|
| 122 | os2rgb->bRed = rgb->red;
|
|---|
| 123 | os2rgb->bBlue = rgb->blue;
|
|---|
| 124 | os2rgb->bGreen = rgb->green;
|
|---|
| 125 | os2rgb++;
|
|---|
| 126 | rgb++;
|
|---|
| 127 | }
|
|---|
| 128 | }
|
|---|
| 129 | //write 2*mono pixels + color pixels
|
|---|
| 130 | //There are icons without an XOR mask, so check for it
|
|---|
| 131 | if(bmpHdr->biSizeImage == colorsize) {
|
|---|
| 132 | memset((char *)os2rgb, 0, bwsize);
|
|---|
| 133 | memset((char *)os2rgb+bwsize, 0, bwsize);
|
|---|
| 134 | memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
|
|---|
| 135 | }
|
|---|
| 136 | else {
|
|---|
| 137 | memcpy((char *)os2rgb, (char *)rgb+colorsize, bwsize);
|
|---|
| 138 | memcpy((char *)os2rgb+bwsize, (char *)rgb+colorsize, bwsize);
|
|---|
| 139 | memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
|
|---|
| 140 | }
|
|---|
| 141 | *OS2ResSize = iconsize;
|
|---|
| 142 | return((PBYTE)iconhdr);
|
|---|
| 143 | }
|
|---|
| 144 | //******************************************************************************
|
|---|
| 145 | //******************************************************************************
|
|---|
| 146 | void FreeIcon(void *os2icon)
|
|---|
| 147 | {
|
|---|
| 148 | free(os2icon);
|
|---|
| 149 | }
|
|---|
| 150 | //******************************************************************************
|
|---|
| 151 | //******************************************************************************
|
|---|