Graphviz 13.0.0~dev.20250511.0440
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
18enum {
24};
25
26static gboolean writer(const char *buf, gsize count, GError **error,
27 void *data) {
28 (void)error;
29 return count == gvwrite(data, buf, count);
30}
31
32static void gdk_format(GVJ_t * job)
33{
34 char *const format_strs[] = {
35 [FORMAT_BMP] = "bmp",
36 [FORMAT_ICO] = "ico",
37 [FORMAT_JPEG] = "jpeg",
38 [FORMAT_PNG] = "png",
39 [FORMAT_TIFF] = "tiff"
40 };
41 assert(job->device.id >= 0);
42 assert(job->device.id < sizeof(format_strs) / sizeof(format_strs[0]));
43 char *const format_str = format_strs[job->device.id];
44 GdkPixbuf *pixbuf;
45
46 argb2rgba(job->width, job->height, job->imagedata);
47
48 assert(job->width <= INT_MAX / BYTES_PER_PIXEL && "width out of range");
49 assert(job->height <= INT_MAX && "height out of range");
50
51 pixbuf = gdk_pixbuf_new_from_data(
52 job->imagedata, // data
53 GDK_COLORSPACE_RGB, // colorspace
54 TRUE, // has_alpha
55 8, // bits_per_sample
56 (int)job->width, // width
57 (int)job->height, // height
58 BYTES_PER_PIXEL * (int)job->width, // rowstride
59 NULL, // destroy_fn
60 NULL // destroy_fn_data
61 );
62
63 gdk_pixbuf_save_to_callback(pixbuf, writer, job, format_str, NULL, NULL);
64
65 g_object_unref(pixbuf);
66}
67
69 NULL, /* gdk_initialize */
71 NULL, /* gdk_finalize */
72};
73
76 | GVDEVICE_DOES_TRUECOLOR,/* flags */
77 {0.,0.}, /* default margin - points */
78 {0.,0.}, /* default page width, height - points */
79 {96.,96.}, /* dpi */
80};
81
83 {FORMAT_BMP, "bmp:cairo", 6, &gdk_engine, &device_features_gdk},
84 {FORMAT_ICO, "ico:cairo", 6, &gdk_engine, &device_features_gdk},
85 {FORMAT_JPEG, "jpe:cairo", 6, &gdk_engine, &device_features_gdk},
86 {FORMAT_JPEG, "jpeg:cairo", 6, &gdk_engine, &device_features_gdk},
87 {FORMAT_JPEG, "jpg:cairo", 6, &gdk_engine, &device_features_gdk},
88 {FORMAT_PNG, "png:cairo", 6, &gdk_engine, &device_features_gdk},
89 {FORMAT_TIFF, "tif:cairo", 6, &gdk_engine, &device_features_gdk},
90 {FORMAT_TIFF, "tiff:cairo", 6, &gdk_engine, &device_features_gdk},
91 {0, NULL, 0, NULL, NULL}
92};
node NULL
Definition grammar.y:163
Arithmetic helper functions.
@ BYTES_PER_PIXEL
Definition gv_math.h:87
static void argb2rgba(size_t width, size_t height, unsigned char *data)
Definition gv_math.h:105
#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
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)
@ FORMAT_ICO
@ FORMAT_JPEG
@ FORMAT_TIFF
@ FORMAT_BMP
@ FORMAT_PNG
table Syntax error
Definition htmlparse.y:294
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