changeset 12:18e14722f58a

Clean up the framebuffer rasterization code.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 18 May 2010 20:32:38 +0300
parents 2105d2dfefa3
children e5049100f6ac
files pwplib/sdl.c
diffstat 1 files changed, 21 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/pwplib/sdl.c	Tue May 18 18:47:16 2010 +0300
+++ b/pwplib/sdl.c	Tue May 18 20:32:38 2010 +0300
@@ -21,15 +21,15 @@
     int width, height, vflags;
     SDL_Surface *screen;
     SDL_Color cols[PWP_NCOLORS];
-    u32 lookup[256];
+    Uint32 lookup[256];
 } pwp_SDL;
 
 
 static void pwp_SDL_dump_rast_4x4()
 {
-    u32 *d = (u32 *) pwp_SDL.screen->pixels;
-    int x, y, j = 0;
-    u8 *ss = (u8 *) pwplib.videobuf.d;
+    Uint8 *dst = pwp_SDL.screen->pixels;
+    Uint8 *src = pwplib.videobuf.d;
+    int y;
 
     if (SDL_MUSTLOCK(pwp_SDL.screen) != 0)
     {
@@ -41,19 +41,21 @@
         }
     }
 
-    for (y = pwplib.videobuf.height * 2; y; y--)
+    for (y = pwplib.videobuf.height; y; y--)
     {
-        u8 *s = ss;
-
-        for (x = pwplib.videobuf.width; x; x--)
-            *d++ = pwp_SDL.lookup[*s++];
+        int y2;
+        for (y2 = 4; y2; y2--)
+        {
+            int x;
+            Uint32 *d = (Uint32 *)dst;
+            Uint8 *s = src;
 
-        j = (j + 1) & 1;
-        if (!j)
-            ss += pwplib.videobuf.width;
-        
-        if (pwp_SDL.screen->pitch > pwp_SDL.screen->w)
-            d += pwp_SDL.screen->pitch - pwp_SDL.screen->w;
+            for (x = pwplib.videobuf.width; x; x--)
+                *d++ = pwp_SDL.lookup[*s++];
+            
+            dst += pwp_SDL.screen->pitch;
+        }
+        src += pwplib.videobuf.width;
     }
 
     if (SDL_MUSTLOCK(pwp_SDL.screen) != 0)
@@ -104,7 +106,7 @@
 
     /* Set pwplib internal parameters */
     pwplib.videobuf.width = pwp_SDL.width / 4;
-    pwplib.videobuf.height = pwp_SDL.height / 4;
+    pwplib.videobuf.height = pwp_SDL.height / 8;
     pwplib.dump_rast = pwp_SDL_dump_rast_4x4;
 
     /* NOTICE! Here we assume that SDL audio will be used also .. this is kind of a hack,
@@ -129,11 +131,13 @@
         return 0;
     }
 
+    fprintf(stderr, "\nSDL_surface: %d x %d, pitch=%d\n", pwp_SDL.screen->w, pwp_SDL.screen->h, pwp_SDL.screen->pitch);
+    
     /* Set window caption, if any */
     SDL_WM_SetCaption(PWP_WINNAME, PWP_WINNAME);
 
 
-    /* Generate palette and rasterizations */
+    /* Generate palette and rasterization lookup table */
     for (i = 0; i < PWP_NCOLORS; i++)
     {
         int r, g, b;