| 1 | /* $Id: cvticon.cpp,v 1.1 1999-09-15 23:32:53 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * PE2LX icons | 
|---|
| 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 <misc.h> | 
|---|
| 27 |  | 
|---|
| 28 | //****************************************************************************** | 
|---|
| 29 | //****************************************************************************** | 
|---|
| 30 | ULONG QueryConvertedIconSize(WINBITMAPINFOHEADER *bmpHdr, int size) | 
|---|
| 31 | { | 
|---|
| 32 | int bwsize, colorsize, rgbsize, iconsize; | 
|---|
| 33 |  | 
|---|
| 34 | bwsize   = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8; | 
|---|
| 35 | colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2); | 
|---|
| 36 | //SvL: 28-09-'98: only for <= 8 | 
|---|
| 37 | if(bmpHdr->biBitCount <= 8) | 
|---|
| 38 | rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2); | 
|---|
| 39 | else  rgbsize = 0; | 
|---|
| 40 |  | 
|---|
| 41 | switch(bmpHdr->biBitCount) { | 
|---|
| 42 | case 1: | 
|---|
| 43 | colorsize /= 8; | 
|---|
| 44 | break; | 
|---|
| 45 | case 4: | 
|---|
| 46 | colorsize /= 2; | 
|---|
| 47 | break; | 
|---|
| 48 | case 8: | 
|---|
| 49 | break; | 
|---|
| 50 | case 16: | 
|---|
| 51 | colorsize *= 2; | 
|---|
| 52 | break; | 
|---|
| 53 | case 24: | 
|---|
| 54 | colorsize *= 3; | 
|---|
| 55 | break; | 
|---|
| 56 | case 32: | 
|---|
| 57 | colorsize *= 4; | 
|---|
| 58 | break; | 
|---|
| 59 | } | 
|---|
| 60 | if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) { | 
|---|
| 61 | bmpHdr->biSizeImage = bwsize + colorsize; | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header | 
|---|
| 65 | if(bmpHdr->biSizeImage < colorsize) { | 
|---|
| 66 | bmpHdr->biSizeImage = colorsize; | 
|---|
| 67 | } | 
|---|
| 68 | //bitmapfileheader for AndXor mask + 2 RGB structs + bitmapfileheader | 
|---|
| 69 | //for color bitmap + RGB structs for all the colors | 
|---|
| 70 | //SvL, 3-3-98: 2*bwsize | 
|---|
| 71 | iconsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) + | 
|---|
| 72 | rgbsize + 2*bwsize + bmpHdr->biSizeImage; | 
|---|
| 73 |  | 
|---|
| 74 | return iconsize; | 
|---|
| 75 | } | 
|---|
| 76 | //****************************************************************************** | 
|---|
| 77 | //NOTE: offsetBits is the value added to the offBits bitmap structure members | 
|---|
| 78 | //      (handy for converting icon groups) | 
|---|
| 79 | //****************************************************************************** | 
|---|
| 80 | void *ConvertIcon(WINBITMAPINFOHEADER *bmpHdr, int size, int *os2size, int offsetBits) | 
|---|
| 81 | { | 
|---|
| 82 | RGBQUAD *rgb; | 
|---|
| 83 | RGB2    *os2rgb; | 
|---|
| 84 | int bwsize, i, colorsize, rgbsize, iconsize; | 
|---|
| 85 | BITMAPFILEHEADER2 *iconhdr; | 
|---|
| 86 | BITMAPFILEHEADER2 *iconhdr2; | 
|---|
| 87 |  | 
|---|
| 88 | bwsize   = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8; | 
|---|
| 89 | colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2); | 
|---|
| 90 | //SvL: 28-09-'98: only for <= 8 | 
|---|
| 91 | if(bmpHdr->biBitCount <= 8) | 
|---|
| 92 | rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2); | 
|---|
| 93 | else  rgbsize = 0; | 
|---|
| 94 |  | 
|---|
| 95 | switch(bmpHdr->biBitCount) { | 
|---|
| 96 | case 1: | 
|---|
| 97 | colorsize /= 8; | 
|---|
| 98 | break; | 
|---|
| 99 | case 4: | 
|---|
| 100 | colorsize /= 2; | 
|---|
| 101 | break; | 
|---|
| 102 | case 8: | 
|---|
| 103 | break; | 
|---|
| 104 | case 16: | 
|---|
| 105 | colorsize *= 2; | 
|---|
| 106 | break; | 
|---|
| 107 | case 24: | 
|---|
| 108 | colorsize *= 3; | 
|---|
| 109 | break; | 
|---|
| 110 | case 32: | 
|---|
| 111 | colorsize *= 4; | 
|---|
| 112 | break; | 
|---|
| 113 | } | 
|---|
| 114 | if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) { | 
|---|
| 115 | bmpHdr->biSizeImage = bwsize + colorsize; | 
|---|
| 116 | } | 
|---|
| 117 | dprintf(("Icon size    : %d", bmpHdr->biSizeImage)); | 
|---|
| 118 | dprintf(("Icon Width   : %d", bmpHdr->biWidth)); | 
|---|
| 119 | //height for both the XOR and AND bitmap (color & BW) | 
|---|
| 120 | dprintf(("Height       : %d", bmpHdr->biHeight)); | 
|---|
| 121 | dprintf(("Icon Bitcount: %d", bmpHdr->biBitCount)); | 
|---|
| 122 | dprintf(("Icon Compress: %d", bmpHdr->biCompression)); | 
|---|
| 123 |  | 
|---|
| 124 | //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header | 
|---|
| 125 | if(bmpHdr->biSizeImage < colorsize) { | 
|---|
| 126 | bmpHdr->biSizeImage = colorsize; | 
|---|
| 127 | } | 
|---|
| 128 | //bitmapfileheader for AndXor mask + 2 RGB structs + bitmapfileheader | 
|---|
| 129 | //for color bitmap + RGB structs for all the colors | 
|---|
| 130 | //SvL, 3-3-98: 2*bwsize | 
|---|
| 131 | iconsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) + | 
|---|
| 132 | rgbsize + 2*bwsize + bmpHdr->biSizeImage; | 
|---|
| 133 | #if 0 | 
|---|
| 134 | //SvL: Not necessary anymore | 
|---|
| 135 | //There are icons without an XOR mask, so check for it | 
|---|
| 136 | if(bmpHdr->biSizeImage == colorsize) { | 
|---|
| 137 | iconsize += bwsize; | 
|---|
| 138 | } | 
|---|
| 139 | #endif | 
|---|
| 140 | iconhdr  = (BITMAPFILEHEADER2 *)malloc(iconsize); | 
|---|
| 141 | memset(iconhdr, 0, iconsize); | 
|---|
| 142 | iconhdr->usType        = BFT_COLORICON; | 
|---|
| 143 | iconhdr->cbSize        = sizeof(BITMAPFILEHEADER2); | 
|---|
| 144 | iconhdr->xHotspot      = 0; | 
|---|
| 145 | iconhdr->yHotspot      = 0; | 
|---|
| 146 | iconhdr->offBits       = 2*sizeof(BITMAPFILEHEADER2) + | 
|---|
| 147 | 2*sizeof(RGB2) + rgbsize + offsetBits; | 
|---|
| 148 | iconhdr->bmp2.cbFix    = sizeof(BITMAPINFOHEADER2); | 
|---|
| 149 | iconhdr->bmp2.cx       = (USHORT)bmpHdr->biWidth; | 
|---|
| 150 | iconhdr->bmp2.cy       = (USHORT)bmpHdr->biHeight; | 
|---|
| 151 | iconhdr->bmp2.cPlanes  = 1; | 
|---|
| 152 | iconhdr->bmp2.cBitCount= 1; | 
|---|
| 153 | iconhdr->bmp2.ulCompression   = BCA_UNCOMP; | 
|---|
| 154 | iconhdr->bmp2.ulColorEncoding = BCE_RGB; | 
|---|
| 155 | os2rgb                 = (RGB2 *)(iconhdr+1); | 
|---|
| 156 | memset(os2rgb, 0, sizeof(RGB2)); | 
|---|
| 157 | memset(os2rgb+1, 0xff, sizeof(RGB)); //not reserved byte! | 
|---|
| 158 | iconhdr2               = (BITMAPFILEHEADER2 *)(os2rgb+2); | 
|---|
| 159 | iconhdr2->usType       = BFT_COLORICON; | 
|---|
| 160 | iconhdr2->cbSize       = sizeof(BITMAPFILEHEADER2); | 
|---|
| 161 | iconhdr2->xHotspot     = 0; | 
|---|
| 162 | iconhdr2->yHotspot     = 0; | 
|---|
| 163 | iconhdr2->offBits      = 2*sizeof(BITMAPFILEHEADER2) + | 
|---|
| 164 | 2*sizeof(RGB2) + rgbsize + 2*bwsize + offsetBits; | 
|---|
| 165 | iconhdr2->bmp2.cbFix   = sizeof(BITMAPINFOHEADER2); | 
|---|
| 166 | iconhdr2->bmp2.cx      = (USHORT)bmpHdr->biWidth; | 
|---|
| 167 | iconhdr2->bmp2.cy      = (USHORT)(bmpHdr->biHeight/2); | 
|---|
| 168 | iconhdr2->bmp2.cPlanes = bmpHdr->biPlanes; | 
|---|
| 169 | iconhdr2->bmp2.cBitCount= bmpHdr->biBitCount; | 
|---|
| 170 | iconhdr2->bmp2.ulCompression   = BCA_UNCOMP; | 
|---|
| 171 | iconhdr2->bmp2.ulColorEncoding = BCE_RGB; | 
|---|
| 172 | os2rgb                 = (RGB2 *)(iconhdr2+1); | 
|---|
| 173 | rgb                    = (RGBQUAD *)(bmpHdr+1); | 
|---|
| 174 | if(bmpHdr->biBitCount < 24) { | 
|---|
| 175 | for(i=0;i<(1<<bmpHdr->biBitCount);i++) { | 
|---|
| 176 | os2rgb->bRed   = rgb->red; | 
|---|
| 177 | os2rgb->bBlue  = rgb->blue; | 
|---|
| 178 | os2rgb->bGreen = rgb->green; | 
|---|
| 179 | os2rgb++; | 
|---|
| 180 | rgb++; | 
|---|
| 181 | } | 
|---|
| 182 | } | 
|---|
| 183 | //write 2*mono pixels + color pixels | 
|---|
| 184 | //There are icons without an XOR mask, so check for it | 
|---|
| 185 | if(bmpHdr->biSizeImage == colorsize) | 
|---|
| 186 | { | 
|---|
| 187 | memset((char *)os2rgb, 0, bwsize); | 
|---|
| 188 | memset((char *)os2rgb+bwsize, 0, bwsize); | 
|---|
| 189 | memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize); | 
|---|
| 190 | } | 
|---|
| 191 | else { | 
|---|
| 192 | memcpy((char *)os2rgb, (char *)rgb+colorsize, bwsize); | 
|---|
| 193 | memcpy((char *)os2rgb+bwsize, (char *)rgb+colorsize, bwsize); | 
|---|
| 194 | memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize); | 
|---|
| 195 | } | 
|---|
| 196 | *os2size = iconsize; | 
|---|
| 197 | return (void *)iconhdr; | 
|---|
| 198 | } | 
|---|
| 199 | //****************************************************************************** | 
|---|
| 200 | //****************************************************************************** | 
|---|