New grow and skid sounds from remaxim
[supertux.git] / src / video / sdl_texture.cpp
index a536ad3..05bf5a2 100644 (file)
@@ -431,6 +431,7 @@ namespace
       int opaque = 0;
       int semitransparent = 0;
       int alphasum = 0;
+      int squaredalphasum = 0;
       bool colors[(1 << 12)];
       memset(colors, 0, (1 << 12) * sizeof(bool));
 
@@ -475,48 +476,16 @@ namespace
           {
             opaque++;
             alphasum += alpha;
+            squaredalphasum += alpha * alpha;
           }
           else
           {
             semitransparent++;
-            alphasum += alpha;
+            squaredalphasum += alpha * alpha;
           }
-          colors[((red & 0xf0) << 4) | (green & 0xf0) | ((blue & 0xf0) >> 4)] = true;
-        }
-      }
-      int avgalpha = (opaque + semitransparent) ? alphasum / (opaque + semitransparent) : 0;
-      int alphavariance = 0;
-      for(int y = 0;y < src->h;y++) {
-        for(int x = 0;x < src->w;x++) {
-          Uint8 *pixel = (Uint8 *) src->pixels + y * src->pitch + x * bpp;
-          Uint32 mapped = 0;
-          switch(bpp) {
-            case 1:
-              mapped = *pixel;
-              break;
-            case 2:
-              mapped = *(Uint16 *)pixel;
-              break;
-            case 3:
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
-              mapped |= pixel[0] << 16;
-              mapped |= pixel[1] << 8;
-              mapped |= pixel[2] << 0;
-#else
-              mapped |= pixel[0] << 0;
-              mapped |= pixel[1] << 8;
-              mapped |= pixel[2] << 16;
-#endif
-              break;
-            case 4:
-              mapped = *(Uint32 *)pixel;
-              break;
-          }
-          Uint8 red, green, blue, alpha;
-          SDL_GetRGBA(mapped, src->format, &red, &green, &blue, &alpha);
-          if(alpha >= 16)
+          if(alpha != 0)
           {
-            alphavariance += (alpha - avgalpha) * (alpha - avgalpha);
+            colors[((red & 0xf0) << 4) | (green & 0xf0) | ((blue & 0xf0) >> 4)] = true;
           }
         }
       }
@@ -524,7 +493,9 @@ namespace
       {
         SDL_UnlockSurface(src);
       }
-      alphavariance /= (opaque + semitransparent) ? (opaque + semitransparent) : 1;
+      int avgalpha = (opaque + semitransparent) ? alphasum / (opaque + semitransparent) : 0;
+      int avgsquaredalpha = (opaque + semitransparent) ? squaredalphasum / (opaque + semitransparent) : 0;
+      int alphavariance = avgsquaredalpha - avgalpha * avgalpha;
       if(semitransparent > ((transparent + opaque + semitransparent) / 8) && alphavariance > 16)
       {
         return SDL_DisplayFormatAlpha(src);
@@ -640,9 +611,11 @@ namespace SDL
     texture = optimize(image);
     //width = texture->w;
     //height = texture->h;
-    int numerator, denominator;
-    float xfactor = (float) config->screenwidth / SCREEN_WIDTH;
-    float yfactor = (float) config->screenheight / SCREEN_HEIGHT;
+    int numerator   = 1;
+    int denominator = 1;
+    //FIXME: float xfactor = (float) config->screenwidth / SCREEN_WIDTH;
+    //FIXME: float yfactor = (float) config->screenheight / SCREEN_HEIGHT;
+    /* FIXME: 
     if(xfactor < yfactor)
     {
       numerator = config->screenwidth;
@@ -653,6 +626,7 @@ namespace SDL
       numerator = config->screenheight;
       denominator = SCREEN_HEIGHT;
     }
+    */
     cache[NO_EFFECT][Color::WHITE] = scale(texture, numerator, denominator);
   }