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