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