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 fin += pcx.bytes_per_line - image_width; // the number of bytes per line is always forced to an even number
163 while(x < image_width)
170 for(x = 0;x < image_width*image_height;x++)
183 =========================================================
187 =========================================================
190 typedef struct _TargaHeader
192 unsigned char id_length, colormap_type, image_type;
193 unsigned short colormap_index, colormap_length;
194 unsigned char colormap_size;
195 unsigned short x_origin, y_origin, width, height;
196 unsigned char pixel_size, attributes;
200 TargaHeader targa_header;
208 qbyte *LoadTGA (qbyte *f, int matchwidth, int matchheight)
211 unsigned char red, green, blue, alpha, run, runlen;
212 qbyte *pixbuf, *image_rgba, *fin, *enddata;
216 targa_header.id_length = f[0];
217 targa_header.colormap_type = f[1];
218 targa_header.image_type = f[2];
220 targa_header.colormap_index = f[3] + f[4] * 256;
221 targa_header.colormap_length = f[5] + f[6] * 256;
222 targa_header.colormap_size = f[7];
223 targa_header.x_origin = f[8] + f[9] * 256;
224 targa_header.y_origin = f[10] + f[11] * 256;
225 targa_header.width = f[12] + f[13] * 256;
226 targa_header.height = f[14] + f[15] * 256;
227 if (matchwidth && targa_header.width != matchwidth)
229 if (matchheight && targa_header.height != matchheight)
231 targa_header.pixel_size = f[16];
232 targa_header.attributes = f[17];
234 if (targa_header.image_type != 2 && targa_header.image_type != 10)
236 Con_Printf ("LoadTGA: Only type 2 and 10 targa RGB images supported\n");
240 if (targa_header.colormap_type != 0 || (targa_header.pixel_size != 32 && targa_header.pixel_size != 24))
242 Con_Printf ("LoadTGA: Only 32 or 24 bit images supported (no colormaps)\n");
246 enddata = f + loadsize;
248 image_width = targa_header.width;
249 image_height = targa_header.height;
251 image_rgba = Mem_Alloc(tempmempool, image_width * image_height * 4);
254 Con_Printf ("LoadTGA: not enough memory for %i by %i image\n", image_width, image_height);
259 if (targa_header.id_length != 0)
260 fin += targa_header.id_length; // skip TARGA image comment
262 // If bit 5 of attributes isn't set, the image has been stored from bottom to top
263 if ((targa_header.attributes & 0x20) == 0)
265 pixbuf = image_rgba + (image_height - 1)*image_width*4;
266 row_inc = -image_width*4*2;
274 if (targa_header.image_type == 2)
276 // Uncompressed, RGB images
277 if (targa_header.pixel_size == 24)
279 if (fin + image_width * image_height * 3 <= enddata)
281 for(y = 0;y < image_height;y++)
283 for(x = 0;x < image_width;x++)
297 if (fin + image_width * image_height * 4 <= enddata)
299 for(y = 0;y < image_height;y++)
301 for(x = 0;x < image_width;x++)
314 else if (targa_header.image_type==10)
316 // Runlength encoded RGB images
319 while (y < image_height && fin < enddata)
324 // RLE compressed run
325 runlen = 1 + (runlen & 0x7f);
326 if (targa_header.pixel_size == 24)
328 if (fin + 3 > enddata)
337 if (fin + 4 > enddata)
345 while (runlen && y < image_height)
348 if (run > image_width - x)
349 run = image_width - x;
359 if (x == image_width)
361 // end of line, advance to next
370 // RLE uncompressed run
371 runlen = 1 + (runlen & 0x7f);
372 while (runlen && y < image_height)
375 if (run > image_width - x)
376 run = image_width - x;
379 if (targa_header.pixel_size == 24)
381 if (fin + run * 3 > enddata)
394 if (fin + run * 4 > enddata)
405 if (x == image_width)
407 // end of line, advance to next
424 qbyte *LoadLMP (qbyte *f, int matchwidth, int matchheight)
431 Con_Printf("LoadLMP: invalid LMP file\n");
435 // parse the very complicated header *chuckle*
436 width = f[0] + f[1] * 256 + f[2] * 65536 + f[3] * 16777216;
437 height = f[4] + f[5] * 256 + f[6] * 65536 + f[7] * 16777216;
438 if ((unsigned) width > 4096 || (unsigned) height > 4096)
440 Con_Printf("LoadLMP: invalid size\n");
443 if ((matchwidth && width != matchwidth) || (matchheight && height != matchheight))
446 if (loadsize < 8 + width * height)
448 Con_Printf("LoadLMP: invalid LMP file\n");
453 image_height = height;
455 image_rgba = Mem_Alloc(tempmempool, image_width * image_height * 4);
458 Con_Printf("LoadLMP: not enough memory for %i by %i image\n", image_width, image_height);
461 Image_Copy8bitRGBA(f + 8, image_rgba, image_width * image_height, d_8to24table);
470 qbyte *LoadLMPAs8Bit (qbyte *f, int matchwidth, int matchheight)
477 Con_Printf("LoadLMPAs8Bit: invalid LMP file\n");
481 // parse the very complicated header *chuckle*
482 width = f[0] + f[1] * 256 + f[2] * 65536 + f[3] * 16777216;
483 height = f[4] + f[5] * 256 + f[6] * 65536 + f[7] * 16777216;
484 if ((unsigned) width > 4096 || (unsigned) height > 4096)
486 Con_Printf("LoadLMPAs8Bit: invalid size\n");
489 if ((matchwidth && width != matchwidth) || (matchheight && height != matchheight))
492 if (loadsize < 8 + width * height)
494 Con_Printf("LoadLMPAs8Bit: invalid LMP file\n");
499 image_height = height;
501 image_8bit = Mem_Alloc(tempmempool, image_width * image_height);
504 Con_Printf("LoadLMPAs8Bit: not enough memory for %i by %i image\n", image_width, image_height);
507 memcpy(image_8bit, f + 8, image_width * image_height);
511 void Image_StripImageExtension (char *in, char *out)
514 end = in + strlen(in);
518 if (strcmp(temp, ".tga") == 0 || strcmp(temp, ".pcx") == 0 || strcmp(temp, ".lmp") == 0)
528 qbyte *loadimagepixels (char *filename, qboolean complain, int matchwidth, int matchheight)
531 char basename[256], name[256], *c;
532 Image_StripImageExtension(filename, basename); // strip .tga, .pcx and .lmp extensions to allow replacement by other types
533 // replace *'s with #, so commandline utils don't get confused when dealing with the external files
534 for (c = basename;*c;c++)
537 sprintf (name, "textures/%s.tga", basename);
538 f = COM_LoadFile(name, true);
541 data = LoadTGA (f, matchwidth, matchheight);
545 sprintf (name, "textures/%s.pcx", basename);
546 f = COM_LoadFile(name, true);
549 data = LoadPCX (f, matchwidth, matchheight);
553 sprintf (name, "%s.tga", basename);
554 f = COM_LoadFile(name, true);
557 data = LoadTGA (f, matchwidth, matchheight);
561 sprintf (name, "%s.pcx", basename);
562 f = COM_LoadFile(name, true);
565 data = LoadPCX (f, matchwidth, matchheight);
569 sprintf (name, "%s.lmp", basename);
570 f = COM_LoadFile(name, true);
573 data = LoadLMP (f, matchwidth, matchheight);
578 Con_Printf ("Couldn't load %s.tga, .pcx, .lmp\n", filename);
582 int image_makemask (qbyte *in, qbyte *out, int size)
586 for (i = 0;i < size;i++)
588 out[0] = out[1] = out[2] = 255;
598 qbyte* loadimagepixelsmask (char* filename, qboolean complain, int matchwidth, int matchheight)
601 in = data = loadimagepixels(filename, complain, matchwidth, matchheight);
604 if (image_makemask(data, data, image_width * image_height))
605 return data; // some transparency
609 return NULL; // all opaque
613 rtexture_t *loadtextureimage (rtexturepool_t *pool, char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap, qboolean precache)
617 if (!(data = loadimagepixels (filename, complain, matchwidth, matchheight)))
619 rt = R_LoadTexture (pool, filename, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
624 rtexture_t *loadtextureimagemask (rtexturepool_t *pool, char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap, qboolean precache)
628 if (!(data = loadimagepixelsmask (filename, complain, matchwidth, matchheight)))
630 rt = R_LoadTexture (pool, filename, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
635 rtexture_t *image_masktex;
636 rtexture_t *loadtextureimagewithmask (rtexturepool_t *pool, char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap, qboolean precache)
642 image_masktex = NULL;
643 if (!(data = loadimagepixels (filename, complain, matchwidth, matchheight)))
645 rt = R_LoadTexture (pool, filename, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
646 count = image_makemask(data, data, image_width * image_height);
649 filename2 = Mem_Alloc(tempmempool, strlen(filename) + 6);
650 sprintf(filename2, "%s_mask", filename);
651 image_masktex = R_LoadTexture (pool, filename2, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
658 qboolean Image_WriteTGARGB_preflipped (char *filename, int width, int height, qbyte *data)
661 qbyte *buffer, *in, *out, *end;
663 buffer = Mem_Alloc(tempmempool, width*height*3 + 18);
665 memset (buffer, 0, 18);
666 buffer[2] = 2; // uncompressed type
667 buffer[12] = (width >> 0) & 0xFF;
668 buffer[13] = (width >> 8) & 0xFF;
669 buffer[14] = (height >> 0) & 0xFF;
670 buffer[15] = (height >> 8) & 0xFF;
671 buffer[16] = 24; // pixel size
676 end = in + width*height*3;
677 for (;in < end;in += 3)
683 ret = COM_WriteFile (filename, buffer, width*height*3 + 18 );
689 void Image_WriteTGARGB (char *filename, int width, int height, qbyte *data)
692 qbyte *buffer, *in, *out, *end;
694 buffer = Mem_Alloc(tempmempool, width*height*3 + 18);
696 memset (buffer, 0, 18);
697 buffer[2] = 2; // uncompressed type
698 buffer[12] = (width >> 0) & 0xFF;
699 buffer[13] = (width >> 8) & 0xFF;
700 buffer[14] = (height >> 0) & 0xFF;
701 buffer[15] = (height >> 8) & 0xFF;
702 buffer[16] = 24; // pixel size
704 // swap rgb to bgr and flip upside down
706 for (y = height - 1;y >= 0;y--)
708 in = data + y * width * 3;
709 end = in + width * 3;
710 for (;in < end;in += 3)
717 COM_WriteFile (filename, buffer, width*height*3 + 18 );
722 void Image_WriteTGARGBA (char *filename, int width, int height, qbyte *data)
725 qbyte *buffer, *in, *out, *end;
727 buffer = Mem_Alloc(tempmempool, width*height*4 + 18);
729 memset (buffer, 0, 18);
730 buffer[2] = 2; // uncompressed type
731 buffer[12] = (width >> 0) & 0xFF;
732 buffer[13] = (width >> 8) & 0xFF;
733 buffer[14] = (height >> 0) & 0xFF;
734 buffer[15] = (height >> 8) & 0xFF;
735 buffer[16] = 32; // pixel size
737 // swap rgba to bgra and flip upside down
739 for (y = height - 1;y >= 0;y--)
741 in = data + y * width * 4;
742 end = in + width * 4;
743 for (;in < end;in += 4)
751 COM_WriteFile (filename, buffer, width*height*4 + 18 );
756 qboolean Image_CheckAlpha(qbyte *data, int size, qboolean rgba)
762 for (end = data + size * 4, data += 3;data < end;data += 4)
768 // color 255 is transparent
769 for (end = data + size;data < end;data++)
776 static void Image_Resample32LerpLine (qbyte *in, qbyte *out, int inwidth, int outwidth)
778 int j, xi, oldx = 0, f, fstep, endx, lerp;
779 fstep = (int) (inwidth*65536.0f/outwidth);
781 for (j = 0,f = 0;j < outwidth;j++, f += fstep)
786 in += (xi - oldx) * 4;
792 *out++ = (qbyte) ((((in[4] - in[0]) * lerp) >> 16) + in[0]);
793 *out++ = (qbyte) ((((in[5] - in[1]) * lerp) >> 16) + in[1]);
794 *out++ = (qbyte) ((((in[6] - in[2]) * lerp) >> 16) + in[2]);
795 *out++ = (qbyte) ((((in[7] - in[3]) * lerp) >> 16) + in[3]);
797 else // last pixel of the line has no pixel to lerp to
807 static void Image_Resample24LerpLine (qbyte *in, qbyte *out, int inwidth, int outwidth)
809 int j, xi, oldx = 0, f, fstep, endx, lerp;
810 fstep = (int) (inwidth*65536.0f/outwidth);
812 for (j = 0,f = 0;j < outwidth;j++, f += fstep)
817 in += (xi - oldx) * 3;
823 *out++ = (qbyte) ((((in[3] - in[0]) * lerp) >> 16) + in[0]);
824 *out++ = (qbyte) ((((in[4] - in[1]) * lerp) >> 16) + in[1]);
825 *out++ = (qbyte) ((((in[5] - in[2]) * lerp) >> 16) + in[2]);
827 else // last pixel of the line has no pixel to lerp to
836 int resamplerowsize = 0;
837 qbyte *resamplerow1 = NULL;
838 qbyte *resamplerow2 = NULL;
839 mempool_t *resamplemempool = NULL;
841 #define LERPBYTE(i) r = resamplerow1[i];out[i] = (qbyte) ((((resamplerow2[i] - r) * lerp) >> 16) + r)
842 void Image_Resample32Lerp(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
844 int i, j, r, yi, oldy, f, fstep, lerp, endy = (inheight-1), inwidth4 = inwidth*4, outwidth4 = outwidth*4;
847 fstep = (int) (inheight*65536.0f/outheight);
851 Image_Resample32LerpLine (inrow, resamplerow1, inwidth, outwidth);
852 Image_Resample32LerpLine (inrow + inwidth4, resamplerow2, inwidth, outwidth);
853 for (i = 0, f = 0;i < outheight;i++,f += fstep)
861 inrow = (qbyte *)indata + inwidth4*yi;
863 memcpy(resamplerow1, resamplerow2, outwidth4);
865 Image_Resample32LerpLine (inrow, resamplerow1, inwidth, outwidth);
866 Image_Resample32LerpLine (inrow + inwidth4, resamplerow2, inwidth, outwidth);
917 resamplerow1 -= outwidth4;
918 resamplerow2 -= outwidth4;
924 inrow = (qbyte *)indata + inwidth4*yi;
926 memcpy(resamplerow1, resamplerow2, outwidth4);
928 Image_Resample32LerpLine (inrow, resamplerow1, inwidth, outwidth);
931 memcpy(out, resamplerow1, outwidth4);
936 void Image_Resample32Nearest(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
939 unsigned frac, fracstep;
940 // relies on int being 4 bytes
944 fracstep = inwidth*0x10000/outwidth;
945 for (i = 0;i < outheight;i++)
947 inrow = (int *)indata + inwidth*(i*inheight/outheight);
948 frac = fracstep >> 1;
952 out[0] = inrow[frac >> 16];frac += fracstep;
953 out[1] = inrow[frac >> 16];frac += fracstep;
954 out[2] = inrow[frac >> 16];frac += fracstep;
955 out[3] = inrow[frac >> 16];frac += fracstep;
961 out[0] = inrow[frac >> 16];frac += fracstep;
962 out[1] = inrow[frac >> 16];frac += fracstep;
967 out[0] = inrow[frac >> 16];frac += fracstep;
973 void Image_Resample24Lerp(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
975 int i, j, r, yi, oldy, f, fstep, lerp, endy = (inheight-1), inwidth3 = inwidth * 3, outwidth3 = outwidth * 3;
978 fstep = (int) (inheight*65536.0f/outheight);
982 Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
983 Image_Resample24LerpLine (inrow + inwidth3, resamplerow2, inwidth, outwidth);
984 for (i = 0, f = 0;i < outheight;i++,f += fstep)
992 inrow = (qbyte *)indata + inwidth3*yi;
994 memcpy(resamplerow1, resamplerow2, outwidth3);
996 Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
997 Image_Resample24LerpLine (inrow + inwidth3, resamplerow2, inwidth, outwidth);
1041 resamplerow1 -= outwidth3;
1042 resamplerow2 -= outwidth3;
1048 inrow = (qbyte *)indata + inwidth3*yi;
1050 memcpy(resamplerow1, resamplerow2, outwidth3);
1052 Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
1055 memcpy(out, resamplerow1, outwidth3);
1060 void Image_Resample24Nolerp(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
1062 int i, j, f, inwidth3 = inwidth * 3;
1063 unsigned frac, fracstep;
1067 fracstep = inwidth*0x10000/outwidth;
1068 for (i = 0;i < outheight;i++)
1070 inrow = (qbyte *)indata + inwidth3*(i*inheight/outheight);
1071 frac = fracstep >> 1;
1075 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1076 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1077 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1078 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1083 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1084 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1089 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1100 void Image_Resample (void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight, int bytesperpixel, int quality)
1102 if (resamplerowsize < outwidth*4)
1105 Mem_Free(resamplerow1);
1106 resamplerowsize = outwidth*4;
1107 if (!resamplemempool)
1108 resamplemempool = Mem_AllocPool("Image Scaling Buffer");
1109 resamplerow1 = Mem_Alloc(resamplemempool, resamplerowsize*2);
1110 resamplerow2 = resamplerow1 + resamplerowsize;
1112 if (bytesperpixel == 4)
1115 Image_Resample32Lerp(indata, inwidth, inheight, outdata, outwidth, outheight);
1117 Image_Resample32Nearest(indata, inwidth, inheight, outdata, outwidth, outheight);
1119 else if (bytesperpixel == 3)
1122 Image_Resample24Lerp(indata, inwidth, inheight, outdata, outwidth, outheight);
1124 Image_Resample24Nolerp(indata, inwidth, inheight, outdata, outwidth, outheight);
1127 Sys_Error("Image_Resample: unsupported bytesperpixel %i\n", bytesperpixel);
1130 // in can be the same as out
1131 void Image_MipReduce(qbyte *in, qbyte *out, int *width, int *height, int destwidth, int destheight, int bytesperpixel)
1134 nextrow = *width * bytesperpixel;
1135 if (*width > destwidth)
1138 if (*height > destheight)
1142 if (bytesperpixel == 4)
1144 for (y = 0;y < *height;y++)
1146 for (x = 0;x < *width;x++)
1148 out[0] = (qbyte) ((in[0] + in[4] + in[nextrow ] + in[nextrow+4]) >> 2);
1149 out[1] = (qbyte) ((in[1] + in[5] + in[nextrow+1] + in[nextrow+5]) >> 2);
1150 out[2] = (qbyte) ((in[2] + in[6] + in[nextrow+2] + in[nextrow+6]) >> 2);
1151 out[3] = (qbyte) ((in[3] + in[7] + in[nextrow+3] + in[nextrow+7]) >> 2);
1155 in += nextrow; // skip a line
1158 else if (bytesperpixel == 3)
1160 for (y = 0;y < *height;y++)
1162 for (x = 0;x < *width;x++)
1164 out[0] = (qbyte) ((in[0] + in[3] + in[nextrow ] + in[nextrow+3]) >> 2);
1165 out[1] = (qbyte) ((in[1] + in[4] + in[nextrow+1] + in[nextrow+4]) >> 2);
1166 out[2] = (qbyte) ((in[2] + in[5] + in[nextrow+2] + in[nextrow+5]) >> 2);
1170 in += nextrow; // skip a line
1174 Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
1179 if (bytesperpixel == 4)
1181 for (y = 0;y < *height;y++)
1183 for (x = 0;x < *width;x++)
1185 out[0] = (qbyte) ((in[0] + in[4]) >> 1);
1186 out[1] = (qbyte) ((in[1] + in[5]) >> 1);
1187 out[2] = (qbyte) ((in[2] + in[6]) >> 1);
1188 out[3] = (qbyte) ((in[3] + in[7]) >> 1);
1194 else if (bytesperpixel == 3)
1196 for (y = 0;y < *height;y++)
1198 for (x = 0;x < *width;x++)
1200 out[0] = (qbyte) ((in[0] + in[3]) >> 1);
1201 out[1] = (qbyte) ((in[1] + in[4]) >> 1);
1202 out[2] = (qbyte) ((in[2] + in[5]) >> 1);
1209 Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
1214 if (*height > destheight)
1218 if (bytesperpixel == 4)
1220 for (y = 0;y < *height;y++)
1222 for (x = 0;x < *width;x++)
1224 out[0] = (qbyte) ((in[0] + in[nextrow ]) >> 1);
1225 out[1] = (qbyte) ((in[1] + in[nextrow+1]) >> 1);
1226 out[2] = (qbyte) ((in[2] + in[nextrow+2]) >> 1);
1227 out[3] = (qbyte) ((in[3] + in[nextrow+3]) >> 1);
1231 in += nextrow; // skip a line
1234 else if (bytesperpixel == 3)
1236 for (y = 0;y < *height;y++)
1238 for (x = 0;x < *width;x++)
1240 out[0] = (qbyte) ((in[0] + in[nextrow ]) >> 1);
1241 out[1] = (qbyte) ((in[1] + in[nextrow+1]) >> 1);
1242 out[2] = (qbyte) ((in[2] + in[nextrow+2]) >> 1);
1246 in += nextrow; // skip a line
1250 Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
1253 Sys_Error("Image_MipReduce: desired size already achieved\n");