Add grayscale option for 3d, helps with colour clashing
authornemo
Sun, 24 Jul 2011 00:25:35 -0400
changeset 5441 39962b855540
parent 5439 25d3784dc0f6
child 5443 83cb9dd54469
Add grayscale option for 3d, helps with colour clashing
QTfrontend/pageoptions.cpp
hedgewars/ArgParsers.inc
hedgewars/uConsts.pas
hedgewars/uLand.pas
hedgewars/uLandObjects.pas
hedgewars/uRender.pas
hedgewars/uTextures.pas
--- a/QTfrontend/pageoptions.cpp	Sat Jul 23 16:07:43 2011 -0400
+++ b/QTfrontend/pageoptions.cpp	Sun Jul 24 00:25:35 2011 -0400
@@ -328,6 +328,12 @@
             CBStereoMode->addItem(QComboBox::tr("Side-by-side"));
             CBStereoMode->addItem(QComboBox::tr("Top-Bottom"));
             CBStereoMode->addItem(QComboBox::tr("Wiggle"));
+            CBStereoMode->addItem(QComboBox::tr("Red/Cyan grayscale"));
+            CBStereoMode->addItem(QComboBox::tr("Cyan/Red grayscale"));
+            CBStereoMode->addItem(QComboBox::tr("Red/Blue grayscale"));
+            CBStereoMode->addItem(QComboBox::tr("Blue/Red grayscale"));
+            CBStereoMode->addItem(QComboBox::tr("Red/Green grayscale"));
+            CBStereoMode->addItem(QComboBox::tr("Green/Red grayscale"));
             connect(CBStereoMode, SIGNAL(currentIndexChanged(int)), this, SLOT(forceFullscreen(int)));
 
             GBAstereolayout->addWidget(CBStereoMode);
--- a/hedgewars/ArgParsers.inc	Sat Jul 23 16:07:43 2011 -0400
+++ b/hedgewars/ArgParsers.inc	Sun Jul 24 00:25:35 2011 -0400
@@ -50,7 +50,14 @@
     UserNick:= DecodeBase64(ParamStr(14));
     val(ParamStr(15), cReducedQuality);
     val(ParamStr(16), tmp);
-    cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp)));
+    cGrayScale:= false;
+    if (tmp > 9) and (tmp < 16) then 
+        begin
+        cGrayScale:= true;
+        cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-9)))
+        end
+    else if tmp <= 9 then cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp)))
+    else cStereoMode:= TStereoMode(max(0, min(ord(high(TStereoMode)), tmp-6)));
     cLocaleFName:= ParamStr(17);
 end;
 
--- a/hedgewars/uConsts.pas	Sat Jul 23 16:07:43 2011 -0400
+++ b/hedgewars/uConsts.pas	Sun Jul 24 00:25:35 2011 -0400
@@ -120,6 +120,16 @@
     cifAllInited = cifRandomize or cifTheme or cifMap;
 
     cTransparentColor: Longword = $00000000;
+    cGrayScale: Boolean = false;
+
+    RGB_LUMINANCE_RED    = 0.212671;
+    RGB_LUMINANCE_GREEN  = 0.715160;
+    RGB_LUMINANCE_BLUE   = 0.072169;
+(*
+    RGB_LUMINANCE_RED    = 0.3333333333;
+    RGB_LUMINANCE_GREEN  = 0.3333333333;
+    RGB_LUMINANCE_BLUE   = 0.3333333333;
+*)
 
     cMaxTeams        = 8;
     cMaxHHIndex      = 7;
--- a/hedgewars/uLand.pas	Sat Jul 23 16:07:43 2011 -0400
+++ b/hedgewars/uLand.pas	Sun Jul 24 00:25:35 2011 -0400
@@ -1096,6 +1096,7 @@
                     end;
                 Land[y,x]:= lfObject
             end;
+
     AddProgress();
 end;
 
@@ -1314,6 +1315,32 @@
 
 FreeLandObjects;
 
