Browse Source

engine: common: imagelib: use rgba_t as RGBA palette type.

pull/2/head
Andrey Akhmichin 5 years ago
parent
commit
e96ea719d5
  1. 6
      engine/common/imagelib/imagelib.h
  2. 32
      engine/common/imagelib/img_bmp.c
  3. 3
      engine/common/imagelib/img_tga.c

6
engine/common/imagelib/imagelib.h

@ -105,6 +105,12 @@ typedef struct imglib_s @@ -105,6 +105,12 @@ typedef struct imglib_s
========================================================================
*/
#define BI_SIZE 40 // size of bitmap info header.
#if !defined(BI_RGB)
#define BI_RGB 0 // uncompressed RGB bitmap(defined in wingdi.h)
#endif
#pragma pack( 1 )
typedef struct
{

32
engine/common/imagelib/img_bmp.c

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

3
engine/common/imagelib/img_tga.c

@ -25,7 +25,8 @@ qboolean Image_LoadTGA( const char *name, const byte *buffer, fs_offset_t filesi @@ -25,7 +25,8 @@ qboolean Image_LoadTGA( const char *name, const byte *buffer, fs_offset_t filesi
{
int i, columns, rows, row_inc, row, col;
byte *buf_p, *pixbuf, *targa_rgba;
byte palette[256][4], red = 0, green = 0, blue = 0, alpha = 0;
rgba_t palette[256];
byte red = 0, green = 0, blue = 0, alpha = 0;
int readpixelcount, pixelcount;
int reflectivity[3] = { 0, 0, 0 };
qboolean compressed;

Loading…
Cancel
Save