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