+if cGrayScale then
+    begin
+    if (cReducedQuality and rqBlurryLand) = 0 then
+        for x:= leftX to rightX do
+            for y:= topY to LAND_HEIGHT-1 do
+                begin
+                w:= LandPixels[y,x];
+                w:= round(((w shr RShift and $FF) * RGB_LUMINANCE_RED +
+                      (w shr BShift and $FF) * RGB_LUMINANCE_GREEN +
+                      (w shr GShift and $FF) * RGB_LUMINANCE_BLUE));
+                if w > 255 then w:= 255;
+                w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y,x] and AMask);
+                LandPixels[y,x]:= w or (LandPixels[y, x] and AMask)
+                end
+    else
+        for x:= leftX div 2 to rightX div 2 do
+            for y:= topY div 2 to LAND_HEIGHT-1 div 2 do
+                begin
+                w:= LandPixels[y div 2,x div 2];
+                w:= ((w shr RShift and $FF) +  (w shr BShift and $FF) + (w shr GShift and $FF)) div 3;
+                if w > 255 then w:= 255;
+               w:= (w and $FF shl RShift) or (w and $FF shl BShift) or (w and $FF shl GShift) or (LandPixels[y div 2,x div 2] and AMask);
+                LandPixels[y,x]:= w or (LandPixels[y div 2, x div 2] and AMask)
+                end
+    end;
+
 UpdateLandTexture(0, LAND_WIDTH, 0, LAND_HEIGHT);
 end;
 
--- a/hedgewars/uLandObjects.pas	Sat Jul 23 16:07:43 2011 -0400
+++ b/hedgewars/uLandObjects.pas	Sun Jul 24 00:25:35 2011 -0400
@@ -372,7 +372,7 @@
 var s, key: shortstring;
     f: textfile;
     i: LongInt;
-    ii: Longword;
+    ii, t: Longword;
     c1, c2: TSDL_Color;
 
     procedure CheckRect(Width, Height, x, y, w, h: LongWord);
@@ -415,6 +415,14 @@
         c1.g:= StrToInt(Trim(Copy(s, 1, Pred(i))));
         Delete(s, 1, i);
         c1.b:= StrToInt(Trim(s));
+        if cGrayScale then
+            begin
+            t:= round(c1.r * RGB_LUMINANCE_RED + c1.g * RGB_LUMINANCE_GREEN + c1.b * RGB_LUMINANCE_BLUE);
+            if t > 255 then t:= 255;
+            c1.r:= t;
+            c1.g:= t;
+            c1.b:= t
+            end;
         glClearColor(c1.r / 255, c1.g / 255, c1.b / 255, 0.99);
         SDSkyColor.r:= byte(c1.r * SDTint div 255);
         SDSkyColor.g:= byte(c1.g * SDTint div 255);
@@ -441,6 +449,14 @@
         Delete(s, 1, i);
         WaterColorArray[0].b:= StrToInt(Trim(s));
         WaterColorArray[0].a := 255;
+        if cGrayScale then
+            begin
+            t:= round(WaterColorArray[0].r * RGB_LUMINANCE_RED + WaterColorArray[0].g * RGB_LUMINANCE_GREEN + WaterColorArray[0].b * RGB_LUMINANCE_BLUE);
+            if t > 255 then t:= 255;
+            WaterColorArray[0].r:= t;
+            WaterColorArray[0].g:= t;
+            WaterColorArray[0].b:= t
+            end;
         WaterColorArray[1]:= WaterColorArray[0];
         end
     else if key = 'water-bottom' then
@@ -453,6 +469,14 @@
         Delete(s, 1, i);
         WaterColorArray[2].b:= StrToInt(Trim(s));
         WaterColorArray[2].a := 255;
+        if cGrayScale then
+            begin
+            t:= round(WaterColorArray[2].r * RGB_LUMINANCE_RED + WaterColorArray[2].g * RGB_LUMINANCE_GREEN + WaterColorArray[2].b * RGB_LUMINANCE_BLUE);
+            if t > 255 then t:= 255;
+            WaterColorArray[2].r:= t;
+            WaterColorArray[2].g:= t;
+            WaterColorArray[2].b:= t
+            end;
         WaterColorArray[3]:= WaterColorArray[2];
         end
     else if key = 'water-opacity' then
