hedgewars/uTextures.pas
changeset 5441 39962b855540
parent 4976 088d40d8aba2
child 6303 3edb3c857995
--- a/hedgewars/uTextures.pas	Sat Jul 23 16:07:43 2011 -0400
+++ b/hedgewars/uTextures.pas	Sun Jul 24 00:25:35 2011 -0400
@@ -131,6 +131,24 @@
 if SDL_MustLock(surf) then
     SDLTry(SDL_LockSurface(surf) >= 0, true);
 
+fromP4:= Surf^.pixels;
+
+if cGrayScale then
+    for y:= 0 to Pred(Surf^.h) do
+        begin
+        for x:= 0 to Pred(Surf^.w) do 
+            begin
+            tw:= fromP4^[x];
+            tw:= round((tw shr RShift and $FF) * RGB_LUMINANCE_RED +  
+                  (tw shr GShift and $FF) * RGB_LUMINANCE_GREEN + 
+                  (tw shr BShift and $FF) * RGB_LUMINANCE_BLUE);
+            if tw > 255 then tw:= 255;
+            tw:= (tw and $FF shl RShift) or (tw and $FF shl BShift) or (tw and $FF shl GShift) or (fromP4^[x] and AMask);
+            fromP4^[x]:= tw;
+            end;
+        fromP4:= @(fromP4^[Surf^.pitch div 4])
+        end;
+        
 if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then
     begin
     tw:= toPowerOf2(Surf^.w);