51 unsigned char temptable[768];
55 for (
i = 0;
i < 256;
i++ )
57 temptable[
i*3+0] = ( palette[
i] >> 0 ) & 0xff;
58 temptable[
i*3+1] = ( palette[
i] >> 8 ) & 0xff;
59 temptable[
i*3+2] = ( palette[
i] >> 16 ) & 0xff;
73 if ( !qglSelectTextureSGIS && !qglActiveTextureARB )
79 qglEnable( GL_TEXTURE_2D );
85 qglDisable( GL_TEXTURE_2D );
96 if ( !qglSelectTextureSGIS && !qglActiveTextureARB )
115 if ( qglSelectTextureSGIS )
117 qglSelectTextureSGIS(
texture );
119 else if ( qglActiveTextureARB )
121 qglActiveTextureARB(
texture );
122 qglClientActiveTextureARB(
texture );
128 static int lastmodes[2] = { -1, -1 };
132 qglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
mode );
146 qglBindTexture (GL_TEXTURE_2D, texnum);
172 {
"GL_NEAREST", GL_NEAREST, GL_NEAREST},
173 {
"GL_LINEAR", GL_LINEAR, GL_LINEAR},
174 {
"GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST},
175 {
"GL_LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR},
176 {
"GL_NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST},
177 {
"GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR}
180 #define NUM_GL_MODES (sizeof(modes) / sizeof (glmode_t))
190 {
"GL_RGBA", GL_RGBA},
191 {
"GL_RGBA8", GL_RGBA8},
192 {
"GL_RGB5_A1", GL_RGB5_A1},
193 {
"GL_RGBA4", GL_RGBA4},
194 {
"GL_RGBA2", GL_RGBA2},
197 #define NUM_GL_ALPHA_MODES (sizeof(gl_alpha_modes) / sizeof (gltmode_t))
202 {
"GL_RGB8", GL_RGB8},
203 {
"GL_RGB5", GL_RGB5},
204 {
"GL_RGB4", GL_RGB4},
205 {
"GL_R3_G3_B2", GL_R3_G3_B2},
207 {
"GL_RGB2", GL_RGB2_EXT},
211 #define NUM_GL_SOLID_MODES (sizeof(gl_solid_modes) / sizeof (gltmode_t))
244 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
gl_filter_min);
245 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
gl_filter_max);
308 const char *palstrings[2] =
360 #define BLOCK_WIDTH 256
361 #define BLOCK_HEIGHT 256
382 for (
j=0 ;
j<
w ;
j++)
399 for (
i=0 ;
i<
w ;
i++)
439 int dataByte, runLength;
482 out = malloc ( (pcx->
ymax+1) * (pcx->
xmax+1) );
490 *palette = malloc(768);
491 memcpy (*palette, (
byte *)pcx + len - 768, 768);
501 for (
x=0 ;
x<=pcx->
xmax ; )
505 if((dataByte & 0xC0) == 0xC0)
507 runLength = dataByte & 0x3F;
513 while(runLength-- > 0)
519 if ( raw - (
byte *)pcx > len)
553 int columns, rows, numPixels;
609 columns = targa_header.
width;
610 rows = targa_header.
height;
611 numPixels = columns * rows;
618 targa_rgba = malloc (numPixels*4);
625 for(row=rows-1; row>=0; row--) {
626 pixbuf = targa_rgba + row*columns*4;
627 for(column=0; column<columns; column++) {
644 alphabyte = *buf_p++;
648 *pixbuf++ = alphabyte;
655 unsigned char red,
green,
blue,alphabyte,packetHeader,packetSize,
j;
656 for(row=rows-1; row>=0; row--) {
657 pixbuf = targa_rgba + row*columns*4;
658 for(column=0; column<columns; ) {
659 packetHeader= *buf_p++;
660 packetSize = 1 + (packetHeader & 0x7f);
661 if (packetHeader & 0x80) {
673 alphabyte = *buf_p++;
677 for(
j=0;
j<packetSize;
j++) {
683 if (column==columns) {
689 pixbuf = targa_rgba + row*columns*4;
694 for(
j=0;
j<packetSize;
j++) {
709 alphabyte = *buf_p++;
713 *pixbuf++ = alphabyte;
717 if (column==columns) {
723 pixbuf = targa_rgba + row*columns*4;
759 #define FLOODFILL_FIFO_SIZE 0x1000
760 #define FLOODFILL_FIFO_MASK (FLOODFILL_FIFO_SIZE - 1)
762 #define FLOODFILL_STEP( off, dx, dy ) \
764 if (pos[off] == fillcolor) \
767 fifo[inpt].x = x + (dx), fifo[inpt].y = y + (dy); \
768 inpt = (inpt + 1) & FLOODFILL_FIFO_MASK; \
770 else if (pos[off] != 255) fdc = pos[off]; \
775 byte fillcolor = *
skin;
777 int inpt = 0, outpt = 0;
778 int filledcolor = -1;
781 if (filledcolor == -1)
785 for (
i = 0;
i < 256; ++
i)
794 if ((fillcolor == filledcolor) || (fillcolor == 255))
800 fifo[inpt].
x = 0, fifo[inpt].
y = 0;
803 while (outpt != inpt)
805 int x = fifo[outpt].
x,
y = fifo[outpt].
y;
806 int fdc = filledcolor;
827 void GL_ResampleTexture (
unsigned *in,
int inwidth,
int inheight,
unsigned *out,
int outwidth,
int outheight)
830 unsigned *inrow, *inrow2;
831 unsigned frac, fracstep;
832 unsigned p1[1024], p2[1024];
833 byte *pix1, *pix2, *pix3, *pix4;
835 fracstep = inwidth*0x10000/outwidth;
838 for (
i=0 ;
i<outwidth ;
i++)
840 p1[
i] = 4*(frac>>16);
843 frac = 3*(fracstep>>2);
844 for (
i=0 ;
i<outwidth ;
i++)
846 p2[
i] = 4*(frac>>16);
850 for (
i=0 ;
i<outheight ;
i++, out += outwidth)
852 inrow = in + inwidth*(
int)((
i+0.25)*inheight/outheight);
853 inrow2 = in + inwidth*(
int)((
i+0.75)*inheight/outheight);
854 frac = fracstep >> 1;
855 for (
j=0 ;
j<outwidth ;
j++)
857 pix1 = (
byte *)inrow + p1[
j];
858 pix2 = (
byte *)inrow + p2[
j];
859 pix3 = (
byte *)inrow2 + p1[
j];
860 pix4 = (
byte *)inrow2 + p2[
j];
861 ((
byte *)(out+
j))[0] = (pix1[0] + pix2[0] + pix3[0] + pix4[0])>>2;
862 ((
byte *)(out+
j))[1] = (pix1[1] + pix2[1] + pix3[1] + pix4[1])>>2;
863 ((
byte *)(out+
j))[2] = (pix1[2] + pix2[2] + pix3[2] + pix4[2])>>2;
864 ((
byte *)(out+
j))[3] = (pix1[3] + pix2[3] + pix3[3] + pix4[3])>>2;
886 c = inwidth*inheight;
887 for (
i=0 ;
i<c ;
i++, p+=4)
901 c = inwidth*inheight;
902 for (
i=0 ;
i<c ;
i++, p+=4)
928 for (
j=0 ;
j<
width ;
j+=8, out+=4, in+=8)
930 out[0] = (in[0] + in[4] + in[
width+0] + in[
width+4])>>2;
931 out[1] = (in[1] + in[5] + in[
width+1] + in[
width+5])>>2;
932 out[2] = (in[2] + in[6] + in[
width+2] + in[
width+6])>>2;
933 out[3] = (in[3] + in[7] + in[
width+3] + in[
width+7])>>2;
949 for (
i = 0;
i < scaled_width * scaled_height;
i++ )
951 unsigned int r, g, b, c;
953 r = ( scaled[0] >> 3 ) & 31;
954 g = ( scaled[1] >> 2 ) & 63;
955 b = ( scaled[2] >> 3 ) & 31;
957 c =
r | ( g << 5 ) | ( b << 11 );
971 unsigned scaled[256*256];
972 unsigned char paletted_texture[256*256];
973 int scaled_width, scaled_height;
980 for (scaled_width = 1 ; scaled_width <
width ; scaled_width<<=1)
984 for (scaled_height = 1 ; scaled_height <
height ; scaled_height<<=1)
997 if (scaled_width > 256)
999 if (scaled_height > 256)
1000 scaled_height = 256;
1002 if (scaled_width < 1)
1004 if (scaled_height < 1)
1010 if (scaled_width * scaled_height >
sizeof(scaled)/4)
1015 scan = ((
byte *)data) + 3;
1017 for (
i=0 ;
i<c ;
i++, scan += 4)
1032 "Unknown number of texture components %i\n",
1039 gluBuild2DMipmaps (GL_TEXTURE_2D, samples,
width,
height, GL_RGBA, GL_UNSIGNED_BYTE,
trans);
1040 else if (scaled_width ==
width && scaled_height ==
height)
1041 qglTexImage2D (GL_TEXTURE_2D, 0, comp,
width,
height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
trans);
1045 scaled_width, scaled_height, GL_UNSIGNED_BYTE, scaled);
1046 qglTexImage2D (GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
1050 if (scaled_width ==
width && scaled_height ==
height)
1058 qglTexImage2D( GL_TEXTURE_2D,
1070 qglTexImage2D (GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
1085 qglTexImage2D( GL_TEXTURE_2D,
1097 qglTexImage2D( GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled );
1105 while (scaled_width > 1 || scaled_height > 1)
1107 GL_MipMap ((
byte *)scaled, scaled_width, scaled_height);
1109 scaled_height >>= 1;
1110 if (scaled_width < 1)
1112 if (scaled_height < 1)
1119 qglTexImage2D( GL_TEXTURE_2D,
1131 qglTexImage2D (GL_TEXTURE_2D,
miplevel, comp, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
1141 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
gl_filter_min);
1142 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
gl_filter_max);
1146 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
gl_filter_max);
1147 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
gl_filter_max);
1179 unsigned trans[512*256];
1188 if ( qglColorTableEXT &&
1192 qglTexImage2D( GL_TEXTURE_2D,
1202 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
gl_filter_max);
1203 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
gl_filter_max);
1207 for (
i=0 ;
i<
s ;
i++)
1220 else if (
i > 0 && data[
i-1] != 255)
1222 else if (
i <
s-1 && data[
i+1] != 255)
1266 if (strlen(
name) >=
sizeof(image->
name))
1294 for (
j=0 ;
j<image->
width ;
j++, k++)
1297 image->
scrap =
true;
1307 image->
scrap =
false;
1367 byte *pic, *palette;
1391 if (!strcmp(
name+len-4,
".pcx"))
1398 else if (!strcmp(
name+len-4,
".wal"))
1402 else if (!strcmp(
name+len-4,
".tga"))
1460 qglDeleteTextures (1, &image->
texnum);
1461 memset (image, 0,
sizeof(*image));
1485 for (
i=0 ;
i<256 ;
i++)
1491 v = (255<<24) + (
r<<0) + (g<<8) + (b<<16);
1526 if ( qglColorTableEXT )
1538 for (
i = 0;
i < 256;
i++ )
1548 inf = 255 * pow ( (
i+0.5)/255.5 , g ) + 0.5;
1557 for (
i=0 ;
i<256 ;
i++)
1581 qglDeleteTextures (1, &image->
texnum);
1582 memset (image, 0,
sizeof(*image));