Graphviz 13.0.0~dev.20250121.0651
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 "config.h"
12#include <assert.h>
13#include <gvc/gvplugin_device.h>
14#include <gvc/gvio.h>
15#include <limits.h>
16#include <util/gv_math.h>
17#include <util/unreachable.h>
18#ifdef HAVE_PANGOCAIRO
19#include <gdk-pixbuf/gdk-pixbuf.h>
20
21typedef enum {
28
29static gboolean writer(const char *buf, gsize count, GError **error,
30 void *data) {
31 (void)error;
32 return count == gvwrite(data, buf, count);
33}
34
35static void gdk_format(GVJ_t * job)
36{
37 char *format_str = "";
38 GdkPixbuf *pixbuf;
39
40 switch (job->device.id) {
41 case FORMAT_BMP:
42 format_str = "bmp";
43 break;
44 case FORMAT_ICO:
45 format_str = "ico";
46 break;
47 case FORMAT_JPEG:
48 format_str = "jpeg";
49 break;
50 case FORMAT_PNG:
51 format_str = "png";
52 break;
53 case FORMAT_TIFF:
54 format_str = "tiff";
55 break;
56 default:
58 }
59
60 argb2rgba(job->width, job->height, job->imagedata);
61
62 assert(job->width <= INT_MAX / BYTES_PER_PIXEL && "width out of range");
63 assert(job->height <= INT_MAX && "height out of range");
64
65 pixbuf = gdk_pixbuf_new_from_data(
66 job->imagedata, // data
67 GDK_COLORSPACE_RGB, // colorspace
68 TRUE, // has_alpha
69 8, // bits_per_sample
70 (int)job->width, // width
71 (int)job->height, // height
72 BYTES_PER_PIXEL * (int)job->width, // rowstride
73 NULL, // destroy_fn
74 NULL // destroy_fn_data
75 );
76
77 gdk_pixbuf_save_to_callback(pixbuf, writer, job, format_str, NULL, NULL);
78
79 g_object_unref(pixbuf);
80}
81
82static gvdevice_engine_t gdk_engine = {
83 NULL, /* gdk_initialize */
84 gdk_format,
85 NULL, /* gdk_finalize */
86};
87
88static gvdevice_features_t device_features_gdk = {
90 | GVDEVICE_DOES_TRUECOLOR,/* flags */
91 {0.,0.}, /* default margin - points */
92 {0.,0.}, /* default page width, height - points */
93 {96.,96.}, /* dpi */
94};
95#endif
96
98#ifdef HAVE_PANGOCAIRO
99 {FORMAT_BMP, "bmp:cairo", 6, &gdk_engine, &device_features_gdk},
100 {FORMAT_ICO, "ico:cairo", 6, &gdk_engine, &device_features_gdk},
101 {FORMAT_JPEG, "jpe:cairo", 6, &gdk_engine, &device_features_gdk},
102 {FORMAT_JPEG, "jpeg:cairo", 6, &gdk_engine, &device_features_gdk},
103 {FORMAT_JPEG, "jpg:cairo", 6, &gdk_engine, &device_features_gdk},
104 {FORMAT_PNG, "png:cairo", 6, &gdk_engine, &device_features_gdk},
105 {FORMAT_TIFF, "tif:cairo", 6, &gdk_engine, &device_features_gdk},
106 {FORMAT_TIFF, "tiff:cairo", 6, &gdk_engine, &device_features_gdk},
107#endif
108 {0, NULL, 0, NULL, NULL}
109};
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:180
gvplugin_installed_t gvdevice_gdk_types[]
format_type
@ FORMAT_TIFF
@ FORMAT_BMP
@ FORMAT_ICO
@ FORMAT_JPEG
Definition gvrender_gd.c:37
@ FORMAT_PNG
Definition gvrender_gd.c:38
static cairo_status_t writer(void *closure, const unsigned char *data, unsigned int length)
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
#define UNREACHABLE()
Definition unreachable.h:30