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