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 png.c


From: Nehal Mistry
Subject: [Stratagus-CVS] stratagus/src/video linedraw.c png.c
Date: Mon, 17 Nov 2003 20:50:16 -0500

CVSROOT:        /cvsroot/stratagus
Module name:    stratagus
Branch:         
Changes by:     Nehal Mistry <address@hidden>   03/11/17 20:50:16

Modified files:
        src/video      : linedraw.c png.c 

Log message:
        can take screenshots with USE_SDL_SURFACE

Patches:
Index: stratagus/src/video/linedraw.c
diff -u stratagus/src/video/linedraw.c:1.41 stratagus/src/video/linedraw.c:1.42
--- stratagus/src/video/linedraw.c:1.41 Mon Nov 17 15:33:17 2003
+++ stratagus/src/video/linedraw.c      Mon Nov 17 20:50:15 2003
@@ -27,7 +27,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: linedraw.c,v 1.41 2003/11/17 20:33:17 nehalmistry Exp $
+//     $Id: linedraw.c,v 1.42 2003/11/18 01:50:15 nehalmistry Exp $
 
 //@{
 
@@ -448,6 +448,7 @@
 
 #ifdef USE_SDL_SURFACE
     // FIXME: BIG todo
+    // FIXME: optimize all these
 global void InitLineDraw()
 {
 }
@@ -475,9 +476,13 @@
 {
     DebugCheck(1);
 }
-global void VideoDrawVLine(SDL_Color color, int x, int y, int width)
+global void VideoDrawVLine(SDL_Color color, int x, int y, int height)
 {
-    DebugCheck(1);
+    int i;
+
+    for (i = 1; i < height; ++i) {
+       VideoDrawPixel(color, x, y + i);
+    }
 }
 global void VideoDrawTransVLine(SDL_Color color, int x, int y,
     int height, unsigned char alpha)
@@ -491,7 +496,11 @@
 
 global void VideoDrawHLine(SDL_Color color, int x, int y, int width)
 {
-    DebugCheck(1);
+    int i;
+
+    for (i = 1; i < width; ++i) {
+       VideoDrawPixel(color, x + i, y);
+    }
 }
 global void VideoDrawHLineClip(SDL_Color color, int x, int y, int width)
 {
@@ -534,7 +543,6 @@
     for (i = 1; i < h; ++i) {
        VideoDrawPixel(color, x, y + i);
        VideoDrawPixel(color, x + w, y + i);
-
     }
 }
 
@@ -554,14 +562,26 @@
     for (i = 1; i < h; ++i) {
        VideoDrawPixel(color, x, y + i);
        VideoDrawPixel(color, x + w, y + i);
-
     }
 }
 
 global void VideoDrawTransRectangle(SDL_Color color, int x, int y,
     int w, int h, unsigned char alpha)
 {
-    DebugCheck(1);
+    int i;
+
+    // FIXME: transparency
+    // FIXME: should be able to optimize this
+
+    for (i = 0; i <= w; ++i) {
+       VideoDrawPixel(color, x + i, y);
+       VideoDrawPixel(color, x + i, y + h);
+    }
+
+    for (i = 1; i < h; ++i) {
+       VideoDrawPixel(color, x, y + i);
+       VideoDrawPixel(color, x + w, y + i);
+    }
 }
 
 global void VideoFillRectangle(SDL_Color color, int x, int y,
Index: stratagus/src/video/png.c
diff -u stratagus/src/video/png.c:1.25 stratagus/src/video/png.c:1.26
--- stratagus/src/video/png.c:1.25      Mon Nov 17 14:14:48 2003
+++ stratagus/src/video/png.c   Mon Nov 17 20:50:15 2003
@@ -26,7 +26,7 @@
 //      Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 //      02111-1307, USA.
 //
-//     $Id: png.c,v 1.25 2003/11/17 19:14:48 nehalmistry Exp $
+//     $Id: png.c,v 1.26 2003/11/18 01:50:15 nehalmistry Exp $
 
 //@{
 
@@ -293,14 +293,19 @@
 */
 global void SaveScreenshotPNG(const char* name)
 {
-#ifdef USE_SDL_SURFACE
-#else
     FILE* fp;
     png_structp png_ptr;
     png_infop info_ptr;
     unsigned char* row;
     int i;
     int j;
+#ifdef USE_SDL_SURFACE
+//    Uint32 c;
+    int bpp;
+
+    bpp = TheScreen->format->BytesPerPixel;
+#else
+#endif
 
     fp = fopen(name, "wb");
     if (fp == NULL) {
@@ -343,6 +348,48 @@
     png_write_info(png_ptr, info_ptr);
 
     for (i = 0; i < VideoHeight; ++i) {
+#ifdef USE_SDL_SURFACE
+       switch (VideoDepth) {
+           case 15: {
+               Uint16 c;
+               for (j = 0; j < VideoWidth; ++j) {
+                   c = ((Uint16*)TheScreen->pixels)[j + i * VideoWidth];
+                   row[j * 3 + 0] = (((c >> 0) & 0x1f) * 0xff) / 0x1f;
+                   row[j * 3 + 1] = (((c >> 5) & 0x1f) * 0xff) / 0x1f;
+                   row[j * 3 + 2] = (((c >> 10) & 0x1f) * 0xff) / 0x1f;
+               }
+               break;
+           }
+           case 16: {
+               Uint16 c;
+               for (j = 0; j < VideoWidth; ++j) {
+                   c = ((Uint16*)TheScreen->pixels)[j + i * VideoWidth];
+                   row[j * 3 + 0] = (((c >> 0) & 0x1f) * 0xff) / 0x1f;
+                   row[j * 3 + 1] = (((c >> 5) & 0x3f) * 0xff) / 0x3f;
+                   row[j * 3 + 2] = (((c >> 11) & 0x1f) * 0xff) / 0x1f;
+               }
+               break;
+           }
+           case 24: {
+               Uint8 c;
+               for (j = 0; j < VideoWidth; ++j) {
+                   c = ((Uint8*)TheScreen->pixels)[j * bpp + i * VideoWidth * 
3];
+                   memcpy(row, TheScreen->pixels + i * VideoWidth, VideoWidth 
* 3);
+               }
+               break;
+           }
+           case 32: {
+               Uint32 c;
+               for (j = 0; j < VideoWidth; ++j) {
+                   c = ((Uint32*)TheScreen->pixels)[j + i * VideoWidth];
+                   row[j * 3 + 0] = ((c >> 0) & 0xff);
+                   row[j * 3 + 1] = ((c >> 8) & 0xff);
+                   row[j * 3 + 2] = ((c >> 16) & 0xff);
+               }
+               break;
+           }
+       }
+#else
        switch (VideoDepth) {
        case 8:
            // FIXME: Finish
@@ -381,6 +428,7 @@
            }
            break;
        }
+#endif
        png_write_row(png_ptr, row);
     }
 
@@ -394,7 +442,6 @@
     free(row);
 
     fclose(fp);
-#endif
 }
 
 //@}




reply via email to

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