r5315 vince - in /branches/vince/netsurf-fb/framebuffer: fb_16bpp_plotters.c fb_plotters.c

netsurf at semichrome.net netsurf at semichrome.net
Sun Sep 14 19:58:57 BST 2008


Author: vince
Date: Sun Sep 14 13:58:57 2008
New Revision: 5315

URL: http://source.netsurf-browser.org?rev=5315&view=rev
Log:
improve 16bpp image plot

Modified:
    branches/vince/netsurf-fb/framebuffer/fb_16bpp_plotters.c
    branches/vince/netsurf-fb/framebuffer/fb_plotters.c

Modified: branches/vince/netsurf-fb/framebuffer/fb_16bpp_plotters.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_16bpp_plotters.c?rev=5315&r1=5314&r2=5315&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_16bpp_plotters.c (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_16bpp_plotters.c Sun Sep 14 13:58:57 2008
@@ -85,6 +85,8 @@
                 if (!fb_plotters_clip_line_ctx(&x0, &y0, &x1, &y1))
                         return true; /* line outside clipping */
 
+                LOG(("%d, %d, %d, %d", x0,y0,x1,y1));
+
                 /* the horizontal distance of the line */
                 dx = x1 - x0;
                 dxabs = abs (dx);
@@ -139,8 +141,8 @@
 static bool fb_16bpp_rectangle(int x0, int y0, int width, int height,
 			int line_width, colour c, bool dotted, bool dashed)
 {
-        LOG(("%d, %d, %d, %d, %d, 0x%lx, %d, %d",
-             x0,y0,width,height,line_width,c,dotted,dashed));
+        /*LOG(("%d, %d, %d, %d, %d, 0x%lx, %d, %d",
+          x0,y0,width,height,line_width,c,dotted,dashed));*/
 
         fb_16bpp_line(x0, y0, x0 + width, y0, line_width, c, dotted, dashed);
         fb_16bpp_line(x0, y0 + height, x0 + width, y0 + height, line_width, c, dotted, dashed);
@@ -153,7 +155,7 @@
 {
         int pnt;
         int *cur;
-        LOG(("p %p, n %d, fill 0x%lx", p, n, fill));
+        /*LOG(("p %p, n %d, fill 0x%lx", p, n, fill));*/
         
         for (pnt = 1; pnt < n; pnt++) {
                 cur = p + (pnt << 1);
@@ -170,7 +172,7 @@
         uint16_t ent;
         uint16_t *pvideo;
 
-        LOG(("x0 %d, y0 %d, x1 %d, y1 %d, c 0x%lx", x0, y0, x1, y1, c));
+        /*LOG(("x0 %d, y0 %d, x1 %d, y1 %d, c 0x%lx", x0, y0, x1, y1, c));*/
 
         fb_plotters_clip_rect_ctx(&x0, &y0, &x1, &y1);
 
@@ -193,7 +195,7 @@
 
 static bool fb_16bpp_clg(colour c)
 {
-        LOG(("c %lx", c));
+        /* LOG(("c %lx", c)); */
         fb_16bpp_fill(fb_plot_ctx.x0,
                          fb_plot_ctx.y0,
                          fb_plot_ctx.x1,
@@ -248,8 +250,8 @@
               ((bg & 0xF80000) >> 19);
 
 
-        LOG(("x %d, y %d, style %p, txt %.*s , len %d, bg 0x%lx, fg 0x%lx",
-             x,y,style,length,text,length,bg,c));
+        /*LOG(("x %d, y %d, style %p, txt %.*s , len %d, bg 0x%lx, fg 0x%lx",
+          x,y,style,length,text,length,bg,c));*/
 
         for (chr=0; chr < length; chr++) {
                 pvideo = fb_16bpp_get_xy_loc(x + (chr * (fb_font->width)), y, current_window);
@@ -289,6 +291,13 @@
 	return true;
 }
 
+static inline colour fb_16bpp_to_colour(uint16_t pixel)
+{
+        return ((pixel & 0x1F) << 19) | 
+              ((pixel & 0x7E0) << 5) |
+              ((pixel & 0xF800) >> 8);
+}
+
 static bool fb_16bpp_bitmap(int x, int y, int width, int height,
 			struct bitmap *bitmap, colour bg,
                         struct content *content)
@@ -298,19 +307,47 @@
         colour abpixel; /* alphablended pixel */
         u16_t fbpixel; /* framebuffer pixel */
         int xloop, yloop;
-
-        pvideo = fb_16bpp_get_xy_loc(x, y, current_window);
-
-        LOG(("x %d, y %d, width %d, height %d, bitmap %p, content %p", 
-             x,y,width,height,bitmap,content));
+        int x0,y0,x1,y1;
+
+        /* LOG(("x %d, y %d, width %d, height %d, bitmap %p, content %p", 
+           x,y,width,height,bitmap,content));*/
+
+        /* TODO here we should scale the image from bitmap->width to width, for
+         * now simply crop. 
+         */
+        if (width > bitmap->width)
+                width = bitmap->width;
+
+        if (height > bitmap->height)
+                height = bitmap->height;
+
+        /* The part of the scaled image actually displayed is cropped to the
+         * current context. 
+         */
+        x0 = x;
+        y0 = y;
+        x1 = x + width;
+        y1 = y + height;
+
+        if (!fb_plotters_clip_rect_ctx(&x0, &y0, &x1, &y1))
+                return true;
+
+        if (height > (y1 - y0))
+                height = (y1 - y0);
+
+        if (width > (x1 - x0))
+                width = (x1 - x0);
+
+        /* plot the image */
+        pvideo = fb_16bpp_get_xy_loc(x0, y0, current_window);
 
         for (yloop = 0; yloop < height; yloop++) {
                 for (xloop = 0; xloop < width; xloop++) {
                         abpixel = pixel[(yloop * bitmap->width) + xloop];
                         if ((abpixel & 0xFF000000) != 0) {
-                                if ((abpixel & 0xFF000000) != 0xFF) {
-                                        fbpixel = *(pvideo + xloop);
-                                        abpixel = fb_plotters_ablend(abpixel, fbpixel);
+                                if ((abpixel & 0xFF000000) != 0xFF000000) {
+                                        abpixel = fb_plotters_ablend(abpixel, 
+                                         fb_16bpp_to_colour(*(pvideo + xloop)));
                                 }
 
                                 *(pvideo + xloop) =

Modified: branches/vince/netsurf-fb/framebuffer/fb_plotters.c
URL: http://source.netsurf-browser.org/branches/vince/netsurf-fb/framebuffer/fb_plotters.c?rev=5315&r1=5314&r2=5315&view=diff
==============================================================================
--- branches/vince/netsurf-fb/framebuffer/fb_plotters.c (original)
+++ branches/vince/netsurf-fb/framebuffer/fb_plotters.c Sun Sep 14 13:58:57 2008
@@ -38,9 +38,23 @@
 /* Current plotting context */
 bbox_t fb_plot_ctx;
 
+#define REGION(x,y,cx1,cx2,cy1,cy2) ( ( (y) > (cy2) ? 8 : 0) |  \
+                                      ( (y) < (cy1) ? 4 : 0) |  \
+                                      ( (x) > (cx2) ? 2 : 0) |  \
+                                      ( (x) < (cx1) ? 1 : 0) )
+
 bool fb_plotters_clip_rect(const bbox_t *clip, 
                            int *x0, int *y0, int *x1, int *y1)
 {
+        char region1 = REGION(*x0, *y0,
+                               clip->x0, clip->x1, clip->y0, clip->y1);
+        char region2 = REGION(*x1, *y1,
+                               clip->x0, clip->x1, clip->y0, clip->y1);
+
+        /* area lies entirely outside the clipping rectangle */
+        if ((region1 | region2) && (region1 & region2))
+                return false; 
+
         if (*x0 < clip->x0)
                 *x0 = clip->x0;
         if (*x0 > clip->x1)
@@ -74,11 +88,6 @@
 bool fb_plotters_clip_line(const bbox_t *clip, 
                            int *x0, int *y0, int *x1, int *y1)
 {
-#define REGION(x,y,cx1,cx2,cy1,cy2) ( ( (y) > (cy2) ? 8 : 0) |  \
-                                      ( (y) < (cy1) ? 4 : 0) |  \
-                                      ( (x) > (cx2) ? 2 : 0) |  \
-                                      ( (x) < (cx1) ? 1 : 0) )
-
         char region1 = REGION(*x0, *y0,
                                clip->x0, clip->x1, clip->y0, clip->y1);
         char region2 = REGION(*x1, *y1,
@@ -177,10 +186,22 @@
 	return true;
 }
 
-
+// a 19 b 182 g 0 r 0
 colour fb_plotters_ablend(colour pixel, colour scrpixel)
 {
-        return pixel;
+        int opacity = (pixel >> 24) & 0xFF;
+        int r,g,b;
+
+        r = (((pixel & 0xFF) * opacity) >> 8) +
+            (((scrpixel & 0xFF) * (0xFF - opacity)) >> 8);
+
+        g = ((((pixel & 0xFF00) >> 8) * opacity) >> 8) +
+            ((((scrpixel & 0xFF00) >> 8) * (0xFF - opacity)) >> 8);
+
+        b = ((((pixel & 0xFF0000) >> 16) * opacity) >> 8) +
+            ((((scrpixel & 0xFF0000) >> 16) * (0xFF - opacity)) >> 8);
+        
+        return r | (g << 8) | (b << 16);
 }
 
 /*




More information about the netsurf-commits mailing list