optimizations and best color depth attempt
[fbgfx] / src / tunnel.c
index f4b3984..c6504ce 100644 (file)
@@ -1,6 +1,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <math.h>
+#include <assert.h>
 #include <imago2.h>
 #include "tpool.h"
 #include "tunnel.h"
@@ -172,29 +173,10 @@ static void tunnel_color(int *rp, int *gp, int *bp, long toffs, unsigned int tpa
 }
 
 #define PACK_RGB16(r, g, b) \
-       (((((r) >> 3) & 0x1f) << 11) | ((((g) >> 2) & 0x3f) << 5) | ((b) & 0x1f))
+       (((((r) >> 3) & 0x1f) << 11) | ((((g) >> 2) & 0x3f) << 5) | (((b) >> 3) & 0x1f))
 #define PACK_RGB32(r, g, b) \
        ((((r) & 0xff) << 16) | (((g) & 0xff) << 8) | ((b) & 0xff))
 
-#define PUTPIXEL(pixtype, col) \
-       do { \
-               int k; \
-               pixtype *ptr = pixels; \
-               for(k=0; k<VSCALE; k++) { \
-                       switch(USCALE) { \
-                       case 4: \
-                               ptr[3] = col; \
-                       case 3: \
-                               ptr[2] = col; \
-                       case 2: \
-                               ptr[1] = col; \
-                       case 1: \
-                               *ptr = col; \
-                       } \
-                       ptr += xsz; \
-               } \
-       } while(0)
-
 static void draw_tunnel_range16(void *pix, int starty, int num_lines)
 {
        int i, j;
@@ -202,7 +184,7 @@ static void draw_tunnel_range16(void *pix, int starty, int num_lines)
        unsigned char *fog = tunnel_fog + starty * vxsz;
 
        long toffs = time_msec / 4;
-       unsigned short *pixels = (unsigned short*)pix + starty * xsz * VSCALE;
+       unsigned int *pixels = (unsigned int*)pix + starty * (xsz >> 1);
 
        for(i=0; i<num_lines; i++) {
                for(j=0; j<vxsz; j++) {
@@ -211,11 +193,8 @@ static void draw_tunnel_range16(void *pix, int starty, int num_lines)
 
                        tunnel_color(&r, &g, &b, toffs, *tmap++, *fog++);
                        col = PACK_RGB16(r, g, b);
-
-                       PUTPIXEL(unsigned short, col);
-                       pixels += USCALE;
+                       *pixels++ = col;
                }
-               pixels += xsz * (VSCALE - 1);
        }
 }
 
@@ -236,10 +215,9 @@ static void draw_tunnel_range32(void *pix, int starty, int num_lines)
                        tunnel_color(&r, &g, &b, toffs, *tmap++, *fog++);
                        col = PACK_RGB32(r, g, b);
 
-                       PUTPIXEL(unsigned int, col);
-                       pixels += USCALE;
+                       *pixels++ = col;
+                       *pixels++ = col;
                }
-               pixels += xsz * (VSCALE - 1);
        }
 }