| 1 | /* $Id: icon.cpp,v 1.5 1999-08-04 13:10:14 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 <os2.h> | 
|---|
| 20 | #include <stdio.h> | 
|---|
| 21 | #include <string.h> | 
|---|
| 22 | #include <stdlib.h> | 
|---|
| 23 | #include <iostream.h> | 
|---|
| 24 | #include <string.h> | 
|---|
| 25 | #include "pefile.h" | 
|---|
| 26 | #include "lx.h" | 
|---|
| 27 | #include "icon.h" | 
|---|
| 28 | #include "misc.h" | 
|---|
| 29 |  | 
|---|
| 30 |  | 
|---|
| 31 | //****************************************************************************** | 
|---|
| 32 | //****************************************************************************** | 
|---|
| 33 | OS2Icon::OS2Icon(int id, WINBITMAPINFOHEADER *bmpHdr, int size) : | 
|---|
| 34 | id(0), next(NULL), iconhdr(NULL), iconsize(0), prevoffset(0) | 
|---|
| 35 | { | 
|---|
| 36 | RGBQUAD *rgb; | 
|---|
| 37 | RGB2    *os2rgb; | 
|---|
| 38 | int bwsize, i, colorsize, rgbsize; | 
|---|
| 39 | OS2Icon *icon = OS2Icon::icons; | 
|---|
| 40 |  | 
|---|
| 41 | if(icon != NULL) { | 
|---|
| 42 | while(icon->next != NULL) { | 
|---|
| 43 | icon = icon->next; | 
|---|
| 44 | } | 
|---|
| 45 | icon->next = this; | 
|---|
| 46 | } | 
|---|
| 47 | else  icons      = this; | 
|---|
| 48 |  | 
|---|
| 49 | this->id = id; | 
|---|
| 50 | bwsize   = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8; | 
|---|
| 51 | colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2); | 
|---|
| 52 | //SvL: 28-09-'98: only for <= 8 | 
|---|
| 53 | if(bmpHdr->biBitCount <= 8) | 
|---|
| 54 | rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2); | 
|---|
| 55 | else  rgbsize = 0; | 
|---|
| 56 |  | 
|---|
| 57 | switch(bmpHdr->biBitCount) { | 
|---|
| 58 | case 1: | 
|---|
| 59 | colorsize /= 8; | 
|---|
| 60 | break; | 
|---|
| 61 | case 4: | 
|---|
| 62 | colorsize /= 2; | 
|---|
| 63 | break; | 
|---|
| 64 | case 8: | 
|---|
| 65 | break; | 
|---|
| 66 | case 16: | 
|---|
| 67 | colorsize *= 2; | 
|---|
| 68 | break; | 
|---|
| 69 | case 24: | 
|---|
| 70 | colorsize *= 3; | 
|---|
| 71 | break; | 
|---|
| 72 | case 32: | 
|---|
| 73 | colorsize *= 4; | 
|---|
| 74 | break; | 
|---|
| 75 | } | 
|---|
| 76 | if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) { | 
|---|
| 77 | bmpHdr->biSizeImage = bwsize + colorsize; | 
|---|
| 78 | } | 
|---|
| 79 | cout << "Icon size    : " << bmpHdr->biSizeImage << endl; | 
|---|
| 80 | cout << "Icon Width   : " << bmpHdr->biWidth << endl; | 
|---|
| 81 | //height for both the XOR and AND bitmap (color & BW) | 
|---|
| 82 | cout << "Height       : " << bmpHdr->biHeight << endl; | 
|---|
| 83 | cout << "Icon Bitcount: " << bmpHdr->biBitCount << endl; | 
|---|
| 84 | cout << "Icon Compress: " << bmpHdr->biCompression << endl; | 
|---|
| 85 |  | 
|---|
| 86 | //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header | 
|---|
| 87 | if(bmpHdr->biSizeImage < colorsize) { | 
|---|
| 88 | bmpHdr->biSizeImage = colorsize; | 
|---|
| 89 | } | 
|---|
| 90 | //bitmapfileheader for AndXor mask + 2 RGB structs + bitmapfileheader | 
|---|
| 91 | //for color bitmap + RGB structs for all the colors | 
|---|
| 92 | //SvL, 3-3-98: 2*bwsize | 
|---|
| 93 | iconsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) + | 
|---|
| 94 | rgbsize + 2*bwsize + bmpHdr->biSizeImage; | 
|---|
| 95 | //There are icons without an XOR mask, so check for it | 
|---|
| 96 | if(bmpHdr->biSizeImage == colorsize) { | 
|---|
| 97 | iconsize += bwsize; | 
|---|
| 98 | } | 
|---|
| 99 | iconhdr  = (BITMAPFILEHEADER2 *)malloc(iconsize); | 
|---|
| 100 | memset(iconhdr, 0, iconsize); | 
|---|
| 101 | iconhdr->usType        = BFT_COLORICON; | 
|---|
| 102 | iconhdr->cbSize        = sizeof(BITMAPFILEHEADER2); | 
|---|
| 103 | iconhdr->xHotspot      = 0; | 
|---|
| 104 | iconhdr->yHotspot      = 0; | 
|---|
| 105 | iconhdr->offBits       = 2*sizeof(BITMAPFILEHEADER2) + | 
|---|
| 106 | 2*sizeof(RGB2) + rgbsize; | 
|---|
| 107 | iconhdr->bmp2.cbFix    = sizeof(BITMAPINFOHEADER2); | 
|---|
| 108 | iconhdr->bmp2.cx       = (USHORT)bmpHdr->biWidth; | 
|---|
| 109 | iconhdr->bmp2.cy       = (USHORT)bmpHdr->biHeight; | 
|---|
| 110 | iconhdr->bmp2.cPlanes  = 1; | 
|---|
| 111 | iconhdr->bmp2.cBitCount= 1; | 
|---|
| 112 | iconhdr->bmp2.ulCompression   = BCA_UNCOMP; | 
|---|
| 113 | iconhdr->bmp2.ulColorEncoding = BCE_RGB; | 
|---|
| 114 | os2rgb                 = (RGB2 *)(iconhdr+1); | 
|---|
| 115 | memset(os2rgb, 0, sizeof(RGB2)); | 
|---|
| 116 | memset(os2rgb+1, 0xff, sizeof(RGB2)); //not reserved byte | 
|---|
| 117 | iconhdr2               = (BITMAPFILEHEADER2 *)(os2rgb+2); | 
|---|
| 118 | iconhdr2->usType       = BFT_COLORICON; | 
|---|
| 119 | iconhdr2->cbSize       = sizeof(BITMAPFILEHEADER2); | 
|---|
| 120 | iconhdr2->xHotspot     = 0; | 
|---|
| 121 | iconhdr2->yHotspot     = 0; | 
|---|
| 122 | iconhdr2->offBits      = 2*sizeof(BITMAPFILEHEADER2) + | 
|---|
| 123 | 2*sizeof(RGB2) + rgbsize + 2*bwsize; | 
|---|
| 124 | iconhdr2->bmp2.cbFix   = sizeof(BITMAPINFOHEADER2); | 
|---|
| 125 | iconhdr2->bmp2.cx      = (USHORT)bmpHdr->biWidth; | 
|---|
| 126 | iconhdr2->bmp2.cy      = (USHORT)(bmpHdr->biHeight/2); | 
|---|
| 127 | iconhdr2->bmp2.cPlanes = bmpHdr->biPlanes; | 
|---|
| 128 | iconhdr2->bmp2.cBitCount= bmpHdr->biBitCount; | 
|---|
| 129 | iconhdr2->bmp2.ulCompression   = BCA_UNCOMP; | 
|---|
| 130 | iconhdr2->bmp2.ulColorEncoding = BCE_RGB; | 
|---|
| 131 | os2rgb                 = (RGB2 *)(iconhdr2+1); | 
|---|
| 132 | rgb                    = (RGBQUAD *)(bmpHdr+1); | 
|---|
| 133 | if(bmpHdr->biBitCount < 24) { | 
|---|
| 134 | for(i=0;i<(1<<bmpHdr->biBitCount);i++) { | 
|---|
| 135 | ////            cout << "(R,G,B) = (" << (int)rgb->red << ", " << (int)rgb->green << ", " << (int)rgb->blue << ")" << endl; | 
|---|
| 136 | os2rgb->bRed   = rgb->red; | 
|---|
| 137 | os2rgb->bBlue  = rgb->blue; | 
|---|
| 138 | os2rgb->bGreen = rgb->green; | 
|---|
| 139 | os2rgb++; | 
|---|
| 140 | rgb++; | 
|---|
| 141 | } | 
|---|
| 142 | } | 
|---|
| 143 | //write 2*mono pixels + color pixels | 
|---|
| 144 | //There are icons without an XOR mask, so check for it | 
|---|
| 145 | if(bmpHdr->biSizeImage == colorsize) { | 
|---|
| 146 | memset((char *)os2rgb, 0, bwsize); | 
|---|
| 147 | memset((char *)os2rgb+bwsize, 0, bwsize); | 
|---|
| 148 | memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize); | 
|---|
| 149 | } | 
|---|
| 150 | else { | 
|---|
| 151 | memcpy((char *)os2rgb, (char *)rgb+colorsize, bwsize); | 
|---|
| 152 | memcpy((char *)os2rgb+bwsize, (char *)rgb+colorsize, bwsize); | 
|---|
| 153 | memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize); | 
|---|
| 154 | } | 
|---|
| 155 | } | 
|---|
| 156 | //****************************************************************************** | 
|---|
| 157 | //****************************************************************************** | 
|---|
| 158 | void OS2Icon::SetIconHdrOffset(int offset) | 
|---|
| 159 | { | 
|---|
| 160 | iconhdr->offBits  += offset - prevoffset; | 
|---|
| 161 | iconhdr2->offBits += offset - prevoffset; | 
|---|
| 162 | //remember in case icons are used in multiple groups | 
|---|
| 163 | //(can't imagine this ever happening, but you never know) | 
|---|
| 164 | prevoffset         = offset; | 
|---|
| 165 | } | 
|---|
| 166 | //****************************************************************************** | 
|---|
| 167 | //****************************************************************************** | 
|---|
| 168 | OS2Icon::~OS2Icon() | 
|---|
| 169 | { | 
|---|
| 170 | if(iconhdr)   free(iconhdr); | 
|---|
| 171 | } | 
|---|
| 172 | //****************************************************************************** | 
|---|
| 173 | //****************************************************************************** | 
|---|
| 174 | int OS2Icon::QueryIconSize() | 
|---|
| 175 | { | 
|---|
| 176 | return(iconsize); | 
|---|
| 177 | } | 
|---|
| 178 | //****************************************************************************** | 
|---|
| 179 | //****************************************************************************** | 
|---|
| 180 | BITMAPFILEHEADER2 *OS2Icon::GetIconHeader() | 
|---|
| 181 | { | 
|---|
| 182 | return(iconhdr); | 
|---|
| 183 | } | 
|---|
| 184 | //****************************************************************************** | 
|---|
| 185 | //****************************************************************************** | 
|---|
| 186 | /*static*/ OS2Icon *OS2Icon::GetIcon(int id) | 
|---|
| 187 | { | 
|---|
| 188 | OS2Icon *icon = OS2Icon::icons; | 
|---|
| 189 |  | 
|---|
| 190 | while(icon != NULL) { | 
|---|
| 191 | if(icon->id == id)      return(icon); | 
|---|
| 192 | icon = icon->next; | 
|---|
| 193 | } | 
|---|
| 194 | return(NULL); | 
|---|
| 195 | } | 
|---|
| 196 | //****************************************************************************** | 
|---|
| 197 | //****************************************************************************** | 
|---|
| 198 | /*static*/ void OS2Icon::DestroyAll() | 
|---|
| 199 | { | 
|---|
| 200 | OS2Icon *icon = OS2Icon::icons, *next; | 
|---|
| 201 |  | 
|---|
| 202 | while(icon != NULL) { | 
|---|
| 203 | next = icon->next; | 
|---|
| 204 | delete(icon); | 
|---|
| 205 | icon = next; | 
|---|
| 206 | } | 
|---|
| 207 | } | 
|---|
| 208 | //****************************************************************************** | 
|---|
| 209 | //****************************************************************************** | 
|---|
| 210 | OS2Icon *OS2Icon::icons = NULL; | 
|---|