source: trunk/src/user32/icon.cpp@ 96

Last change on this file since 96 was 96, checked in by phaller, 26 years ago

Add: added cvs variable $Id$ to source files.

File size: 4.8 KB
Line 
1/* $Id: icon.cpp,v 1.3 1999-06-10 16:50:39 phaller Exp $ */
2
3/*
4 *
5 * Project Odin Software License can be found in LICENSE.TXT
6 *
7 */
8/*
9 * Win32 icon conversion functions for OS/2
10 *
11 * Copyright 1998 Sander van Leeuwen
12 *
13 */
14#define INCL_GPIBITMAPS
15#define INCL_BITMAPFILEFORMAT
16#define INCL_DOSFILEMGR /* File Manager values */
17#define INCL_DOSERRORS /* DOS Error values */
18#define INCL_DOSPROCESS /* DOS Process values */
19#define INCL_DOSMISC /* DOS Miscellanous values */
20#define INCL_WIN
21#include <os2.h>
22#include <stdio.h>
23#include <string.h>
24#include <stdlib.h>
25#include <iostream.h>
26#include <string.h>
27#define _ICON_C_
28
29#define DWORD ULONG
30#define LPVOID VOID *
31#define WORD USHORT
32#define WCHAR USHORT
33#define HANDLE ULONG
34#define LPWSTR WCHAR *
35
36#include "icon.h"
37#include "misc.h"
38
39//******************************************************************************
40//******************************************************************************
41PBYTE ConvertWin32Icon(PBYTE presbits, DWORD dwResSize, DWORD *OS2ResSize)
42{
43 WINBITMAPINFOHEADER *bmpHdr = (WINBITMAPINFOHEADER *)presbits;
44 BITMAPFILEHEADER *iconhdr;
45 BITMAPFILEHEADER *iconhdr2;
46 RGBQUAD *rgb;
47 RGB *os2rgb;
48 int bwsize, i, colorsize, rgbsize, iconsize;
49
50 bwsize = (bmpHdr->biWidth*(bmpHdr->biHeight/2))/8;
51 colorsize = bmpHdr->biWidth*(bmpHdr->biHeight/2);
52 if(bmpHdr->biBitCount < 24)
53 rgbsize = (1<<bmpHdr->biBitCount)*sizeof(RGB);
54 else rgbsize = 0;
55
56 switch(bmpHdr->biBitCount) {
57 case 1:
58 colorsize /= 8;
59 break;
60 case 4:
61 colorsize /= 2;
62 break;
63 case 8:
64 break;
65 case 16:
66 colorsize *= 2;
67 break;
68 case 24:
69 colorsize *= 3;
70 break;
71 case 32:
72 colorsize *= 4;
73 break;
74 }
75 if(bmpHdr->biSizeImage == 0 && bmpHdr->biCompression == 0) {
76 bmpHdr->biSizeImage = bwsize + colorsize;
77 }
78#if 0
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#endif
86
87 //bitmapfileheader for AndXor mask + 2 RGB structs + bitmapfileheader
88 //for color bitmap + RGB structs for all the colors
89 //SvL, 15-3-98: 2*bwsize
90 iconsize = 2*sizeof(BITMAPFILEHEADER) + 2*sizeof(RGB) +
91 rgbsize + 2*bwsize + bmpHdr->biSizeImage;
92 //There are icons without an XOR mask, so check for it
93 if(bmpHdr->biSizeImage == colorsize) {
94 iconsize += bwsize;
95 }
96 iconhdr = (BITMAPFILEHEADER *)malloc(iconsize);
97 iconhdr->usType = BFT_COLORICON;
98 iconhdr->cbSize = sizeof(BITMAPFILEHEADER);
99 iconhdr->xHotspot = 0;
100 iconhdr->yHotspot = 0;
101 iconhdr->offBits = 2*sizeof(BITMAPFILEHEADER) +
102 2*sizeof(RGB) + rgbsize;
103 iconhdr->bmp.cbFix = sizeof(BITMAPINFOHEADER);
104 iconhdr->bmp.cx = (USHORT)bmpHdr->biWidth;
105 iconhdr->bmp.cy = (USHORT)bmpHdr->biHeight;
106 iconhdr->bmp.cPlanes = 1;
107 iconhdr->bmp.cBitCount = 1;
108 os2rgb = (RGB *)(iconhdr+1);
109 memset(os2rgb, 0, sizeof(RGB));
110 memset(os2rgb+1, 0xff, sizeof(RGB));
111 iconhdr2 = (BITMAPFILEHEADER *)(os2rgb+2);
112 iconhdr2->usType = BFT_COLORICON;
113 iconhdr2->cbSize = sizeof(BITMAPFILEHEADER);
114 iconhdr2->xHotspot = 0;
115 iconhdr2->yHotspot = 0;
116 iconhdr2->offBits = 2*sizeof(BITMAPFILEHEADER) +
117 2*sizeof(RGB) + rgbsize + 2*bwsize;
118 iconhdr2->bmp.cbFix = sizeof(BITMAPINFOHEADER);
119 iconhdr2->bmp.cx = (USHORT)bmpHdr->biWidth;
120 iconhdr2->bmp.cy = (USHORT)(bmpHdr->biHeight/2);
121 iconhdr2->bmp.cPlanes = bmpHdr->biPlanes;
122 iconhdr2->bmp.cBitCount= bmpHdr->biBitCount;
123 os2rgb = (RGB *)(iconhdr2+1);
124 rgb = (RGBQUAD *)(bmpHdr+1);
125 if(bmpHdr->biBitCount < 24) {
126 for(i=0;i<(1<<bmpHdr->biBitCount);i++) {
127 os2rgb->bRed = rgb->red;
128 os2rgb->bBlue = rgb->blue;
129 os2rgb->bGreen = rgb->green;
130 os2rgb++;
131 rgb++;
132 }
133 }
134 //write 2*mono pixels + color pixels
135 //There are icons without an XOR mask, so check for it
136 if(bmpHdr->biSizeImage == colorsize) {
137 memset((char *)os2rgb, 0, bwsize);
138 memset((char *)os2rgb+bwsize, 0, bwsize);
139 memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
140 }
141 else {
142 memcpy((char *)os2rgb, (char *)rgb+colorsize, bwsize);
143 memcpy((char *)os2rgb+bwsize, (char *)rgb+colorsize, bwsize);
144 memcpy((char *)os2rgb+2*bwsize, (char *)rgb, colorsize);
145 }
146 *OS2ResSize = iconsize;
147 return((PBYTE)iconhdr);
148}
149//******************************************************************************
150//******************************************************************************
151void FreeIcon(void *os2icon)
152{
153 free(os2icon);
154}
155//******************************************************************************
156//******************************************************************************
Note: See TracBrowser for help on using the repository browser.