[Libdlo] SVG renderer
Phil Endecott
spam_from_libdlo at chezphil.org
Sun May 24 13:59:50 PDT 2009
All,
Here is a simple SVG renderer using librsvg. On Friday it was crashing
if I asked for
more than 189 lines of output and I assumed this was because I didn't
understand how to
use gobjects properly. I now know more than I ever wanted to know
about gobject reference
counting and resorted to valgrind, which pointed me to the same bit of
libdlo that Q has
just sent a patch for. Thanks Q! So this now works, with Q's buffer
overflow bug, and
my earlier patch to add claim_default_device().
BTW valgrind also reports lots of use of undefined data warnings which
I think are
probably because it doesn't know about the usb ioctls; does anyone know
anything about
this?
This works fine with my mimo; with my dongle I'm not sure what it's
supposed to do with
screen modes. I have a 1600x1200 DVI monitor and I don't think the
dongle supports that
(does it?). I would hope that the default initialisation would choose
the highest res
mode that it does support. Instead I seem to get a 0x0 mode. I can
then set 1024x768,
which works, but 1280x1024 (which should be supported, right?) fails
with "unsupported
mode parameters".
Here's the code; compile with something like:
gcc -o dlorsvg -I/usr/include/gtk-2.0 -I/usr/include/glib-2.0 -I/usr/lib/glib-2.0/include
-W -Wall -O dlorsvg.c -ldlo -lrsvg-2 -lgdk_pixbuf-2.0
#include <libdlo.h>
#include <librsvg-2/librsvg/rsvg.h>
#include <stdio.h>
static void check(dlo_retcode_t err)
{
if (err!=dlo_ok) {
fprintf(stderr,"DLO error: %s\n",dlo_strerror(err));
}
}
static void usage()
{
fprintf(stderr,"dlorsvg [--dlo:display <serial>] <image.svg>\n");
}
int main(int argc, char* argv[])
{
dlo_init_t dlo_init_flags;
check(dlo_init(dlo_init_flags));
dlo_claim_t dlo_claim_flags;
dlo_dev_t d = dlo_claim_default_device(&argc, argv, dlo_claim_flags, 0);
if (!d) {
fprintf(stderr,"no device found\n");
exit(1);
}
dlo_mode_t* mode = dlo_get_mode(d);
if (argc!=2) {
usage();
exit(1);
}
const char* fn = argv[1];
check(dlo_fill_rect(d,0,0,0));
rsvg_init();
GError* error = NULL;
GdkPixbuf* pixbuf = rsvg_pixbuf_from_file_at_size(fn,
mode->view.width,mode->view.height,
&error);
if (error) {
fprintf(stderr,"GError\n");
exit(1);
}
dlo_bmpflags_t bmpflags = { false };
dlo_fbuf_t fbuf = { gdk_pixbuf_get_width(pixbuf), gdk_pixbuf_get_height(pixbuf),
dlo_pixfmt_abgr8888, gdk_pixbuf_get_pixels(pixbuf),
gdk_pixbuf_get_rowstride(pixbuf)/4 };
dlo_dot_t origin = {0,0};
dlo_copy_host_bmp(d,bmpflags,&fbuf,NULL,&origin);
return 0;
}
More information about the Libdlo
mailing list