minor performance improvements, optional mouse, mouse cursor now drawn
[dosdemo] / src / gfxutil.c
index cb51780..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;
        }
 
@@ -149,20 +150,21 @@ void draw_line(int x0, int y0, int x1, int y1, unsigned short color)
                int sum = sptr[0] * (rad + 1); \
                int count = (rad * 2 + 1) << 8; \
                int midsize = w - rad * 2; \
+               int firstpix = sptr[0]; \
                int lastpix = sptr[pstep * (w - 1)]; \
                /* add up the contributions for the -1 pixel */ \
                for(j=0; j<rad; j++) { \
                        sum += sptr[pstep * j]; \
                } \
                /* first part adding sptr[rad] and subtracting sptr[0] */ \
-               for(j=0; j<rad + 1; j++) { \
-                       sum += (int)sptr[pstep * rad] - (int)sptr[0]; \
+               for(j=0; j<=rad; j++) { \
+                       sum += (int)sptr[pstep * rad] - firstpix; \
                        sptr += pstep; \
                        *dptr = scale * sum / count; \
                        dptr += pstep; \
                } \
                /* middle part adding sptr[rad] and subtracting sptr[-(rad+1)] */ \
-               for(j=0; j<midsize - 1; j++) { \
+               for(j=1; j<midsize; j++) { \
                        sum += (int)sptr[pstep * rad] - (int)sptr[-(rad + 1) * pstep]; \
                        sptr += pstep; \
                        *dptr = scale * sum / count; \
@@ -201,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;
+       }
+
+}