7 void Image_GammaRemapRGB(qbyte *in, qbyte *out, int pixels, qbyte *gammar, qbyte *gammag, qbyte *gammab)
11 out[0] = gammar[in[0]];
12 out[1] = gammag[in[1]];
13 out[2] = gammab[in[2]];
19 // note: pal must be 32bit color
20 void Image_Copy8bitRGBA(qbyte *in, qbyte *out, int pixels, int *pal)
22 int *iout = (void *)out;
58 =================================================================
62 =================================================================
71 unsigned short xmin,ymin,xmax,ymax;
72 unsigned short hres,vres;
73 unsigned char palette[48];
76 unsigned short bytes_per_line;
77 unsigned short palette_type;
86 qbyte* LoadPCX (qbyte *f, int matchwidth, int matchheight)
89 qbyte *palette, *a, *b, *image_rgba, *fin, *pbuf, *enddata;
90 int x, y, x2, dataByte;
92 if (loadsize < sizeof(pcx) + 768)
94 Con_Printf ("Bad pcx file\n");
100 memcpy(&pcx, fin, sizeof(pcx));
103 // LordHavoc: big-endian support ported from QF newtree
104 pcx.xmax = LittleShort (pcx.xmax);
105 pcx.xmin = LittleShort (pcx.xmin);
106 pcx.ymax = LittleShort (pcx.ymax);
107 pcx.ymin = LittleShort (pcx.ymin);
108 pcx.hres = LittleShort (pcx.hres);
109 pcx.vres = LittleShort (pcx.vres);
110 pcx.bytes_per_line = LittleShort (pcx.bytes_per_line);
111 pcx.palette_type = LittleShort (pcx.palette_type);
113 if (pcx.manufacturer != 0x0a || pcx.version != 5 || pcx.encoding != 1 || pcx.bits_per_pixel != 8 || pcx.xmax > 320 || pcx.ymax > 256)
115 Con_Printf ("Bad pcx file\n");
119 if (matchwidth && (pcx.xmax+1) != matchwidth)
123 if (matchheight && (pcx.ymax+1) != matchheight)
128 image_width = pcx.xmax+1;
129 image_height = pcx.ymax+1;
131 palette = f + loadsize - 768;
133 image_rgba = Mem_Alloc(tempmempool, image_width*image_height*4);
136 Con_Printf("LoadPCX: not enough memory for %i by %i image\n", image_width, image_height);
139 pbuf = image_rgba + image_width*image_height*3;
142 for (y = 0;y < image_height && fin < enddata;y++)
144 a = pbuf + y * image_width;
145 for (x = 0;x < image_width && fin < enddata;)
152 x2 = x + (dataByte & 0x3F);
154 if (x2 > image_width)
155 x2 = image_width; // technically an error
162 while(x < image_width)
169 for(x = 0;x < image_width*image_height;x++)
182 =========================================================
186 =========================================================
189 typedef struct _TargaHeader
191 unsigned char id_length, colormap_type, image_type;
192 unsigned short colormap_index, colormap_length;
193 unsigned char colormap_size;
194 unsigned short x_origin, y_origin, width, height;
195 unsigned char pixel_size, attributes;
199 TargaHeader targa_header;
207 qbyte *LoadTGA (qbyte *f, int matchwidth, int matchheight)
209 int columns, rows, row, column;
210 qbyte *pixbuf, *image_rgba, *fin, *enddata;
214 targa_header.id_length = f[0];
215 targa_header.colormap_type = f[1];
216 targa_header.image_type = f[2];
218 targa_header.colormap_index = f[3] + f[4] * 256;
219 targa_header.colormap_length = f[5] + f[6] * 256;
220 targa_header.colormap_size = f[7];
221 targa_header.x_origin = f[8] + f[9] * 256;
222 targa_header.y_origin = f[10] + f[11] * 256;
223 targa_header.width = f[12] + f[13] * 256;
224 targa_header.height = f[14] + f[15] * 256;
225 if (matchwidth && targa_header.width != matchwidth)
227 if (matchheight && targa_header.height != matchheight)
229 targa_header.pixel_size = f[16];
230 targa_header.attributes = f[17];
232 if (targa_header.image_type != 2 && targa_header.image_type != 10)
234 Con_Printf ("LoadTGA: Only type 2 and 10 targa RGB images supported\n");
238 if (targa_header.colormap_type != 0 || (targa_header.pixel_size != 32 && targa_header.pixel_size != 24))
240 Con_Printf ("LoadTGA: Only 32 or 24 bit images supported (no colormaps)\n");
244 enddata = f + loadsize;
246 columns = targa_header.width;
247 rows = targa_header.height;
249 image_rgba = Mem_Alloc(tempmempool, columns * rows * 4);
252 Con_Printf ("LoadTGA: not enough memory for %i by %i image\n", columns, rows);
257 if (targa_header.id_length != 0)
258 fin += targa_header.id_length; // skip TARGA image comment
260 if (targa_header.image_type == 2)
262 // Uncompressed, RGB images
263 for(row = rows - 1;row >= 0;row--)
265 pixbuf = image_rgba + row*columns*4;
266 for(column = 0;column < columns;column++)
268 switch (targa_header.pixel_size)
271 if (fin + 3 > enddata)
280 if (fin + 4 > enddata)
292 else if (targa_header.image_type==10)
294 // Runlength encoded RGB images
295 unsigned char red = 0, green = 0, blue = 0, alphabyte = 0, packetHeader, packetSize, j;
296 for(row = rows - 1;row >= 0;row--)
298 pixbuf = image_rgba + row * columns * 4;
299 for(column = 0;column < columns;)
303 packetHeader = *fin++;
304 packetSize = 1 + (packetHeader & 0x7f);
305 if (packetHeader & 0x80)
308 switch (targa_header.pixel_size)
311 if (fin + 3 > enddata)
319 if (fin + 4 > enddata)
328 for(j = 0;j < packetSize;j++)
333 *pixbuf++ = alphabyte;
335 if (column == columns)
337 // run spans across rows
343 pixbuf = image_rgba + row * columns * 4;
349 // non run-length packet
350 for(j = 0;j < packetSize;j++)
352 switch (targa_header.pixel_size)
355 if (fin + 3 > enddata)
364 if (fin + 4 > enddata)
374 if (column == columns)
376 // pixel packet run spans across rows
382 pixbuf = image_rgba + row * columns * 4;
392 image_width = columns;
402 qbyte *LoadLMP (qbyte *f, int matchwidth, int matchheight)
409 Con_Printf("LoadLMP: invalid LMP file\n");
413 // parse the very complicated header *chuckle*
414 width = f[0] + f[1] * 256 + f[2] * 65536 + f[3] * 16777216;
415 height = f[4] + f[5] * 256 + f[6] * 65536 + f[7] * 16777216;
416 if ((unsigned) width > 4096 || (unsigned) height > 4096)
418 Con_Printf("LoadLMP: invalid size\n");
421 if ((matchwidth && width != matchwidth) || (matchheight && height != matchheight))
424 if (loadsize < 8 + width * height)
426 Con_Printf("LoadLMP: invalid LMP file\n");
431 image_height = height;
433 image_rgba = Mem_Alloc(tempmempool, image_width * image_height * 4);
436 Con_Printf("LoadLMP: not enough memory for %i by %i image\n", image_width, image_height);
439 Image_Copy8bitRGBA(f + 8, image_rgba, image_width * image_height, d_8to24table);
443 void Image_StripImageExtension (char *in, char *out)
446 end = in + strlen(in);
450 if (strcmp(temp, ".tga") == 0 || strcmp(temp, ".pcx") == 0 || strcmp(temp, ".lmp") == 0)
460 qbyte *loadimagepixels (char *filename, qboolean complain, int matchwidth, int matchheight)
463 char basename[256], name[256], *c;
464 Image_StripImageExtension(filename, basename); // strip .tga, .pcx and .lmp extensions to allow replacement by other types
465 // replace *'s with #, so commandline utils don't get confused when dealing with the external files
466 for (c = basename;*c;c++)
469 sprintf (name, "textures/%s.tga", basename);
470 f = COM_LoadFile(name, true);
473 data = LoadTGA (f, matchwidth, matchheight);
477 sprintf (name, "textures/%s.pcx", basename);
478 f = COM_LoadFile(name, true);
481 data = LoadPCX (f, matchwidth, matchheight);
485 sprintf (name, "%s.tga", basename);
486 f = COM_LoadFile(name, true);
489 data = LoadTGA (f, matchwidth, matchheight);
493 sprintf (name, "%s.pcx", basename);
494 f = COM_LoadFile(name, true);
497 data = LoadPCX (f, matchwidth, matchheight);
501 sprintf (name, "%s.lmp", basename);
502 f = COM_LoadFile(name, true);
505 data = LoadLMP (f, matchwidth, matchheight);
510 Con_Printf ("Couldn't load %s.tga, .pcx, .lmp\n", filename);
514 int image_makemask (qbyte *in, qbyte *out, int size)
518 for (i = 0;i < size;i++)
520 out[0] = out[1] = out[2] = 255;
530 qbyte* loadimagepixelsmask (char* filename, qboolean complain, int matchwidth, int matchheight)
533 in = data = loadimagepixels(filename, complain, matchwidth, matchheight);
536 if (image_makemask(data, data, image_width * image_height))
537 return data; // some transparency
541 return NULL; // all opaque
545 rtexture_t *loadtextureimage (rtexturepool_t *pool, char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap, qboolean precache)
549 if (!(data = loadimagepixels (filename, complain, matchwidth, matchheight)))
551 rt = R_LoadTexture (pool, filename, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
556 rtexture_t *loadtextureimagemask (rtexturepool_t *pool, char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap, qboolean precache)
560 if (!(data = loadimagepixelsmask (filename, complain, matchwidth, matchheight)))
562 rt = R_LoadTexture (pool, filename, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
567 rtexture_t *image_masktex;
568 rtexture_t *loadtextureimagewithmask (rtexturepool_t *pool, char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap, qboolean precache)
574 image_masktex = NULL;
575 if (!(data = loadimagepixels (filename, complain, matchwidth, matchheight)))
577 rt = R_LoadTexture (pool, filename, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
578 count = image_makemask(data, data, image_width * image_height);
581 filename2 = Mem_Alloc(tempmempool, strlen(filename) + 6);
582 sprintf(filename2, "%s_mask", filename);
583 image_masktex = R_LoadTexture (pool, filename2, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
590 void Image_WriteTGARGB_preflipped (char *filename, int width, int height, qbyte *data)
592 qbyte *buffer, *in, *out, *end;
594 buffer = Mem_Alloc(tempmempool, width*height*3 + 18);
596 memset (buffer, 0, 18);
597 buffer[2] = 2; // uncompressed type
598 buffer[12] = (width >> 0) & 0xFF;
599 buffer[13] = (width >> 8) & 0xFF;
600 buffer[14] = (height >> 0) & 0xFF;
601 buffer[15] = (height >> 8) & 0xFF;
602 buffer[16] = 24; // pixel size
607 end = in + width*height*3;
608 for (;in < end;in += 3)
614 COM_WriteFile (filename, buffer, width*height*3 + 18 );
619 void Image_WriteTGARGB (char *filename, int width, int height, qbyte *data)
622 qbyte *buffer, *in, *out, *end;
624 buffer = Mem_Alloc(tempmempool, width*height*3 + 18);
626 memset (buffer, 0, 18);
627 buffer[2] = 2; // uncompressed type
628 buffer[12] = (width >> 0) & 0xFF;
629 buffer[13] = (width >> 8) & 0xFF;
630 buffer[14] = (height >> 0) & 0xFF;
631 buffer[15] = (height >> 8) & 0xFF;
632 buffer[16] = 24; // pixel size
634 // swap rgb to bgr and flip upside down
636 for (y = height - 1;y >= 0;y--)
638 in = data + y * width * 3;
639 end = in + width * 3;
640 for (;in < end;in += 3)
647 COM_WriteFile (filename, buffer, width*height*3 + 18 );
652 void Image_WriteTGARGBA (char *filename, int width, int height, qbyte *data)
655 qbyte *buffer, *in, *out, *end;
657 buffer = Mem_Alloc(tempmempool, width*height*4 + 18);
659 memset (buffer, 0, 18);
660 buffer[2] = 2; // uncompressed type
661 buffer[12] = (width >> 0) & 0xFF;
662 buffer[13] = (width >> 8) & 0xFF;
663 buffer[14] = (height >> 0) & 0xFF;
664 buffer[15] = (height >> 8) & 0xFF;
665 buffer[16] = 32; // pixel size
667 // swap rgba to bgra and flip upside down
669 for (y = height - 1;y >= 0;y--)
671 in = data + y * width * 4;
672 end = in + width * 4;
673 for (;in < end;in += 4)
681 COM_WriteFile (filename, buffer, width*height*4 + 18 );
686 qboolean Image_CheckAlpha(qbyte *data, int size, qboolean rgba)
692 for (end = data + size * 4, data += 3;data < end;data += 4)
698 // color 255 is transparent
699 for (end = data + size;data < end;data++)
706 static void Image_Resample32LerpLine (qbyte *in, qbyte *out, int inwidth, int outwidth)
708 int j, xi, oldx = 0, f, fstep, endx, lerp;
709 fstep = (int) (inwidth*65536.0f/outwidth);
711 for (j = 0,f = 0;j < outwidth;j++, f += fstep)
716 in += (xi - oldx) * 4;
722 *out++ = (qbyte) ((((in[4] - in[0]) * lerp) >> 16) + in[0]);
723 *out++ = (qbyte) ((((in[5] - in[1]) * lerp) >> 16) + in[1]);
724 *out++ = (qbyte) ((((in[6] - in[2]) * lerp) >> 16) + in[2]);
725 *out++ = (qbyte) ((((in[7] - in[3]) * lerp) >> 16) + in[3]);
727 else // last pixel of the line has no pixel to lerp to
737 static void Image_Resample24LerpLine (qbyte *in, qbyte *out, int inwidth, int outwidth)
739 int j, xi, oldx = 0, f, fstep, endx, lerp;
740 fstep = (int) (inwidth*65536.0f/outwidth);
742 for (j = 0,f = 0;j < outwidth;j++, f += fstep)
747 in += (xi - oldx) * 3;
753 *out++ = (qbyte) ((((in[3] - in[0]) * lerp) >> 16) + in[0]);
754 *out++ = (qbyte) ((((in[4] - in[1]) * lerp) >> 16) + in[1]);
755 *out++ = (qbyte) ((((in[5] - in[2]) * lerp) >> 16) + in[2]);
757 else // last pixel of the line has no pixel to lerp to
766 int resamplerowsize = 0;
767 qbyte *resamplerow1 = NULL;
768 qbyte *resamplerow2 = NULL;
769 mempool_t *resamplemempool = NULL;
771 #define LERPBYTE(i) r = resamplerow1[i];out[i] = (qbyte) ((((resamplerow2[i] - r) * lerp) >> 16) + r)
772 void Image_Resample32Lerp(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
774 int i, j, r, yi, oldy, f, fstep, lerp, endy = (inheight-1), inwidth4 = inwidth*4, outwidth4 = outwidth*4;
777 fstep = (int) (inheight*65536.0f/outheight);
781 Image_Resample32LerpLine (inrow, resamplerow1, inwidth, outwidth);
782 Image_Resample32LerpLine (inrow + inwidth4, resamplerow2, inwidth, outwidth);
783 for (i = 0, f = 0;i < outheight;i++,f += fstep)
791 inrow = (qbyte *)indata + inwidth4*yi;
793 memcpy(resamplerow1, resamplerow2, outwidth4);
795 Image_Resample32LerpLine (inrow, resamplerow1, inwidth, outwidth);
796 Image_Resample32LerpLine (inrow + inwidth4, resamplerow2, inwidth, outwidth);
847 resamplerow1 -= outwidth4;
848 resamplerow2 -= outwidth4;
854 inrow = (qbyte *)indata + inwidth4*yi;
856 memcpy(resamplerow1, resamplerow2, outwidth4);
858 Image_Resample32LerpLine (inrow, resamplerow1, inwidth, outwidth);
861 memcpy(out, resamplerow1, outwidth4);
866 void Image_Resample32Nearest(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
869 unsigned frac, fracstep;
870 // relies on int being 4 bytes
874 fracstep = inwidth*0x10000/outwidth;
875 for (i = 0;i < outheight;i++)
877 inrow = (int *)indata + inwidth*(i*inheight/outheight);
878 frac = fracstep >> 1;
882 out[0] = inrow[frac >> 16];frac += fracstep;
883 out[1] = inrow[frac >> 16];frac += fracstep;
884 out[2] = inrow[frac >> 16];frac += fracstep;
885 out[3] = inrow[frac >> 16];frac += fracstep;
891 out[0] = inrow[frac >> 16];frac += fracstep;
892 out[1] = inrow[frac >> 16];frac += fracstep;
897 out[0] = inrow[frac >> 16];frac += fracstep;
903 void Image_Resample24Lerp(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
905 int i, j, r, yi, oldy, f, fstep, lerp, endy = (inheight-1), inwidth3 = inwidth * 3, outwidth3 = outwidth * 3;
908 fstep = (int) (inheight*65536.0f/outheight);
912 Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
913 Image_Resample24LerpLine (inrow + inwidth3, resamplerow2, inwidth, outwidth);
914 for (i = 0, f = 0;i < outheight;i++,f += fstep)
922 inrow = (qbyte *)indata + inwidth3*yi;
924 memcpy(resamplerow1, resamplerow2, outwidth3);
926 Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
927 Image_Resample24LerpLine (inrow + inwidth3, resamplerow2, inwidth, outwidth);
971 resamplerow1 -= outwidth3;
972 resamplerow2 -= outwidth3;
978 inrow = (qbyte *)indata + inwidth3*yi;
980 memcpy(resamplerow1, resamplerow2, outwidth3);
982 Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
985 memcpy(out, resamplerow1, outwidth3);
990 void Image_Resample24Nolerp(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
992 int i, j, f, inwidth3 = inwidth * 3;
993 unsigned frac, fracstep;
997 fracstep = inwidth*0x10000/outwidth;
998 for (i = 0;i < outheight;i++)
1000 inrow = (qbyte *)indata + inwidth3*(i*inheight/outheight);
1001 frac = fracstep >> 1;
1005 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1006 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1007 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1008 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1013 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1014 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1019 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1030 void Image_Resample (void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight, int bytesperpixel, int quality)
1032 if (resamplerowsize < outwidth*4)
1035 Mem_Free(resamplerow1);
1036 resamplerowsize = outwidth*4;
1037 if (!resamplemempool)
1038 resamplemempool = Mem_AllocPool("Image Scaling Buffer");
1039 resamplerow1 = Mem_Alloc(resamplemempool, resamplerowsize*2);
1040 resamplerow2 = resamplerow1 + resamplerowsize;
1042 if (bytesperpixel == 4)
1045 Image_Resample32Lerp(indata, inwidth, inheight, outdata, outwidth, outheight);
1047 Image_Resample32Nearest(indata, inwidth, inheight, outdata, outwidth, outheight);
1049 else if (bytesperpixel == 3)
1052 Image_Resample24Lerp(indata, inwidth, inheight, outdata, outwidth, outheight);
1054 Image_Resample24Nolerp(indata, inwidth, inheight, outdata, outwidth, outheight);
1057 Sys_Error("Image_Resample: unsupported bytesperpixel %i\n", bytesperpixel);
1060 // in can be the same as out
1061 void Image_MipReduce(qbyte *in, qbyte *out, int *width, int *height, int destwidth, int destheight, int bytesperpixel)
1064 nextrow = *width * bytesperpixel;
1065 if (*width > destwidth)
1068 if (*height > destheight)
1072 if (bytesperpixel == 4)
1074 for (y = 0;y < *height;y++)
1076 for (x = 0;x < *width;x++)
1078 out[0] = (qbyte) ((in[0] + in[4] + in[nextrow ] + in[nextrow+4]) >> 2);
1079 out[1] = (qbyte) ((in[1] + in[5] + in[nextrow+1] + in[nextrow+5]) >> 2);
1080 out[2] = (qbyte) ((in[2] + in[6] + in[nextrow+2] + in[nextrow+6]) >> 2);
1081 out[3] = (qbyte) ((in[3] + in[7] + in[nextrow+3] + in[nextrow+7]) >> 2);
1085 in += nextrow; // skip a line
1088 else if (bytesperpixel == 3)
1090 for (y = 0;y < *height;y++)
1092 for (x = 0;x < *width;x++)
1094 out[0] = (qbyte) ((in[0] + in[3] + in[nextrow ] + in[nextrow+3]) >> 2);
1095 out[1] = (qbyte) ((in[1] + in[4] + in[nextrow+1] + in[nextrow+4]) >> 2);
1096 out[2] = (qbyte) ((in[2] + in[5] + in[nextrow+2] + in[nextrow+5]) >> 2);
1100 in += nextrow; // skip a line
1104 Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
1109 if (bytesperpixel == 4)
1111 for (y = 0;y < *height;y++)
1113 for (x = 0;x < *width;x++)
1115 out[0] = (qbyte) ((in[0] + in[4]) >> 1);
1116 out[1] = (qbyte) ((in[1] + in[5]) >> 1);
1117 out[2] = (qbyte) ((in[2] + in[6]) >> 1);
1118 out[3] = (qbyte) ((in[3] + in[7]) >> 1);
1124 else if (bytesperpixel == 3)
1126 for (y = 0;y < *height;y++)
1128 for (x = 0;x < *width;x++)
1130 out[0] = (qbyte) ((in[0] + in[3]) >> 1);
1131 out[1] = (qbyte) ((in[1] + in[4]) >> 1);
1132 out[2] = (qbyte) ((in[2] + in[5]) >> 1);
1139 Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
1144 if (*height > destheight)
1148 if (bytesperpixel == 4)
1150 for (y = 0;y < *height;y++)
1152 for (x = 0;x < *width;x++)
1154 out[0] = (qbyte) ((in[0] + in[nextrow ]) >> 1);
1155 out[1] = (qbyte) ((in[1] + in[nextrow+1]) >> 1);
1156 out[2] = (qbyte) ((in[2] + in[nextrow+2]) >> 1);
1157 out[3] = (qbyte) ((in[3] + in[nextrow+3]) >> 1);
1161 in += nextrow; // skip a line
1164 else if (bytesperpixel == 3)
1166 for (y = 0;y < *height;y++)
1168 for (x = 0;x < *width;x++)
1170 out[0] = (qbyte) ((in[0] + in[nextrow ]) >> 1);
1171 out[1] = (qbyte) ((in[1] + in[nextrow+1]) >> 1);
1172 out[2] = (qbyte) ((in[2] + in[nextrow+2]) >> 1);
1176 in += nextrow; // skip a line
1180 Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
1183 Sys_Error("Image_MipReduce: desired size already achieved\n");