optimizations and best color depth attempt
authorJohn Tsiombikas <nuclear@mutantstargoat.com>
Sun, 21 Aug 2016 02:42:35 +0000 (05:42 +0300)
committerJohn Tsiombikas <nuclear@mutantstargoat.com>
Sun, 21 Aug 2016 02:42:35 +0000 (05:42 +0300)
src/main.c
src/tunnel.c

index 9e27509..f0588c0 100644 (file)
@@ -20,19 +20,26 @@ static int quit;
 
 int main(void)
 {
+       int i, trybpp[] = {32, 24, 16, 0};
+
        fbgfx_save_video_mode();
-       if(!(vmem = fbgfx_get_video_mode(&xsz, &ysz, &depth))) {
-               return 1;
-       }
+       fbgfx_get_video_mode(&xsz, &ysz, &depth);
 
-       /*if(!(vmem = fbgfx_set_video_mode(xsz, ysz, 16))) {
-               return 1;
+       for(i=0; trybpp[i]; i++) {
+               if(!(vmem = fbgfx_set_video_mode(xsz, ysz, trybpp[i]))) {
+                       continue;
+               }
+               fbgfx_get_video_mode(&xsz, &ysz, &depth);
+               if(depth == trybpp[i]) {
+                       break;
+               }
+               fprintf(stderr, "failed to set color depth: %dbpp\n", trybpp[i]);
        }
-       fbgfx_get_video_mode(&xsz, &ysz, &depth);
-       if(depth != 16) {
-               fprintf(stderr, "failed to set color depth: 16bpp\n");
+       if(trybpp[i] == 0) {
+               fprintf(stderr, "no usable color depths found\n");
                goto end;
-       }*/
+       }
+
        if(fbev_init() == -1) {
                goto end;
        }
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);
        }
 }