stratagus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Stratagus-CVS] stratagus/src/map map_fog.c


From: Nehal Mistry
Subject: [Stratagus-CVS] stratagus/src/map map_fog.c
Date: Sat, 29 Nov 2003 21:29:09 -0500

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Nehal Mistry <address@hidden>   03/11/29 21:29:08

Modified files:
        src/map        : map_fog.c 

Log message:
        implement fow saturation

Patches:
Index: stratagus/src/map/map_fog.c
diff -u stratagus/src/map/map_fog.c:1.122 stratagus/src/map/map_fog.c:1.123
--- stratagus/src/map/map_fog.c:1.122   Sat Nov 29 19:47:08 2003
+++ stratagus/src/map/map_fog.c Sat Nov 29 21:29:08 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: map_fog.c,v 1.122 2003/11/30 00:47:08 nehalmistry Exp $
+//     $Id: map_fog.c,v 1.123 2003/11/30 02:29:08 nehalmistry Exp $
 
 //@{
 
@@ -580,10 +580,13 @@
     SDL_Color csrc;
     SDL_Color cdest;
     unsigned char alpha;
+    unsigned char sat;
+    unsigned char max;
 
     drect.x = x;
     drect.y = y;
 
+    // Contrast
     SDL_BlitSurface(SolidFog, NULL, TheScreen, &drect);
 
     csrc.r = 255;
@@ -591,16 +594,31 @@
     csrc.b = 255;
 
     alpha = (255 - FogOfWarBrightness * 255 / 100);
+    sat = 100 - FogOfWarSaturation;
 
     SDL_LockSurface(TheScreen);
     for (i = y; i < y + TileSizeY; ++i) {
        for (j = x; j < x + TileSizeX; ++j) {
            p = &((Uint16*)TheScreen->pixels)[j + i * VideoWidth];
            if (*p) {
+               // Brightness
                SDL_GetRGB(*p, TheScreen->format, &cdest.r, &cdest.g, &cdest.b);
                cdest.r = ((cdest.r * alpha) + (csrc.r * (255 - alpha))) >> 8;
                cdest.g = ((cdest.g * alpha) + (csrc.g * (255 - alpha))) >> 8;
                cdest.b = ((cdest.b * alpha) + (csrc.b * (255 - alpha))) >> 8;
+
+               // Saturation
+               if (cdest.r > cdest.g && cdest.r > cdest.b) {
+                   max = cdest.r;
+               } else if (cdest.g > cdest.b) {
+                   max = cdest.g;
+               } else {
+                   max = cdest.b;
+               }
+               cdest.r += (max - cdest.r) * sat / 100;
+               cdest.g += (max - cdest.g) * sat / 100;
+               cdest.b += (max - cdest.b) * sat / 100;
+
                *p = SDL_MapRGB(TheScreen->format, cdest.r, cdest.g, cdest.b);
            }
        }
@@ -640,6 +658,8 @@
     SDL_Color csrc;
     SDL_Color cdest;
     unsigned char alpha;
+    unsigned char sat;
+    unsigned char max;
 
     tilepitch = TheMap.TileGraphic->Width / TileSizeX;
 
@@ -651,6 +671,7 @@
     drect.x = x;
     drect.y = y;
 
+    // Contrast
     alpha = TheMap.TileGraphic->Surface->format->alpha;
     SDL_SetAlpha(TheMap.TileGraphic->Surface, SDL_SRCALPHA,
        (100 - FogOfWarContrast) * 255 / 100);
@@ -662,6 +683,7 @@
     csrc.b = 255;
 
     alpha = (255 - FogOfWarBrightness * 255 / 100);
+    sat = 100 - FogOfWarSaturation;
 
     SDL_LockSurface(TheScreen);
     for (i = y; i < y + TileSizeY; ++i) {
@@ -673,9 +695,23 @@
                &cdest.r, &cdest.g, &cdest.b);
            if (!(cdest.r | cdest.g | cdest.b) && *p) {
                SDL_GetRGB(*p, TheScreen->format, &cdest.r, &cdest.g, &cdest.b);
+               // Brightness
                cdest.r = ((cdest.r * alpha) + (csrc.r * (255 - alpha))) >> 8;
                cdest.g = ((cdest.g * alpha) + (csrc.g * (255 - alpha))) >> 8;
                cdest.b = ((cdest.b * alpha) + (csrc.b * (255 - alpha))) >> 8;
+
+               // Saturation
+               if (cdest.r > cdest.g && cdest.r > cdest.b) {
+                   max = cdest.r;
+               } else if (cdest.g > cdest.b) {
+                   max = cdest.g;
+               } else {
+                   max = cdest.b;
+               }
+               cdest.r += (max - cdest.r) * sat / 100;
+               cdest.g += (max - cdest.g) * sat / 100;
+               cdest.b += (max - cdest.b) * sat / 100;
+
                *p = SDL_MapRGB(TheScreen->format, cdest.r, cdest.g, cdest.b);
            }
        }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]