1 | /* $Id: icon.cpp,v 1.1 1999-05-24 20:19:54 ktk 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 | RGB *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(RGB);
|
---|
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(BITMAPFILEHEADER) + 2*sizeof(RGB) +
|
---|
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 = (BITMAPFILEHEADER *)malloc(iconsize);
|
---|
100 | iconhdr->usType = BFT_COLORICON;
|
---|
101 | iconhdr->cbSize = sizeof(BITMAPFILEHEADER);
|
---|
102 | iconhdr->xHotspot = 0;
|
---|
103 | iconhdr->yHotspot = 0;
|
---|
104 | iconhdr->offBits = 2*sizeof(BITMAPFILEHEADER) +
|
---|
105 | 2*sizeof(RGB) + rgbsize;
|
---|
106 | iconhdr->bmp.cbFix = sizeof(BITMAPINFOHEADER);
|
---|
107 | iconhdr->bmp.cx = (USHORT)bmpHdr->biWidth;
|
---|
108 | iconhdr->bmp.cy = (USHORT)bmpHdr->biHeight;
|
---|
109 | iconhdr->bmp.cPlanes = 1;
|
---|
110 | iconhdr->bmp.cBitCount = 1;
|
---|
111 | os2rgb = (RGB *)(iconhdr+1);
|
---|
112 | memset(os2rgb, 0, sizeof(RGB));
|
---|
113 | memset(os2rgb+1, 0xff, sizeof(RGB));
|
---|
114 | iconhdr2 = (BITMAPFILEHEADER *)(os2rgb+2);
|
---|
115 | iconhdr2->usType = BFT_COLORICON;
|
---|
116 | iconhdr2->cbSize = sizeof(BITMAPFILEHEADER);
|
---|
117 | iconhdr2->xHotspot = 0;
|
---|
118 | iconhdr2->yHotspot = 0;
|
---|
119 | iconhdr2->offBits = 2*sizeof(BITMAPFILEHEADER) +
|
---|
120 | 2*sizeof(RGB) + rgbsize + 2*bwsize;
|
---|
121 | iconhdr2->bmp.cbFix = sizeof(BITMAPINFOHEADER);
|
---|
122 | iconhdr2->bmp.cx = (USHORT)bmpHdr->biWidth;
|
---|
123 | iconhdr2->bmp.cy = (USHORT)(bmpHdr->biHeight/2);
|
---|
124 | iconhdr2->bmp.cPlanes = bmpHdr->biPlanes;
|
---|
125 | iconhdr2->bmp.cBitCount= bmpHdr->biBitCount;
|
---|
126 | os2rgb = (RGB *)(iconhdr2+1);
|
---|
127 | rgb = (RGBQUAD *)(bmpHdr+1);
|
---|
128 | if(bmpHdr->biBitCount < 24) {
|
---|
129 | for(i=0;i<(1<<bmpHdr->biBitCount);i++) {
|
---|
130 | //// cout << "(R,G,B) = (" << (int)rgb->red << ", " << (int)rgb->green << ", " << (int)rgb->blue << ")" << endl;
|
---|
131 | os2rgb->bRed = rgb->red;
|
---|
132 | os2rgb->bBlue = rgb->blue;
|
---|
133 | os2rgb->bGreen = rgb->green;
|
---|
134 | os2rgb++;
|
---|
135 | rgb++;
|
---|
136 | }
|
---|
137 | }
|
---|
138 | //write 2*mono pixels + color pixels
|
---|
139 | //There are icons without an XOR mask, so check for it
|
---|
140 | if(bmpHdr->biSizeImage == colorsize) {
|
---|
141 | memset((char *)os2rgb, 0, bwsize);
|
---|
142 | memset((char *)os2rgb+bwsize, 0, bwsize);
|
---|
143 | memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
|
---|
144 | }
|
---|
145 | else {
|
---|
146 | memcpy((char *)os2rgb, (char *)rgb+colorsize, bwsize);
|
---|
147 | memcpy((char *)os2rgb+bwsize, (char *)rgb+colorsize, bwsize);
|
---|
148 | memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
|
---|
149 | }
|
---|
150 | }
|
---|
151 | //******************************************************************************
|
---|
152 | //******************************************************************************
|
---|
153 | void OS2Icon::SetIconHdrOffset(int offset)
|
---|
154 | {
|
---|
155 | iconhdr->offBits += offset - prevoffset;
|
---|
156 | iconhdr2->offBits += offset - prevoffset;
|
---|
157 | //remember in case icons are used in multiple groups
|
---|
158 | //(can't imagine this ever happening, but you never know)
|
---|
159 | prevoffset = offset;
|
---|
160 | }
|
---|
161 | //******************************************************************************
|
---|
162 | //******************************************************************************
|
---|
163 | OS2Icon::~OS2Icon()
|
---|
164 | {
|
---|
165 | if(iconhdr) free(iconhdr);
|
---|
166 | }
|
---|
167 | //******************************************************************************
|
---|
168 | //******************************************************************************
|
---|
169 | int OS2Icon::QueryIconSize()
|
---|
170 | {
|
---|
171 | return(iconsize);
|
---|
172 | }
|
---|
173 | //******************************************************************************
|
---|
174 | //******************************************************************************
|
---|
175 | BITMAPFILEHEADER *OS2Icon::GetIconHeader()
|
---|
176 | {
|
---|
177 | return(iconhdr);
|
---|
178 | }
|
---|
179 | //******************************************************************************
|
---|
180 | //******************************************************************************
|
---|
181 | /*static*/ OS2Icon *OS2Icon::GetIcon(int id)
|
---|
182 | {
|
---|
183 | OS2Icon *icon = OS2Icon::icons;
|
---|
184 |
|
---|
185 | while(icon != NULL) {
|
---|
186 | if(icon->id == id) return(icon);
|
---|
187 | icon = icon->next;
|
---|
188 | }
|
---|
189 | return(NULL);
|
---|
190 | }
|
---|
191 | //******************************************************************************
|
---|
192 | //******************************************************************************
|
---|
193 | /*static*/ void OS2Icon::DestroyAll()
|
---|
194 | {
|
---|
195 | OS2Icon *icon = OS2Icon::icons, *next;
|
---|
196 |
|
---|
197 | while(icon != NULL) {
|
---|
198 | next = icon->next;
|
---|
199 | delete(icon);
|
---|
200 | icon = next;
|
---|
201 | }
|
---|
202 | }
|
---|
203 | //******************************************************************************
|
---|
204 | //******************************************************************************
|
---|
205 | OS2Icon *OS2Icon::icons = NULL;
|
---|