| 1 | /* $Id: cvticon.cpp,v 1.6 1999-10-27 10:35:41 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 | char *pAnd, *pXor;
|
|---|
| 88 |
|
|---|
| 89 | bwsize = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
|
|---|
| 90 | colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
|
|---|
| 91 | //SvL: 28-09-'98: only for <= 8
|
|---|
| 92 | if(bmpHdr->biBitCount <= 8)
|
|---|
| 93 | rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2);
|
|---|
| 94 | else rgbsize = 0;
|
|---|
| 95 |
|
|---|
| 96 | switch(bmpHdr->biBitCount) {
|
|---|
| 97 | case 1:
|
|---|
| 98 | colorsize /= 8;
|
|---|
| 99 | break;
|
|---|
| 100 | case 4:
|
|---|
| 101 | colorsize /= 2;
|
|---|
| 102 | break;
|
|---|
| 103 | case 8:
|
|---|
| 104 | break;
|
|---|
| 105 | case 16:
|
|---|
| 106 | colorsize *= 2;
|
|---|
| 107 | break;
|
|---|
| 108 | case 24:
|
|---|
| 109 | colorsize *= 3;
|
|---|
| 110 | break;
|
|---|
| 111 | case 32:
|
|---|
| 112 | colorsize *= 4;
|
|---|
| 113 | break;
|
|---|
| 114 | }
|
|---|
| 115 | if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) {
|
|---|
| 116 | bmpHdr->biSizeImage = bwsize + colorsize;
|
|---|
| 117 | }
|
|---|
| 118 | dprintf(("Icon size : %d", bmpHdr->biSizeImage));
|
|---|
| 119 | dprintf(("Icon Width : %d", bmpHdr->biWidth));
|
|---|
| 120 | //height for both the XOR and AND bitmap (color & BW)
|
|---|
| 121 | dprintf(("Height : %d", bmpHdr->biHeight));
|
|---|
| 122 | dprintf(("Icon Bitcount: %d", bmpHdr->biBitCount));
|
|---|
| 123 | dprintf(("Icon Compress: %d", bmpHdr->biCompression));
|
|---|
| 124 |
|
|---|
| 125 | //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header
|
|---|
| 126 | if(bmpHdr->biSizeImage < colorsize) {
|
|---|
| 127 | bmpHdr->biSizeImage = colorsize;
|
|---|
| 128 | }
|
|---|
| 129 | //bitmapfileheader for AndXor mask + 2 RGB structs + bitmapfileheader
|
|---|
| 130 | //for color bitmap + RGB structs for all the colors
|
|---|
| 131 | //SvL, 3-3-98: 2*bwsize
|
|---|
| 132 | iconsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) +
|
|---|
| 133 | rgbsize + 2*bwsize + bmpHdr->biSizeImage;
|
|---|
| 134 |
|
|---|
| 135 | iconhdr = (BITMAPFILEHEADER2 *)malloc(iconsize);
|
|---|
| 136 | memset(iconhdr, 0, iconsize);
|
|---|
| 137 | iconhdr->usType = BFT_COLORICON;
|
|---|
| 138 | iconhdr->cbSize = sizeof(BITMAPFILEHEADER2);
|
|---|
| 139 | iconhdr->xHotspot = 0;
|
|---|
| 140 | iconhdr->yHotspot = 0;
|
|---|
| 141 | iconhdr->offBits = 2*sizeof(BITMAPFILEHEADER2) +
|
|---|
| 142 | 2*sizeof(RGB2) + rgbsize + offsetBits;
|
|---|
| 143 | iconhdr->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
|
|---|
| 144 | iconhdr->bmp2.cx = (USHORT)bmpHdr->biWidth;
|
|---|
| 145 | iconhdr->bmp2.cy = (USHORT)bmpHdr->biHeight;
|
|---|
| 146 | iconhdr->bmp2.cPlanes = 1;
|
|---|
| 147 | iconhdr->bmp2.cBitCount= 1;
|
|---|
| 148 | iconhdr->bmp2.ulCompression = BCA_UNCOMP;
|
|---|
| 149 | iconhdr->bmp2.ulColorEncoding = BCE_RGB;
|
|---|
| 150 | os2rgb = (RGB2 *)(iconhdr+1);
|
|---|
| 151 | memset(os2rgb, 0, sizeof(RGB2));
|
|---|
| 152 | memset(os2rgb+1, 0xff, sizeof(RGB)); //not reserved byte!
|
|---|
| 153 | iconhdr2 = (BITMAPFILEHEADER2 *)(os2rgb+2);
|
|---|
| 154 | iconhdr2->usType = BFT_COLORICON;
|
|---|
| 155 | iconhdr2->cbSize = sizeof(BITMAPFILEHEADER2);
|
|---|
| 156 | iconhdr2->xHotspot = 0;
|
|---|
| 157 | iconhdr2->yHotspot = 0;
|
|---|
| 158 | iconhdr2->offBits = 2*sizeof(BITMAPFILEHEADER2) +
|
|---|
| 159 | 2*sizeof(RGB2) + rgbsize + 2*bwsize + offsetBits;
|
|---|
| 160 | iconhdr2->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
|
|---|
| 161 | iconhdr2->bmp2.cx = (USHORT)bmpHdr->biWidth;
|
|---|
| 162 | iconhdr2->bmp2.cy = (USHORT)(bmpHdr->biHeight/2);
|
|---|
| 163 | iconhdr2->bmp2.cPlanes = bmpHdr->biPlanes;
|
|---|
| 164 | iconhdr2->bmp2.cBitCount= bmpHdr->biBitCount;
|
|---|
| 165 | iconhdr2->bmp2.ulCompression = BCA_UNCOMP;
|
|---|
| 166 | iconhdr2->bmp2.ulColorEncoding = BCE_RGB;
|
|---|
| 167 | os2rgb = (RGB2 *)(iconhdr2+1);
|
|---|
| 168 | rgb = (RGBQUAD *)(bmpHdr+1);
|
|---|
| 169 | if(bmpHdr->biBitCount <= 8) {
|
|---|
| 170 | for(i=0;i<(1<<bmpHdr->biBitCount);i++) {
|
|---|
| 171 | os2rgb->bRed = rgb->red;
|
|---|
| 172 | os2rgb->bBlue = rgb->blue;
|
|---|
| 173 | os2rgb->bGreen = rgb->green;
|
|---|
| 174 | os2rgb++;
|
|---|
| 175 | rgb++;
|
|---|
| 176 | }
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | pXor = (char *)os2rgb;
|
|---|
| 180 | pAnd = (char *)os2rgb + bwsize;
|
|---|
| 181 |
|
|---|
| 182 | if ((size - (bmpHdr->biSize - rgbsize - colorsize)) == bwsize) {
|
|---|
| 183 | char *q;
|
|---|
| 184 | int i, linesize;
|
|---|
| 185 |
|
|---|
| 186 | linesize = bmpHdr->biWidth / 8;
|
|---|
| 187 | q = (char *)rgb + colorsize;
|
|---|
| 188 | for (i = 0; i < (bmpHdr->biHeight/2); i++) {
|
|---|
| 189 | memcpy (pAnd, q, linesize);
|
|---|
| 190 | pAnd += linesize;
|
|---|
| 191 | q += linesize;
|
|---|
| 192 |
|
|---|
| 193 | memcpy (pXor, q, linesize);
|
|---|
| 194 | pXor += linesize;
|
|---|
| 195 | q += linesize;
|
|---|
| 196 | }
|
|---|
| 197 | } else {
|
|---|
| 198 | memcpy (pAnd, (char *)rgb + colorsize, bwsize);
|
|---|
| 199 | memset (pXor, 0, bwsize);
|
|---|
| 200 | }
|
|---|
| 201 | memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
|
|---|
| 202 |
|
|---|
| 203 | *os2size = iconsize;
|
|---|
| 204 | return (void *)iconhdr;
|
|---|
| 205 | }
|
|---|
| 206 | //******************************************************************************
|
|---|
| 207 | //******************************************************************************
|
|---|