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;
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 (targa_header.image_type == 2)
263 // Uncompressed, RGB images
264 for(row = rows - 1;row >= 0;row--)
266 pixbuf = image_rgba + row*columns*4;
267 for(column = 0;column < columns;column++)
269 switch (targa_header.pixel_size)
272 if (fin + 3 > enddata)
281 if (fin + 4 > enddata)
293 else if (targa_header.image_type==10)
295 // Runlength encoded RGB images
296 unsigned char red = 0, green = 0, blue = 0, alphabyte = 0, packetHeader, packetSize, j;
297 for(row = rows - 1;row >= 0;row--)
299 pixbuf = image_rgba + row * columns * 4;
300 for(column = 0;column < columns;)
304 packetHeader = *fin++;
305 packetSize = 1 + (packetHeader & 0x7f);
306 if (packetHeader & 0x80)
309 switch (targa_header.pixel_size)
312 if (fin + 3 > enddata)
320 if (fin + 4 > enddata)
329 for(j = 0;j < packetSize;j++)
334 *pixbuf++ = alphabyte;
336 if (column == columns)
338 // run spans across rows
344 pixbuf = image_rgba + row * columns * 4;
350 // non run-length packet
351 for(j = 0;j < packetSize;j++)
353 switch (targa_header.pixel_size)
356 if (fin + 3 > enddata)
365 if (fin + 4 > enddata)
375 if (column == columns)
377 // pixel packet run spans across rows
383 pixbuf = image_rgba + row * columns * 4;
393 image_width = columns;
403 qbyte *LoadLMP (qbyte *f, int matchwidth, int matchheight)
410 Con_Printf("LoadLMP: invalid LMP file\n");
414 // parse the very complicated header *chuckle*
415 width = f[0] + f[1] * 256 + f[2] * 65536 + f[3] * 16777216;
416 height = f[4] + f[5] * 256 + f[6] * 65536 + f[7] * 16777216;
417 if ((unsigned) width > 4096 || (unsigned) height > 4096)
419 Con_Printf("LoadLMP: invalid size\n");
422 if ((matchwidth && width != matchwidth) || (matchheight && height != matchheight))
425 if (loadsize < 8 + width * height)
427 Con_Printf("LoadLMP: invalid LMP file\n");
432 image_height = height;
434 image_rgba = Mem_Alloc(tempmempool, image_width * image_height * 4);
437 Con_Printf("LoadLMP: not enough memory for %i by %i image\n", image_width, image_height);
440 Image_Copy8bitRGBA(f + 8, image_rgba, image_width * image_height, d_8to24table);
444 void Image_StripImageExtension (char *in, char *out)
447 end = in + strlen(in);
451 if (strcmp(temp, ".tga") == 0 || strcmp(temp, ".pcx") == 0 || strcmp(temp, ".lmp") == 0)
461 qbyte *loadimagepixels (char *filename, qboolean complain, int matchwidth, int matchheight)
464 char basename[256], name[256], *c;
465 Image_StripImageExtension(filename, basename); // strip .tga, .pcx and .lmp extensions to allow replacement by other types
466 // replace *'s with #, so commandline utils don't get confused when dealing with the external files
467 for (c = basename;*c;c++)
470 sprintf (name, "textures/%s.tga", basename);
471 f = COM_LoadFile(name, true);
474 data = LoadTGA (f, matchwidth, matchheight);
478 sprintf (name, "textures/%s.pcx", basename);
479 f = COM_LoadFile(name, true);
482 data = LoadPCX (f, matchwidth, matchheight);
486 sprintf (name, "%s.tga", basename);
487 f = COM_LoadFile(name, true);
490 data = LoadTGA (f, matchwidth, matchheight);
494 sprintf (name, "%s.pcx", basename);
495 f = COM_LoadFile(name, true);
498 data = LoadPCX (f, matchwidth, matchheight);
502 sprintf (name, "%s.lmp", basename);
503 f = COM_LoadFile(name, true);
506 data = LoadLMP (f, matchwidth, matchheight);
511 Con_Printf ("Couldn't load %s.tga, .pcx, .lmp\n", filename);
515 int image_makemask (qbyte *in, qbyte *out, int size)
519 for (i = 0;i < size;i++)
521 out[0] = out[1] = out[2] = 255;
531 qbyte* loadimagepixelsmask (char* filename, qboolean complain, int matchwidth, int matchheight)
534 in = data = loadimagepixels(filename, complain, matchwidth, matchheight);
537 if (image_makemask(data, data, image_width * image_height))
538 return data; // some transparency
542 return NULL; // all opaque
546 rtexture_t *loadtextureimage (rtexturepool_t *pool, char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap, qboolean precache)
550 if (!(data = loadimagepixels (filename, complain, matchwidth, matchheight)))
552 rt = R_LoadTexture (pool, filename, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
557 rtexture_t *loadtextureimagemask (rtexturepool_t *pool, char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap, qboolean precache)
561 if (!(data = loadimagepixelsmask (filename, complain, matchwidth, matchheight)))
563 rt = R_LoadTexture (pool, filename, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
568 rtexture_t *image_masktex;
569 rtexture_t *loadtextureimagewithmask (rtexturepool_t *pool, char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap, qboolean precache)
575 image_masktex = NULL;
576 if (!(data = loadimagepixels (filename, complain, matchwidth, matchheight)))
578 rt = R_LoadTexture (pool, filename, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
579 count = image_makemask(data, data, image_width * image_height);
582 filename2 = Mem_Alloc(tempmempool, strlen(filename) + 6);
583 sprintf(filename2, "%s_mask", filename);
584 image_masktex = R_LoadTexture (pool, filename2, image_width, image_height, data, TEXTYPE_RGBA, TEXF_ALPHA | (mipmap ? TEXF_MIPMAP : 0) | (precache ? TEXF_PRECACHE : 0));
591 qboolean Image_WriteTGARGB_preflipped (char *filename, int width, int height, qbyte *data)
594 qbyte *buffer, *in, *out, *end;
596 buffer = Mem_Alloc(tempmempool, width*height*3 + 18);
598 memset (buffer, 0, 18);
599 buffer[2] = 2; // uncompressed type
600 buffer[12] = (width >> 0) & 0xFF;
601 buffer[13] = (width >> 8) & 0xFF;
602 buffer[14] = (height >> 0) & 0xFF;
603 buffer[15] = (height >> 8) & 0xFF;
604 buffer[16] = 24; // pixel size
609 end = in + width*height*3;
610 for (;in < end;in += 3)
616 ret = COM_WriteFile (filename, buffer, width*height*3 + 18 );
622 void Image_WriteTGARGB (char *filename, int width, int height, qbyte *data)
625 qbyte *buffer, *in, *out, *end;
627 buffer = Mem_Alloc(tempmempool, width*height*3 + 18);
629 memset (buffer, 0, 18);
630 buffer[2] = 2; // uncompressed type
631 buffer[12] = (width >> 0) & 0xFF;
632 buffer[13] = (width >> 8) & 0xFF;
633 buffer[14] = (height >> 0) & 0xFF;
634 buffer[15] = (height >> 8) & 0xFF;
635 buffer[16] = 24; // pixel size
637 // swap rgb to bgr and flip upside down
639 for (y = height - 1;y >= 0;y--)
641 in = data + y * width * 3;
642 end = in + width * 3;
643 for (;in < end;in += 3)
650 COM_WriteFile (filename, buffer, width*height*3 + 18 );
655 void Image_WriteTGARGBA (char *filename, int width, int height, qbyte *data)
658 qbyte *buffer, *in, *out, *end;
660 buffer = Mem_Alloc(tempmempool, width*height*4 + 18);
662 memset (buffer, 0, 18);
663 buffer[2] = 2; // uncompressed type
664 buffer[12] = (width >> 0) & 0xFF;
665 buffer[13] = (width >> 8) & 0xFF;
666 buffer[14] = (height >> 0) & 0xFF;
667 buffer[15] = (height >> 8) & 0xFF;
668 buffer[16] = 32; // pixel size
670 // swap rgba to bgra and flip upside down
672 for (y = height - 1;y >= 0;y--)
674 in = data + y * width * 4;
675 end = in + width * 4;
676 for (;in < end;in += 4)
684 COM_WriteFile (filename, buffer, width*height*4 + 18 );
689 qboolean Image_CheckAlpha(qbyte *data, int size, qboolean rgba)
695 for (end = data + size * 4, data += 3;data < end;data += 4)
701 // color 255 is transparent
702 for (end = data + size;data < end;data++)
709 static void Image_Resample32LerpLine (qbyte *in, qbyte *out, int inwidth, int outwidth)
711 int j, xi, oldx = 0, f, fstep, endx, lerp;
712 fstep = (int) (inwidth*65536.0f/outwidth);
714 for (j = 0,f = 0;j < outwidth;j++, f += fstep)
719 in += (xi - oldx) * 4;
725 *out++ = (qbyte) ((((in[4] - in[0]) * lerp) >> 16) + in[0]);
726 *out++ = (qbyte) ((((in[5] - in[1]) * lerp) >> 16) + in[1]);
727 *out++ = (qbyte) ((((in[6] - in[2]) * lerp) >> 16) + in[2]);
728 *out++ = (qbyte) ((((in[7] - in[3]) * lerp) >> 16) + in[3]);
730 else // last pixel of the line has no pixel to lerp to
740 static void Image_Resample24LerpLine (qbyte *in, qbyte *out, int inwidth, int outwidth)
742 int j, xi, oldx = 0, f, fstep, endx, lerp;
743 fstep = (int) (inwidth*65536.0f/outwidth);
745 for (j = 0,f = 0;j < outwidth;j++, f += fstep)
750 in += (xi - oldx) * 3;
756 *out++ = (qbyte) ((((in[3] - in[0]) * lerp) >> 16) + in[0]);
757 *out++ = (qbyte) ((((in[4] - in[1]) * lerp) >> 16) + in[1]);
758 *out++ = (qbyte) ((((in[5] - in[2]) * lerp) >> 16) + in[2]);
760 else // last pixel of the line has no pixel to lerp to
769 int resamplerowsize = 0;
770 qbyte *resamplerow1 = NULL;
771 qbyte *resamplerow2 = NULL;
772 mempool_t *resamplemempool = NULL;
774 #define LERPBYTE(i) r = resamplerow1[i];out[i] = (qbyte) ((((resamplerow2[i] - r) * lerp) >> 16) + r)
775 void Image_Resample32Lerp(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
777 int i, j, r, yi, oldy, f, fstep, lerp, endy = (inheight-1), inwidth4 = inwidth*4, outwidth4 = outwidth*4;
780 fstep = (int) (inheight*65536.0f/outheight);
784 Image_Resample32LerpLine (inrow, resamplerow1, inwidth, outwidth);
785 Image_Resample32LerpLine (inrow + inwidth4, resamplerow2, inwidth, outwidth);
786 for (i = 0, f = 0;i < outheight;i++,f += fstep)
794 inrow = (qbyte *)indata + inwidth4*yi;
796 memcpy(resamplerow1, resamplerow2, outwidth4);
798 Image_Resample32LerpLine (inrow, resamplerow1, inwidth, outwidth);
799 Image_Resample32LerpLine (inrow + inwidth4, resamplerow2, inwidth, outwidth);
850 resamplerow1 -= outwidth4;
851 resamplerow2 -= outwidth4;
857 inrow = (qbyte *)indata + inwidth4*yi;
859 memcpy(resamplerow1, resamplerow2, outwidth4);
861 Image_Resample32LerpLine (inrow, resamplerow1, inwidth, outwidth);
864 memcpy(out, resamplerow1, outwidth4);
869 void Image_Resample32Nearest(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
872 unsigned frac, fracstep;
873 // relies on int being 4 bytes
877 fracstep = inwidth*0x10000/outwidth;
878 for (i = 0;i < outheight;i++)
880 inrow = (int *)indata + inwidth*(i*inheight/outheight);
881 frac = fracstep >> 1;
885 out[0] = inrow[frac >> 16];frac += fracstep;
886 out[1] = inrow[frac >> 16];frac += fracstep;
887 out[2] = inrow[frac >> 16];frac += fracstep;
888 out[3] = inrow[frac >> 16];frac += fracstep;
894 out[0] = inrow[frac >> 16];frac += fracstep;
895 out[1] = inrow[frac >> 16];frac += fracstep;
900 out[0] = inrow[frac >> 16];frac += fracstep;
906 void Image_Resample24Lerp(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
908 int i, j, r, yi, oldy, f, fstep, lerp, endy = (inheight-1), inwidth3 = inwidth * 3, outwidth3 = outwidth * 3;
911 fstep = (int) (inheight*65536.0f/outheight);
915 Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
916 Image_Resample24LerpLine (inrow + inwidth3, resamplerow2, inwidth, outwidth);
917 for (i = 0, f = 0;i < outheight;i++,f += fstep)
925 inrow = (qbyte *)indata + inwidth3*yi;
927 memcpy(resamplerow1, resamplerow2, outwidth3);
929 Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
930 Image_Resample24LerpLine (inrow + inwidth3, resamplerow2, inwidth, outwidth);
974 resamplerow1 -= outwidth3;
975 resamplerow2 -= outwidth3;
981 inrow = (qbyte *)indata + inwidth3*yi;
983 memcpy(resamplerow1, resamplerow2, outwidth3);
985 Image_Resample24LerpLine (inrow, resamplerow1, inwidth, outwidth);
988 memcpy(out, resamplerow1, outwidth3);
993 void Image_Resample24Nolerp(void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight)
995 int i, j, f, inwidth3 = inwidth * 3;
996 unsigned frac, fracstep;
1000 fracstep = inwidth*0x10000/outwidth;
1001 for (i = 0;i < outheight;i++)
1003 inrow = (qbyte *)indata + inwidth3*(i*inheight/outheight);
1004 frac = fracstep >> 1;
1008 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1009 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1010 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1011 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1016 f = (frac >> 16)*3;*out++ = inrow[f+0];*out++ = inrow[f+1];*out++ = inrow[f+2];frac += fracstep;
1017 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;
1033 void Image_Resample (void *indata, int inwidth, int inheight, void *outdata, int outwidth, int outheight, int bytesperpixel, int quality)
1035 if (resamplerowsize < outwidth*4)
1038 Mem_Free(resamplerow1);
1039 resamplerowsize = outwidth*4;
1040 if (!resamplemempool)
1041 resamplemempool = Mem_AllocPool("Image Scaling Buffer");
1042 resamplerow1 = Mem_Alloc(resamplemempool, resamplerowsize*2);
1043 resamplerow2 = resamplerow1 + resamplerowsize;
1045 if (bytesperpixel == 4)
1048 Image_Resample32Lerp(indata, inwidth, inheight, outdata, outwidth, outheight);
1050 Image_Resample32Nearest(indata, inwidth, inheight, outdata, outwidth, outheight);
1052 else if (bytesperpixel == 3)
1055 Image_Resample24Lerp(indata, inwidth, inheight, outdata, outwidth, outheight);
1057 Image_Resample24Nolerp(indata, inwidth, inheight, outdata, outwidth, outheight);
1060 Sys_Error("Image_Resample: unsupported bytesperpixel %i\n", bytesperpixel);
1063 // in can be the same as out
1064 void Image_MipReduce(qbyte *in, qbyte *out, int *width, int *height, int destwidth, int destheight, int bytesperpixel)
1067 nextrow = *width * bytesperpixel;
1068 if (*width > destwidth)
1071 if (*height > destheight)
1075 if (bytesperpixel == 4)
1077 for (y = 0;y < *height;y++)
1079 for (x = 0;x < *width;x++)
1081 out[0] = (qbyte) ((in[0] + in[4] + in[nextrow ] + in[nextrow+4]) >> 2);
1082 out[1] = (qbyte) ((in[1] + in[5] + in[nextrow+1] + in[nextrow+5]) >> 2);
1083 out[2] = (qbyte) ((in[2] + in[6] + in[nextrow+2] + in[nextrow+6]) >> 2);
1084 out[3] = (qbyte) ((in[3] + in[7] + in[nextrow+3] + in[nextrow+7]) >> 2);
1088 in += nextrow; // skip a line
1091 else if (bytesperpixel == 3)
1093 for (y = 0;y < *height;y++)
1095 for (x = 0;x < *width;x++)
1097 out[0] = (qbyte) ((in[0] + in[3] + in[nextrow ] + in[nextrow+3]) >> 2);
1098 out[1] = (qbyte) ((in[1] + in[4] + in[nextrow+1] + in[nextrow+4]) >> 2);
1099 out[2] = (qbyte) ((in[2] + in[5] + in[nextrow+2] + in[nextrow+5]) >> 2);
1103 in += nextrow; // skip a line
1107 Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
1112 if (bytesperpixel == 4)
1114 for (y = 0;y < *height;y++)
1116 for (x = 0;x < *width;x++)
1118 out[0] = (qbyte) ((in[0] + in[4]) >> 1);
1119 out[1] = (qbyte) ((in[1] + in[5]) >> 1);
1120 out[2] = (qbyte) ((in[2] + in[6]) >> 1);
1121 out[3] = (qbyte) ((in[3] + in[7]) >> 1);
1127 else if (bytesperpixel == 3)
1129 for (y = 0;y < *height;y++)
1131 for (x = 0;x < *width;x++)
1133 out[0] = (qbyte) ((in[0] + in[3]) >> 1);
1134 out[1] = (qbyte) ((in[1] + in[4]) >> 1);
1135 out[2] = (qbyte) ((in[2] + in[5]) >> 1);
1142 Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
1147 if (*height > destheight)
1151 if (bytesperpixel == 4)
1153 for (y = 0;y < *height;y++)
1155 for (x = 0;x < *width;x++)
1157 out[0] = (qbyte) ((in[0] + in[nextrow ]) >> 1);
1158 out[1] = (qbyte) ((in[1] + in[nextrow+1]) >> 1);
1159 out[2] = (qbyte) ((in[2] + in[nextrow+2]) >> 1);
1160 out[3] = (qbyte) ((in[3] + in[nextrow+3]) >> 1);
1164 in += nextrow; // skip a line
1167 else if (bytesperpixel == 3)
1169 for (y = 0;y < *height;y++)
1171 for (x = 0;x < *width;x++)
1173 out[0] = (qbyte) ((in[0] + in[nextrow ]) >> 1);
1174 out[1] = (qbyte) ((in[1] + in[nextrow+1]) >> 1);
1175 out[2] = (qbyte) ((in[2] + in[nextrow+2]) >> 1);
1179 in += nextrow; // skip a line
1183 Sys_Error("Image_MipReduce: unsupported bytesperpixel %i\n", bytesperpixel);
1186 Sys_Error("Image_MipReduce: desired size already achieved\n");