1 | /* $Id: dib.cpp,v 1.5 2000-02-16 14:34:16 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Win32 DIB functions for OS/2
|
---|
5 | *
|
---|
6 | * Copyright 1999 Sander van Leeuwen (OS/2 Port)
|
---|
7 | *
|
---|
8 | * Based on Wine code (objects\dib.c):
|
---|
9 | *
|
---|
10 | * GDI device-independent bitmaps
|
---|
11 | *
|
---|
12 | * Copyright 1993,1994 Alexandre Julliard
|
---|
13 | *
|
---|
14 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
15 | *
|
---|
16 | *
|
---|
17 | */
|
---|
18 |
|
---|
19 | #include <os2win.h>
|
---|
20 | #include <stdlib.h>
|
---|
21 | #include <misc.h>
|
---|
22 |
|
---|
23 | #define DBG_LOCALLOG DBG_dib
|
---|
24 | #include "dbglocal.h"
|
---|
25 |
|
---|
26 | /***********************************************************************
|
---|
27 | * DIB_GetDIBWidthBytes
|
---|
28 | *
|
---|
29 | * Return the width of a DIB bitmap in bytes. DIB bitmap data is 32-bit aligned.
|
---|
30 | * http://www.microsoft.com/msdn/sdk/platforms/doc/sdk/win32/struc/src/str01.htm
|
---|
31 | */
|
---|
32 | int DIB_GetDIBWidthBytes( int width, int depth )
|
---|
33 | {
|
---|
34 | int words;
|
---|
35 |
|
---|
36 | switch(depth)
|
---|
37 | {
|
---|
38 | case 1: words = (width + 31) / 32; break;
|
---|
39 | case 4: words = (width + 7) / 8; break;
|
---|
40 | case 8: words = (width + 3) / 4; break;
|
---|
41 | case 15:
|
---|
42 | case 16: words = (width + 1) / 2; break;
|
---|
43 | case 24: words = (width * 3 + 3)/4; break;
|
---|
44 |
|
---|
45 | default:
|
---|
46 | dprintf(("(%d): Unsupported depth\n", depth ));
|
---|
47 | /* fall through */
|
---|
48 | case 32:
|
---|
49 | words = width;
|
---|
50 | }
|
---|
51 | return 4 * words;
|
---|
52 | }
|
---|
53 |
|
---|
54 | /***********************************************************************
|
---|
55 | * DIB_GetDIBImageBytes
|
---|
56 | *
|
---|
57 | * Return the number of bytes used to hold the image in a DIB bitmap.
|
---|
58 | */
|
---|
59 | int DIB_GetDIBImageBytes( int width, int height, int depth )
|
---|
60 | {
|
---|
61 | return DIB_GetDIBWidthBytes( width, depth ) * abs( height );
|
---|
62 | }
|
---|
63 |
|
---|
64 |
|
---|
65 | /***********************************************************************
|
---|
66 | * DIB_BitmapInfoSize
|
---|
67 | *
|
---|
68 | * Return the size of the bitmap info structure including color table.
|
---|
69 | */
|
---|
70 | int DIB_BitmapInfoSize( BITMAPINFO * info, WORD coloruse )
|
---|
71 | {
|
---|
72 | int colors;
|
---|
73 |
|
---|
74 | if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
|
---|
75 | {
|
---|
76 | BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)info;
|
---|
77 | colors = (core->bcBitCount <= 8) ? 1 << core->bcBitCount : 0;
|
---|
78 | return sizeof(BITMAPCOREHEADER) + colors *
|
---|
79 | ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBTRIPLE) : sizeof(WORD));
|
---|
80 | }
|
---|
81 | else /* assume BITMAPINFOHEADER */
|
---|
82 | {
|
---|
83 | colors = info->bmiHeader.biClrUsed;
|
---|
84 | if (!colors && (info->bmiHeader.biBitCount <= 8))
|
---|
85 | colors = 1 << info->bmiHeader.biBitCount;
|
---|
86 | return sizeof(BITMAPINFOHEADER) + colors *
|
---|
87 | ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 |
|
---|
92 | /***********************************************************************
|
---|
93 | * DIB_GetBitmapInfo
|
---|
94 | *
|
---|
95 | * Get the info from a bitmap header.
|
---|
96 | * Return 1 for INFOHEADER, 0 for COREHEADER, -1 for error.
|
---|
97 | */
|
---|
98 | int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, DWORD *width,
|
---|
99 | int *height, WORD *bpp, WORD *compr )
|
---|
100 | {
|
---|
101 | if (header->biSize == sizeof(BITMAPINFOHEADER))
|
---|
102 | {
|
---|
103 | *width = header->biWidth;
|
---|
104 | *height = header->biHeight;
|
---|
105 | *bpp = header->biBitCount;
|
---|
106 | *compr = header->biCompression;
|
---|
107 | return 1;
|
---|
108 | }
|
---|
109 | if (header->biSize == sizeof(BITMAPCOREHEADER))
|
---|
110 | {
|
---|
111 | BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)header;
|
---|
112 | *width = core->bcWidth;
|
---|
113 | *height = core->bcHeight;
|
---|
114 | *bpp = core->bcBitCount;
|
---|
115 | *compr = 0;
|
---|
116 | return 0;
|
---|
117 | }
|
---|
118 | dprintf(("(%ld): wrong size for header\n", header->biSize ));
|
---|
119 | return -1;
|
---|
120 | }
|
---|
121 |
|
---|
122 | /***********************************************************************
|
---|
123 | * DIB_FixColorsToLoadflags
|
---|
124 | *
|
---|
125 | * Change color table entries when LR_LOADTRANSPARENT or LR_LOADMAP3DCOLORS
|
---|
126 | * are in loadflags
|
---|
127 | */
|
---|
128 | void DIB_FixColorsToLoadflags(BITMAPINFO * bmi, UINT loadflags, BYTE pix)
|
---|
129 | {
|
---|
130 | int colors, bitcount;
|
---|
131 | COLORREF c_W, c_S, c_F, c_L, c_C;
|
---|
132 | int incr,i;
|
---|
133 | RGBQUAD *ptr;
|
---|
134 | char *colorptr;
|
---|
135 |
|
---|
136 | //SvL: Wine code doesn't work for OS/2 1.3 bitmaps
|
---|
137 | if (bmi->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
|
---|
138 | {
|
---|
139 | if (bmi->bmiHeader.biBitCount > 8) return;
|
---|
140 | colors = bmi->bmiHeader.biClrUsed;
|
---|
141 | bitcount = bmi->bmiHeader.biBitCount;
|
---|
142 | colorptr = (char*)bmi->bmiColors;
|
---|
143 | incr = 4;
|
---|
144 | }
|
---|
145 | else
|
---|
146 | if (bmi->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
|
---|
147 | {
|
---|
148 | BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)bmi;
|
---|
149 |
|
---|
150 | if (core->bcBitCount > 8) return;
|
---|
151 | colors = (1 << core->bcBitCount);
|
---|
152 | bitcount = core->bcBitCount;
|
---|
153 | colorptr = (char*)(core + 1);
|
---|
154 | incr = 3;
|
---|
155 | }
|
---|
156 | else
|
---|
157 | {
|
---|
158 | dprintf(("Wrong bitmap header size!\n"));
|
---|
159 | return;
|
---|
160 | }
|
---|
161 |
|
---|
162 | if (!colors && (bitcount <= 8))
|
---|
163 | colors = 1 << bitcount;
|
---|
164 |
|
---|
165 | c_W = GetSysColor(COLOR_WINDOW);
|
---|
166 | c_S = GetSysColor(COLOR_3DSHADOW);
|
---|
167 | c_F = GetSysColor(COLOR_3DFACE);
|
---|
168 | c_L = GetSysColor(COLOR_3DLIGHT);
|
---|
169 | if (loadflags & LR_LOADTRANSPARENT) {
|
---|
170 | switch (bitcount) {
|
---|
171 | case 1: pix = pix >> 7; break;
|
---|
172 | case 4: pix = pix >> 4; break;
|
---|
173 | case 8: break;
|
---|
174 | default:
|
---|
175 | dprintf(("(%d): Unsupported depth\n", bitcount));
|
---|
176 | return;
|
---|
177 | }
|
---|
178 | if (pix >= colors) {
|
---|
179 | dprintf(("pixel has color index greater than biClrUsed!\n"));
|
---|
180 | return;
|
---|
181 | }
|
---|
182 | if (loadflags & LR_LOADMAP3DCOLORS) c_W = c_F;
|
---|
183 | ptr = (RGBQUAD*)((char*)colorptr+pix*incr);
|
---|
184 |
|
---|
185 | ptr->rgbBlue = GetBValue(c_W);
|
---|
186 | ptr->rgbGreen = GetGValue(c_W);
|
---|
187 | ptr->rgbRed = GetRValue(c_W);
|
---|
188 | }
|
---|
189 | if (loadflags & LR_LOADMAP3DCOLORS) {
|
---|
190 | for (i=0; i<colors; i++) {
|
---|
191 | ptr = (RGBQUAD*)(colorptr +i*incr);
|
---|
192 | c_C = RGB(ptr->rgbRed, ptr->rgbGreen, ptr->rgbBlue);
|
---|
193 | if (c_C == RGB(128, 128, 128)) {
|
---|
194 | ptr->rgbRed = GetRValue(c_S);
|
---|
195 | ptr->rgbGreen = GetGValue(c_S);
|
---|
196 | ptr->rgbBlue = GetBValue(c_S);
|
---|
197 | } else if (c_C == RGB(192, 192, 192)) {
|
---|
198 | ptr->rgbRed = GetRValue(c_F);
|
---|
199 | ptr->rgbGreen = GetGValue(c_F);
|
---|
200 | ptr->rgbBlue = GetBValue(c_F);
|
---|
201 | } else if (c_C == RGB(223, 223, 223)) {
|
---|
202 | ptr->rgbRed = GetRValue(c_L);
|
---|
203 | ptr->rgbGreen = GetGValue(c_L);
|
---|
204 | ptr->rgbBlue = GetBValue(c_L);
|
---|
205 | }
|
---|
206 | }
|
---|
207 | }
|
---|
208 |
|
---|
209 | }
|
---|