@@ -566,6 +590,14 @@
         Delete(s, 1, i);
         SDWaterColorArray[0].b:= StrToInt(Trim(s));
         SDWaterColorArray[0].a := 255;
+        if cGrayScale then
+            begin
+            t:= round(SDWaterColorArray[0].r * RGB_LUMINANCE_RED + SDWaterColorArray[0].g * RGB_LUMINANCE_GREEN + SDWaterColorArray[0].b * RGB_LUMINANCE_BLUE);
+            if t > 255 then t:= 255;
+            SDWaterColorArray[0].r:= t;
+            SDWaterColorArray[0].g:= t;
+            SDWaterColorArray[0].b:= t
+            end;
         SDWaterColorArray[1]:= SDWaterColorArray[0];
         end
     else if key = 'sd-water-bottom' then
@@ -578,6 +610,14 @@
         Delete(s, 1, i);
         SDWaterColorArray[2].b:= StrToInt(Trim(s));
         SDWaterColorArray[2].a := 255;
+        if cGrayScale then
+            begin
+            t:= round(SDWaterColorArray[2].r * RGB_LUMINANCE_RED + SDWaterColorArray[2].g * RGB_LUMINANCE_GREEN + SDWaterColorArray[2].b * RGB_LUMINANCE_BLUE);
+            if t > 255 then t:= 255;
+            SDWaterColorArray[2].r:= t;
+            SDWaterColorArray[2].g:= t;
+            SDWaterColorArray[2].b:= t
+            end;
         SDWaterColorArray[3]:= SDWaterColorArray[2];
         end
     else if key = 'sd-water-opacity' then cSDWaterOpacity:= StrToInt(Trim(s))
@@ -612,6 +652,14 @@
             c1.g:= StrToInt(Trim(Copy(s, 1, Pred(i))));
             Delete(s, 1, i);
             c1.b:= StrToInt(Trim(s));
+            if cGrayScale then
+                begin
+                t:= round(c1.r * RGB_LUMINANCE_RED + c1.g * RGB_LUMINANCE_GREEN + c1.b * RGB_LUMINANCE_BLUE);
+                if t > 255 then t:= 255;
+                c1.r:= t;
+                c1.g:= t;
+                c1.b:= t
+                end;
             glClearColor(c1.r / 255, c1.g / 255, c1.b / 255, 0.99);
             SDSkyColor.r:= byte(c1.r * SDTint div 255);
             SDSkyColor.g:= byte(c1.g * SDTint div 255);
--- a/hedgewars/uRender.pas	Sat Jul 23 16:07:43 2011 -0400
+++ b/hedgewars/uRender.pas	Sun Jul 24 00:25:35 2011 -0400
@@ -22,7 +22,7 @@
 
 interface
 
-uses SDLh, uTypes, GLunit;
+uses SDLh, uTypes, GLunit, uConsts;
 
 procedure DrawSpriteFromRect(Sprite: TSprite; r: TSDL_Rect; X, Y, Height, Position: LongInt);
 procedure DrawFromRect(X, Y, W, H: LongInt; r: PSDL_Rect; SourceTexture: PTexture);
@@ -453,11 +453,20 @@
 
 
 procedure Tint(r, g, b, a: Byte); inline;
-var nc: Longword;
+var nc, tw: Longword;
 begin
 nc:= (a shl 24) or (b shl 16) or (g shl 8) or r;
 if nc = lastTint then
     exit;
+if cGrayScale then
+    begin
+    tw:= round(r * RGB_LUMINANCE_RED + g * RGB_LUMINANCE_GREEN + b * RGB_LUMINANCE_BLUE);
+    if tw > 255 then tw:= 255;
+    r:= tw;
+    g:= tw;
+    b:= tw
+    end;
+
 glColor4ub(r, g, b, a);
 lastTint:= nc;
 end;
--- 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);