Graphviz 13.0.0~dev.20241220.2304
Loading...
Searching...
No Matches
gvdevice_quartz.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
13#include <gvc/gvplugin_device.h>
14
15#include "gvplugin_quartz.h"
16#include <stdbool.h>
17
18#if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ >= 1040 && defined(HAVE_PANGOCAIRO)
19
20static const void *memory_data_consumer_get_byte_pointer(void *info)
21{
22 return info;
23}
24
25CGDataProviderDirectCallbacks memory_data_provider_callbacks = {
26 0,
27 memory_data_consumer_get_byte_pointer,
28 NULL,
29 NULL,
30 NULL
31};
32
33static void quartz_format(GVJ_t *job)
34{
35 /* image destination -> data consumer -> job's gvdevice */
36 /* data provider <- job's imagedata */
37 CGDataConsumerRef data_consumer = CGDataConsumerCreate(job, &device_data_consumer_callbacks);
38 CGImageDestinationRef image_destination =
39 CGImageDestinationCreateWithDataConsumer(data_consumer,
40 format_to_uti((format_type)job->device.id), 1, NULL);
41 CGDataProviderRef data_provider = CGDataProviderCreateDirect(job->imagedata, BYTES_PER_PIXEL * job->width * job->height, &memory_data_provider_callbacks);
42
43 /* add the bitmap image to the destination and save it */
44 CGColorSpaceRef color_space = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
45 CGImageRef image = CGImageCreate (
46 job->width, /* width in pixels */
47 job->height, /* height in pixels */
48 BITS_PER_COMPONENT, /* bits per component */
49 BYTES_PER_PIXEL * 8, /* bits per pixel */
50 BYTES_PER_PIXEL * job->width, /* bytes per row: exactly width # of pixels */
51 color_space, /* color space: sRGB */
52 kCGImageAlphaPremultipliedFirst|kCGBitmapByteOrder32Little, /* bitmap info: corresponds to CAIRO_FORMAT_ARGB32 */
53 data_provider, /* data provider: from imagedata */
54 NULL, /* decode: don't remap colors */
55 false, // don't interpolate
56 kCGRenderingIntentDefault /* rendering intent (what to do with out-of-gamut colors): default */
57 );
58 CGImageDestinationAddImage(image_destination, image, NULL);
59 CGImageDestinationFinalize(image_destination);
60
61 /* clean up */
62 CGImageRelease(image);
63 CGColorSpaceRelease(color_space);
64 CGDataProviderRelease(data_provider);
65 if (image_destination)
66 CFRelease(image_destination);
67 CGDataConsumerRelease(data_consumer);
68}
69
70static gvdevice_engine_t quartz_engine = {
71 NULL, /* quartz_initialize */
72 quartz_format,
73 NULL, /* quartz_finalize */
74};
75
76static gvdevice_features_t device_features_quartz = {
78 | GVDEVICE_DOES_TRUECOLOR,/* flags */
79 {0.,0.}, /* default margin - points */
80 {0.,0.}, /* default page width, height - points */
81 {96.,96.}, /* dpi */
82};
83
84gvplugin_installed_t gvdevice_quartz_types_for_cairo[] = {
85 {FORMAT_BMP, "bmp:cairo", 7, &quartz_engine, &device_features_quartz},
86 {FORMAT_GIF, "gif:cairo", 7, &quartz_engine, &device_features_quartz},
87 {FORMAT_EXR, "exr:cairo", 7, &quartz_engine, &device_features_quartz},
88 {FORMAT_ICNS, "icns:cairo", 7, &quartz_engine, &device_features_quartz},
89 {FORMAT_ICO, "ico:cairo", 7, &quartz_engine, &device_features_quartz},
90 {FORMAT_JPEG, "jpe:cairo", 7, &quartz_engine, &device_features_quartz},
91 {FORMAT_JPEG, "jpeg:cairo", 7, &quartz_engine, &device_features_quartz},
92 {FORMAT_JPEG, "jpg:cairo", 7, &quartz_engine, &device_features_quartz},
93 {FORMAT_JPEG2000, "jp2:cairo", 7, &quartz_engine, &device_features_quartz},
94 {FORMAT_PICT, "pct:cairo", 7, &quartz_engine, &device_features_quartz},
95 {FORMAT_PICT, "pict:cairo", 7, &quartz_engine, &device_features_quartz},
96 {FORMAT_PNG, "png:cairo", 7, &quartz_engine, &device_features_quartz},
97 {FORMAT_PSD, "psd:cairo", 7, &quartz_engine, &device_features_quartz},
98 {FORMAT_SGI, "sgi:cairo", 7, &quartz_engine, &device_features_quartz},
99 {FORMAT_TIFF, "tif:cairo", 7, &quartz_engine, &device_features_quartz},
100 {FORMAT_TIFF, "tiff:cairo", 7, &quartz_engine, &device_features_quartz},
101 {FORMAT_TGA, "tga:cairo", 7, &quartz_engine, &device_features_quartz},
102 {0, NULL, 0, NULL, NULL}
103};
104
105#endif
node NULL
Definition grammar.y:163
#define GVDEVICE_DOES_TRUECOLOR
Definition gvcjob.h:90
#define GVDEVICE_BINARY_FORMAT
Definition gvcjob.h:91
format_type
static const int BYTES_PER_PIXEL
@ FORMAT_TIFF
@ FORMAT_BMP
CGDataConsumerCallbacks device_data_consumer_callbacks
static const int BITS_PER_COMPONENT
@ FORMAT_ICO
@ FORMAT_PICT
@ FORMAT_EXR
@ FORMAT_JPEG2000
@ FORMAT_TGA
@ FORMAT_ICNS
@ FORMAT_PSD
@ FORMAT_SGI
@ FORMAT_JPEG
Definition gvrender_gd.c:37
@ FORMAT_GIF
Definition gvrender_gd.c:36
@ FORMAT_PNG
Definition gvrender_gd.c:38
T_cell image
Definition htmlparse.y:340
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
ingroup plugin_api
Definition gvplugin.h:35