|
|
@ -16,18 +16,6 @@ GNU General Public License for more details. |
|
|
|
#include "imagelib.h" |
|
|
|
#include "imagelib.h" |
|
|
|
#include "mathlib.h" |
|
|
|
#include "mathlib.h" |
|
|
|
|
|
|
|
|
|
|
|
#define BI_SIZE 40 //size of bitmap info header.
|
|
|
|
|
|
|
|
#if !XASH_WIN32 |
|
|
|
|
|
|
|
#define BI_RGB 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef struct tagRGBQUAD { |
|
|
|
|
|
|
|
BYTE rgbBlue; |
|
|
|
|
|
|
|
BYTE rgbGreen; |
|
|
|
|
|
|
|
BYTE rgbRed; |
|
|
|
|
|
|
|
BYTE rgbReserved; |
|
|
|
|
|
|
|
} RGBQUAD; |
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
============= |
|
|
|
============= |
|
|
|
Image_LoadBMP |
|
|
|
Image_LoadBMP |
|
|
@ -36,7 +24,7 @@ Image_LoadBMP |
|
|
|
qboolean Image_LoadBMP( const char *name, const byte *buffer, fs_offset_t filesize ) |
|
|
|
qboolean Image_LoadBMP( const char *name, const byte *buffer, fs_offset_t filesize ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
byte *buf_p, *pixbuf; |
|
|
|
byte *buf_p, *pixbuf; |
|
|
|
byte palette[256][4]; |
|
|
|
rgba_t palette[256]; |
|
|
|
int i, columns, column, rows, row, bpp = 1; |
|
|
|
int i, columns, column, rows, row, bpp = 1; |
|
|
|
int cbPalBytes = 0, padSize = 0, bps = 0; |
|
|
|
int cbPalBytes = 0, padSize = 0, bps = 0; |
|
|
|
int reflectivity[3] = { 0, 0, 0 }; |
|
|
|
int reflectivity[3] = { 0, 0, 0 }; |
|
|
@ -103,9 +91,9 @@ qboolean Image_LoadBMP( const char *name, const byte *buffer, fs_offset_t filesi |
|
|
|
if( bhdr.colors == 0 ) |
|
|
|
if( bhdr.colors == 0 ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
bhdr.colors = 256; |
|
|
|
bhdr.colors = 256; |
|
|
|
cbPalBytes = ( 1 << bhdr.bitsPerPixel ) * sizeof( RGBQUAD ); |
|
|
|
cbPalBytes = ( 1 << bhdr.bitsPerPixel ) * sizeof( rgba_t ); |
|
|
|
} |
|
|
|
} |
|
|
|
else cbPalBytes = bhdr.colors * sizeof( RGBQUAD ); |
|
|
|
else cbPalBytes = bhdr.colors * sizeof( rgba_t ); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
memcpy( palette, buf_p, cbPalBytes ); |
|
|
|
memcpy( palette, buf_p, cbPalBytes ); |
|
|
@ -308,7 +296,7 @@ qboolean Image_SaveBMP( const char *name, rgbdata_t *pix ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
file_t *pfile = NULL; |
|
|
|
file_t *pfile = NULL; |
|
|
|
size_t total_size, cur_size; |
|
|
|
size_t total_size, cur_size; |
|
|
|
RGBQUAD rgrgbPalette[256]; |
|
|
|
rgba_t rgrgbPalette[256]; |
|
|
|
dword cbBmpBits; |
|
|
|
dword cbBmpBits; |
|
|
|
byte *clipbuf = NULL; |
|
|
|
byte *clipbuf = NULL; |
|
|
|
byte *pb, *pbBmpBits; |
|
|
|
byte *pb, *pbBmpBits; |
|
|
@ -349,7 +337,7 @@ qboolean Image_SaveBMP( const char *name, rgbdata_t *pix ) |
|
|
|
// after create sprite or lump image, it's just standard requiriments
|
|
|
|
// after create sprite or lump image, it's just standard requiriments
|
|
|
|
biTrueWidth = ((pix->width + 3) & ~3); |
|
|
|
biTrueWidth = ((pix->width + 3) & ~3); |
|
|
|
cbBmpBits = biTrueWidth * pix->height * pixel_size; |
|
|
|
cbBmpBits = biTrueWidth * pix->height * pixel_size; |
|
|
|
cbPalBytes = ( pixel_size == 1 ) ? 256 * sizeof( RGBQUAD ) : 0; |
|
|
|
cbPalBytes = ( pixel_size == 1 ) ? 256 * sizeof( rgba_t ) : 0; |
|
|
|
|
|
|
|
|
|
|
|
// Bogus file header check
|
|
|
|
// Bogus file header check
|
|
|
|
hdr.id[0] = 'B'; |
|
|
|
hdr.id[0] = 'B'; |
|
|
@ -379,15 +367,15 @@ qboolean Image_SaveBMP( const char *name, rgbdata_t *pix ) |
|
|
|
// copy over used entries
|
|
|
|
// copy over used entries
|
|
|
|
for( i = 0; i < (int)hdr.colors; i++ ) |
|
|
|
for( i = 0; i < (int)hdr.colors; i++ ) |
|
|
|
{ |
|
|
|
{ |
|
|
|
rgrgbPalette[i].rgbRed = *pb++; |
|
|
|
rgrgbPalette[i][2] = *pb++; |
|
|
|
rgrgbPalette[i].rgbGreen = *pb++; |
|
|
|
rgrgbPalette[i][1] = *pb++; |
|
|
|
rgrgbPalette[i].rgbBlue = *pb++; |
|
|
|
rgrgbPalette[i][0] = *pb++; |
|
|
|
|
|
|
|
|
|
|
|
// bmp feature - can store 32-bit palette if present
|
|
|
|
// bmp feature - can store 32-bit palette if present
|
|
|
|
// some viewers e.g. fimg.exe can show alpha-chanell for it
|
|
|
|
// some viewers e.g. fimg.exe can show alpha-chanell for it
|
|
|
|
if( pix->type == PF_INDEXED_32 ) |
|
|
|
if( pix->type == PF_INDEXED_32 ) |
|
|
|
rgrgbPalette[i].rgbReserved = *pb++; |
|
|
|
rgrgbPalette[i][3] = *pb++; |
|
|
|
else rgrgbPalette[i].rgbReserved = 0; |
|
|
|
else rgrgbPalette[i][3] = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// write palette
|
|
|
|
// write palette
|
|
|
|