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)
210 int columns, rows, row, column, row_inc;
211 qbyte *pixbuf, *image_rgba, *fin, *enddata;
215 targa_header.id_length = f[0];
216 targa_header.colormap_type = f[1];
217 targa_header.image_type = f[2];
219 targa_header.colormap_index = f[3] + f[4] * 256;
220 targa_header.colormap_length = f[5] + f[6] * 256;
221 targa_header.colormap_size = f[7];
222 targa_header.x_origin = f[8] + f[9] * 256;
223 targa_header.y_origin = f[10] + f[11] * 256;
224 targa_header.width = f[12] + f[13] * 256;
225 targa_header.height = f[14] + f[15] * 256;
226 if (matchwidth && targa_header.width != matchwidth)
228 if (matchheight && targa_header.height != matchheight)
230 targa_header.pixel_size = f[16];
231 targa_header.attributes = f[17];
233 if (targa_header.image_type != 2 && targa_header.image_type != 10)
235 Con_Printf ("LoadTGA: Only type 2 and 10 targa RGB images supported\n");
239 if (targa_header.colormap_type != 0 || (targa_header.pixel_size != 32 && targa_header.pixel_size != 24))
241 Con_Printf ("LoadTGA: Only 32 or 24 bit images supported (no colormaps)\n");
245 enddata = f + loadsize;
247 columns = targa_header.width;
248 rows = targa_header.height;
250 image_rgba = Mem_Alloc(tempmempool, columns * rows * 4);
253 Con_Printf ("LoadTGA: not enough memory for %i by %i image\n", columns, rows);
258 if (targa_header.id_length != 0)
259 fin += targa_header.id_length; // skip TARGA image comment
261 // If bit 5 of attributes isn't set, the image has been stored from bottom to top
262 if ((targa_header.attributes & 0x20) == 0)
264 pixbuf = image_rgba + (rows - 1)*columns*4;
265 row_inc = -columns*4*2;
273 if (targa_header.image_type == 2)
275 // Uncompressed, RGB images
276 for(row = 0;row < rows;row++)
278 for(column = 0;column < columns;column++)
280 switch (targa_header.pixel_size)
283 if (fin + 3 > enddata)
292 if (fin + 4 > enddata)
305 else if (targa_header.image_type==10)
307 // Runlength encoded RGB images
308 unsigned char red = 0, green = 0, blue = 0, alphabyte = 0, packetHeader, packetSize, j;
309 for(row = 0;row < rows;row++)
311 for(column = 0;column < columns;)
315 packetHeader = *fin++;
316 packetSize = 1 + (packetHeader & 0x7f);
317 if (packetHeader & 0x80)
320 switch (targa_header.pixel_size)
323 if (fin + 3 > enddata)
331 if (fin + 4 > enddata)
340 for(j = 0;j < packetSize;j++)
345 *pixbuf++ = alphabyte;
347 if (column == columns)
349 // run spans across rows
361 // non run-length packet
362 for(j = 0;j < packetSize;j++)
364 switch (targa_header.pixel_size)
367 if (fin + 3 > enddata)
376 if (fin + 4 > enddata)
386 if (column == columns)
388 // pixel packet run spans across rows
405 image_width = columns;
415 qbyte *LoadLMP (qbyte *f, int matchwidth, int matchheight)
422 Con_Printf("LoadLMP: invalid LMP file\n");
426 // parse the very complicated header *chuckle*
427 width = f[0] + f[1] * 256 + f[2] * 65536 + f[3] * 16777216;
428 height = f[4] + f[5] * 256 + f[6] * 65536 + f[7] * 16777216;
429 if ((unsigned) width > 4096 || (unsigned) height > 4096)
431 Con_Printf("LoadLMP: invalid size\n");
434 if ((matchwidth && width != matchwidth) || (matchheight && height != matchheight))
437 if (loadsize < 8 + width * height)
439 Con_Printf("LoadLMP: invalid LMP file\n");
444 image_height = height;
446 image_rgba = Mem_Alloc(tempmempool, image_width * image_height * 4);
449 Con_Printf("LoadLMP: not enough memory for %i by %i image\n", image_width, image_height);
452 Image_Copy8bitRGBA(f + 8, image_rgba, image_width * image_height, d_8to24table);
456 void Image_StripImageExtension (char *in, char *out)
459 end = in + strlen(in);
463 if (strcmp(temp, ".tga") == 0 || strcmp(temp, ".pcx") == 0 || strcmp(temp, ".lmp") == 0)
473 qbyte *loadimagepixels (char *filename, qboolean complain, int matchwidth, int matchheight)
476 char basename[256], name[256], *c;
477 Image_StripImageExtension(filename, basename); // strip .tga, .pcx and .lmp extensions to allow replacement by other types
478 // replace *'s with #, so commandline utils don't get confused when dealing with the external files
479 for (c = basename;*c;c++)
482 sprintf (name, "textures/%s.tga", basename);
483 f = COM_LoadFile(name, true);
486 data = LoadTGA (f, matchwidth, matchheight);
490 sprintf (name, "textures/%s.pcx", basename);
491 f = COM_LoadFile(name, true);
494 data = LoadPCX (f, matchwidth, matchheight);
498 sprintf (name, "%s.tga", basename);
499 f = COM_LoadFile(name, true);
502 data = LoadTGA (f, matchwidth, matchheight);
506 sprintf (name, "%s.pcx", basename);
507 f = COM_LoadFile(name, true);
510 data = LoadPCX (f, matchwidth, matchheight);
514 sprintf (name, "%s.lmp", basename);
515 f = COM_LoadFile(name, true);
518 data = LoadLMP (f, matchwidth, matchheight);
523 Con_Printf ("Couldn't load %s.tga, .pcx, .lmp\n", filename);
527 int image_makemask (qbyte *in, qbyte *out, int size)
531 for (i = 0;i < size;i++)
533 out[0] = out[1] = out[2] = 255;
543 qbyte* loadimagepixelsmask (char* filename, qboolean complain, int matchwidth, int matchheight)
546 in = data = loadimagepixels(filename, complain, matchwidth, matchheight);
549 if (image_makemask(data, data, image_width * image_height))
550 return data; // some transparency
554 return NULL; // all opaque
558 rtexture_t *loadtextureimage (rtexturepool_t *pool, char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap, qboolean precache)
562 if (!(data = loadimagepixels (filename, complain, matchwidth, matchheight)))
564 rt = R_LoadTexture (pool, filename, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
569 rtexture_t *loadtextureimagemask (rtexturepool_t *pool, char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap, qboolean precache)
573 if (!(data = loadimagepixelsmask (filename, complain, matchwidth, matchheight)))
575 rt = R_LoadTexture (pool, filename, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
580 rtexture_t *image_masktex;
581 rtexture_t *loadtextureimagewithmask (rtexturepool_t *pool, char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap, qboolean precache)
587 image_masktex = NULL;
588 if (!(data = loadimagepixels (filename, complain, matchwidth, matchheight)))
590 rt = R_LoadTexture (pool, filename, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
591 count = image_makemask(data, data, image_width * image_height);
594 filename2 = Mem_Alloc(tempmempool, strlen(filename) + 6);
595 sprintf(filename2, "%s_mask", filename);
596 image_masktex = R_LoadTexture (pool, filename2, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
603 qboolean Image_WriteTGARGB_preflipped (char *filename, int width, int height, qbyte *data)
606 qbyte *buffer, *in, *out, *end;
608 buffer = Mem_Alloc(tempmempool, width*height*3 + 18);
610 memset (buffer, 0, 18);
611 buffer[2] = 2; // uncompressed type
612 buffer[12] = (width >> 0) & 0xFF;
613 buffer[13] = (width >> 8) & 0xFF;
614 buffer[14] = (height >> 0) & 0xFF;
615 buffer[15] = (height >> 8) & 0xFF;
616 buffer[16] = 24; // pixel size
621 end = in + width*height*3;
622 for (;in < end;in += 3)
628 ret = COM_WriteFile (filename, buffer, width*height*3 + 18 );
634 void Image_WriteTGARGB (char *filename, int width, int height, qbyte *data)
637 qbyte *buffer, *in, *out, *end;
639 buffer = Mem_Alloc(tempmempool, width*height*3 + 18);
641 memset (buffer, 0, 18);
642 buffer[2] = 2; // uncompressed type
643 buffer[12] = (width >> 0) & 0xFF;
644 buffer[13] = (width >> 8) & 0xFF;
645 buffer[14] = (height >> 0) & 0xFF;
646 buffer[15] = (height >> 8) & 0xFF;
647 buffer[16] = 24; // pixel size
649 // swap rgb to bgr and flip upside down
651 for (y = height - 1;y >= 0;y--)
653 in = data + y * width * 3;
654 end = in + width * 3;
655 for (;in < end;in += 3)
662 COM_WriteFile (filename, buffer, width*height*3 + 18 );
667 void Image_WriteTGARGBA (char *filename, int width, int height, qbyte *data)
670 qbyte *buffer, *in, *out, *end;
672 buffer = Mem_Alloc(tempmempool, width*height*4 + 18);
674 memset (buffer, 0, 18);
675 buffer[2] = 2; // uncompressed type
676 buffer[12] = (width >> 0) & 0xFF;
677 buffer[13] = (width >> 8) & 0xFF;
678 buffer[14] = (height >> 0) & 0xFF;
679 buffer[15] = (height >> 8) & 0xFF;
680 buffer[16] = 32; // pixel size
682 // swap rgba to bgra and flip upside down
684 for (y = height - 1;y >= 0;y--)
686 in = data + y * width * 4;
687 end = in + width * 4;
688 for (;in < end;in += 4)
696 COM_WriteFile (filename, buffer, width*height*4 + 18 );
701 qboolean Image_CheckAlpha(qbyte *data, int size, qboolean rgba)
707 for (end = data + size * 4, data += 3;data < end;data += 4)
713 // color 255 is transparent
714 for (end = data + size;data < end;data++)
721 static void Image_Resample32LerpLine (qbyte *in, qbyte *out, int inwidth, int outwidth)
723 int j, xi, oldx = 0, f, fstep, endx, lerp;
724 fstep = (int) (inwidth*65536.0f/outwidth);
726 for (j = 0,f = 0;j < outwidth;j++, f += fstep)
731 in += (xi - oldx) * 4;
737 *out++ = (qbyte) ((((in[4] - in[0]) * lerp) >> 16) + in[0]);
738 *out++ = (qbyte) ((((in[5] - in[1]) * lerp) >> 16) + in[1]);
739 *out++ = (qbyte) ((((in[6] - in[2]) * lerp) >> 16) + in[2]);
740 *out++ = (qbyte) ((((in[7] - in[3]) * lerp) >> 16) + in[3]);
742 else // last pixel of the line has no pixel to lerp to
752 static void Image_Resample24LerpLine (qbyte *in, qbyte *out, int inwidth, int outwidth)
754 int j, xi, oldx = 0, f, fstep, endx, lerp;
755 fstep = (int) (inwidth*65536.0f/outwidth);
757 for (j = 0,f = 0;j < outwidth;j++, f += fstep)
762 in += (xi - oldx) * 3;
768 *out++ = (qbyte) ((((in[3] - in[0]) * lerp) >> 16) + in[0]);
769 *out++ = (qbyte) ((((in[4] - in[1]) * lerp) >> 16) + in[1]);
770 *out++ = (qbyte) ((((in[5] - in[2]) * lerp) >> 16) + in[2]);
772 else // last pixel of the line has no pixel to lerp to
781 int resamplerowsize = 0;
782 qbyte *resamplerow1 = NULL;
783 qbyte *resamplerow2 = NULL;
784 mempool_t *resamplemempool = NULL;
786 #define LERPBYTE(i) r = resamplerow1[i];out[i] = (qbyte) ((((resamplerow2[i] - r) * lerp) >> 16) + r)
787 void Image_Resample32Lerp(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
789 int i, j, r, yi, oldy, f, fstep, lerp, endy = (inheight-1), inwidth4 = inwidth*4, outwidth4 = outwidth*4;
792 fstep = (int) (inheight*65536.0f/outheight);
796 Image_Resample32LerpLine (inrow, resamplerow1, inwidth, outwidth);
797 Image_Resample32LerpLine (inrow + inwidth4, resamplerow2, inwidth, outwidth);
798 for (i = 0, f = 0;i < outheight;i++,f += fstep)
806 inrow = (qbyte *)indata + inwidth4*yi;
808 memcpy(resamplerow1, resamplerow2, outwidth4);
810 Image_Resample32LerpLine (inrow, resamplerow1, inwidth, outwidth);
811 Image_Resample32LerpLine (inrow + inwidth4, resamplerow2, inwidth, outwidth);
862 resamplerow1 -= outwidth4;
863 resamplerow2 -= outwidth4;
869 inrow = (qbyte *)indata + inwidth4*yi;
871 memcpy(resamplerow1, resamplerow2, outwidth4);
873 Image_Resample32LerpLine (inrow, resamplerow1, inwidth, outwidth);
876 memcpy(out, resamplerow1, outwidth4);
881 void Image_Resample32Nearest(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
884 unsigned frac, fracstep;
885 // relies on int being 4 bytes
889 fracstep = inwidth*0x10000/outwidth;
890 for (i = 0;i < outheight;i++)
892 inrow = (int *)indata + inwidth*(i*inheight/outheight);
893 frac = fracstep >> 1;
897 out[0] = inrow[frac >> 16];frac += fracstep;
898 out[1] = inrow[frac >> 16];frac += fracstep;
899 out[2] = inrow[frac >> 16];frac += fracstep;
900 out[3] = inrow[frac >> 16];frac += fracstep;
906 out[0] = inrow[frac >> 16];frac += fracstep;
907 out[1] = inrow[frac >> 16];frac += fracstep;
912 out[0] = inrow[frac >> 16];frac += fracstep;
918 void Image_Resample24Lerp(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
920 int i, j, r, yi, oldy, f, fstep, lerp, endy = (inheight-1), inwidth3 = inwidth * 3, outwidth3 = outwidth * 3;
923 fstep = (int) (inheight*65536.0f/outheight);
927 Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
928 Image_Resample24LerpLine (inrow + inwidth3, resamplerow2, inwidth, outwidth);
929 for (i = 0, f = 0;i < outheight;i++,f += fstep)
937 inrow = (qbyte *)indata + inwidth3*yi;
939 memcpy(resamplerow1, resamplerow2, outwidth3);
941 Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
942 Image_Resample24LerpLine (inrow + inwidth3, resamplerow2, inwidth, outwidth);
986 resamplerow1 -= outwidth3;
987 resamplerow2 -= outwidth3;
993 inrow = (qbyte *)indata + inwidth3*yi;
995 memcpy(resamplerow1, resamplerow2, outwidth3);
997 Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
1000 memcpy(out, resamplerow1, outwidth3);
1005 void Image_Resample24Nolerp(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
1007 int i, j, f, inwidth3 = inwidth * 3;
1008 unsigned frac, fracstep;
1012 fracstep = inwidth*0x10000/outwidth;
1013 for (i = 0;i < outheight;i++)
1015 inrow = (qbyte *)indata + inwidth3*(i*inheight/outheight);
1016 frac = fracstep >> 1;
1020 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1021 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1022 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1023 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1028 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1029 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1034 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1045 void Image_Resample (void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight, int bytesperpixel, int quality)
1047 if (resamplerowsize < outwidth*4)
1050 Mem_Free(resamplerow1);
1051 resamplerowsize = outwidth*4;
1052 if (!resamplemempool)
1053 resamplemempool = Mem_AllocPool("Image Scaling Buffer");
1054 resamplerow1 = Mem_Alloc(resamplemempool, resamplerowsize*2);
1055 resamplerow2 = resamplerow1 + resamplerowsize;
1057 if (bytesperpixel == 4)
1060 Image_Resample32Lerp(indata, inwidth, inheight, outdata, outwidth, outheight);
1062 Image_Resample32Nearest(indata, inwidth, inheight, outdata, outwidth, outheight);
1064 else if (bytesperpixel == 3)
1067 Image_Resample24Lerp(indata, inwidth, inheight, outdata, outwidth, outheight);
1069 Image_Resample24Nolerp(indata, inwidth, inheight, outdata, outwidth, outheight);
1072 Sys_Error("Image_Resample: unsupported bytesperpixel %i\n", bytesperpixel);
1075 // in can be the same as out
1076 void Image_MipReduce(qbyte *in, qbyte *out, int *width, int *height, int destwidth, int destheight, int bytesperpixel)
1079 nextrow = *width * bytesperpixel;
1080 if (*width > destwidth)
1083 if (*height > destheight)
1087 if (bytesperpixel == 4)
1089 for (y = 0;y < *height;y++)
1091 for (x = 0;x < *width;x++)
1093 out[0] = (qbyte) ((in[0] + in[4] + in[nextrow ] + in[nextrow+4]) >> 2);
1094 out[1] = (qbyte) ((in[1] + in[5] + in[nextrow+1] + in[nextrow+5]) >> 2);
1095 out[2] = (qbyte) ((in[2] + in[6] + in[nextrow+2] + in[nextrow+6]) >> 2);
1096 out[3] = (qbyte) ((in[3] + in[7] + in[nextrow+3] + in[nextrow+7]) >> 2);
1100 in += nextrow; // skip a line
1103 else if (bytesperpixel == 3)
1105 for (y = 0;y < *height;y++)
1107 for (x = 0;x < *width;x++)
1109 out[0] = (qbyte) ((in[0] + in[3] + in[nextrow ] + in[nextrow+3]) >> 2);
1110 out[1] = (qbyte) ((in[1] + in[4] + in[nextrow+1] + in[nextrow+4]) >> 2);
1111 out[2] = (qbyte) ((in[2] + in[5] + in[nextrow+2] + in[nextrow+5]) >> 2);
1115 in += nextrow; // skip a line
1119 Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
1124 if (bytesperpixel == 4)
1126 for (y = 0;y < *height;y++)
1128 for (x = 0;x < *width;x++)
1130 out[0] = (qbyte) ((in[0] + in[4]) >> 1);
1131 out[1] = (qbyte) ((in[1] + in[5]) >> 1);
1132 out[2] = (qbyte) ((in[2] + in[6]) >> 1);
1133 out[3] = (qbyte) ((in[3] + in[7]) >> 1);
1139 else if (bytesperpixel == 3)
1141 for (y = 0;y < *height;y++)
1143 for (x = 0;x < *width;x++)
1145 out[0] = (qbyte) ((in[0] + in[3]) >> 1);
1146 out[1] = (qbyte) ((in[1] + in[4]) >> 1);
1147 out[2] = (qbyte) ((in[2] + in[5]) >> 1);
1154 Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
1159 if (*height > destheight)
1163 if (bytesperpixel == 4)
1165 for (y = 0;y < *height;y++)
1167 for (x = 0;x < *width;x++)
1169 out[0] = (qbyte) ((in[0] + in[nextrow ]) >> 1);
1170 out[1] = (qbyte) ((in[1] + in[nextrow+1]) >> 1);
1171 out[2] = (qbyte) ((in[2] + in[nextrow+2]) >> 1);
1172 out[3] = (qbyte) ((in[3] + in[nextrow+3]) >> 1);
1176 in += nextrow; // skip a line
1179 else if (bytesperpixel == 3)
1181 for (y = 0;y < *height;y++)
1183 for (x = 0;x < *width;x++)
1185 out[0] = (qbyte) ((in[0] + in[nextrow ]) >> 1);
1186 out[1] = (qbyte) ((in[1] + in[nextrow+1]) >> 1);
1187 out[2] = (qbyte) ((in[2] + in[nextrow+2]) >> 1);
1191 in += nextrow; // skip a line
1195 Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
1198 Sys_Error("Image_MipReduce: desired size already achieved\n");