mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-03 09:44:24 +03:00
Implement sprite support for GTK using librosprite
svn path=/trunk/netsurf/; revision=4051
This commit is contained in:
parent
2a5ffe493e
commit
9402e110e9
5
Makefile
5
Makefile
@ -112,11 +112,12 @@ GTKCFLAGS := -std=c99 -Dgtk -Dnsgtk \
|
||||
-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 $(PKG_CONFIG) --cflags librosprite) \
|
||||
$(shell xml2-config --cflags)
|
||||
|
||||
GTKLDFLAGS := $(shell $(PKG_CONFIG) --cflags --libs libglade-2.0 gtk+-2.0 gthread-2.0 gmodule-2.0 librsvg-2.0)
|
||||
GTKLDFLAGS := $(shell $(PKG_CONFIG) --cflags --libs libglade-2.0 gtk+-2.0 gthread-2.0 gmodule-2.0 librsvg-2.0 librosprite)
|
||||
CFLAGS += $(GTKCFLAGS)
|
||||
LDFLAGS += $(GTKLDFLAGS) $(shell $(PKG_CONFIG) --libs lcms)
|
||||
|
||||
|
@ -23,7 +23,7 @@ S_COMMON := $(addprefix content/,$(S_CONTENT)) \
|
||||
$(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))
|
||||
|
||||
|
@ -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 @@ static const struct mime_entry mime_map[] = {
|
||||
#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 @@ const char *content_type_name[] = {
|
||||
"JNG",
|
||||
"MNG",
|
||||
#endif
|
||||
#ifdef WITH_SPRITE
|
||||
#if defined(WITH_SPRITE) || defined(WITH_NSSPRITE)
|
||||
"SPRITE",
|
||||
#endif
|
||||
#ifdef WITH_DRAW
|
||||
@ -301,6 +304,10 @@ static const struct handler_entry handler_map[] = {
|
||||
{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},
|
||||
|
@ -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 @@ struct content {
|
||||
#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
|
||||
|
@ -48,7 +48,7 @@ typedef enum {
|
||||
CONTENT_JNG,
|
||||
CONTENT_MNG,
|
||||
#endif
|
||||
#ifdef WITH_SPRITE
|
||||
#if defined(WITH_SPRITE) || defined(WITH_NSSPRITE)
|
||||
CONTENT_SPRITE,
|
||||
#endif
|
||||
#ifdef WITH_DRAW
|
||||
|
125
image/nssprite.c
Normal file
125
image/nssprite.c
Normal file
@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright 2008 James Shaw <js102@zepler.net>
|
||||
*
|
||||
* 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
|
41
image/nssprite.h
Normal file
41
image/nssprite.h
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2008 James Shaw <js102@zepler.net>
|
||||
*
|
||||
* 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
|
@ -66,7 +66,7 @@ static const content_type image_types[] = {
|
||||
CONTENT_JNG,
|
||||
CONTENT_MNG,
|
||||
#endif
|
||||
#ifdef WITH_SPRITE
|
||||
#if defined(WITH_SPRITE) || defined(WITH_NSSPRITE)
|
||||
CONTENT_SPRITE,
|
||||
#endif
|
||||
#ifdef WITH_DRAW
|
||||
|
@ -73,6 +73,7 @@ char *strndup(const char *s, size_t n);
|
||||
#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 @@ char *strndup(const char *s, size_t n);
|
||||
#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
|
||||
|
Loading…
Reference in New Issue
Block a user