00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <os2win.h>
00020 #include <stdlib.h>
00021 #include <misc.h>
00022 #include "dib.h"
00023
00024 #define DBG_LOCALLOG DBG_dib
00025 #include "dbglocal.h"
00026
00027
00028
00029
00030
00031
00032
00033 int WIN32API DIB_GetDIBWidthBytes( int width, int depth )
00034 {
00035 int words;
00036
00037 switch(depth)
00038 {
00039 case 1: words = (width + 31) / 32; break;
00040 case 4: words = (width + 7) / 8; break;
00041 case 8: words = (width + 3) / 4; break;
00042 case 15:
00043 case 16: words = (width + 1) / 2; break;
00044 case 24: words = (width * 3 + 3)/4; break;
00045
00046 default:
00047 dprintf(("(%d): Unsupported depth\n", depth ));
00048
00049 case 32:
00050 words = width;
00051 }
00052 return 4 * words;
00053 }
00054
00055
00056
00057
00058
00059
00060 int DIB_GetDIBImageBytes( int width, int height, int depth )
00061 {
00062 return DIB_GetDIBWidthBytes( width, depth ) * abs( height );
00063 }
00064
00065
00066
00067
00068
00069
00070
00071 int DIB_BitmapInfoSize( BITMAPINFO * info, WORD coloruse )
00072 {
00073 int colors;
00074
00075 if (info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
00076 {
00077 BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)info;
00078 colors = (core->bcBitCount <= 8) ? 1 << core->bcBitCount : 0;
00079 return sizeof(BITMAPCOREHEADER) + colors *
00080 ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBTRIPLE) : sizeof(WORD));
00081 }
00082 else
00083 {
00084 colors = info->bmiHeader.biClrUsed;
00085 if (!colors && (info->bmiHeader.biBitCount <= 8))
00086 colors = 1 << info->bmiHeader.biBitCount;
00087 return sizeof(BITMAPINFOHEADER) + colors *
00088 ((coloruse == DIB_RGB_COLORS) ? sizeof(RGBQUAD) : sizeof(WORD));
00089 }
00090 }
00091
00092
00093
00094
00095
00096
00097
00098
00099 int DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, DWORD *width,
00100 int *height, WORD *bpp, WORD *compr )
00101 {
00102 if (header->biSize == sizeof(BITMAPINFOHEADER))
00103 {
00104 *width = header->biWidth;
00105 *height = header->biHeight;
00106 *bpp = header->biBitCount;
00107 *compr = header->biCompression;
00108 return 1;
00109 }
00110 if (header->biSize == sizeof(BITMAPCOREHEADER))
00111 {
00112 BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)header;
00113 *width = core->bcWidth;
00114 *height = core->bcHeight;
00115 *bpp = core->bcBitCount;
00116 *compr = 0;
00117 return 0;
00118 }
00119 dprintf(("(%ld): wrong size for header\n", header->biSize ));
00120 return -1;
00121 }
00122
00123
00124
00125
00126
00127
00128
00129 void DIB_FixColorsToLoadflags(BITMAPINFO * bmi, UINT loadflags, BYTE pix)
00130 {
00131 int colors, bitcount;
00132 COLORREF c_W, c_S, c_F, c_L, c_C;
00133 int incr,i;
00134 RGBQUAD *ptr;
00135 char *colorptr;
00136
00137
00138 if (bmi->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
00139 {
00140 if (bmi->bmiHeader.biBitCount > 8) return;
00141 colors = bmi->bmiHeader.biClrUsed;
00142 bitcount = bmi->bmiHeader.biBitCount;
00143 colorptr = (char*)bmi->bmiColors;
00144 incr = 4;
00145 }
00146 else
00147 if (bmi->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
00148 {
00149 BITMAPCOREHEADER *core = (BITMAPCOREHEADER *)bmi;
00150
00151 if (core->bcBitCount > 8) return;
00152 colors = (1 << core->bcBitCount);
00153 bitcount = core->bcBitCount;
00154 colorptr = (char*)(core + 1);
00155 incr = 3;
00156 }
00157 else
00158 {
00159 dprintf(("Wrong bitmap header size!\n"));
00160 return;
00161 }
00162
00163 if (!colors && (bitcount <= 8))
00164 colors = 1 << bitcount;
00165
00166 c_W = GetSysColor(COLOR_WINDOW);
00167 c_S = GetSysColor(COLOR_3DSHADOW);
00168 c_F = GetSysColor(COLOR_3DFACE);
00169 c_L = GetSysColor(COLOR_3DLIGHT);
00170 if (loadflags & LR_LOADTRANSPARENT) {
00171 switch (bitcount) {
00172 case 1: pix = pix >> 7; break;
00173 case 4: pix = pix >> 4; break;
00174 case 8: break;
00175 default:
00176 dprintf(("(%d): Unsupported depth\n", bitcount));
00177 return;
00178 }
00179 if (pix >= colors) {
00180 dprintf(("pixel has color index greater than biClrUsed!\n"));
00181 return;
00182 }
00183 if (loadflags & LR_LOADMAP3DCOLORS) c_W = c_F;
00184 ptr = (RGBQUAD*)((char*)colorptr+pix*incr);
00185
00186 ptr->rgbBlue = GetBValue(c_W);
00187 ptr->rgbGreen = GetGValue(c_W);
00188 ptr->rgbRed = GetRValue(c_W);
00189 }
00190 if (loadflags & LR_LOADMAP3DCOLORS) {
00191 for (i=0; i<colors; i++) {
00192 ptr = (RGBQUAD*)(colorptr +i*incr);
00193 c_C = RGB(ptr->rgbRed, ptr->rgbGreen, ptr->rgbBlue);
00194 if (c_C == RGB(128, 128, 128)) {
00195 ptr->rgbRed = GetRValue(c_S);
00196 ptr->rgbGreen = GetGValue(c_S);
00197 ptr->rgbBlue = GetBValue(c_S);
00198 } else if (c_C == RGB(192, 192, 192)) {
00199 ptr->rgbRed = GetRValue(c_F);
00200 ptr->rgbGreen = GetGValue(c_F);
00201 ptr->rgbBlue = GetBValue(c_F);
00202 } else if (c_C == RGB(223, 223, 223)) {
00203 ptr->rgbRed = GetRValue(c_L);
00204 ptr->rgbGreen = GetGValue(c_L);
00205 ptr->rgbBlue = GetBValue(c_L);
00206 }
00207 }
00208 }
00209
00210 }
00211
00212
00213
00214
00215
00216
00217
00218 int WIN32API BITMAP_GetWidthBytes( INT bmWidth, INT bpp )
00219 {
00220 switch(bpp)
00221 {
00222 case 1:
00223 return 2 * ((bmWidth+15) >> 4);
00224
00225 case 24:
00226 bmWidth *= 3;
00227 case 8:
00228 return bmWidth + (bmWidth & 1);
00229
00230 case 32:
00231 return bmWidth * 4;
00232
00233 case 16:
00234 case 15:
00235 return bmWidth * 2;
00236
00237 case 4:
00238 return 2 * ((bmWidth+3) >> 2);
00239
00240 default:
00241 dprintf(("BITMAP_GetWidthBytes: Unknown depth %d, please report.\n", bpp ));
00242 }
00243 return -1;
00244 }