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