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

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

PE loader resource convertion changes

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