summaryrefslogtreecommitdiff
path: root/content/handlers/image/rsvg.c
diff options
context:
space:
mode:
Diffstat (limited to 'content/handlers/image/rsvg.c')
-rw-r--r--content/handlers/image/rsvg.c66
1 files changed, 37 insertions, 29 deletions
diff --git a/content/handlers/image/rsvg.c b/content/handlers/image/rsvg.c
index 1bf4b4403..2ba1b49f5 100644
--- a/content/handlers/image/rsvg.c
+++ b/content/handlers/image/rsvg.c
@@ -16,8 +16,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-/** \file
- * Content handler for image/svg using librsvg (implementation).
+/**
+ * \file
+ * implementation of content handler for image/svg using librsvg.
*
* SVG files are rendered to a NetSurf bitmap by creating a Cairo rendering
* surface (content_rsvg_data.cs) over the bitmap's data, creating a Cairo
@@ -38,6 +39,8 @@
#include <librsvg/rsvg-cairo.h>
#endif
+#include <nsutils/endian.h>
+
#include "utils/log.h"
#include "utils/utils.h"
#include "utils/messages.h"
@@ -61,17 +64,14 @@ typedef struct rsvg_content {
static nserror rsvg_create_svg_data(rsvg_content *c)
{
- union content_msg_data msg_data;
-
c->rsvgh = NULL;
c->cs = NULL;
c->ct = NULL;
c->bitmap = NULL;
if ((c->rsvgh = rsvg_handle_new()) == NULL) {
- LOG("rsvg_handle_new() returned NULL.");
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ NSLOG(netsurf, INFO, "rsvg_handle_new() returned NULL.");
+ content_broadcast_errorcode(&c->base, NSERROR_NOMEM);
return NSERROR_NOMEM;
}
@@ -114,14 +114,13 @@ static bool rsvg_process_data(struct content *c, const char *data,
unsigned int size)
{
rsvg_content *d = (rsvg_content *) c;
- union content_msg_data msg_data;
GError *err = NULL;
if (rsvg_handle_write(d->rsvgh, (const guchar *)data, (gsize)size,
&err) == FALSE) {
- LOG("rsvg_handle_write returned an error: %s", err->message);
- msg_data.error = err->message;
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ NSLOG(netsurf, INFO,
+ "rsvg_handle_write returned an error: %s", err->message);
+ content_broadcast_errorcode(c, NSERROR_SVG_ERROR);
return false;
}
@@ -142,15 +141,21 @@ static inline void rsvg_argb_to_abgr(uint8_t *pixels,
int width, int height, size_t rowstride)
{
uint8_t *p = pixels;
+ int boff = 0, roff = 2;
+
+ if (endian_host_is_le() == false) {
+ boff = 1;
+ roff = 3;
+ }
for (int y = 0; y < height; y++) {
for (int x = 0; x < width; x++) {
/* Swap R and B */
- const uint8_t r = p[x+3];
+ const uint8_t r = p[4*x+roff];
- p[x+3] = p[x];
+ p[4*x+roff] = p[4*x+boff];
- p[x] = r;
+ p[4*x+boff] = r;
}
p += rowstride;
@@ -160,14 +165,13 @@ static inline void rsvg_argb_to_abgr(uint8_t *pixels,
static bool rsvg_convert(struct content *c)
{
rsvg_content *d = (rsvg_content *) c;
- union content_msg_data msg_data;
RsvgDimensionData rsvgsize;
GError *err = NULL;
if (rsvg_handle_close(d->rsvgh, &err) == FALSE) {
- LOG("rsvg_handle_close returned an error: %s", err->message);
- msg_data.error = err->message;
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ NSLOG(netsurf, INFO,
+ "rsvg_handle_close returned an error: %s", err->message);
+ content_broadcast_errorcode(c, NSERROR_SVG_ERROR);
return false;
}
@@ -183,9 +187,9 @@ static bool rsvg_convert(struct content *c)
if ((d->bitmap = guit->bitmap->create(c->width, c->height,
BITMAP_NEW)) == NULL) {
- LOG("Failed to create bitmap for rsvg render.");
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ NSLOG(netsurf, INFO,
+ "Failed to create bitmap for rsvg render.");
+ content_broadcast_errorcode(c, NSERROR_NOMEM);
return false;
}
@@ -194,16 +198,16 @@ static bool rsvg_convert(struct content *c)
CAIRO_FORMAT_ARGB32,
c->width, c->height,
guit->bitmap->get_rowstride(d->bitmap))) == NULL) {
- LOG("Failed to create Cairo image surface for rsvg render.");
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ NSLOG(netsurf, INFO,
+ "Failed to create Cairo image surface for rsvg render.");
+ content_broadcast_errorcode(c, NSERROR_NOMEM);
return false;
}
if ((d->ct = cairo_create(d->cs)) == NULL) {
- LOG("Failed to create Cairo drawing context for rsvg render.");
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ NSLOG(netsurf, INFO,
+ "Failed to create Cairo drawing context for rsvg render.");
+ content_broadcast_errorcode(c, NSERROR_NOMEM);
return false;
}
@@ -234,8 +238,12 @@ static bool rsvg_redraw(struct content *c, struct content_redraw_data *data,
if (data->repeat_y)
flags |= BITMAPF_REPEAT_Y;
- return ctx->plot->bitmap(data->x, data->y, data->width, data->height,
- rsvgcontent->bitmap, data->background_colour, flags);
+ return (ctx->plot->bitmap(ctx,
+ rsvgcontent->bitmap,
+ data->x, data->y,
+ data->width, data->height,
+ data->background_colour,
+ flags) == NSERROR_OK);
}
static void rsvg_destroy(struct content *c)