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