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