Graphviz  2.41.20171026.1811
gvdevice_devil.c
Go to the documentation of this file.
1 /* $Id$ $Revision$ */
2 /* vim:set shiftwidth=4 ts=8: */
3 
4 /*************************************************************************
5  * Copyright (c) 2011 AT&T Intellectual Property
6  * All rights reserved. This program and the accompanying materials
7  * are made available under the terms of the Eclipse Public License v1.0
8  * which accompanies this distribution, and is available at
9  * http://www.eclipse.org/legal/epl-v10.html
10  *
11  * Contributors: See CVS logs. Details at http://www.graphviz.org/
12  *************************************************************************/
13 
14 #include "config.h"
15 
16 #include "gvplugin_device.h"
17 #include <IL/il.h>
18 #include <IL/ilu.h>
19 
20 static void
21 Y_inv ( unsigned int width, unsigned int height, char *data)
22 {
23  unsigned int x, y, *a, *b, t;
24 
25  a = (unsigned int*)data;
26  b = a + (height-1) * width;
27  for (y = 0; y < height/2; y++) {
28  for (x = 0; x < width; x++) {
29  t = *a;
30  *a++ = *b;
31  *b++ = t;
32  }
33  b -= 2*width;
34  }
35 }
36 
37 static void devil_format(GVJ_t * job)
38 {
39  ILuint ImgId;
40  ILenum Error;
41  ILboolean rc;
42 
43  // Check if the shared lib's version matches the executable's version.
44  if (ilGetInteger(IL_VERSION_NUM) < IL_VERSION ||
45  iluGetInteger(ILU_VERSION_NUM) < ILU_VERSION) {
46  fprintf(stderr, "DevIL version is different...exiting!\n");
47  }
48 
49  // Initialize DevIL.
50  ilInit();
51 
52  // Generate the main image name to use.
53  ilGenImages(1, &ImgId);
54 
55  // Bind this image name.
56  ilBindImage(ImgId);
57 
58  // cairo's inmemory image format needs inverting for DevIL
59  Y_inv ( job->width, job->height, job->imagedata );
60 
61  // let the DevIL do its thing
62  rc = ilTexImage( job->width, job->height,
63  1, // Depth
64  4, // Bpp
65  IL_BGRA, // Format
66  IL_UNSIGNED_BYTE,// Type
67  job->imagedata);
68 
69  // output to the provided open file handle
70  ilSaveF(job->device.id, job->output_file);
71 
72  // We're done with the image, so delete it.
73  ilDeleteImages(1, &ImgId);
74 
75  // Simple Error detection loop that displays the Error to the user in a human-readable form.
76  while ((Error = ilGetError())) {
77  fprintf(stderr, "Error: %s\n", iluErrorString(Error));
78  }
79 }
80 
81 static gvdevice_engine_t devil_engine = {
82  NULL, /* devil_initialize */
83  devil_format,
84  NULL, /* devil_finalize */
85 };
86 
87 static gvdevice_features_t device_features_devil = {
90  | GVDEVICE_DOES_TRUECOLOR,/* flags */
91  {0.,0.}, /* default margin - points */
92  {0.,0.}, /* default page width, height - points */
93  {96.,96.}, /* svg 72 dpi */
94 };
95 
97  {IL_BMP, "bmp:cairo", -1, &devil_engine, &device_features_devil},
98  {IL_JPG, "jpg:cairo", -1, &devil_engine, &device_features_devil},
99  {IL_JPG, "jpe:cairo", -1, &devil_engine, &device_features_devil},
100  {IL_JPG, "jpeg:cairo", -1, &devil_engine, &device_features_devil},
101  {IL_PNG, "png:cairo", -1, &devil_engine, &device_features_devil},
102  {IL_TIF, "tif:cairo", -1, &devil_engine, &device_features_devil},
103  {IL_TIF, "tiff:cairo", -1, &devil_engine, &device_features_devil},
104  {IL_TGA, "tga:cairo", -1, &devil_engine, &device_features_devil},
105  {0, NULL, 0, NULL, NULL}
106 };
char * imagedata
Definition: gvcjob.h:306
#define GVDEVICE_BINARY_FORMAT
Definition: gvcjob.h:93
unsigned int width
Definition: gvcjob.h:336
Definition: gvcjob.h:271
gvplugin_active_device_t device
Definition: gvcjob.h:295
#define GVDEVICE_NO_WRITER
Definition: gvcjob.h:95
gvplugin_installed_t gvdevice_devil_types[]
#define NULL
Definition: logic.h:39
FILE * output_file
Definition: gvcjob.h:286
unsigned int height
Definition: gvcjob.h:337
Definition: legal.c:60
#define GVDEVICE_DOES_TRUECOLOR
Definition: gvcjob.h:92