2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 int fgetLittleShort( FILE *f ){
35 return (short)( b1 + b2 * 256 );
38 int fgetLittleLong( FILE *f ){
46 return b1 + ( b2 << 8 ) + ( b3 << 16 ) + ( b4 << 24 );
49 int bufLittleShort( byte *buf, int len, int *pos ){
52 if ( ( len - *pos ) < 2 ) {
53 Error( "Unexpected buffer end" );
56 b1 = buf[*pos]; *pos += 1;
57 b2 = buf[*pos]; *pos += 1;
59 return (short)( b1 + b2 * 256 );
62 int bufLittleLong( byte *buf, int len, int *pos ){
65 if ( ( len - *pos ) < 4 ) {
66 Error( "Unexpected buffer end" );
69 b1 = buf[*pos]; *pos += 1;
70 b2 = buf[*pos]; *pos += 1;
71 b3 = buf[*pos]; *pos += 1;
72 b4 = buf[*pos]; *pos += 1;
74 return b1 + ( b2 << 8 ) + ( b3 << 16 ) + ( b4 << 24 );
79 ============================================================================
83 ============================================================================
87 typedef unsigned char UBYTE;
88 //conflicts with windows typedef short WORD;
89 typedef unsigned short UWORD;
114 UWORD transparentColor;
115 UBYTE xAspect,yAspect;
116 short pageWidth,pageHeight;
119 extern bmhd_t bmhd; // will be in native byte order
123 #define FORMID ( 'F' + ( 'O' << 8 ) + ( (int)'R' << 16 ) + ( (int)'M' << 24 ) )
124 #define ILBMID ( 'I' + ( 'L' << 8 ) + ( (int)'B' << 16 ) + ( (int)'M' << 24 ) )
125 #define PBMID ( 'P' + ( 'B' << 8 ) + ( (int)'M' << 16 ) + ( (int)' ' << 24 ) )
126 #define BMHDID ( 'B' + ( 'M' << 8 ) + ( (int)'H' << 16 ) + ( (int)'D' << 24 ) )
127 #define BODYID ( 'B' + ( 'O' << 8 ) + ( (int)'D' << 16 ) + ( (int)'Y' << 24 ) )
128 #define CMAPID ( 'C' + ( 'M' << 8 ) + ( (int)'A' << 16 ) + ( (int)'P' << 24 ) )
146 Source must be evenly aligned!
149 byte *LBMRLEDecompress( byte *source,byte *unpacked, int bpwidth ){
160 rept = ( rept ^ 0xff ) + 2;
162 memset( unpacked,b,rept );
165 else if ( rept < 0x80 ) {
167 memcpy( unpacked,source,rept );
172 rept = 0; // rept of 0x80 is NOP
177 } while ( count < bpwidth );
179 if ( count > bpwidth ) {
180 Error( "Decompression exceeded width!\n" );
193 void LoadLBM( const char *filename, byte **picture, byte **palette ){
194 byte *LBMbuffer, *picbuffer, *cmapbuffer;
196 byte *LBM_P, *LBMEND_P;
200 int formtype,formlength;
201 int chunktype,chunklength;
203 // qiet compiler warnings
210 LoadFile( filename, (void **)&LBMbuffer );
213 // parse the LBM header
216 if ( *(int *)LBMbuffer != LittleLong( FORMID ) ) {
217 Error( "No FORM ID at start of file!\n" );
221 formlength = BigLong( *(int *)LBM_P );
223 LBMEND_P = LBM_P + Align( formlength );
225 formtype = LittleLong( *(int *)LBM_P );
227 if ( formtype != ILBMID && formtype != PBMID ) {
228 Error( "Unrecognized form type: %c%c%c%c\n", formtype & 0xff
229 ,( formtype >> 8 ) & 0xff,( formtype >> 16 ) & 0xff,( formtype >> 24 ) & 0xff );
238 while ( LBM_P < LBMEND_P )
240 chunktype = LBM_P[0] + ( LBM_P[1] << 8 ) + ( LBM_P[2] << 16 ) + ( LBM_P[3] << 24 );
242 chunklength = LBM_P[3] + ( LBM_P[2] << 8 ) + ( LBM_P[1] << 16 ) + ( LBM_P[0] << 24 );
248 memcpy( &bmhd,LBM_P,sizeof( bmhd ) );
249 bmhd.w = BigShort( bmhd.w );
250 bmhd.h = BigShort( bmhd.h );
251 bmhd.x = BigShort( bmhd.x );
252 bmhd.y = BigShort( bmhd.y );
253 bmhd.pageWidth = BigShort( bmhd.pageWidth );
254 bmhd.pageHeight = BigShort( bmhd.pageHeight );
258 cmapbuffer = safe_malloc( 768 );
259 memset( cmapbuffer, 0, 768 );
260 memcpy( cmapbuffer, LBM_P, chunklength );
266 pic_p = picbuffer = safe_malloc( bmhd.w * bmhd.h );
267 if ( formtype == PBMID ) {
271 for ( y = 0 ; y < bmhd.h ; y++, pic_p += bmhd.w )
273 if ( bmhd.compression == cm_rle1 ) {
274 body_p = LBMRLEDecompress( (byte *)body_p
277 else if ( bmhd.compression == cm_none ) {
278 memcpy( pic_p,body_p,bmhd.w );
279 body_p += Align( bmhd.w );
289 Error( "%s is an interlaced LBM, not packed", filename );
294 LBM_P += Align( chunklength );
299 *picture = picbuffer;
302 *palette = cmapbuffer;
308 ============================================================================
312 ============================================================================
320 void WriteLBMfile( const char *filename, byte *data,
321 int width, int height, byte *palette ){
323 int *formlength, *bmhdlength, *cmaplength, *bodylength;
327 lbm = lbmptr = safe_malloc( width * height + 1000 );
337 formlength = (int*)lbmptr;
338 lbmptr += 4; // leave space for length
353 bmhdlength = (int *)lbmptr;
354 lbmptr += 4; // leave space for length
356 memset( &basebmhd,0,sizeof( basebmhd ) );
357 basebmhd.w = BigShort( (short)width );
358 basebmhd.h = BigShort( (short)height );
359 basebmhd.nPlanes = BigShort( 8 );
360 basebmhd.xAspect = BigShort( 5 );
361 basebmhd.yAspect = BigShort( 6 );
362 basebmhd.pageWidth = BigShort( (short)width );
363 basebmhd.pageHeight = BigShort( (short)height );
365 memcpy( lbmptr,&basebmhd,sizeof( basebmhd ) );
366 lbmptr += sizeof( basebmhd );
368 length = lbmptr - (byte *)bmhdlength - 4;
369 *bmhdlength = BigLong( length );
371 *lbmptr++ = 0; // pad chunk to even offset
382 cmaplength = (int *)lbmptr;
383 lbmptr += 4; // leave space for length
385 memcpy( lbmptr,palette,768 );
388 length = lbmptr - (byte *)cmaplength - 4;
389 *cmaplength = BigLong( length );
391 *lbmptr++ = 0; // pad chunk to even offset
402 bodylength = (int *)lbmptr;
403 lbmptr += 4; // leave space for length
405 memcpy( lbmptr,data,width * height );
406 lbmptr += width * height;
408 length = lbmptr - (byte *)bodylength - 4;
409 *bodylength = BigLong( length );
411 *lbmptr++ = 0; // pad chunk to even offset
417 length = lbmptr - (byte *)formlength - 4;
418 *formlength = BigLong( length );
420 *lbmptr++ = 0; // pad chunk to even offset
426 SaveFile( filename, lbm, lbmptr - lbm );
432 ============================================================================
436 ============================================================================
445 unsigned short xmin,ymin,xmax,ymax;
446 unsigned short hres,vres;
447 unsigned char palette[48];
450 unsigned short bytes_per_line;
451 unsigned short palette_type;
453 unsigned char data; // unbounded
464 #define DECODEPCX( b, d, r ) d = *b++; if ( ( d & 0xC0 ) == 0xC0 ) {r = d & 0x3F; d = *b++; }else{r = 1; }
466 void LoadPCX( const char *filename, byte **pic, byte **palette, int *width, int *height ){
471 int dataByte, runLength;
476 len = vfsLoadFile( filename, (void **)&raw, 0 );
478 Error( "LoadPCX: Couldn't read %s", filename );
482 /* parse the PCX file */
486 pcx->xmin = LittleShort( pcx->xmin );
487 pcx->ymin = LittleShort( pcx->ymin );
488 pcx->xmax = LittleShort( pcx->xmax );
489 pcx->ymax = LittleShort( pcx->ymax );
490 pcx->hres = LittleShort( pcx->hres );
491 pcx->vres = LittleShort( pcx->vres );
492 pcx->bytes_per_line = LittleShort( pcx->bytes_per_line );
493 pcx->palette_type = LittleShort( pcx->palette_type );
495 if ( pcx->manufacturer != 0x0a
497 || pcx->encoding != 1
498 || pcx->bits_per_pixel != 8
500 || pcx->ymax >= 480 ) {
501 Error( "Bad pcx file %s", filename );
505 *palette = safe_malloc( 768 );
506 memcpy( *palette, (byte *)pcx + len - 768, 768 );
510 *width = pcx->xmax + 1;
513 *height = pcx->ymax + 1;
520 out = safe_malloc( ( pcx->ymax + 1 ) * ( pcx->xmax + 1 ) );
522 Error( "LoadPCX: couldn't allocate" );
528 /* RR2DO2: pcx fix */
529 lsize = pcx->color_planes * pcx->bytes_per_line;
531 /* go scanline by scanline */
532 for ( y = 0; y <= pcx->ymax; y++, pix += pcx->xmax + 1 )
536 for ( x = 0; x <= pcx->xmax; )
539 DECODEPCX( raw, dataByte, runLength );
540 while ( runLength-- > 0 )
541 pix[ x++ ] = dataByte;
544 /* RR2DO2: discard any other data */
547 DECODEPCX( raw, dataByte, runLength );
550 while ( runLength-- > 0 )
555 if ( raw - (byte *) pcx > len ) {
556 Error( "PCX file %s was malformed", filename );
568 void WritePCXfile( const char *filename, byte *data,
569 int width, int height, byte *palette ){
574 pcx = safe_malloc( width * height * 2 + 1000 );
575 memset( pcx, 0, sizeof( *pcx ) );
577 pcx->manufacturer = 0x0a; // PCX id
578 pcx->version = 5; // 256 color
579 pcx->encoding = 1; // uncompressed
580 pcx->bits_per_pixel = 8; // 256 color
583 pcx->xmax = LittleShort( (short)( width - 1 ) );
584 pcx->ymax = LittleShort( (short)( height - 1 ) );
585 pcx->hres = LittleShort( (short)width );
586 pcx->vres = LittleShort( (short)height );
587 pcx->color_planes = 1; // chunky image
588 pcx->bytes_per_line = LittleShort( (short)width );
589 pcx->palette_type = LittleShort( 1 ); // not a grey scale
594 for ( i = 0 ; i < height ; i++ )
596 for ( j = 0 ; j < width ; j++ )
598 if ( ( *data & 0xc0 ) != 0xc0 ) {
610 *pack++ = 0x0c; // palette ID byte
611 for ( i = 0 ; i < 768 ; i++ )
612 *pack++ = *palette++;
615 length = pack - (byte *)pcx;
616 SaveFile( filename, pcx, length );
622 ============================================================================
626 ============================================================================
632 // we can't just use these structures, because
633 // compiler structure alignment will not be portable
634 // on this unaligned stuff
636 typedef struct tagBITMAPFILEHEADER { // bmfh
644 typedef struct tagBITMAPINFOHEADER{ // bmih
652 LONG biXPelsPerMeter;
653 LONG biYPelsPerMeter;
655 DWORD biClrImportant;
658 typedef struct tagBITMAPINFO { // bmi
659 BITMAPINFOHEADER bmiHeader;
660 RGBQUAD bmiColors[1];
663 typedef struct tagBITMAPCOREHEADER { // bmch
671 typedef struct _BITMAPCOREINFO { // bmci
672 BITMAPCOREHEADER bmciHeader;
673 RGBTRIPLE bmciColors[1];
683 void LoadBMP( const char *filename, byte **pic, byte **palette, int *width, int *height ){
692 byte bcPalette[1024];
697 len = vfsLoadFile( filename, (void **)&in, 0 );
699 Error( "Couldn't read %s", filename );
702 i = bufLittleShort( in, len, &pos );
703 if ( i != 'B' + ( 'M' << 8 ) ) {
704 Error( "%s is not a bmp file", filename );
707 /* bfSize = */ bufLittleLong( in, len, &pos );
708 bufLittleShort( in, len, &pos );
709 bufLittleShort( in, len, &pos );
710 bfOffBits = bufLittleLong( in, len, &pos );
712 // the size will tell us if it is a
713 // bitmapinfo or a bitmapcore
714 structSize = bufLittleLong( in, len, &pos );
715 if ( structSize == 40 ) {
717 bcWidth = bufLittleLong( in, len, &pos );
718 bcHeight = bufLittleLong( in, len, &pos );
719 bcPlanes = bufLittleShort( in, len, &pos );
720 bcBitCount = bufLittleShort( in, len, &pos );
725 memcpy( bcPalette, in + pos, 1024 );
727 *palette = safe_malloc( 768 );
729 for ( i = 0 ; i < 256 ; i++ )
731 ( *palette )[i * 3 + 0] = bcPalette[i * 4 + 2];
732 ( *palette )[i * 3 + 1] = bcPalette[i * 4 + 1];
733 ( *palette )[i * 3 + 2] = bcPalette[i * 4 + 0];
737 else if ( structSize == 12 ) {
739 bcWidth = bufLittleShort( in, len, &pos );
740 bcHeight = bufLittleShort( in, len, &pos );
741 bcPlanes = bufLittleShort( in, len, &pos );
742 bcBitCount = bufLittleShort( in, len, &pos );
745 memcpy( bcPalette, in + pos, 768 );
747 *palette = safe_malloc( 768 );
749 for ( i = 0 ; i < 256 ; i++ ) {
750 ( *palette )[i * 3 + 0] = bcPalette[i * 3 + 2];
751 ( *palette )[i * 3 + 1] = bcPalette[i * 3 + 1];
752 ( *palette )[i * 3 + 2] = bcPalette[i * 3 + 0];
757 Error( "%s had strange struct size", filename );
760 if ( bcPlanes != 1 ) {
761 Error( "%s was not a single plane image", filename );
764 if ( bcBitCount != 8 ) {
765 Error( "%s was not an 8 bit image", filename );
768 if ( bcHeight < 0 ) {
769 bcHeight = -bcHeight;
788 out = safe_malloc( bcWidth * bcHeight );
793 for ( i = 0 ; i < bcHeight ; i++ ) {
794 memcpy( out + bcWidth * ( bcHeight - 1 - i ), in + pos, bcWidth );
799 memcpy( out, in + pos, bcWidth * bcHeight );
800 pos += bcWidth * bcHeight;
808 ============================================================================
812 ============================================================================
819 Will load either an lbm or pcx, depending on extension.
820 Any of the return pointers can be NULL if you don't want them.
823 void Load256Image( const char *name, byte **pixels, byte **palette, int *width, int *height ){
826 ExtractFileExtension( name, ext );
827 if ( !Q_stricmp( ext, "lbm" ) ) {
828 LoadLBM( name, pixels, palette );
836 else if ( !Q_stricmp( ext, "pcx" ) ) {
837 LoadPCX( name, pixels, palette, width, height );
839 else if ( !Q_stricmp( ext, "bmp" ) ) {
840 LoadBMP( name, pixels, palette, width, height );
843 Error( "%s doesn't have a known image extension", name );
852 Will save either an lbm or pcx, depending on extension.
855 void Save256Image( const char *name, byte *pixels, byte *palette,
856 int width, int height ){
859 ExtractFileExtension( name, ext );
860 if ( !Q_stricmp( ext, "lbm" ) ) {
861 WriteLBMfile( name, pixels, width, height, palette );
863 else if ( !Q_stricmp( ext, "pcx" ) ) {
864 WritePCXfile( name, pixels, width, height, palette );
867 Error( "%s doesn't have a known image extension", name );
875 ============================================================================
879 ============================================================================
882 typedef struct _TargaHeader {
883 unsigned char id_length, colormap_type, image_type;
884 unsigned short colormap_index, colormap_length;
885 unsigned char colormap_size;
886 unsigned short x_origin, y_origin, width, height;
887 unsigned char pixel_size, attributes;
890 void TargaError( TargaHeader *t, const char *message ){
891 Sys_Printf( "%s\n:TargaHeader:\nuint8 id_length = %i;\nuint8 colormap_type = %i;\nuint8 image_type = %i;\nuint16 colormap_index = %i;\nuint16 colormap_length = %i;\nuint8 colormap_size = %i;\nuint16 x_origin = %i;\nuint16 y_origin = %i;\nuint16 width = %i;\nuint16 height = %i;\nuint8 pixel_size = %i;\nuint8 attributes = %i;\n", message, t->id_length, t->colormap_type, t->image_type, t->colormap_index, t->colormap_length, t->colormap_size, t->x_origin, t->y_origin, t->width, t->height, t->pixel_size, t->attributes );
899 void LoadTGABuffer( const byte *f, const byte *enddata, byte **pic, int *width, int *height ){
900 int x, y, row_inc, compressed, readpixelcount, red, green, blue, alpha, runlen, pindex, alphabits, image_width, image_height;
901 byte *pixbuf, *image_rgba;
904 TargaHeader targa_header;
905 unsigned char palette[256 * 4];
909 // abort if it is too small to parse
910 if ( enddata - f < 19 ) {
914 targa_header.id_length = f[0];
915 targa_header.colormap_type = f[1];
916 targa_header.image_type = f[2];
918 targa_header.colormap_index = f[3] + f[4] * 256;
919 targa_header.colormap_length = f[5] + f[6] * 256;
920 targa_header.colormap_size = f[7];
921 targa_header.x_origin = f[8] + f[9] * 256;
922 targa_header.y_origin = f[10] + f[11] * 256;
923 targa_header.width = image_width = f[12] + f[13] * 256;
924 targa_header.height = image_height = f[14] + f[15] * 256;
926 targa_header.pixel_size = f[16];
927 targa_header.attributes = f[17];
929 // advance to end of header
932 // skip TARGA image comment (usually 0 bytes)
933 fin += targa_header.id_length;
935 // read/skip the colormap if present (note: according to the TARGA spec it
936 // can be present even on truecolor or greyscale images, just not used by
938 if ( targa_header.colormap_type ) {
939 if ( targa_header.colormap_length > 256 ) {
940 TargaError( &targa_header, "LoadTGA: only up to 256 colormap_length supported\n" );
943 if ( targa_header.colormap_index ) {
944 TargaError( &targa_header, "LoadTGA: colormap_index not supported\n" );
947 if ( targa_header.colormap_size == 24 ) {
948 for ( x = 0; x < targa_header.colormap_length; x++ )
950 palette[x * 4 + 2] = *fin++;
951 palette[x * 4 + 1] = *fin++;
952 palette[x * 4 + 0] = *fin++;
953 palette[x * 4 + 3] = 255;
956 else if ( targa_header.colormap_size == 32 ) {
957 for ( x = 0; x < targa_header.colormap_length; x++ )
959 palette[x * 4 + 2] = *fin++;
960 palette[x * 4 + 1] = *fin++;
961 palette[x * 4 + 0] = *fin++;
962 palette[x * 4 + 3] = *fin++;
967 TargaError( &targa_header, "LoadTGA: Only 32 and 24 bit colormap_size supported\n" );
972 // check our pixel_size restrictions according to image_type
973 if ( targa_header.image_type == 2 || targa_header.image_type == 10 ) {
974 if ( targa_header.pixel_size != 24 && targa_header.pixel_size != 32 ) {
975 TargaError( &targa_header, "LoadTGA: only 24bit and 32bit pixel sizes supported for type 2 and type 10 images\n" );
979 else if ( targa_header.image_type == 1 || targa_header.image_type == 9 ) {
980 if ( targa_header.pixel_size != 8 ) {
981 TargaError( &targa_header, "LoadTGA: only 8bit pixel size for type 1, 3, 9, and 11 images supported\n" );
985 else if ( targa_header.image_type == 3 || targa_header.image_type == 11 ) {
986 if ( targa_header.pixel_size != 8 ) {
987 TargaError( &targa_header, "LoadTGA: only 8bit pixel size for type 1, 3, 9, and 11 images supported\n" );
993 TargaError( &targa_header, "LoadTGA: Only type 1, 2, 3, 9, 10, and 11 targa RGB images supported" );
997 if ( targa_header.attributes & 0x10 ) {
998 TargaError( &targa_header, "LoadTGA: origin must be in top left or bottom left, top right and bottom right are not supported\n" );
1002 // number of attribute bits per pixel, we only support 0 or 8
1003 alphabits = targa_header.attributes & 0x0F;
1004 if ( alphabits != 8 && alphabits != 0 ) {
1005 TargaError( &targa_header, "LoadTGA: only 0 or 8 attribute (alpha) bits supported\n" );
1009 image_rgba = safe_malloc( image_width * image_height * 4 );
1010 if ( !image_rgba ) {
1011 Sys_Printf( "LoadTGA: not enough memory for %i by %i image\n", image_width, image_height );
1015 // If bit 5 of attributes isn't set, the image has been stored from bottom to top
1016 if ( ( targa_header.attributes & 0x20 ) == 0 ) {
1017 pixbuf = image_rgba + ( image_height - 1 ) * image_width * 4;
1018 row_inc = -image_width * 4 * 2;
1022 pixbuf = image_rgba;
1026 compressed = targa_header.image_type == 9 || targa_header.image_type == 10 || targa_header.image_type == 11;
1029 red = green = blue = alpha = 255;
1030 while ( y < image_height )
1032 // decoder is mostly the same whether it's compressed or not
1033 readpixelcount = 1000000;
1035 if ( compressed && fin < enddata ) {
1037 // high bit indicates this is an RLE compressed run
1038 if ( runlen & 0x80 ) {
1041 runlen = 1 + ( runlen & 0x7f );
1044 while ( ( runlen-- ) && y < image_height )
1046 if ( readpixelcount > 0 ) {
1048 red = green = blue = alpha = 255;
1049 if ( fin < enddata ) {
1050 switch ( targa_header.image_type )
1056 if ( pindex >= targa_header.colormap_length ) {
1057 pindex = 0; // error
1059 p = palette + pindex * 4;
1069 if ( fin < enddata ) {
1072 if ( fin < enddata ) {
1075 if ( targa_header.pixel_size == 32 && fin < enddata ) {
1082 red = green = blue = *fin++;
1095 if ( x == image_width ) {
1096 // end of line, advance to next
1106 *width = image_width;
1109 *height = image_height;
1119 void LoadTGA( const char *name, byte **pixels, int *width, int *height ){
1125 nLen = vfsLoadFile( name, (void **)&buffer, 0 );
1127 Error( "Couldn't read %s", name );
1130 LoadTGABuffer( buffer, buffer + nLen, pixels, width, height );
1140 void WriteTGA( const char *filename, byte *data, int width, int height ) {
1146 buffer = safe_malloc( width * height * 4 + 18 );
1147 memset( buffer, 0, 18 );
1148 buffer[2] = 2; // uncompressed type
1149 buffer[12] = width & 255;
1150 buffer[13] = width >> 8;
1151 buffer[14] = height & 255;
1152 buffer[15] = height >> 8;
1153 buffer[16] = 32; // pixel size
1156 c = 18 + width * height * 4;
1157 for ( i = 18 ; i < c ; i += 4 )
1159 buffer[i] = data[i - 18 + 2]; // blue
1160 buffer[i + 1] = data[i - 18 + 1]; // green
1161 buffer[i + 2] = data[i - 18 + 0]; // red
1162 buffer[i + 3] = data[i - 18 + 3]; // alpha
1165 f = fopen( filename, "wb" );
1166 fwrite( buffer, 1, c, f );
1172 void WriteTGAGray( const char *filename, byte *data, int width, int height ) {
1176 memset( buffer, 0, 18 );
1177 buffer[2] = 3; // uncompressed type
1178 buffer[12] = width & 255;
1179 buffer[13] = width >> 8;
1180 buffer[14] = height & 255;
1181 buffer[15] = height >> 8;
1182 buffer[16] = 8; // pixel size
1184 f = fopen( filename, "wb" );
1185 fwrite( buffer, 1, 18, f );
1186 fwrite( data, 1, width * height, f );
1191 ============================================================================
1195 ============================================================================
1202 Any of the return pointers can be NULL if you don't want them.
1205 void Load32BitImage( const char *name, unsigned **pixels, int *width, int *height ){
1214 ExtractFileExtension( name, ext );
1215 if ( !Q_stricmp( ext, "tga" ) ) {
1216 LoadTGA( name, (byte **)pixels, width, height );
1219 Load256Image( name, &pixels8, &palette, width, height );
1223 size = *width * *height;
1224 pixels32 = safe_malloc( size * 4 );
1225 *pixels = (unsigned *)pixels32;
1226 for ( i = 0 ; i < size ; i++ ) {
1228 pixels32[i * 4 + 0] = palette[ v * 3 + 0 ];
1229 pixels32[i * 4 + 1] = palette[ v * 3 + 1 ];
1230 pixels32[i * 4 + 2] = palette[ v * 3 + 2 ];
1231 pixels32[i * 4 + 3] = 0xff;