r5393 vince - /branches/vince/netsurf-fb/framebuffer/fb_32bpp_plotters.c

netsurf at semichrome.net netsurf at semichrome.net
Sun Sep 21 23:34:38 BST 2008


Author: vince
Date: Sun Sep 21 17:34:38 2008
New Revision: 5393

URL: http://source.netsurf-browser.org?rev=5393&view=rev
Log:
fix 32bpp line plotting

Modified:
    branches/vince/netsurf-fb/framebuffer/fb_32bpp_plotters.c

Modified: branches/vince/netsurf-fb/framebuffer/fb_32bpp_plotters.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_32bpp_plotters.c?rev=5393&r1=5392&r2=5393&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_32bpp_plotters.c (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_32bpp_plotters.c Sun Sep 21 17:34:38 2008
@@ -38,26 +38,104 @@
                             (x << 2));
 }
 
+#define SIGN(x)  ((x<0) ?  -1  :  ((x>0) ? 1 : 0))
+
+static bool fb_32bpp_line(int x0, int y0, int x1, int y1, int width,
+			colour c, bool dotted, bool dashed)
+{
+        int w;
+        uint32_t ent;
+        uint32_t *pvideo;
+
+        int x, y, i;
+        int dx, dy, sdy;
+        int dxabs, dyabs;
+
+        if (y1 > fb_plot_ctx.y1)
+                return true;
+        if (y0 < fb_plot_ctx.y0)
+                return true;
+
+        ent = ((c & 0xff0000) >> 16) | (c & 0xff00) | ((c & 0xff) << 16);
+
+        if (y0 == y1) {
+                /* horizontal line special cased */
+                fb_plotters_clip_rect_ctx(&x0, &y0, &x1, &y1);
+
+                pvideo = fb_32bpp_get_xy_loc(x0, y0);
+
+                w = x1 - x0;
+                while (w-- > 0) {
+                        *(pvideo + w) = ent;
+                }
+                return true;
+        } else {
+                /* standard bresenham line */
+                if (!fb_plotters_clip_line_ctx(&x0, &y0, &x1, &y1))
+                        return true; /* line outside clipping */
+
+                /* the horizontal distance of the line */
+                dx = x1 - x0;
+                dxabs = abs (dx);
+
+                /* the vertical distance of the line */
+                dy = y1 - y0;
+                dyabs = abs (dy);
+
+                sdy = dx ? SIGN(dy) * SIGN(dx) : SIGN(dy);
+
+                if (dx >= 0)
+                        pvideo = fb_32bpp_get_xy_loc(x0, y0);
+                else
+                        pvideo = fb_32bpp_get_xy_loc(x1, y1);
+
+                x = dyabs >> 1;
+                y = dxabs >> 1;
+
+                if (dxabs >= dyabs) { 
+                        /* the line is more horizontal than vertical */
+                        for (i = 0; i <= dxabs; i++) {
+                                *pvideo = ent;
+
+                                pvideo++;
+                                y += dyabs;
+                                if (y >= dxabs) {
+                                        y -= dxabs;
+                                        pvideo += sdy * (framebuffer->linelen>>2);
+                                }
+                        }
+                } else {
+                        /* the line is more vertical than horizontal */
+                        for (i = 0; i <= dyabs; i++) {
+                                *pvideo = ent;
+                                pvideo += sdy * (framebuffer->linelen >> 2);
+
+                                x += dxabs;
+                                if (x >= dyabs) {
+                                        x -= dyabs;
+                                        pvideo++;
+                                }
+                        }
+                }
+                
+        }
+
+	return true;
+}
+
 static bool fb_32bpp_rectangle(int x0, int y0, int width, int height,
 			int line_width, colour c, bool dotted, bool dashed)
 {
-        LOG(("%s(%d, %d, %d, %d, %d, 0x%lx, %d, %d)\n", __func__, 
-             x0,y0,width,height,line_width,c,dotted,dashed));
-	return true;
-}
-
-static bool fb_32bpp_line(int x0, int y0, int x1, int y1, int width,
-			colour c, bool dotted, bool dashed)
-{
-        LOG(("%s(%d, %d, %d, %d, %d, 0x%lx, %d, %d)\n", __func__, 
-             x0,y0,x1,y1,width,c,dotted,dashed));
-
-	return true;
-}
+        fb_32bpp_line(x0, y0, x0 + width, y0, line_width, c, dotted, dashed);
+        fb_32bpp_line(x0, y0 + height, x0 + width, y0 + height, line_width, c, dotted, dashed);
+        fb_32bpp_line(x0, y0, x0, y0 + height, line_width, c, dotted, dashed);
+        fb_32bpp_line(x0 + width, y0, x0 + width, y0 + height, line_width, c, dotted, dashed);
+	return true;
+}
+
 
 static bool fb_32bpp_polygon(int *p, unsigned int n, colour fill)
 {
-        LOG(("%s(%p, %d, 0x%lx)\n", __func__, p,n,fill));
         return fb_plotters_polygon(p, n, fill, fb_32bpp_line);
 }
 
