This is an automated email from the git hooks/post-receive script.

smcv pushed a commit to annotated tag 1.42d
in repository iortcw.

commit f149cf079cb226ddd68315bc23b914cf3816de40
Author: m4n4t4...@gmail.com 
<m4n4t4...@gmail.com@e65d2741-a53d-b2dc-ae96-bb75fa5e4c4a>
Date:   Tue Jul 22 19:47:55 2014 +0000

    All: Rend2: Replace R_MipMapsRGB() with faster version
---
 MP/code/rend2/tr_extramath.h |  3 ---
 MP/code/rend2/tr_image.c     | 64 +++++++++++++++++++++++++-------------------
 SP/code/rend2/tr_extramath.h |  3 ---
 SP/code/rend2/tr_image.c     | 64 +++++++++++++++++++++++++-------------------
 4 files changed, 72 insertions(+), 62 deletions(-)

diff --git a/MP/code/rend2/tr_extramath.h b/MP/code/rend2/tr_extramath.h
index 0223c64..9327153 100644
--- a/MP/code/rend2/tr_extramath.h
+++ b/MP/code/rend2/tr_extramath.h
@@ -56,9 +56,6 @@ void Mat4SimpleInverse( const mat4_t in, mat4_t out);
 #define ByteToFloat(a)          ((float)(a) * 1.0f/255.0f)
 #define FloatToByte(a)          (byte)((a) * 255.0f)
 
-#define RGBtosRGB(a)            (((a) < 0.0031308f) ? (12.92f * (a)) : (1.055f 
* pow((a), 0.41666f) - 0.055f))
-#define sRGBtoRGB(a)            (((a) <= 0.04045f)  ? ((a) / 12.92f) : 
(pow((((a) + 0.055f) / 1.055f), 2.4)) )
-
 static ID_INLINE int VectorCompare4(const vec4_t v1, const vec4_t v2)
 {
        if(v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2] || v1[3] != v2[3])
diff --git a/MP/code/rend2/tr_image.c b/MP/code/rend2/tr_image.c
index 47e28f3..b04226c 100644
--- a/MP/code/rend2/tr_image.c
+++ b/MP/code/rend2/tr_image.c
@@ -1497,43 +1497,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;
+
+       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;
 
-                               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);
+                               *out++ = (byte)(powf(total, 1.0f / 2.2f) * 
255.0f);
+                       }
+                       *out++ = (*(in) + *(in + 4)) >> 1; in += 5;
+               }
+               
+               return;
+       }
 
-                               total *= 0.25f;
+       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 );
 }
 
 /*
diff --git a/SP/code/rend2/tr_extramath.h b/SP/code/rend2/tr_extramath.h
index 0223c64..9327153 100644
--- a/SP/code/rend2/tr_extramath.h
+++ b/SP/code/rend2/tr_extramath.h
@@ -56,9 +56,6 @@ void Mat4SimpleInverse( const mat4_t in, mat4_t out);
 #define ByteToFloat(a)          ((float)(a) * 1.0f/255.0f)
 #define FloatToByte(a)          (byte)((a) * 255.0f)
 
-#define RGBtosRGB(a)            (((a) < 0.0031308f) ? (12.92f * (a)) : (1.055f 
* pow((a), 0.41666f) - 0.055f))
-#define sRGBtoRGB(a)            (((a) <= 0.04045f)  ? ((a) / 12.92f) : 
(pow((((a) + 0.055f) / 1.055f), 2.4)) )
-
 static ID_INLINE int VectorCompare4(const vec4_t v1, const vec4_t v2)
 {
        if(v1[0] != v2[0] || v1[1] != v2[1] || v1[2] != v2[2] || v1[3] != v2[3])
diff --git a/SP/code/rend2/tr_image.c b/SP/code/rend2/tr_image.c
index 87c79d5..33803ca 100644
--- a/SP/code/rend2/tr_image.c
+++ b/SP/code/rend2/tr_image.c
@@ -1486,43 +1486,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;
+
+       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;
 
-                               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);
+                               *out++ = (byte)(powf(total, 1.0f / 2.2f) * 
255.0f);
+                       }
+                       *out++ = (*(in) + *(in + 4)) >> 1; in += 5;
+               }
+               
+               return;
+       }
 
-                               total *= 0.25f;
+       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 );
 }
 
 /*

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-games/iortcw.git

_______________________________________________
Pkg-games-commits mailing list
Pkg-games-commits@lists.alioth.debian.org
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits

Reply via email to