stratagus-cvs
[Top][All Lists]
Advanced

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

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


From: Jimmy Salmon
Subject: [Stratagus-CVS] stratagus/src video/linedraw.c map/map_fog.c in...
Date: Wed, 03 Dec 2003 14:18:31 -0500

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Jimmy Salmon <address@hidden>   03/12/03 14:18:30

Modified files:
        src/video      : linedraw.c 
        src/map        : map_fog.c 
        src/include    : video.h 

Log message:
        Added 24bpp support

Patches:
Index: stratagus/src/include/video.h
diff -u stratagus/src/include/video.h:1.101 stratagus/src/include/video.h:1.102
--- stratagus/src/include/video.h:1.101 Mon Dec  1 23:00:14 2003
+++ stratagus/src/include/video.h       Wed Dec  3 14:18:30 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: video.h,v 1.101 2003/12/02 04:00:14 nehalmistry Exp $
+//     $Id: video.h,v 1.102 2003/12/03 19:18:30 jsalmon3 Exp $
 
 #ifndef __VIDEO_H__
 #define __VIDEO_H__
@@ -36,6 +36,13 @@
 #ifdef USE_SDL_SURFACE
 
 #include "SDL.h"
+
+typedef struct _uint24_
+{
+    Uint8 a;
+    Uint8 b;
+    Uint8 c;
+} Uint24;
 
 typedef struct _graphic_
 {
Index: stratagus/src/map/map_fog.c
diff -u stratagus/src/map/map_fog.c:1.132 stratagus/src/map/map_fog.c:1.133
--- stratagus/src/map/map_fog.c:1.132   Mon Dec  1 12:00:08 2003
+++ stratagus/src/map/map_fog.c Wed Dec  3 14:18:29 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: map_fog.c,v 1.132 2003/12/01 17:00:08 jsalmon3 Exp $
+//     $Id: map_fog.c,v 1.133 2003/12/03 19:18:29 jsalmon3 Exp $
 
 //@{
 
@@ -572,7 +572,7 @@
 
     VideoLockScreen();
     for (i = y; i < ey; ++i) {
-       p = &((Uint16*)TheScreen->pixels)[x + i * VideoWidth];
+       p = (Uint16*)TheScreen->pixels + x + i * VideoWidth;
        for (j = x; j < ex; ++j) {
            *p = ((Uint16*)FogOfWarAlphaTable)[*p];
            ++p;
@@ -602,7 +602,7 @@
 
     VideoLockScreen();
     for (i = y; i < ey; ++i) {
-       p = &((Uint16*)TheScreen->pixels)[x + i * VideoWidth];
+       p = (Uint16*)TheScreen->pixels + x + i * VideoWidth;
        ptile = &((Uint8*)TheMap.TileGraphic->Surface->pixels)[
            sy + (i - y) * TheMap.TileGraphic->Surface->w + sx];
        for (j = x; j < ex; ++j) {
@@ -618,12 +618,11 @@
 
 // Routines for 24 bit displays .. -------------------------------------------
 
-// FIXME: not written
 global void VideoDraw24OnlyFogAlpha(int x, int y)
 {
     int i;
     int j;
-    Uint16* p;
+    Uint24* p;
     int ex;
     int ey;
 
@@ -632,21 +631,21 @@
 
     VideoLockScreen();
     for (i = y; i < ey; ++i) {
-       p = &((Uint16*)TheScreen->pixels)[x + i * VideoWidth];
+       p = (Uint24*)TheScreen->pixels + x + i * VideoWidth;
        for (j = x; j < ex; ++j) {
-           *p = ((Uint16*)FogOfWarAlphaTable)[*p];
+           *p = ((Uint24*)FogOfWarAlphaTable)[
+               ((p->a & 0xf8) >> 3) | ((p->b & 0xfc) << 3) | ((p->c & 0xf8) << 
8)];
            ++p;
        }
     }
     VideoUnlockScreen();
 }
 
-// FIXME: not written
 global void VideoDraw24FogAlpha(const int tile, int x, int y)
 {
     int i;
     int j;
-    Uint16* p;
+    Uint24* p;
     Uint8* ptile;
     int tilepitch;
     int sx;
@@ -663,12 +662,13 @@
 
     VideoLockScreen();
     for (i = y; i < ey; ++i) {
-       p = &((Uint16*)TheScreen->pixels)[x + i * VideoWidth];
+       p = (Uint24*)TheScreen->pixels + x + i * VideoWidth;
        ptile = &((Uint8*)TheMap.TileGraphic->Surface->pixels)[
            sy + (i - y) * TheMap.TileGraphic->Surface->w + sx];
        for (j = x; j < ex; ++j) {
            if (COLOR_FOG_P(*ptile)) {
-               *p = ((Uint16*)FogOfWarAlphaTable)[*p];
+               *p = ((Uint24*)FogOfWarAlphaTable)[
+                   ((p->a & 0xf8) >> 3) | ((p->b & 0xfc) << 3) | ((p->c & 
0xf8) << 8)];
            }
            ++p;
            ++ptile;
@@ -692,7 +692,7 @@
 
     VideoLockScreen();
     for (i = y; i < ey; ++i) {
-       p = &((Uint32*)TheScreen->pixels)[x + i * VideoWidth];
+       p = (Uint32*)TheScreen->pixels + x + i * VideoWidth;
        for (j = x; j < ex; ++j) {
            *p = ((Uint32*)FogOfWarAlphaTable)[
                ((*p & 0xf8) >> 3) | ((*p & 0xfc00) >> 5) | ((*p & 0xf80000) >> 
8)];
@@ -723,7 +723,7 @@
 
     VideoLockScreen();
     for (i = y; i < ey; ++i) {
-       p = &((Uint32*)TheScreen->pixels)[x + i * VideoWidth];
+       p = (Uint32*)TheScreen->pixels + x + i * VideoWidth;
        ptile = &((Uint8*)TheMap.TileGraphic->Surface->pixels)[
            sy + (i - y) * TheMap.TileGraphic->Surface->w + sx];
        for (j = x; j < ex; ++j) {
@@ -3145,6 +3145,41 @@
                VideoDrawOnlyFog = VideoDraw16OnlyFogAlpha;
                break;
            case 24:
+               rshft = ( 0);
+               gshft = ( 5);
+               bshft = (11);
+               rmask = (0x1F << rshft);
+               gmask = (0x3F << gshft);
+               bmask = (0x1F << bshft);
+               rloss = ( 3);
+               gloss = ( 2);
+               bloss = ( 3);
+
+               n = 1 << (sizeof(Uint16) * 8);
+               if (!FogOfWarAlphaTable) {
+                   FogOfWarAlphaTable = malloc(n * sizeof(Uint24));
+               }
+               for (i = 0; i < n; ++i) {
+                   r = (i & rmask) >> rshft << rloss;
+                   g = (i & gmask) >> gshft << gloss;
+                   b = (i & bmask) >> bshft << bloss;
+                   v = r + g + b;
+
+                   r = ((((r * 3 - v) * FogOfWarSaturation + v * 100) *
+                       FogOfWarContrast) + FogOfWarBrightness * 25600 * 3) / 
30000;
+                   g = ((((g * 3 - v) * FogOfWarSaturation + v * 100) *
+                       FogOfWarContrast) + FogOfWarBrightness * 25600 * 3) / 
30000;
+                   b = ((((b * 3 - v) * FogOfWarSaturation + v * 100) *
+                       FogOfWarContrast) + FogOfWarBrightness * 25600 * 3) / 
30000;
+
+                   // Boundings
+                   r = r < 0 ? 0 : r > 255 ? 255 : r;
+                   g = g < 0 ? 0 : g > 255 ? 255 : g;
+                   b = b < 0 ? 0 : b > 255 ? 255 : b;
+                   ((Uint24*)FogOfWarAlphaTable)[i].a = r;
+                   ((Uint24*)FogOfWarAlphaTable)[i].b = g;
+                   ((Uint24*)FogOfWarAlphaTable)[i].c = b;
+               }
                VideoDrawFog = VideoDraw24FogAlpha;
                VideoDrawOnlyFog = VideoDraw24OnlyFogAlpha;
                break;
Index: stratagus/src/video/linedraw.c
diff -u stratagus/src/video/linedraw.c:1.62 stratagus/src/video/linedraw.c:1.63
--- stratagus/src/video/linedraw.c:1.62 Tue Dec  2 00:44:42 2003
+++ stratagus/src/video/linedraw.c      Wed Dec  3 14:18:29 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: linedraw.c,v 1.62 2003/12/02 05:44:42 nehalmistry Exp $
+//     $Id: linedraw.c,v 1.63 2003/12/03 19:18:29 jsalmon3 Exp $
 
 //@{
 
@@ -457,6 +457,13 @@
     VideoUnlockScreen();
 }
 
+global void VideoDrawPixel24(Uint32 color, int x, int y)
+{
+    VideoLockScreen();
+    ((Uint24*)TheScreen->pixels)[x + y * VideoWidth] = *(Uint24*)&color;
+    VideoUnlockScreen();
+}
+
 global void VideoDrawPixel32(Uint32 color, int x, int y)
 {
     VideoLockScreen();
@@ -473,7 +480,7 @@
 
     VideoLockScreen();
 
-    p = &((Uint16*)TheScreen->pixels)[x + y * VideoWidth];
+    p = (Uint16*)TheScreen->pixels + x + y * VideoWidth;
     color = (((color << 16) | color) & 0x07E0F81F);
     dp = *p;
     dp = ((dp << 16) | dp) & 0x07E0F81F;
@@ -483,6 +490,34 @@
     VideoUnlockScreen();
 }
 
+global void VideoDrawTransPixel24(Uint32 color, int x, int y, unsigned char 
alpha)
+{
+    unsigned long sp2;
+    unsigned long dp1;
+    unsigned long dp2;
+    Uint24* p;
+
+    alpha = 255 - alpha;
+
+    VideoLockScreen();
+
+    p = (Uint24*)TheScreen->pixels + x + y * VideoWidth;
+
+    sp2 = (color & 0xFF00FF00) >> 8;
+    color &= 0x00FF00FF;
+
+    dp1 = *(Uint32*)p;
+    dp2 = (dp1 & 0xFF00FF00) >> 8;
+    dp1 &= 0x00FF00FF;
+
+    dp1 = ((((dp1-color) * alpha) >> 8) + color) & 0x00FF00FF;
+    dp2 = ((((dp2-sp2) * alpha) >> 8) + sp2) & 0x00FF00FF;
+    dp2 = (dp1 | (dp2 << 8));
+    *p = *(Uint24*)&dp2;
+
+    VideoUnlockScreen();
+}
+
 global void VideoDrawTransPixel32(Uint32 color, int x, int y, unsigned char 
alpha)
 {
     unsigned long sp2;
@@ -494,7 +529,7 @@
 
     VideoLockScreen();
 
-    p = &((Uint32*)TheScreen->pixels)[x + y * VideoWidth];
+    p = (Uint32*)TheScreen->pixels + x + y * VideoWidth;
 
     sp2 = (color & 0xFF00FF00) >> 8;
     color &= 0x00FF00FF;
@@ -1177,6 +1212,10 @@
        case 16:
            VideoDrawPixel = VideoDrawPixel16;
            VideoDrawTransPixel = VideoDrawTransPixel16;
+           break;
+       case 24:
+           VideoDrawPixel = VideoDrawPixel24;
+           VideoDrawTransPixel = VideoDrawTransPixel24;
            break;
        case 32:
            VideoDrawPixel = VideoDrawPixel32;




reply via email to

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