Graphviz 12.0.1~dev.20240716.0800
Loading...
Searching...
No Matches
gvdevice_devil.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#include <IL/il.h>
15#include <IL/ilu.h>
16
17static void
18Y_inv ( unsigned int width, unsigned int height, char *data)
19{
20 unsigned int x, y, *a, *b, t;
21
22 a = (unsigned int*)data;
23 b = a + (height-1) * width;
24 for (y = 0; y < height/2; y++) {
25 for (x = 0; x < width; x++) {
26 t = *a;
27 *a++ = *b;
28 *b++ = t;
29 }
30 b -= 2*width;
31 }
32}
33
34static void devil_format(GVJ_t * job)
35{
36 ILuint ImgId;
37
38 // Check if the shared lib's version matches the executable's version.
39 if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
40 iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION) {
41 fprintf(stderr, "DevIL version is different...exiting!\n");
42 }
43
44 // Initialize DevIL.
45 ilInit();
46
47 // Generate the main image name to use.
48 ilGenImages(1, &ImgId);
49
50 // Bind this image name.
51 ilBindImage(ImgId);
52
53 // cairo's in-memory image format needs inverting for DevIL
54 Y_inv ( job->width, job->height, job->imagedata );
55
56 // let the DevIL do its thing
57 (void)ilTexImage(job->width, job->height,
58 1, // Depth
59 4, // Bpp
60 IL_BGRA, // Format
61 IL_UNSIGNED_BYTE,// Type
62 job->imagedata);
63
64 // check the last step succeeded
65 ILenum Error = ilGetError();
66 if (Error == 0) {
67 // output to the provided open file handle
68 ilSaveF((ILenum)job->device.id, job->output_file);
69 } else {
70 fprintf(stderr, "Error: %s\n", iluErrorString(Error));
71 }
72
73 // We're done with the image, so delete it.
74 ilDeleteImages(1, &ImgId);
75
76 // Simple Error detection loop that displays the Error to the user in a human-readable form.
77 while ((Error = ilGetError())) {
78 fprintf(stderr, "Error: %s\n", iluErrorString(Error));
79 }
80}
81
83 NULL, /* devil_initialize */
85 NULL, /* devil_finalize */
86};
87
91 | GVDEVICE_DOES_TRUECOLOR,/* flags */
92 {0.,0.}, /* default margin - points */
93 {0.,0.}, /* default page width, height - points */
94 {96.,96.}, /* svg 72 dpi */
95};
96
98 {IL_BMP, "bmp:cairo", -1, &devil_engine, &device_features_devil},
99 {IL_JPG, "jpg:cairo", -1, &devil_engine, &device_features_devil},
100 {IL_JPG, "jpe:cairo", -1, &devil_engine, &device_features_devil},
101 {IL_JPG, "jpeg:cairo", -1, &devil_engine, &device_features_devil},
102 {IL_PNG, "png:cairo", -1, &devil_engine, &device_features_devil},
103 {IL_TIF, "tif:cairo", -1, &devil_engine, &device_features_devil},
104 {IL_TIF, "tiff:cairo", -1, &devil_engine, &device_features_devil},
105 {IL_TGA, "tga:cairo", -1, &devil_engine, &device_features_devil},
106 {0, NULL, 0, NULL, NULL}
107};
node NULL
Definition grammar.y:149
#define GVDEVICE_NO_WRITER
Definition gvcjob.h:93
#define GVDEVICE_DOES_TRUECOLOR
Definition gvcjob.h:90
#define GVDEVICE_BINARY_FORMAT
Definition gvcjob.h:91
static gvdevice_engine_t devil_engine
static void Y_inv(unsigned int width, unsigned int height, char *data)
static gvdevice_features_t device_features_devil
gvplugin_installed_t gvdevice_devil_types[]
static void devil_format(GVJ_t *job)
@ Error
Definition parse.h:20
char * imagedata
Definition gvcjob.h:297
gvplugin_active_device_t device
Definition gvcjob.h:286
FILE * output_file
Definition gvcjob.h:277
unsigned int width
Definition gvcjob.h:327
unsigned int height
Definition gvcjob.h:328
Definition legal.c:50
ingroup plugin_api
Definition gvplugin.h:35