source: trunk/src/user32/new/icon.cpp@ 345

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

Accelerator + icon changes

File size: 4.9 KB
Line 
1/* $Id: icon.cpp,v 1.2 1999-07-20 15:46:53 sandervl Exp $ */
2
3/*
4 * Win32 icon conversion functions for OS/2
5 *
6 * Copyright 1998 Sander van Leeuwen
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> //Odin32 OS/2 api wrappers
20#include <stdio.h>
21#include <string.h>
22#include <stdlib.h>
23#include <iostream.h>
24#include <string.h>
25#define _ICON_C_
26
27#define DWORD ULONG
28#define LPVOID VOID *
29#define WORD USHORT
30#define WCHAR USHORT
31#define HANDLE ULONG
32#define LPWSTR WCHAR *
33
34#include "icon.h"
35#include "misc.h"
36
37//******************************************************************************
38//******************************************************************************
39PBYTE ConvertWin32Icon(PBYTE presbits, DWORD dwResSize, DWORD *OS2ResSize)
40{
41 WINBITMAPINFOHEADER *bmpHdr = (WINBITMAPINFOHEADER *)presbits;
42 BITMAPFILEHEADER *iconhdr;
43 BITMAPFILEHEADER *iconhdr2;
44 RGBQUAD *rgb;
45 RGB *os2rgb;
46 int bwsize, i, colorsize, rgbsize, iconsize;
47
48 bwsize = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
49 colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
50 if(bmpHdr->biBitCount < 24)
51 rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB);
52 else rgbsize = 0;
53
54 switch(bmpHdr->biBitCount) {
55 case 1:
56 colorsize /= 8;
57 break;
58 case 4:
59 colorsize /= 2;
60 break;
61 case 8:
62 break;
63 case 16:
64 colorsize *= 2;
65 break;
66 case 24:
67 colorsize *= 3;
68 break;
69 case 32:
70 colorsize *= 4;
71 break;
72 }
73 if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) {
74 bmpHdr->biSizeImage = bwsize + colorsize;
75 }
76#if 0
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#endif
84
85 //bitmapfileheader for AndXor mask + 2 RGB structs + bitmapfileheader
86 //for color bitmap + RGB structs for all the colors
87 //SvL, 15-3-98: 2*bwsize
88 iconsize = 2*sizeof(BITMAPFILEHEADER) + 2*sizeof(RGB) +
89 rgbsize + 2*bwsize + bmpHdr->biSizeImage;
90 //There are icons without an XOR mask, so check for it
91 if(bmpHdr->biSizeImage == colorsize) {
92 iconsize += bwsize;
93 }
94 iconhdr = (BITMAPFILEHEADER *)malloc(iconsize);
95 iconhdr->usType = BFT_COLORICON;
96 iconhdr->cbSize = sizeof(BITMAPFILEHEADER);
97 iconhdr->xHotspot = 0;
98 iconhdr->yHotspot = 0;
99 iconhdr->offBits = 2*sizeof(BITMAPFILEHEADER) +
100 2*sizeof(RGB) + rgbsize;
101 iconhdr->bmp.cbFix = sizeof(BITMAPINFOHEADER);
102 iconhdr->bmp.cx = (USHORT)bmpHdr->biWidth;
103 iconhdr->bmp.cy = (USHORT)bmpHdr->biHeight;
104 iconhdr->bmp.cPlanes = 1;
105 iconhdr->bmp.cBitCount = 1;
106 os2rgb = (RGB *)(iconhdr+1);
107 memset(os2rgb, 0, sizeof(RGB));
108 memset(os2rgb+1, 0xff, sizeof(RGB));
109 iconhdr2 = (BITMAPFILEHEADER *)(os2rgb+2);
110 iconhdr2->usType = BFT_COLORICON;
111 iconhdr2->cbSize = sizeof(BITMAPFILEHEADER);
112 iconhdr2->xHotspot = 0;
113 iconhdr2->yHotspot = 0;
114 iconhdr2->offBits = 2*sizeof(BITMAPFILEHEADER) +
115 2*sizeof(RGB) + rgbsize + 2*bwsize;
116 iconhdr2->bmp.cbFix = sizeof(BITMAPINFOHEADER);
117 iconhdr2->bmp.cx = (USHORT)bmpHdr->biWidth;
118 iconhdr2->bmp.cy = (USHORT)(bmpHdr->biHeight/2);
119 iconhdr2->bmp.cPlanes = bmpHdr->biPlanes;
120 iconhdr2->bmp.cBitCount= bmpHdr->biBitCount;
121 os2rgb = (RGB *)(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 memset((char *)os2rgb, 0, bwsize);
136 memset((char *)os2rgb+bwsize, 0, bwsize);
137 memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
138 }
139 else {
140 memcpy((char *)os2rgb, (char *)rgb+colorsize, bwsize);
141 memcpy((char *)os2rgb+bwsize, (char *)rgb+colorsize, bwsize);
142 memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
143 }
144 *OS2ResSize = iconsize;
145 return((PBYTE)iconhdr);
146}
147//******************************************************************************
148//******************************************************************************
149void FreeIcon(void *os2icon)
150{
151 free(os2icon);
152}
153//******************************************************************************
154//******************************************************************************
Note: See TracBrowser for help on using the repository browser.