26 #include "librsvg-2.0/librsvg/rsvg.h"
41 RsvgHandle *handle =
NULL;
42 RsvgDimensionData dimensions;
43 #if LIBRSVG_MAJOR_VERSION > 2 || LIBRSVG_MAJOR_VERSION == 2 && LIBRSVG_MINOR_VERSION >= 52
44 RsvgRectangle viewport = { 0 };
46 RsvgDimensionData unscaled_dimensions;
48 cairo_surface_t *image =
NULL;
49 cairo_t *crender =
NULL;
62 #if LIBRSVG_MAJOR_VERSION > 2 || LIBRSVG_MAJOR_VERSION == 2 && LIBRSVG_MINOR_VERSION >= 52
63 gret = rsvg_handle_get_intrinsic_size_in_pixels(handle, &viewport.width, &viewport.height);
65 viewport.width =
s->width ?
s->width : 100;
66 viewport.height =
s->height ?
s->height : 100;
68 dimensions.width = (
int)viewport.width;
69 dimensions.height = (
int)viewport.height;
71 rsvg_handle_get_dimensions(handle, &dimensions);
72 rsvg_handle_get_dimensions(handle, &unscaled_dimensions);
74 dimensions.width =
s->width ?
s->width : dimensions.width;
75 dimensions.height =
s->height ?
s->height : dimensions.height;
76 if (
s->keep_ar && (
s->width ||
s->height)) {
77 #if LIBRSVG_MAJOR_VERSION > 2 || LIBRSVG_MAJOR_VERSION == 2 && LIBRSVG_MINOR_VERSION >= 52
78 double default_ar = viewport.width / viewport.height;
80 double default_ar = unscaled_dimensions.width/(
double)unscaled_dimensions.height;
83 dimensions.width =
lrintf(dimensions.height * default_ar);
85 dimensions.height =
lrintf(dimensions.width / default_ar);
93 viewport.width = dimensions.width;
94 viewport.height = dimensions.height;
103 image = cairo_image_surface_create_for_data(
frame->
data[0], CAIRO_FORMAT_ARGB32,
106 if (cairo_surface_status(image) != CAIRO_STATUS_SUCCESS) {
111 crender = cairo_create(image);
114 cairo_set_operator(crender, CAIRO_OPERATOR_CLEAR);
115 cairo_paint(crender);
116 cairo_restore(crender);
118 #if LIBRSVG_MAJOR_VERSION > 2 || LIBRSVG_MAJOR_VERSION == 2 && LIBRSVG_MINOR_VERSION >= 52
119 gret = rsvg_handle_render_document(handle, crender, &viewport, &
error);
121 cairo_scale(crender, dimensions.width / (
double)unscaled_dimensions.width,
122 dimensions.height / (
double)unscaled_dimensions.height);
123 gret = rsvg_handle_render_cairo(handle, crender);
139 g_object_unref(handle);
141 cairo_destroy(crender);
143 cairo_surface_destroy(image);
148 #define OFFSET(x) offsetof(LibRSVGContext, x)
149 #define DEC (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_VIDEO_PARAM)
171 .p.wrapper_name =
"librsvg",