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