minor performance improvements, optional mouse, mouse cursor now drawn
[dosdemo] / src / gfxutil.c
index b82a612..259b56d 100644 (file)
@@ -1,3 +1,4 @@
+#include <string.h>
 #include "gfxutil.h"
 #include "demo.h"
 
@@ -100,7 +101,7 @@ void draw_line(int x0, int y0, int x1, int y1, unsigned short color)
        int i, dx, dy, x_inc, y_inc, error;
        unsigned short *fb = fb_pixels;
 
-       fb += y0 * fb_width + x0;
+       fb += y0 * FB_WIDTH + x0;
 
        dx = x1 - x0;
        dy = y1 - y0;
@@ -112,9 +113,9 @@ void draw_line(int x0, int y0, int x1, int y1, unsigned short color)
                dx = -dx;
        }
        if(dy >= 0) {
-               y_inc = fb_width;
+               y_inc = FB_WIDTH;
        } else {
-               y_inc = -fb_width;
+               y_inc = -FB_WIDTH;
                dy = -dy;
        }
 
@@ -202,3 +203,41 @@ void blur_grey_vert(uint16_t *dest, uint16_t *src, int xsz, int ysz, int rad, in
 
        BLUR(ysz, xsz, pixel_step, scanline_step);
 }
+
+void convimg_rgb24_rgb16(uint16_t *dest, unsigned char *src, int xsz, int ysz)
+{
+       int i;
+       int npixels = xsz * ysz;
+
+       for(i=0; i<npixels; i++) {
+               int r = *src++;
+               int g = *src++;
+               int b = *src++;
+               *dest++ = PACK_RGB16(r, g, b);
+       }
+}
+
+void blitfb(uint16_t *dest, uint16_t *src, int width, int height, int pitch_pix)
+{
+       int i;
+       for(i=0; i<height; i++) {
+               memcpy(dest, src, width * 2);
+               dest += 320;
+               src += pitch_pix;
+       }
+}
+
+void blitfb_key(uint16_t *dest, uint16_t *src, int width, int height, int pitch_pix, uint16_t key)
+{
+       int i, j, dadv = 320 - width;
+
+       for(i=0; i<height; i++) {
+               for(j=0; j<width; j++) {
+                       uint16_t scol = *src++;
+                       if(scol != key) *dest = scol;
+                       dest++;
+               }
+               dest += dadv;
+       }
+
+}