At long last, I've done some netsurf hacking. I attach a patch which uses librosprite to provide sprite rendering in netsurf. I've hacked the netsurf Makefile to build against my local copy of librosprite -- grep for -I../../ and -L../../ to find them. If someone could fix these, or tell me how, that'd be great.
librosprite can be found at svn://svn.netsurf-browser.org/trunk/netsurf. The test harness requires SDL to run, otherwise, there are no dependencies. Thanks Hertzsprung
Index: render/box_construct.c =================================================================== --- render/box_construct.c (revision 4050) +++ render/box_construct.c (working copy) @@ -66,7 +66,7 @@ CONTENT_JNG, CONTENT_MNG, #endif -#ifdef WITH_SPRITE +#if defined(WITH_SPRITE) || defined(WITH_NSSPRITE) CONTENT_SPRITE, #endif #ifdef WITH_DRAW Index: image/nssprite.c =================================================================== --- image/nssprite.c (revision 0) +++ image/nssprite.c (revision 0) @@ -0,0 +1,125 @@ + /* + * Copyright 2008 James Shaw <[EMAIL PROTECTED]> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** \file + * Content for image/x-riscos-sprite (librosprite implementation). + * + */ + +#include <assert.h> +#include <librosprite.h> +#include <string.h> +#include <stdlib.h> +#include "utils/config.h" +#include "desktop/plotters.h" +#include "content/content.h" +#include "utils/log.h" +#include "utils/messages.h" +#include "utils/utils.h" + +#ifdef WITH_NSSPRITE + +#define ERRCHK(x) do { \ + rosprite_error err = x; \ + if (err == ROSPRITE_EOF) { \ + LOG(("Got ROSPRITE_EOF when loading sprite file")); \ + return false; \ + } else if (err == ROSPRITE_BADMODE) { \ + LOG(("Got ROSPRITE_BADMODE when loading sprite file")); \ + return false; \ + } else if (err == ROSPRITE_OK) { \ + } else { \ + return false; \ + } \ +} while(0) + +/** + * Convert a CONTENT_SPRITE for display. + * + * No conversion is necessary. We merely read the sprite dimensions. + */ + +bool nssprite_convert(struct content *c, int width, int height) +{ + struct rosprite_mem_context* ctx; + ERRCHK(rosprite_create_mem_context(c->source_data, c->total_size, &ctx)); + + struct rosprite_area* sprite_area; + ERRCHK(rosprite_load(rosprite_mem_reader, ctx, &sprite_area)); + rosprite_destroy_mem_context(ctx); + c->data.nssprite.sprite_area = sprite_area; + + assert(sprite_area->sprite_count > 0); + + struct rosprite* sprite = sprite_area->sprites[0]; + + c->bitmap = bitmap_create(sprite->width, sprite->height, BITMAP_NEW); + if (!c->bitmap) { + return false; + } + char* imagebuf = bitmap_get_buffer(c->bitmap); + unsigned int row_width = bitmap_get_rowstride(c->bitmap); + + memcpy(imagebuf, sprite->image, row_width * sprite->height); // TODO: avoid copying entire image buffer + + /* reverse byte order of each word */ + for (uint32_t y = 0; y < sprite->height; y++) { + for (uint32_t x = 0; x < sprite->width; x++) { + int offset = 4 * (y * sprite->width + x); + uint32_t r = imagebuf[offset+3]; + uint32_t g = imagebuf[offset+2]; + uint32_t b = imagebuf[offset+1]; + uint32_t a = imagebuf[offset]; + imagebuf[offset] = r; + imagebuf[offset+1] = g; + imagebuf[offset+2] = b; + imagebuf[offset+3] = a; + } + } + + c->width = sprite->width; + c->height = sprite->height; + c->status = CONTENT_STATUS_DONE; + return true; +} + + +/** + * Destroy a CONTENT_SPRITE and free all resources it owns. + */ + +void nssprite_destroy(struct content *c) +{ + rosprite_destroy_sprite_area(c->data.nssprite.sprite_area); +} + + +/** + * Redraw a CONTENT_SPRITE. + */ + +bool nssprite_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, + float scale, colour background_colour) +{ + return plot.bitmap(x, y, width, height, + c->bitmap, background_colour); +} + +#endif Index: image/nssprite.h =================================================================== --- image/nssprite.h (revision 0) +++ image/nssprite.h (revision 0) @@ -0,0 +1,41 @@ +/* + * Copyright 2008 James Shaw <[EMAIL PROTECTED]> + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +/** \file + * Content for image/x-riscos-sprite (librosprite interface). + */ + +#ifndef _NETSURF_NS_SPRITE_H_ +#define _NETSURF_NS_SPRITE_H_ + +#include <stdbool.h> + +struct content; + +struct content_nssprite_data { + struct rosprite_area* sprite_area; +}; + +bool nssprite_convert(struct content *c, int width, int height); +void nssprite_destroy(struct content *c); +bool nssprite_redraw(struct content *c, int x, int y, + int width, int height, + int clip_x0, int clip_y0, int clip_x1, int clip_y1, + float scale, colour background_colour); + +#endif Index: Makefile.sources =================================================================== --- Makefile.sources (revision 4050) +++ Makefile.sources (working copy) @@ -23,7 +23,7 @@ $(addprefix desktop/,$(S_DESKTOP)) S_IMAGE := bmp.c bmpread.c gif.c gifread.c ico.c jpeg.c \ - mng.c svg.c rsvg.c + mng.c nssprite.c svg.c rsvg.c # S_IMAGE are sources related to image management S_IMAGE := $(addprefix image/,$(S_IMAGE)) Index: utils/config.h =================================================================== --- utils/config.h (revision 4050) +++ utils/config.h (working copy) @@ -73,6 +73,7 @@ #else /* We're likely to have a working mmap() */ #define WITH_MMAP + #define WITH_NSSPRITE #if !defined(DEBUG_BUILD) /* Use librsvg and Cairo for rendering SVG */ #define WITH_RSVG @@ -83,6 +84,10 @@ #error Cannot build WITH_NS_SVG and WITH_RSVG both enabled #endif +#if defined(WITH_NSSPRITE) && defined(WITH_SPRITE) + #error Cannot build WITH_NSSPRITE and WITH_SPRITE both enabled +#endif + #if defined(riscos) || defined(DEBUG_BUILD) /* Export modules */ #define WITH_SAVE_COMPLETE Index: content/content.h =================================================================== --- content/content.h (revision 4050) +++ content/content.h (working copy) @@ -51,6 +51,9 @@ #ifdef WITH_SPRITE #include "riscos/sprite.h" #endif +#ifdef WITH_NSSPRITE +#include "image/nssprite.h" +#endif #ifdef WITH_DRAW #include "riscos/draw.h" #endif @@ -173,6 +176,9 @@ #ifdef WITH_SPRITE struct content_sprite_data sprite; #endif +#ifdef WITH_NSSPRITE + struct content_nssprite_data nssprite; +#endif #ifdef WITH_DRAW struct content_draw_data draw; #endif Index: content/content_type.h =================================================================== --- content/content_type.h (revision 4050) +++ content/content_type.h (working copy) @@ -48,7 +48,7 @@ CONTENT_JNG, CONTENT_MNG, #endif -#ifdef WITH_SPRITE +#if defined(WITH_SPRITE) || defined(WITH_NSSPRITE) CONTENT_SPRITE, #endif #ifdef WITH_DRAW Index: content/content.c =================================================================== --- content/content.c (revision 4050) +++ content/content.c (working copy) @@ -63,6 +63,9 @@ #ifdef WITH_SPRITE #include "riscos/sprite.h" #endif +#ifdef WITH_NSSPRITE +#include "image/nssprite.h" +#endif #ifdef WITH_DRAW #include "riscos/draw.h" #endif @@ -168,7 +171,7 @@ #ifdef WITH_BMP {"image/x-ms-bmp", CONTENT_BMP}, #endif -#ifdef WITH_SPRITE +#if defined(WITH_SPRITE) || defined(WITH_NSSPRITE) {"image/x-riscos-sprite", CONTENT_SPRITE}, #endif #ifdef WITH_BMP @@ -205,7 +208,7 @@ "JNG", "MNG", #endif -#ifdef WITH_SPRITE +#if defined(WITH_SPRITE) || defined(WITH_NSSPRITE) "SPRITE", #endif #ifdef WITH_DRAW @@ -301,6 +304,10 @@ {0, 0, sprite_convert, 0, sprite_destroy, 0, sprite_redraw, 0, 0, 0, false}, #endif +#ifdef WITH_NSSPRITE + {0, 0, nssprite_convert, + 0, nssprite_destroy, 0, nssprite_redraw, 0, 0, 0, false}, +#endif #ifdef WITH_DRAW {0, 0, draw_convert, 0, draw_destroy, 0, draw_redraw, 0, 0, 0, false}, @@ -769,6 +776,7 @@ c->locked = true; c->available_width = width; if (handler_map[c->type].convert) { + LOG(("calling content handler's convert function for type %d", c->type)); if (!handler_map[c->type].convert(c, width, height)) { c->status = CONTENT_STATUS_ERROR; c->locked = false; Index: Makefile =================================================================== --- Makefile (revision 4050) +++ Makefile (working copy) @@ -100,7 +100,7 @@ LDFLAGS := -lxml2 -lz -lm -lcurl -lssl -lcrypto -lmng -ljpeg else LDFLAGS := $(shell $(PKG_CONFIG) --libs libxml-2.0 libcurl openssl) -LDFLAGS += -lz -lm -lmng -ljpeg +LDFLAGS += -lz -lm -lmng -ljpeg -lrosprite -L../../libsprite/trunk/ endif ifeq ($(TARGET),gtk) @@ -112,7 +112,7 @@ -D_XOPEN_SOURCE=600 \ -D_POSIX_C_SOURCE=200112L \ -D_NETBSD_SOURCE \ - $(WARNFLAGS) -I. -g -O \ + $(WARNFLAGS) -I. -I../../libsprite/trunk/ -g -O \ $(shell $(PKG_CONFIG) --cflags libglade-2.0 gtk+-2.0 librsvg-2.0) \ $(shell xml2-config --cflags)
