2024-03-28 22:20 UTC

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0002488NetSurfFramebuffer-specificpublic2019-05-06 13:16
ReporterAnthony J. Bentley 
Assigned To 
SeveritymajorReproducibilityalways 
StatusconfirmedResolutionopen 
PlatformPowerPCOSOpenBSDOS Version
Product Version 
Target VersionFixed in Version 
Summary0002488: Framebuffer bad endianness when loading images
DescriptionWhen "netsurf-fb -b 8" or "netsurf-fb -b 16" is run on OpenBSD/macppc (big-endian), images are not displayed properly.

All graphics in webpages, and all framebuffer bitmaps including mouse pointer and toolbar buttons, have incorrect colors. (fb-8-16.png)

The problem is partly due to some casts of pixdata from uint8_t[] to uint32_t*:

frontends/framebuffer/fbtk/fbtk.c:fbtk_set_ptr()
frontends/framebuffer/fbtk/bitmap.c:fb_redraw_bitmap()
frontends/framebuffer/framebuffer.c:framebuffer_set_cursor()

Naively putting a byteswap in libnsfb's plotting (naive-byteswap.diff) "fixes" the issue, except it doesn't fix the throbber and it leaves some ghosting after the cursor (fb-8-16-with-naive-byteswap.png).

A better fix is probably to generate uint32_t from the start. This is platform-independent and not very intrusive (better-fix.diff), but only fixes generated/fbtk images, and doesn't help with fetched images (fb-8-16-with-better-fix.png). It's a start, though.
TagsNo tags attached.
Fixed in CI build #
Reported in CI build #
URL of problem page
Attached Files
  • png file icon fb-8-16.png (130,366 bytes) 2016-12-04 03:53 -
    png file icon fb-8-16.png (130,366 bytes) 2016-12-04 03:53 +
  • diff file icon naive-byteswap.diff (1,497 bytes) 2016-12-04 03:54 -
    $OpenBSD$
    --- src/plot/common.c.orig	Sat Dec  3 14:40:51 2016
    +++ src/plot/common.c	Sat Dec  3 14:44:00 2016
    @@ -450,7 +450,7 @@ bitmap(nsfb_t *nsfb,
             if (alpha) {
                     for (yloop = yoff; yloop < height; yloop += bmp_stride) {
                             for (xloop = 0; xloop < width; xloop++) {
    -                                abpixel = pixel[yloop + xloop + xoff];
    +                                abpixel = ((pixel[yloop + xloop + xoff] & 0xFF) << 24) | ((pixel[yloop + xloop + xoff] & 0xFF00) << 8) | ((pixel[yloop + xloop + xoff] & 0xFF0000) >> 8) | ((pixel[yloop + xloop + xoff] >> 24) & 0xFF);
                                     if ((abpixel & 0xFF000000) != 0) {
                                             /* pixel is not transparent; have to
                                              * plot something */
    @@ -475,7 +475,7 @@ bitmap(nsfb_t *nsfb,
             } else {
                     for (yloop = yoff; yloop < height; yloop += bmp_stride) {
                             for (xloop = 0; xloop < width; xloop++) {
    -                                abpixel = pixel[yloop + xloop + xoff];
    +                                abpixel = ((pixel[yloop + xloop + xoff] & 0xFF) << 24) | ((pixel[yloop + xloop + xoff] & 0xFF00) << 8) | ((pixel[yloop + xloop + xoff] & 0xFF0000) >> 8) | ((pixel[yloop + xloop + xoff] >> 24) & 0xFF);
                                     *(pvideo + xloop) = colour_to_pixel(
                                                     nsfb, abpixel);
                             }
    
    diff file icon naive-byteswap.diff (1,497 bytes) 2016-12-04 03:54 +
  • png file icon fb-8-16-with-naive-byteswap.png (65,222 bytes) 2016-12-04 03:55 -
    png file icon fb-8-16-with-naive-byteswap.png (65,222 bytes) 2016-12-04 03:55 +
  • diff file icon better-fix.diff (1,261 bytes) 2016-12-04 03:56 -
    $OpenBSD$
    --- frontends/framebuffer/convert_image.c.orig	Sat Nov 19 06:37:41 2016
    +++ frontends/framebuffer/convert_image.c	Sat Dec  3 18:08:10 2016
    @@ -266,7 +266,7 @@ main(int argc, char **argv)
     	fprintf(f, "#include \"framebuffer/gui.h\"\n");
     	fprintf(f, "#include \"framebuffer/fbtk.h\"\n\n");
     
    -	fprintf(f, "static uint8_t %s_pixdata[] = {\n", argv[3]);
    +	fprintf(f, "static uint32_t %s_pixdata[] = {\n", argv[3]);
     	for (y = 0; y < HEIGHT; ++y) {
     		unsigned char *rowptr = bitmap_data + (rowstride * y);
     		if (is_cursor) {
    @@ -275,10 +275,8 @@ main(int argc, char **argv)
     		}
     		fprintf(f, "\t");
     		for (x = 0; x < WIDTH; ++x) {
    -			for (c = 0; c < 4; ++c) {
    -				unsigned char b = *rowptr++;
    -				fprintf(f, "0x%02x, ", b);
    -			}
    +			fprintf(f, "0x%02x%02x%02x%02x, ", rowptr[3], rowptr[2], rowptr[1], rowptr[0]);
    +			rowptr += 4;
     		}
     		fprintf(f, "\n");
     	}
    $OpenBSD$
    --- frontends/framebuffer/fbtk.h.orig	Sat Dec  3 18:03:23 2016
    +++ frontends/framebuffer/fbtk.h	Sat Dec  3 18:03:25 2016
    @@ -69,7 +69,7 @@ typedef struct fbtk_callback_info {
     struct fbtk_bitmap {
             int width;
             int height;
    -        uint8_t *pixdata;
    +        uint32_t *pixdata;
             bool opaque;
     
             /* The following two are only used for cursors */
    
    diff file icon better-fix.diff (1,261 bytes) 2016-12-04 03:56 +
  • png file icon fb-8-16-with-better-patch.png (208,814 bytes) 2016-12-04 03:58 -
    png file icon fb-8-16-with-better-patch.png (208,814 bytes) 2016-12-04 03:58 +

-Relationships
+Relationships

-Notes
Vincent Sanders

~0001467

Vincent Sanders (administrator)

will look at sorting this. currently rummaging around for a big endian system to play with.
+Notes

-Issue History
Date Modified Username Field Change
2016-12-04 03:53 Anthony J. Bentley New Issue
2016-12-04 03:53 Anthony J. Bentley File Added: fb-8-16.png
2016-12-04 03:54 Anthony J. Bentley File Added: naive-byteswap.diff
2016-12-04 03:55 Anthony J. Bentley File Added: fb-8-16-with-naive-byteswap.png
2016-12-04 03:56 Anthony J. Bentley File Added: better-fix.diff
2016-12-04 03:58 Anthony J. Bentley File Added: fb-8-16-with-better-patch.png
2016-12-31 12:29 Vincent Sanders Note Added: 0001467
2016-12-31 12:29 Vincent Sanders Assigned To => Vincent Sanders
2016-12-31 12:29 Vincent Sanders Status new => confirmed
2019-05-06 13:16 Vincent Sanders Assigned To Vincent Sanders =>
+Issue History