diff options
Diffstat (limited to 'src/renderergl2/tr_image.c')
-rw-r--r-- | src/renderergl2/tr_image.c | 64 |
1 files changed, 36 insertions, 28 deletions
diff --git a/src/renderergl2/tr_image.c b/src/renderergl2/tr_image.c index 6f005247..b7237f53 100644 --- a/src/renderergl2/tr_image.c +++ b/src/renderergl2/tr_image.c @@ -1333,43 +1333,51 @@ static void R_MipMap2( byte *in, int inWidth, int inHeight ) { static void R_MipMapsRGB( byte *in, int inWidth, int inHeight) { - int i, j, k; - int outWidth, outHeight; - byte *temp; + int x, y, c, stride; + const byte *in2; + float total; + static float downmipSrgbLookup[256]; + static int downmipSrgbLookupSet = 0; + byte *out = in; - outWidth = inWidth >> 1; - outHeight = inHeight >> 1; - temp = ri.Hunk_AllocateTempMemory( outWidth * outHeight * 4 ); + if (!downmipSrgbLookupSet) { + for (x = 0; x < 256; x++) + downmipSrgbLookup[x] = ((x < 10) ? x / 3294.6f : powf((x / 255.0f + 0.055f) / 1.055f, 2.4f)) * 0.25f; + downmipSrgbLookupSet = 1; + } - for ( i = 0 ; i < outHeight ; i++ ) { - byte *outbyte = temp + ( i * outWidth ) * 4; - byte *inbyte1 = in + ( i * 2 * inWidth ) * 4; - byte *inbyte2 = in + ( (i * 2 + 1) * inWidth ) * 4; - for ( j = 0 ; j < outWidth ; j++ ) { - for ( k = 0 ; k < 3 ; k++ ) { - float total, current; + if (inWidth == 1 && inHeight == 1) + return; - current = ByteToFloat(inbyte1[0]); total = sRGBtoRGB(current); - current = ByteToFloat(inbyte1[4]); total += sRGBtoRGB(current); - current = ByteToFloat(inbyte2[0]); total += sRGBtoRGB(current); - current = ByteToFloat(inbyte2[4]); total += sRGBtoRGB(current); + if (inWidth == 1 || inHeight == 1) { + for (x = (inWidth * inHeight) >> 1; x; x--) { + for (c = 3; c; c--, in++) { + total = (downmipSrgbLookup[*(in)] + downmipSrgbLookup[*(in + 4)]) * 2.0f; - total *= 0.25f; + *out++ = (byte)(powf(total, 1.0f / 2.2f) * 255.0f); + } + *out++ = (*(in) + *(in + 4)) >> 1; in += 5; + } + + return; + } + + stride = inWidth * 4; + inWidth >>= 1; inHeight >>= 1; - inbyte1++; - inbyte2++; + in2 = in + stride; + for (y = inHeight; y; y--, in += stride, in2 += stride) { + for (x = inWidth; x; x--) { + for (c = 3; c; c--, in++, in2++) { + total = downmipSrgbLookup[*(in)] + downmipSrgbLookup[*(in + 4)] + + downmipSrgbLookup[*(in2)] + downmipSrgbLookup[*(in2 + 4)]; - current = RGBtosRGB(total); - *outbyte++ = FloatToByte(current); + *out++ = (byte)(powf(total, 1.0f / 2.2f) * 255.0f); } - *outbyte++ = (inbyte1[0] + inbyte1[4] + inbyte2[0] + inbyte2[4]) >> 2; - inbyte1 += 5; - inbyte2 += 5; + + *out++ = (*(in) + *(in + 4) + *(in2) + *(in2 + 4)) >> 2; in += 5, in2 += 5; } } - - Com_Memcpy( in, temp, outWidth * outHeight * 4 ); - ri.Hunk_FreeTempMemory( temp ); } /* |