source: trunk/src/kernel32/cvticon.cpp@ 589

Last change on this file since 589 was 589, checked in by sandervl, 26 years ago

More PE resource changes

File size: 5.3 KB
Line 
1/* $Id: cvticon.cpp,v 1.2 1999-08-19 19:50:40 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//NOTE: offsetBits is the value added to the offBits bitmap structure members
30// (handy for converting icon groups)
31//******************************************************************************
32void *ConvertIcon(WINBITMAPINFOHEADER *bmpHdr, int size, int offsetBits)
33{
34 RGBQUAD *rgb;
35 RGB2 *os2rgb;
36 int bwsize, i, colorsize, rgbsize, iconsize;
37 BITMAPFILEHEADER2 *iconhdr;
38 BITMAPFILEHEADER2 *iconhdr2;
39
40 bwsize = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
41 colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
42 //SvL: 28-09-'98: only for <= 8
43 if(bmpHdr->biBitCount <= 8)
44 rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB2);
45 else rgbsize = 0;
46
47 switch(bmpHdr->biBitCount) {
48 case 1:
49 colorsize /= 8;
50 break;
51 case 4:
52 colorsize /= 2;
53 break;
54 case 8:
55 break;
56 case 16:
57 colorsize *= 2;
58 break;
59 case 24:
60 colorsize *= 3;
61 break;
62 case 32:
63 colorsize *= 4;
64 break;
65 }
66 if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) {
67 bmpHdr->biSizeImage = bwsize + colorsize;
68 }
69 dprintf(("Icon size : %d", bmpHdr->biSizeImage));
70 dprintf(("Icon Width : %d", bmpHdr->biWidth));
71 //height for both the XOR and AND bitmap (color & BW)
72 dprintf(("Height : %d", bmpHdr->biHeight));
73 dprintf(("Icon Bitcount: %d", bmpHdr->biBitCount));
74 dprintf(("Icon Compress: %d", bmpHdr->biCompression));
75
76 //SvL: 28-09-'98: cllngenu.dll has an incorrect size in the header
77 if(bmpHdr->biSizeImage < colorsize) {
78 bmpHdr->biSizeImage = colorsize;
79 }
80 //bitmapfileheader for AndXor mask + 2 RGB structs + bitmapfileheader
81 //for color bitmap + RGB structs for all the colors
82 //SvL, 3-3-98: 2*bwsize
83 iconsize = 2*sizeof(BITMAPFILEHEADER2) + 2*sizeof(RGB2) +
84 rgbsize + 2*bwsize + bmpHdr->biSizeImage;
85 //There are icons without an XOR mask, so check for it
86 if(bmpHdr->biSizeImage == colorsize) {
87 iconsize += bwsize;
88 }
89 iconhdr = (BITMAPFILEHEADER2 *)malloc(iconsize);
90 memset(iconhdr, 0, iconsize);
91 iconhdr->usType = BFT_COLORICON;
92 iconhdr->cbSize = sizeof(BITMAPFILEHEADER2);
93 iconhdr->xHotspot = 0;
94 iconhdr->yHotspot = 0;
95 iconhdr->offBits = 2*sizeof(BITMAPFILEHEADER2) +
96 2*sizeof(RGB2) + rgbsize + offsetBits;
97 iconhdr->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
98 iconhdr->bmp2.cx = (USHORT)bmpHdr->biWidth;
99 iconhdr->bmp2.cy = (USHORT)bmpHdr->biHeight;
100 iconhdr->bmp2.cPlanes = 1;
101 iconhdr->bmp2.cBitCount= 1;
102 iconhdr->bmp2.ulCompression = BCA_UNCOMP;
103 iconhdr->bmp2.ulColorEncoding = BCE_RGB;
104 os2rgb = (RGB2 *)(iconhdr+1);
105 memset(os2rgb, 0, sizeof(RGB2));
106 memset(os2rgb+1, 0xff, sizeof(RGB2)); //not reserved byte
107 iconhdr2 = (BITMAPFILEHEADER2 *)(os2rgb+2);
108 iconhdr2->usType = BFT_COLORICON;
109 iconhdr2->cbSize = sizeof(BITMAPFILEHEADER2);
110 iconhdr2->xHotspot = 0;
111 iconhdr2->yHotspot = 0;
112 iconhdr2->offBits = 2*sizeof(BITMAPFILEHEADER2) +
113 2*sizeof(RGB2) + rgbsize + 2*bwsize + offsetBits;
114 iconhdr2->bmp2.cbFix = sizeof(BITMAPINFOHEADER2);
115 iconhdr2->bmp2.cx = (USHORT)bmpHdr->biWidth;
116 iconhdr2->bmp2.cy = (USHORT)(bmpHdr->biHeight/2);
117 iconhdr2->bmp2.cPlanes = bmpHdr->biPlanes;
118 iconhdr2->bmp2.cBitCount= bmpHdr->biBitCount;
119 iconhdr2->bmp2.ulCompression = BCA_UNCOMP;
120 iconhdr2->bmp2.ulColorEncoding = BCE_RGB;
121 os2rgb = (RGB2 *)(iconhdr2+1);
122 rgb = (RGBQUAD *)(bmpHdr+1);
123 if(bmpHdr->biBitCount < 24) {
124 for(i=0;i<(1<<bmpHdr->biBitCount);i++) {
125 os2rgb->bRed = rgb->red;
126 os2rgb->bBlue = rgb->blue;
127 os2rgb->bGreen = rgb->green;
128 os2rgb++;
129 rgb++;
130 }
131 }
132 //write 2*mono pixels + color pixels
133 //There are icons without an XOR mask, so check for it
134 if(bmpHdr->biSizeImage == colorsize)
135 {
136 memset((char *)os2rgb, 0, bwsize);
137 memset((char *)os2rgb+bwsize, 0, bwsize);
138 memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
139 }
140 else {
141 memcpy((char *)os2rgb, (char *)rgb+colorsize, bwsize);
142 memcpy((char *)os2rgb+bwsize, (char *)rgb+colorsize, bwsize);
143 memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
144 }
145 return (void *)iconhdr;
146}
147//******************************************************************************
148//******************************************************************************
Note: See TracBrowser for help on using the repository browser.