Graphviz 13.0.0~dev.20250607.1528
Loading...
Searching...
No Matches
gvdevice_gdk.c
Go to the documentation of this file.
1/*************************************************************************
2 * Copyright (c) 2011 AT&T Intellectual Property
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * https://www.eclipse.org/legal/epl-v10.html
7 *
8 * Contributors: Details at https://graphviz.org
9 *************************************************************************/
10
11#include <assert.h>
12#include <gvc/gvplugin_device.h>
13#include <gvc/gvio.h>
14#include <limits.h>
15#include <util/gv_math.h>
16#include <gdk-pixbuf/gdk-pixbuf.h>
17#include <util/agxbuf.h>
18
19enum {
25};
26
27static gboolean writer(const char *buf, gsize count, GError **error,
28 void *data) {
29 (void)error;
30 return count == gvwrite(data, buf, count);
31}
32
33static void gdk_format(GVJ_t * job)
34{
35 char *const format_strs[] = {
36 [FORMAT_BMP] = "bmp",
37 [FORMAT_ICO] = "ico",
38 [FORMAT_JPEG] = "jpeg",
39 [FORMAT_PNG] = "png",
40 [FORMAT_TIFF] = "tiff"
41 };
42 assert(job->device.id >= 0);
43 assert(job->device.id < (int)(sizeof(format_strs) / sizeof(format_strs[0])));
44 char *const format_str = format_strs[job->device.id];
45 GdkPixbuf *pixbuf;
46
47 argb2rgba(job->width, job->height, job->imagedata);
48
49 assert(job->width <= INT_MAX / BYTES_PER_PIXEL && "width out of range");
50 assert(job->height <= INT_MAX && "height out of range");
51
52 pixbuf = gdk_pixbuf_new_from_data(
53 job->imagedata, // data
54 GDK_COLORSPACE_RGB, // colorspace
55 TRUE, // has_alpha
56 8, // bits_per_sample
57 (int)job->width, // width
58 (int)job->height, // height
59 BYTES_PER_PIXEL * (int)job->width, // rowstride
60 NULL, // destroy_fn
61 NULL // destroy_fn_data
62 );
63
64 agxbuf x_dpi = {0};
65 agxbprint(&x_dpi, "%.0f", job->dpi.x);
66 agxbuf y_dpi = {0};
67 agxbprint(&y_dpi, "%.0f", job->dpi.y);
68
69 gdk_pixbuf_save_to_callback(pixbuf, writer, job, format_str, NULL, "x-dpi",
70 agxbuse(&x_dpi), "y-dpi", agxbuse(&y_dpi),
71 NULL);
72
73 agxbfree(&y_dpi);
74 agxbfree(&x_dpi);
75 g_object_unref(pixbuf);
76}
77
79 NULL, /* gdk_initialize */
81 NULL, /* gdk_finalize */
82};
83
86 | GVDEVICE_DOES_TRUECOLOR,/* flags */
87 {0.,0.}, /* default margin - points */
88 {0.,0.}, /* default page width, height - points */
89 {96.,96.}, /* dpi */
90};
91
93 {FORMAT_BMP, "bmp:cairo", 6, &gdk_engine, &device_features_gdk},
94 {FORMAT_ICO, "ico:cairo", 6, &gdk_engine, &device_features_gdk},
95 {FORMAT_JPEG, "jpe:cairo", 6, &gdk_engine, &device_features_gdk},
96 {FORMAT_JPEG, "jpeg:cairo", 6, &gdk_engine, &device_features_gdk},
97 {FORMAT_JPEG, "jpg:cairo", 6, &gdk_engine, &device_features_gdk},
98 {FORMAT_PNG, "png:cairo", 6, &gdk_engine, &device_features_gdk},
99 {FORMAT_TIFF, "tif:cairo", 6, &gdk_engine, &device_features_gdk},
100 {FORMAT_TIFF, "tiff:cairo", 6, &gdk_engine, &device_features_gdk},
101 {0, NULL, 0, NULL, NULL}
102};
static void agxbfree(agxbuf *xb)
free any malloced resources
Definition agxbuf.h:78
static int agxbprint(agxbuf *xb, const char *fmt,...)
Printf-style output to an agxbuf.
Definition agxbuf.h:234
static WUR char * agxbuse(agxbuf *xb)
Definition agxbuf.h:307
node NULL
Definition grammar.y:180
Arithmetic helper functions.
@ BYTES_PER_PIXEL
Definition gv_math.h:88
static void argb2rgba(size_t width, size_t height, unsigned char *data)
Definition gv_math.h:106
#define GVDEVICE_DOES_TRUECOLOR
Definition gvcjob.h:90
#define GVDEVICE_BINARY_FORMAT
Definition gvcjob.h:91
size_t gvwrite(GVJ_t *job, const char *s, size_t len)
Definition gvdevice.c:182
static gvdevice_engine_t gdk_engine
static gvdevice_features_t device_features_gdk
@ FORMAT_ICO
@ FORMAT_JPEG
@ FORMAT_TIFF
@ FORMAT_BMP
@ FORMAT_PNG
gvplugin_installed_t gvdevice_gdk_types[]
static gboolean writer(const char *buf, gsize count, GError **error, void *data)
static void gdk_format(GVJ_t *job)
table Syntax error
Definition htmlparse.y:294
pointf dpi
Definition gvcjob.h:325
gvplugin_active_device_t device
Definition gvcjob.h:286
unsigned char * imagedata
location of imagedata
Definition gvcjob.h:297
unsigned int width
Definition gvcjob.h:327
unsigned int height
Definition gvcjob.h:328
Definition legal.c:50
ingroup plugin_api
Definition gvplugin.h:35
double x
Definition geom.h:29
double y
Definition geom.h:29