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.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/content/handlers/image/rsvg.c b/content/handlers/image/rsvg.c
index 0665f217f..2ba1b49f5 100644
--- a/content/handlers/image/rsvg.c
+++ b/content/handlers/image/rsvg.c
@@ -39,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"
@@ -62,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;
}
@@ -115,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;
}
@@ -143,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;
@@ -161,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;
}
@@ -184,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;
}
@@ -195,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;
}