--- a/hedgewars/uLand.pas Sun Nov 06 12:40:35 2011 -0500
+++ b/hedgewars/uLand.pas Sun Nov 06 13:00:25 2011 -0500
@@ -36,7 +36,7 @@
implementation
uses uConsole, uStore, uRandom, uLandObjects, uIO, uLandTexture, sysutils,
- uVariables, uUtils, uCommands, Adler32, uDebug, uLandPainted;
+ uVariables, uUtils, uCommands, Adler32, uDebug, uLandPainted, uTextures;
operator=(const a, b: direction) c: Boolean;
begin
@@ -302,6 +302,7 @@
// freed in freeModule() below
LandBackSurface:= LoadImage(UserPathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
if LandBackSurface = nil then LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
+ if (LandBackSurface <> nil) and cGrayScale then Surface2GrayScale(LandBackSurface);
tmpsurf:= LoadImage(UserPathz[ptCurrTheme] + '/Border', ifIgnoreCaps or ifTransparent);
if tmpsurf = nil then tmpsurf:= LoadImage(Pathz[ptCurrTheme] + '/Border', ifCritical or ifIgnoreCaps or ifTransparent);
@@ -1180,7 +1181,8 @@
begin
// freed in freeModule() below
LandBackSurface:= LoadImage(UserPathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
- if LandBackSurface = nil then LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent)
+ if LandBackSurface = nil then LandBackSurface:= LoadImage(Pathz[ptCurrTheme] + '/LandBackTex', ifIgnoreCaps or ifTransparent);
+ if (LandBackSurface <> nil) and cGrayScale then Surface2GrayScale(LandBackSurface)
end;
end;
if (tmpsurf <> nil) then
--- a/hedgewars/uLandObjects.pas Sun Nov 06 12:40:35 2011 -0500
+++ b/hedgewars/uLandObjects.pas Sun Nov 06 13:00:25 2011 -0500
@@ -445,6 +445,14 @@
c2.g:= StrToInt(Trim(Copy(s, 1, Pred(i))));
Delete(s, 1, i);
c2.b:= StrToInt(Trim(s));
+ if cGrayScale then
+ begin
+ t:= round(SkyColor.r * RGB_LUMINANCE_RED + SkyColor.g * RGB_LUMINANCE_GREEN + SkyColor.b * RGB_LUMINANCE_BLUE);
+ if t > 255 then t:= 255;
+ c2.r:= t;
+ c2.g:= t;
+ c2.b:= t
+ end;
cExplosionBorderColor:= c2.value or AMask;
end
else if key = 'water-top' then
--- a/hedgewars/uTextures.pas Sun Nov 06 12:40:35 2011 -0500
+++ b/hedgewars/uTextures.pas Sun Nov 06 13:00:25 2011 -0500
@@ -23,6 +23,7 @@
uses SDLh, uTypes;
function NewTexture(width, height: Longword; buf: Pointer): PTexture;
+procedure Surface2GrayScale(surf: PSDL_Surface);
function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture;
procedure FreeTexture(tex: PTexture);
@@ -98,6 +99,27 @@
SetTextureParameters(true);
end;
+procedure Surface2GrayScale(surf: PSDL_Surface);
+var tw, th, x, y: Longword;
+ tmpp: pointer;
+ fromP4: PLongWordArray;
+begin
+fromP4:= Surf^.pixels;
+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;
+end;
function Surface2Tex(surf: PSDL_Surface; enableClamp: boolean): PTexture;
var tw, th, x, y: Longword;
tmpp: pointer;
@@ -133,22 +155,8 @@
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 cGrayScale then Surface2GrayScale(Surf);
+
if (not SupportNPOTT) and (not (isPowerOf2(Surf^.w) and isPowerOf2(Surf^.h))) then
begin
tw:= toPowerOf2(Surf^.w);