50 unsigned char temptable[768];
54 for (
i = 0;
i < 256;
i++ )
56 temptable[
i*3+0] = ( palette[
i] >> 0 ) & 0xff;
57 temptable[
i*3+1] = ( palette[
i] >> 8 ) & 0xff;
58 temptable[
i*3+2] = ( palette[
i] >> 16 ) & 0xff;
72 if ( !qglSelectTextureSGIS && !qglActiveTextureARB )
78 qglEnable( GL_TEXTURE_2D );
84 qglDisable( GL_TEXTURE_2D );
95 if ( !qglSelectTextureSGIS && !qglActiveTextureARB )
114 if ( qglSelectTextureSGIS )
116 qglSelectTextureSGIS(
texture );
118 else if ( qglActiveTextureARB )
120 qglActiveTextureARB(
texture );
121 qglClientActiveTextureARB(
texture );
127 static int lastmodes[2] = { -1, -1 };
131 qglTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,
mode );
145 qglBindTexture (GL_TEXTURE_2D, texnum);
171 {
"GL_NEAREST", GL_NEAREST, GL_NEAREST},
172 {
"GL_LINEAR", GL_LINEAR, GL_LINEAR},
173 {
"GL_NEAREST_MIPMAP_NEAREST", GL_NEAREST_MIPMAP_NEAREST, GL_NEAREST},
174 {
"GL_LINEAR_MIPMAP_NEAREST", GL_LINEAR_MIPMAP_NEAREST, GL_LINEAR},
175 {
"GL_NEAREST_MIPMAP_LINEAR", GL_NEAREST_MIPMAP_LINEAR, GL_NEAREST},
176 {
"GL_LINEAR_MIPMAP_LINEAR", GL_LINEAR_MIPMAP_LINEAR, GL_LINEAR}
179 #define NUM_GL_MODES (sizeof(modes) / sizeof (glmode_t))
189 {
"GL_RGBA", GL_RGBA},
190 {
"GL_RGBA8", GL_RGBA8},
191 {
"GL_RGB5_A1", GL_RGB5_A1},
192 {
"GL_RGBA4", GL_RGBA4},
193 {
"GL_RGBA2", GL_RGBA2},
196 #define NUM_GL_ALPHA_MODES (sizeof(gl_alpha_modes) / sizeof (gltmode_t))
201 {
"GL_RGB8", GL_RGB8},
202 {
"GL_RGB5", GL_RGB5},
203 {
"GL_RGB4", GL_RGB4},
204 {
"GL_R3_G3_B2", GL_R3_G3_B2},
206 {
"GL_RGB2", GL_RGB2_EXT},
210 #define NUM_GL_SOLID_MODES (sizeof(gl_solid_modes) / sizeof (gltmode_t))
243 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
gl_filter_min);
244 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
gl_filter_max);
307 const char *palstrings[2] =
359 #define BLOCK_WIDTH 256
360 #define BLOCK_HEIGHT 256
381 for (
j=0 ;
j<
w ;
j++)
398 for (
i=0 ;
i<
w ;
i++)
438 int dataByte, runLength;
481 out = malloc ( (pcx->
ymax+1) * (pcx->
xmax+1) );
489 *palette = malloc(768);
490 memcpy (*palette, (
byte *)pcx + len - 768, 768);
500 for (
x=0 ;
x<=pcx->
xmax ; )
504 if((dataByte & 0xC0) == 0xC0)
506 runLength = dataByte & 0x3F;
512 while(runLength-- > 0)
518 if ( raw - (
byte *)pcx > len)
552 int columns, rows, numPixels;
608 columns = targa_header.
width;
609 rows = targa_header.
height;
610 numPixels = columns * rows;
617 targa_rgba = malloc (numPixels*4);
624 for(row=rows-1; row>=0; row--) {
625 pixbuf = targa_rgba + row*columns*4;
626 for(column=0; column<columns; column++) {
643 alphabyte = *buf_p++;
647 *pixbuf++ = alphabyte;
654 unsigned char red,
green,
blue,alphabyte,packetHeader,packetSize,
j;
655 for(row=rows-1; row>=0; row--) {
656 pixbuf = targa_rgba + row*columns*4;
657 for(column=0; column<columns; ) {
658 packetHeader= *buf_p++;
659 packetSize = 1 + (packetHeader & 0x7f);
660 if (packetHeader & 0x80) {
672 alphabyte = *buf_p++;
682 for(
j=0;
j<packetSize;
j++) {
688 if (column==columns) {
694 pixbuf = targa_rgba + row*columns*4;
699 for(
j=0;
j<packetSize;
j++) {
714 alphabyte = *buf_p++;
718 *pixbuf++ = alphabyte;
722 if (column==columns) {
728 pixbuf = targa_rgba + row*columns*4;
764 #define FLOODFILL_FIFO_SIZE 0x1000
765 #define FLOODFILL_FIFO_MASK (FLOODFILL_FIFO_SIZE - 1)
767 #define FLOODFILL_STEP( off, dx, dy ) \
769 if (pos[off] == fillcolor) \
772 fifo[inpt].x = x + (dx), fifo[inpt].y = y + (dy); \
773 inpt = (inpt + 1) & FLOODFILL_FIFO_MASK; \
775 else if (pos[off] != 255) fdc = pos[off]; \
780 byte fillcolor = *
skin;
782 int inpt = 0, outpt = 0;
783 int filledcolor = -1;
786 if (filledcolor == -1)
790 for (
i = 0;
i < 256; ++
i)
802 if ((fillcolor == filledcolor) || (fillcolor == 255))
808 fifo[inpt].
x = 0, fifo[inpt].
y = 0;
811 while (outpt != inpt)
813 int x = fifo[outpt].
x,
y = fifo[outpt].
y;
814 int fdc = filledcolor;
835 void GL_ResampleTexture (
unsigned *in,
int inwidth,
int inheight,
unsigned *out,
int outwidth,
int outheight)
838 unsigned *inrow, *inrow2;
839 unsigned frac, fracstep;
840 unsigned p1[1024], p2[1024];
841 byte *pix1, *pix2, *pix3, *pix4;
843 fracstep = inwidth*0x10000/outwidth;
846 for (
i=0 ;
i<outwidth ;
i++)
848 p1[
i] = 4*(frac>>16);
851 frac = 3*(fracstep>>2);
852 for (
i=0 ;
i<outwidth ;
i++)
854 p2[
i] = 4*(frac>>16);
858 for (
i=0 ;
i<outheight ;
i++, out += outwidth)
860 inrow = in + inwidth*(
int)((
i+0.25)*inheight/outheight);
861 inrow2 = in + inwidth*(
int)((
i+0.75)*inheight/outheight);
862 frac = fracstep >> 1;
863 for (
j=0 ;
j<outwidth ;
j++)
865 pix1 = (
byte *)inrow + p1[
j];
866 pix2 = (
byte *)inrow + p2[
j];
867 pix3 = (
byte *)inrow2 + p1[
j];
868 pix4 = (
byte *)inrow2 + p2[
j];
869 ((
byte *)(out+
j))[0] = (pix1[0] + pix2[0] + pix3[0] + pix4[0])>>2;
870 ((
byte *)(out+
j))[1] = (pix1[1] + pix2[1] + pix3[1] + pix4[1])>>2;
871 ((
byte *)(out+
j))[2] = (pix1[2] + pix2[2] + pix3[2] + pix4[2])>>2;
872 ((
byte *)(out+
j))[3] = (pix1[3] + pix2[3] + pix3[3] + pix4[3])>>2;
894 c = inwidth*inheight;
895 for (
i=0 ;
i<c ;
i++, p+=4)
909 c = inwidth*inheight;
910 for (
i=0 ;
i<c ;
i++, p+=4)
936 for (
j=0 ;
j<
width ;
j+=8, out+=4, in+=8)
938 out[0] = (in[0] + in[4] + in[
width+0] + in[
width+4])>>2;
939 out[1] = (in[1] + in[5] + in[
width+1] + in[
width+5])>>2;
940 out[2] = (in[2] + in[6] + in[
width+2] + in[
width+6])>>2;
941 out[3] = (in[3] + in[7] + in[
width+3] + in[
width+7])>>2;
957 for (
i = 0;
i < scaled_width * scaled_height;
i++ )
959 unsigned int r, g, b, c;
961 r = ( scaled[0] >> 3 ) & 31;
962 g = ( scaled[1] >> 2 ) & 63;
963 b = ( scaled[2] >> 3 ) & 31;
965 c =
r | ( g << 5 ) | ( b << 11 );
979 unsigned scaled[256*256];
980 unsigned char paletted_texture[256*256];
981 int scaled_width, scaled_height;
988 for (scaled_width = 1 ; scaled_width <
width ; scaled_width<<=1)
992 for (scaled_height = 1 ; scaled_height <
height ; scaled_height<<=1)
1005 if (scaled_width > 256)
1007 if (scaled_height > 256)
1008 scaled_height = 256;
1010 if (scaled_width < 1)
1012 if (scaled_height < 1)
1018 if (scaled_width * scaled_height >
sizeof(scaled)/4)
1023 scan = ((
byte *)data) + 3;
1025 for (
i=0 ;
i<c ;
i++, scan += 4)
1040 "Unknown number of texture components %i\n",
1047 gluBuild2DMipmaps (GL_TEXTURE_2D, samples,
width,
height, GL_RGBA, GL_UNSIGNED_BYTE, trans);
1048 else if (scaled_width ==
width && scaled_height ==
height)
1049 qglTexImage2D (GL_TEXTURE_2D, 0, comp,
width,
height, 0, GL_RGBA, GL_UNSIGNED_BYTE, trans);
1052 gluScaleImage (GL_RGBA,
width,
height, GL_UNSIGNED_BYTE, trans,
1053 scaled_width, scaled_height, GL_UNSIGNED_BYTE, scaled);
1054 qglTexImage2D (GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
1058 if (scaled_width ==
width && scaled_height ==
height)
1066 qglTexImage2D( GL_TEXTURE_2D,
1068 GL_COLOR_INDEX8_EXT,
1078 qglTexImage2D (GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
1093 qglTexImage2D( GL_TEXTURE_2D,
1095 GL_COLOR_INDEX8_EXT,
1105 qglTexImage2D( GL_TEXTURE_2D, 0, comp, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled );
1113 while (scaled_width > 1 || scaled_height > 1)
1115 GL_MipMap ((
byte *)scaled, scaled_width, scaled_height);
1117 scaled_height >>= 1;
1118 if (scaled_width < 1)
1120 if (scaled_height < 1)
1127 qglTexImage2D( GL_TEXTURE_2D,
1129 GL_COLOR_INDEX8_EXT,
1139 qglTexImage2D (GL_TEXTURE_2D,
miplevel, comp, scaled_width, scaled_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, scaled);
1149 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
gl_filter_min);
1150 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
gl_filter_max);
1154 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
gl_filter_max);
1155 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
gl_filter_max);
1187 unsigned trans[512*256];
1193 if (s >
sizeof(trans)/4)
1196 if ( qglColorTableEXT &&
1200 qglTexImage2D( GL_TEXTURE_2D,
1202 GL_COLOR_INDEX8_EXT,
1210 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
gl_filter_max);
1211 qglTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
gl_filter_max);
1217 for (
i=0 ;
i<s ;
i++)
1230 else if (
i > 0 && data[
i-1] != 255)
1232 else if (
i < s-1 && data[
i+1] != 255)
1279 if (strlen(
name) >=
sizeof(image->
name))
1292 if (!strcmp(s+len-4,
".tga") || !strcmp(s+len-4,
".jpg") || !strcmp(s+len-4,
".png"))
1294 s[len-3] =
'w'; s[len-2] =
'a'; s[len-1] =
'l';
1324 for (
j=0 ;
j<image->
width ;
j++, k++)
1327 image->
scrap =
true;
1337 image->
scrap =
false;
1397 byte *pic, *palette;
1409 while ((ptr=strchr(
name,
'\\'))) {
1429 if (!strcmp(
name+len-4,
".pcx"))
1436 else if (!strcmp(
name+len-4,
".wal"))
1440 else if (!strcmp(
name+len-4,
".tga"))
1499 memset (image, 0,
sizeof(*image));
1523 for (
i=0 ;
i<256 ;
i++)
1529 v = (255<<24) + (
r<<0) + (g<<8) + (b<<16);
1564 if ( qglColorTableEXT )
1576 for (
i = 0;
i < 256;
i++ )
1586 inf = 255 * pow ( (
i+0.5)/255.5 , g ) + 0.5;
1595 for (
i=0 ;
i<256 ;
i++)
1620 memset (image, 0,
sizeof(*image));