-void GL_MipReduce( byte *in, byte *out, int width, int height, int destwidth, int destheight ){
- int x, y, width2, height2, nextrow;
- if ( width > destwidth ) {
- if ( height > destheight ) {
- // reduce both
- width2 = width >> 1;
- height2 = height >> 1;
- nextrow = width << 2;
- for ( y = 0; y < height2; y++ )
- {
- for ( x = 0; x < width2; x++ )
- {
- out[0] = (byte) ( ( in[0] + in[4] + in[nextrow ] + in[nextrow + 4] ) >> 2 );
- out[1] = (byte) ( ( in[1] + in[5] + in[nextrow + 1] + in[nextrow + 5] ) >> 2 );
- out[2] = (byte) ( ( in[2] + in[6] + in[nextrow + 2] + in[nextrow + 6] ) >> 2 );
- out[3] = (byte) ( ( in[3] + in[7] + in[nextrow + 3] + in[nextrow + 7] ) >> 2 );
- out += 4;
- in += 8;
- }
- in += nextrow; // skip a line
- }
- }
- else
- {
- // reduce width
- width2 = width >> 1;
- for ( y = 0; y < height; y++ )
- {
- for ( x = 0; x < width2; x++ )
- {
- out[0] = (byte) ( ( in[0] + in[4] ) >> 1 );
- out[1] = (byte) ( ( in[1] + in[5] ) >> 1 );
- out[2] = (byte) ( ( in[2] + in[6] ) >> 1 );
- out[3] = (byte) ( ( in[3] + in[7] ) >> 1 );
- out += 4;
- in += 8;
- }
- }
- }
- }
- else
- {
- if ( height > destheight ) {
- // reduce height
- height2 = height >> 1;
- nextrow = width << 2;
- for ( y = 0; y < height2; y++ )
- {
- for ( x = 0; x < width; x++ )
- {
- out[0] = (byte) ( ( in[0] + in[nextrow ] ) >> 1 );
- out[1] = (byte) ( ( in[1] + in[nextrow + 1] ) >> 1 );
- out[2] = (byte) ( ( in[2] + in[nextrow + 2] ) >> 1 );
- out[3] = (byte) ( ( in[3] + in[nextrow + 3] ) >> 1 );
- out += 4;
- in += 4;
- }
- in += nextrow; // skip a line
- }
- }
- else{
- Sys_Printf( "GL_MipReduce: desired size already achieved\n" );
- }
- }
+void GL_MipReduce(byte *in, byte *out, int width, int height, int destwidth, int destheight)
+{
+ int x, y, width2, height2, nextrow;
+ if (width > destwidth) {
+ if (height > destheight) {
+ // reduce both
+ width2 = width >> 1;
+ height2 = height >> 1;
+ nextrow = width << 2;
+ for (y = 0; y < height2; y++) {
+ for (x = 0; x < width2; x++) {
+ out[0] = (byte) ((in[0] + in[4] + in[nextrow] + in[nextrow + 4]) >> 2);
+ out[1] = (byte) ((in[1] + in[5] + in[nextrow + 1] + in[nextrow + 5]) >> 2);
+ out[2] = (byte) ((in[2] + in[6] + in[nextrow + 2] + in[nextrow + 6]) >> 2);
+ out[3] = (byte) ((in[3] + in[7] + in[nextrow + 3] + in[nextrow + 7]) >> 2);
+ out += 4;
+ in += 8;
+ }
+ in += nextrow; // skip a line
+ }
+ } else {
+ // reduce width
+ width2 = width >> 1;
+ for (y = 0; y < height; y++) {
+ for (x = 0; x < width2; x++) {
+ out[0] = (byte) ((in[0] + in[4]) >> 1);
+ out[1] = (byte) ((in[1] + in[5]) >> 1);
+ out[2] = (byte) ((in[2] + in[6]) >> 1);
+ out[3] = (byte) ((in[3] + in[7]) >> 1);
+ out += 4;
+ in += 8;
+ }
+ }
+ }
+ } else {
+ if (height > destheight) {
+ // reduce height
+ height2 = height >> 1;
+ nextrow = width << 2;
+ for (y = 0; y < height2; y++) {
+ for (x = 0; x < width; x++) {
+ out[0] = (byte) ((in[0] + in[nextrow]) >> 1);
+ out[1] = (byte) ((in[1] + in[nextrow + 1]) >> 1);
+ out[2] = (byte) ((in[2] + in[nextrow + 2]) >> 1);
+ out[3] = (byte) ((in[3] + in[nextrow + 3]) >> 1);
+ out += 4;
+ in += 4;
+ }
+ in += nextrow; // skip a line
+ }
+ } else {
+ globalOutputStream() << "GL_MipReduce: desired size already achieved\n";
+ }
+ }