Graphviz 13.0.0~dev.20250424.1043
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 /* add the bitmap image to the destination and save it */
46 CGColorSpaceRef color_space = CGColorSpaceCreateWithName(kCGColorSpaceSRGB);
47 CGImageRef image = CGImageCreate (
48 job->width, /* width in pixels */
49 job->height, /* height in pixels */
50 BITS_PER_COMPONENT, /* bits per component */
51 BYTES_PER_PIXEL * 8, /* bits per pixel */
52 BYTES_PER_PIXEL * job->width, /* bytes per row: exactly width # of pixels */
53 color_space, /* color space: sRGB */
54 kCGImageAlphaPremultipliedFirst|kCGBitmapByteOrder32Little, /* bitmap info: corresponds to CAIRO_FORMAT_ARGB32 */
55 data_provider, /* data provider: from imagedata */
56 NULL, /* decode: don't remap colors */
57 false, // don't interpolate
58 kCGRenderingIntentDefault /* rendering intent (what to do with out-of-gamut colors): default */
59 );
60 CGImageDestinationAddImage(image_destination, image, NULL);
61 CGImageDestinationFinalize(image_destination);
62
63 /* clean up */
64 CGImageRelease(image);
65 CGColorSpaceRelease(color_space);
66 CGDataProviderRelease(data_provider);
67 if (image_destination)
68 CFRelease(image_destination);
69 CGDataConsumerRelease(data_consumer);
70}
71
72static gvdevice_engine_t quartz_engine = {
73 NULL, /* quartz_initialize */
74 quartz_format,
75 NULL, /* quartz_finalize */
76};
77
80 | GVDEVICE_DOES_TRUECOLOR,/* flags */
81 {0.,0.}, /* default margin - points */
82 {0.,0.}, /* default page width, height - points */
83 {96.,96.}, /* dpi */
84};
85
87 {FORMAT_BMP, "bmp:cairo", 7, &quartz_engine, &device_features_quartz},
88 {FORMAT_GIF, "gif:cairo", 7, &quartz_engine, &device_features_quartz},
89 {FORMAT_EXR, "exr:cairo", 7, &quartz_engine, &device_features_quartz},
90 {FORMAT_ICNS, "icns:cairo", 7, &quartz_engine, &device_features_quartz},
91 {FORMAT_ICO, "ico:cairo", 7, &quartz_engine, &device_features_quartz},
92 {FORMAT_JPEG, "jpe:cairo", 7, &quartz_engine, &device_features_quartz},
93 {FORMAT_JPEG, "jpeg:cairo", 7, &quartz_engine, &device_features_quartz},
94 {FORMAT_JPEG, "jpg:cairo", 7, &quartz_engine, &device_features_quartz},
95 {FORMAT_JPEG2000, "jp2:cairo", 7, &quartz_engine, &device_features_quartz},
96 {FORMAT_PICT, "pct:cairo", 7, &quartz_engine, &device_features_quartz},
97 {FORMAT_PICT, "pict:cairo", 7, &quartz_engine, &device_features_quartz},
98 {FORMAT_PNG, "png:cairo", 7, &quartz_engine, &device_features_quartz},
99 {FORMAT_PSD, "psd:cairo", 7, &quartz_engine, &device_features_quartz},
100 {FORMAT_SGI, "sgi:cairo", 7, &quartz_engine, &device_features_quartz},
101 {FORMAT_TIFF, "tif:cairo", 7, &quartz_engine, &device_features_quartz},
102 {FORMAT_TIFF, "tiff:cairo", 7, &quartz_engine, &device_features_quartz},
103 {FORMAT_TGA, "tga:cairo", 7, &quartz_engine, &device_features_quartz},
104 {0, NULL, 0, NULL, NULL}
105};
106
107#endif
node NULL
Definition grammar.y:163
Arithmetic helper functions.
@ BYTES_PER_PIXEL
Definition gv_math.h:87
#define GVDEVICE_DOES_TRUECOLOR
Definition gvcjob.h:90
#define GVDEVICE_BINARY_FORMAT
Definition gvcjob.h:91
@ 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_ICO
@ 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
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