fixed loading screen. regression in blitfb
[dosdemo] / src / gfxutil.c
index 0257f79..6f8ca5e 100644 (file)
@@ -1,5 +1,6 @@
-#include "gfxutil.h"
+#include <string.h>
 #include "demo.h"
+#include "gfxutil.h"
 
 enum {
        IN              = 0,
@@ -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;
        }
 
@@ -142,3 +143,138 @@ void draw_line(int x0, int y0, int x1, int y1, unsigned short color)
                }
        }
 }
+
+
+#define BLUR(w, h, pstep, sstep) \
+       for(i=0; i<h; i++) { \
+               int r, g, b; \
+               int rsum = UNPACK_R16(sptr[0]) * (rad + 1); \
+               int gsum = UNPACK_G16(sptr[0]) * (rad + 1); \
+               int bsum = UNPACK_B16(sptr[0]) * (rad + 1); \
+               int count = (rad * 2 + 1) << 8; \
+               int midsize = w - rad * 2; \
+               int rfirstpix = UNPACK_R16(sptr[0]); \
+               int rlastpix = UNPACK_R16(sptr[pstep * (w - 1)]); \
+               int gfirstpix = UNPACK_G16(sptr[0]); \
+               int glastpix = UNPACK_G16(sptr[pstep * (w - 1)]); \
+               int bfirstpix = UNPACK_B16(sptr[0]); \
+               int blastpix = UNPACK_B16(sptr[pstep * (w - 1)]); \
+               /* add up the contributions for the -1 pixel */ \
+               for(j=0; j<rad; j++) { \
+                       rsum += UNPACK_R16(sptr[pstep * j]); \
+                       gsum += UNPACK_G16(sptr[pstep * j]); \
+                       bsum += UNPACK_B16(sptr[pstep * j]); \
+               } \
+               /* first part adding sptr[rad] and subtracting sptr[0] */ \
+               for(j=0; j<=rad; j++) { \
+                       rsum += UNPACK_R16((int)sptr[pstep * rad]) - rfirstpix; \
+                       gsum += UNPACK_G16((int)sptr[pstep * rad]) - gfirstpix; \
+                       bsum += UNPACK_B16((int)sptr[pstep * rad]) - bfirstpix; \
+                       sptr += pstep; \
+                       r = scale * rsum / count; \
+                       g = scale * gsum / count; \
+                       b = scale * bsum / count; \
+                       *dptr = PACK_RGB16(r, g, b); \
+                       dptr += pstep; \
+               } \
+               /* middle part adding sptr[rad] and subtracting sptr[-(rad+1)] */ \
+               for(j=1; j<midsize; j++) { \
+                       rsum += UNPACK_R16((int)sptr[pstep * rad]) - UNPACK_R16((int)sptr[-(rad + 1) * pstep]); \
+                       gsum += UNPACK_G16((int)sptr[pstep * rad]) - UNPACK_G16((int)sptr[-(rad + 1) * pstep]); \
+                       bsum += UNPACK_B16((int)sptr[pstep * rad]) - UNPACK_B16((int)sptr[-(rad + 1) * pstep]); \
+                       sptr += pstep; \
+                       r = scale * rsum / count; \
+                       g = scale * gsum / count; \
+                       b = scale * bsum / count; \
+                       *dptr = PACK_RGB16(r, g, b); \
+                       dptr += pstep; \
+               } \
+               /* last part adding lastpix and subtracting sptr[-(rad+1)] */ \
+               for(j=0; j<rad; j++) { \
+                       rsum += rlastpix - UNPACK_R16((int)sptr[-(rad + 1) * pstep]); \
+                       gsum += glastpix - UNPACK_G16((int)sptr[-(rad + 1) * pstep]); \
+                       bsum += blastpix - UNPACK_B16((int)sptr[-(rad + 1) * pstep]); \
+                       sptr += pstep; \
+                       r = scale * rsum / count; \
+                       g = scale * gsum / count; \
+                       b = scale * bsum / count; \
+                       *dptr = PACK_RGB16(r, g, b); \
+                       dptr += pstep; \
+               } \
+               sptr += sstep; \
+               dptr += sstep; \
+       }
+
+/* TODO bound blur rad to image size to avoid inner loop conditionals */
+/* TODO make version with pow2 (rad*2+1) to avoid div with count everywhere */
+void blur_horiz(uint16_t *dest, uint16_t *src, int xsz, int ysz, int rad, int scale)
+{
+       int i, j;
+       uint16_t *dptr = dest;
+       uint16_t *sptr = src;
+
+       BLUR(xsz, ysz, 1, 0);
+}
+
+
+void blur_vert(uint16_t *dest, uint16_t *src, int xsz, int ysz, int rad, int scale)
+{
+       int i, j;
+       uint16_t *dptr = dest;
+       uint16_t *sptr = src;
+       int pixel_step = xsz;
+       int scanline_step = 1 - ysz * pixel_step;
+
+       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 << 1);
+               dest += 320;
+               src += pitch_pix;
+       }
+}
+
+void blit(uint16_t *dest, int destwidth, uint16_t *src, int width, int height, int pitch_pix)
+{
+       int i, spansz = width << 1;
+       for(i=0; i<height; i++) {
+               memcpy(dest, src, spansz);
+               dest += destwidth;
+               src += pitch_pix;
+       }
+}
+
+void blit_key(uint16_t *dest, int destwidth, uint16_t *src, int width, int height, int pitch_pix, uint16_t key)
+{
+       int i, j;
+       int dadv = destwidth - width;
+       int sadv = pitch_pix - 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;
+               src += sadv;
+       }
+
+}