@@ -68,24 +146,21 @@
 {
         int w;
         int y;
-        uint32_t *video_char_start;
+        uint32_t *pvid;
         uint32_t ent;
 
-        LOG(("%s(%d, %d, %d, %d, 0x%lx)\n", __func__, 
-             x0,y0,x1,y1,c));
-
         fb_plotters_clip_rect_ctx(&x0, &y0, &x1, &y1);
 
         ent = ((c & 0xff0000) >> 16) | (c & 0xff00) | ((c & 0xff) << 16);
 
-        video_char_start = fb_32bpp_get_xy_loc(x0, y0);
+        pvid = fb_32bpp_get_xy_loc(x0, y0);
 
         for (y = y0; y < y1; y++) {
                 w = x1 - x0;
                 while (w-- > 0) {
-                        *(video_char_start + w) = ent;
+                        *(pvid + w) = ent;
                 }
-                video_char_start += (framebuffer->linelen >> 2);
+                pvid += (framebuffer->linelen >> 2);
         }
 
 	return true;
@@ -93,12 +168,11 @@
 
 static bool fb_32bpp_clg(colour c)
 {
-        LOG(("%s(%lx)\n", __func__, c));
         fb_32bpp_fill(fb_plot_ctx.x0, 
-                         fb_plot_ctx.y0, 
-                         fb_plot_ctx.x1, 
-                         fb_plot_ctx.y1, 
-                         c);
+                      fb_plot_ctx.y0, 
+                      fb_plot_ctx.x1, 
+                      fb_plot_ctx.y1, 
+                      c);
 	return true;
 }
 
@@ -216,6 +290,7 @@
         colour abpixel; /* alphablended pixel */
         int xloop, yloop;
         int x0,y0,x1,y1;
+	int xoff, yoff; /* x and y offset into image */
 
         /* LOG(("x %d, y %d, width %d, height %d, bitmap %p, content %p", 
            x,y,width,height,bitmap,content));*/
@@ -246,12 +321,15 @@
         if (width > (x1 - x0))
                 width = (x1 - x0);
 
+	xoff = x0 - x;
+	yoff = y0 - y;
+
         /* plot the image */
         pvideo = fb_32bpp_get_xy_loc(x0, y0);
 
         for (yloop = 0; yloop < height; yloop++) {
                 for (xloop = 0; xloop < width; xloop++) {
-                        abpixel = pixel[(yloop * bitmap->width) + xloop];
+                        abpixel = pixel[((yoff + yloop) * bitmap->width) + xloop + xoff];
                         if ((abpixel & 0xFF000000) != 0) {
                                 if ((abpixel & 0xFF000000) != 0xFF) {
                                         abpixel = fb_plotters_ablend(abpixel, 




More information about the netsurf-commits mailing list