]> granicus.if.org Git - graphviz/commitdiff
Merge formatter and device plugin apis.
authorellson <devnull@localhost>
Wed, 29 Aug 2007 19:39:49 +0000 (19:39 +0000)
committerellson <devnull@localhost>
Wed, 29 Aug 2007 19:39:49 +0000 (19:39 +0000)
Selecting device by format, e.g. -Tsvgz, or -Tpng:cairo:gd
Automatically load correct renderer, e.g. cairo, gd, core_dot
Improve plugin listings.
Accurately reflecte available formats.

plugin/gd/Makefile.am
plugin/gd/gvdevice_gd.c [new file with mode: 0644]
plugin/gd/gvplugin_gd.c
plugin/gd/gvrender_gd.c
plugin/gd/gvrender_gd_vrml.c
plugin/gdk_pixbuf/Makefile.am
plugin/gdk_pixbuf/gvdevice_gdk_pixbuf.c [new file with mode: 0644]

index a68074129b15e5ec07c50dd4be67fd475b4443ae..d41ee2d24b5d49b5863ead9e0d096e305a151a29 100644 (file)
@@ -20,7 +20,7 @@ libgvplugin_gd_C_la_SOURCES = \
        gvrender_gd_vrml.c \
        gvtextlayout_gd.c \
        gvloadimage_gd.c \
-       gvformatter_gd.c
+       gvdevice_gd.c
 
 libgvplugin_gd_la_LDFLAGS = -version-info @VERSION_INFO@ --no-undefined
 libgvplugin_gd_la_SOURCES = $(libgvplugin_gd_C_la_SOURCES)
diff --git a/plugin/gd/gvdevice_gd.c b/plugin/gd/gvdevice_gd.c
new file mode 100644 (file)
index 0000000..8d87619
--- /dev/null
@@ -0,0 +1,179 @@
+/* $Id$ $Revision$ */
+/* vim:set shiftwidth=4 ts=8: */
+
+/**********************************************************
+*      This software is part of the graphviz package      *
+*                http://www.graphviz.org/                 *
+*                                                         *
+*            Copyright (c) 1994-2004 AT&T Corp.           *
+*                and is licensed under the                *
+*            Common Public License, Version 1.0           *
+*                      by AT&T Corp.                      *
+*                                                         *
+*        Information and Software Systems Research        *
+*              AT&T Research, Florham Park NJ             *
+**********************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef WIN32
+#include <fcntl.h>
+#include <io.h>
+#endif
+#include <stdlib.h>
+#include "gvplugin_device.h"
+
+#ifdef HAVE_LIBGD
+#include "gd.h"
+
+typedef enum {
+       FORMAT_GIF,
+       FORMAT_JPEG,
+       FORMAT_PNG,
+       FORMAT_WBMP,
+       FORMAT_GD,
+       FORMAT_GD2,
+       FORMAT_XBM,
+} format_type;
+
+static void gd_format(GVJ_t * job, unsigned int width, unsigned int height, unsigned char *data)
+{
+    gdImagePtr im;
+    unsigned int x, y, *intdata, color, alpha;
+
+#ifdef HAVE_SETMODE
+#ifdef O_BINARY
+    /*
+     * Windows will do \n -> \r\n  translations on stdout
+     * unless told otherwise.
+     */
+    setmode(fileno(job->output_file), O_BINARY);
+#endif
+#endif
+
+    intdata = (unsigned int*)data;
+    im = gdImageCreateTrueColor(width, height);
+    for (y = 0; y < height; y++) {
+        for (x = 0; x < width; x++) {
+           color = *intdata++;
+           /* gd's max alpha is 127 */
+           if ((alpha = (color >> 25) & 0x7f))
+               /* gd's alpha is transparency instead of opacity */
+               color = (color & 0xffffff) | ((127 - alpha) << 24);
+           else
+               color = im->transparent;
+           gdImageSetPixel (im, x, y, color);
+       }
+    }
+
+    switch (job->device.id) {
+#ifdef HAVE_GD_GIF
+    case FORMAT_GIF:
+       gdImageTrueColorToPalette(im, 0, 256);
+       gdImageGif(im, job->output_file);
+        break;
+#endif
+
+#ifdef HAVE_GD_JPEG
+    case FORMAT_JPEG:
+       /*
+        * Write IM to OUTFILE as a JFIF-formatted JPEG image, using
+        * quality JPEG_QUALITY.  If JPEG_QUALITY is in the range
+        * 0-100, increasing values represent higher quality but also
+        * larger image size.  If JPEG_QUALITY is negative, the
+        * IJG JPEG library's default quality is used (which should
+        * be near optimal for many applications).  See the IJG JPEG
+        * library documentation for more details.
+        */ 
+#define JPEG_QUALITY -1
+       gdImageJpeg(im, job->output_file, JPEG_QUALITY);
+       break;
+#endif
+
+#ifdef HAVE_GD_PNG
+    case FORMAT_PNG:
+       gdImagePng(im, job->output_file);
+        break;
+#endif
+
+#if 0
+    case FORMAT_GD:
+       gdImageGd(im, job->output_file);
+       break;
+
+    case FORMAT_GD2:
+#define GD2_CHUNKSIZE 128
+#define GD2_RAW 1
+#define GD2_COMPRESSED 2
+       gdImageGd2(im, job->output_file, GD2_CHUNKSIZE, GD2_COMPRESSED);
+       break;
+
+#ifdef HAVE_GD_GIF
+    case FORMAT_WBMP:
+       /* Use black for the foreground color for the B&W wbmp image. */
+//FIXME - black not defined - is it really needed? 
+       gdImageWBMP(im, black, job->output_file);
+       break;
+#endif
+
+#ifdef HAVE_GD_XPM
+    case FORMAT_XBM:
+       gdImageXbm(im, job->output_file);
+#endif
+
+#endif
+       break;
+    default:
+       break;
+    }
+
+    gdImageDestroy(im);
+}
+
+static gvdevice_engine_t gd_engine = {
+    NULL,
+    gd_format,
+    NULL,
+};
+
+static gvdevice_features_t gd_features = {
+    0,  /* flags */
+};
+
+#endif
+
+gvplugin_installed_t gvdevice_gd_types[] = {
+#ifdef HAVE_LIBGD
+
+#ifdef HAVE_GD_GIF
+    {FORMAT_GIF, "gif:cairo", 10, &gd_engine, &gd_features},
+#endif
+
+#ifdef HAVE_GD_JPEG
+    {FORMAT_JPEG, "jpe:cairo", 5, &gd_engine, &gd_features},
+    {FORMAT_JPEG, "jpeg:cairo", 5, &gd_engine, &gd_features},
+    {FORMAT_JPEG, "jpg:cairo", 5, &gd_engine, &gd_features},
+#endif
+
+#ifdef HAVE_GD_PNG
+    {FORMAT_PNG, "png:cairo", -1, &gd_engine, &gd_features},
+#endif
+
+#if 0
+    {FORMAT_GD, "gd:cairo", -1, &gd_engine, &gd_features},
+    {FORMAT_GD2, "gd2:cairo", -1, &gd_engine, &gd_features},
+
+#ifdef HAVE_GD_GIF
+    {FORMAT_WBMP, "wbmp:cairo", -1, &gd_engine, &gd_features},
+#endif
+
+#ifdef HAVE_GD_XPM
+    {FORMAT_XBM, "xbm:cairo", -1, &gd_engine, &gd_features},
+#endif
+#endif
+
+#endif
+    {0, NULL, 0, NULL, NULL}
+};
index 430672438cc409e4117f3060a80ac79d78eb0f5a..310b3e7bb5390ae0d6a69f50ce43fbb080fdb98a 100644 (file)
@@ -20,14 +20,16 @@ extern gvplugin_installed_t gvrender_gd_types;
 extern gvplugin_installed_t gvrender_vrml_types;
 extern gvplugin_installed_t gvtextlayout_gd_types;
 extern gvplugin_installed_t gvloadimage_gd_types;
-extern gvplugin_installed_t gvformatter_gd_types;
+extern gvplugin_installed_t gvdevice_gd_types;
+extern gvplugin_installed_t gvdevice_gd_types2;
 
 static gvplugin_api_t apis[] = {
     {API_render, &gvrender_gd_types},
     {API_render, &gvrender_vrml_types},
     {API_textlayout, &gvtextlayout_gd_types},
     {API_loadimage, &gvloadimage_gd_types},
-    {API_formatter, &gvformatter_gd_types},
+    {API_device, &gvdevice_gd_types},
+    {API_device, &gvdevice_gd_types2},
     {(api_t)0, 0},
 };
 
index dad2cbca9566e2b31812e79eb0beae56066174d0..2e3f8f4511df76916845aa20a101dabc31d52b02 100644 (file)
@@ -27,6 +27,7 @@
 #include <fcntl.h>
 
 #include "gvplugin_render.h"
+#include "gvplugin_device.h"
 #include "graph.h"     /* for agget  for truecolor test */
 #include "gvcint.h"    /* for gvc->g for agget */
 
@@ -38,11 +39,9 @@ typedef enum {
        FORMAT_JPEG,
        FORMAT_PNG,
        FORMAT_WBMP,
-#if 0
        FORMAT_GD,
        FORMAT_GD2,
        FORMAT_XBM,
-#endif
 } format_type;
 
 extern boolean mapbool(char *);
@@ -82,7 +81,6 @@ static void gdgen_begin_page(GVJ_t * job)
     boolean bg_transparent_p = FALSE;
     gdImagePtr im = NULL;
 
-
     truecolor_str = agget((graph_t*)(job->gvc->g), "truecolor");       /* allow user to force truecolor */
     bgcolor_str = agget((graph_t*)(job->gvc->g), "bgcolor");
 
@@ -198,11 +196,12 @@ static void gdgen_end_page(GVJ_t * job)
            gdImagePng(im, job->output_file);
 #endif
            break;
+
+#if 0
        case FORMAT_WBMP:
            /* Use black for the foreground color for the B&W wbmp image. */
            gdImageWBMP(im, black, job->output_file);
            break;
-#if 0
        case FORMAT_GD:
            gdImageGd(im, job->output_file);
            break;
@@ -594,9 +593,7 @@ static gvrender_features_t gdgen_features_tc = {
     NULL,                      /* knowncolors */
     0,                         /* sizeof knowncolors */
     RGBA_BYTE,                 /* color_type */
-    NULL,                      /* device */
     "gd",                      /* imageloader for usershapes */
-    NULL,                      /* formatter */
 };
 
 static gvrender_features_t gdgen_features = {
@@ -608,33 +605,43 @@ static gvrender_features_t gdgen_features = {
     NULL,                      /* knowncolors */
     0,                         /* sizeof knowncolors */
     RGBA_BYTE,                 /* color_type */
-    NULL,                      /* device */
     "gd",                      /* imageloader for usershapes */
-    NULL,                      /* formatter */
 };
 
 #endif
 
 gvplugin_installed_t gvrender_gd_types[] = {
+#ifdef HAVE_LIBGD
+    {FORMAT_GD, "gd", 1, &gdgen_engine, &gdgen_features},
+#endif
+    {0, NULL, 0, NULL, NULL}
+};
+
+gvplugin_installed_t gvdevice_gd_types2[] = {
 #ifdef HAVE_LIBGD
 #ifdef HAVE_GD_GIF
-    {FORMAT_GIF, "gif", 1, &gdgen_engine, &gdgen_features},
+    {FORMAT_GIF, "gif:gd", 1, NULL, &gdgen_features},
 #endif
 #ifdef HAVE_GD_JPEG
-    {FORMAT_JPEG, "jpg", 1, &gdgen_engine, &gdgen_features_tc},
-    {FORMAT_JPEG, "jpeg", 1, &gdgen_engine, &gdgen_features_tc},
+    {FORMAT_JPEG, "jpe:gd", 1, NULL, &gdgen_features_tc},
+    {FORMAT_JPEG, "jpeg:gd", 1, NULL, &gdgen_features_tc},
+    {FORMAT_JPEG, "jpg:gd", 1, NULL, &gdgen_features_tc},
 #endif
 #ifdef HAVE_GD_PNG
-    {FORMAT_PNG, "png", 1, &gdgen_engine, &gdgen_features_tc},
+    {FORMAT_PNG, "png:gd", 1, NULL, &gdgen_features_tc},
 #endif
-    {FORMAT_WBMP, "wbmp", 1, &gdgen_engine, &gdgen_features},
+
 #if 0
-    {FORMAT_GD, "gd", 1, &gdgen_engine, &gdgen_features_tc},
-    {FORMAT_GD2, "gd2", 1, &gdgen_engine, &gdgen_features_tc},
+    {FORMAT_GD, "gd:gd", 1, NULL, &gdgen_features_tc},
+    {FORMAT_GD2, "gd2:gd", 1, NULL, &gdgen_features_tc},
+#ifdef HAVE_GD_GIF
+    {FORMAT_WBMP, "wbmp:gd", 1, NULL, &gdgen_features},
+#endif
 #ifdef HAVE_GD_XPM
-    {FORMAT_XBM, "xbm", 1, &gdgen_engine, &gdgen_features},
+    {FORMAT_XBM, "xbm:gd", 1, NULL, &gdgen_features},
 #endif
 #endif
+
 #endif
     {0, NULL, 0, NULL, NULL}
 };
index 1a0ab442cd56862027785af5ae005f915146f302..e4f8a1dc0bd784e56ae0aa563de3e458ac4e2424 100644 (file)
@@ -844,9 +844,7 @@ static gvrender_features_t vrml_features = {
     NULL,                       /* knowncolors */
     0,                          /* sizeof knowncolors */
     RGBA_BYTE,                  /* color_type */
-    NULL,                       /* device */
     "vrml",                     /* imageloader for usershapes */
-    NULL,                       /* formatter */
 };
 #endif                         /* HAVE_GD_PNG */
 #endif                         /* HAVE_LIBGD */
index 37f02053708f657ee11cdb9249b14898e2bc5508..5dd9fd75e08ddca7ea43fd732d99df5fb66b7f3a 100644 (file)
@@ -17,7 +17,7 @@ endif
 
 libgvplugin_gdk_pixbuf_C_la_SOURCES = \
        gvplugin_gdk_pixbuf.c \
-       gvformatter_gdk_pixbuf.c
+       gvdevice_gdk_pixbuf.c
 
 libgvplugin_gdk_pixbuf_la_LDFLAGS = -version-info @VERSION_INFO@ -no-undefined
 libgvplugin_gdk_pixbuf_la_SOURCES = $(libgvplugin_gdk_pixbuf_C_la_SOURCES)
diff --git a/plugin/gdk_pixbuf/gvdevice_gdk_pixbuf.c b/plugin/gdk_pixbuf/gvdevice_gdk_pixbuf.c
new file mode 100644 (file)
index 0000000..10748d3
--- /dev/null
@@ -0,0 +1,152 @@
+/* $Id$ $Revision$ */
+/* vim:set shiftwidth=4 ts=8: */
+
+/**********************************************************
+*      This software is part of the graphviz package      *
+*                http://www.graphviz.org/                 *
+*                                                         *
+*            Copyright (c) 1994-2004 AT&T Corp.           *
+*                and is licensed under the                *
+*            Common Public License, Version 1.0           *
+*                      by AT&T Corp.                      *
+*                                                         *
+*        Information and Software Systems Research        *
+*              AT&T Research, Florham Park NJ             *
+**********************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef WIN32
+#include <io.h>
+#include <fcntl.h>
+#endif
+#include "gvplugin_device.h"
+#include <gdk-pixbuf/gdk-pixbuf.h>
+
+typedef enum {
+       FORMAT_BMP,
+       FORMAT_ICO,
+       FORMAT_JPEG,
+       FORMAT_PNG,
+       FORMAT_TIFF,
+    } format_type;
+
+/* 
+ * Does an in-place conversion of a CAIRO ARGB32 image to GDK RGBA
+ */
+static void
+argb2rgba ( unsigned int width, unsigned int height, unsigned char *data)
+{
+    unsigned int x, y;
+    unsigned char r, g, b, a;
+
+#define Ra 2
+#define Ga 1
+#define Ba 0
+#define Aa 3
+
+#define Rb 0
+#define Gb 1
+#define Bb 2
+#define Ab 3
+
+    for (y = 0; y < height; y++) {
+        for (x = 0; x < width; x++) {
+            r = data[Ra];
+            g = data[Ga];
+            b = data[Ba];
+            a = data[Aa];
+
+            data[Rb] = r;
+            data[Gb] = g;
+            data[Bb] = b;
+            data[Ab] = a;
+
+            data += 4;
+        }
+    }
+}
+
+static gboolean
+writer ( const gchar *buf, gsize count, GError **error, gpointer data)
+{
+    error = NULL;
+    if (count == fwrite(buf, 1, count, (FILE *)data))
+        return TRUE;
+    return FALSE;
+}
+
+static void gdk_pixbuf_formatter(GVJ_t * job, unsigned int width, unsigned int height, unsigned char *data)
+{
+    char *format_str = "";
+    GdkPixbuf *pixbuf;
+
+#ifdef HAVE_SETMODE
+#ifdef O_BINARY
+    /*
+     * Windows will do \n -> \r\n  translations on stdout
+     * unless told otherwise.
+     */
+    setmode(fileno(job->output_file), O_BINARY);
+#endif
+#endif
+    switch (job->device.id) {
+    case FORMAT_BMP:
+       format_str = "bmp";
+       break;
+    case FORMAT_ICO:
+       format_str = "ico";
+       break;
+    case FORMAT_JPEG:
+       format_str = "jpeg";
+       break;
+    case FORMAT_PNG:
+       format_str = "png";
+       break;
+    case FORMAT_TIFF:
+       format_str = "tiff";
+       break;
+    }
+
+    argb2rgba(width, height, data);
+
+    pixbuf = gdk_pixbuf_new_from_data(
+                data,                   // data
+                GDK_COLORSPACE_RGB,     // colorspace
+                TRUE,                   // has_alpha
+                8,                      // bits_per_sample
+                width,                  // width
+                height,                 // height
+                4 * width,              // rowstride
+                NULL,                   // destroy_fn
+                NULL                    // destroy_fn_data
+               );
+
+    gdk_pixbuf_save_to_callback(pixbuf, writer, job->output_file, format_str, NULL, NULL);
+
+    gdk_pixbuf_unref(pixbuf);
+}
+
+static gvdevice_engine_t gdk_pixbuf_engine = {
+    NULL,
+    gdk_pixbuf_formatter,
+    NULL,
+};
+
+static gvformatter_features_t gdk_pixbuf_features = {
+    0,  /* flags */
+};
+
+gvplugin_installed_t gvdevice_gdk_pixbuf_types[] = {
+    {FORMAT_BMP, "bmp:cairo", 10, &gdk_pixbuf_engine, &gdk_pixbuf_features},
+    {FORMAT_ICO, "ico:cairo", 10, &gdk_pixbuf_engine, &gdk_pixbuf_features},
+    {FORMAT_JPEG, "jpe:cairo", 10, &gdk_pixbuf_engine, &gdk_pixbuf_features},
+    {FORMAT_JPEG, "jpeg:cairo", 10, &gdk_pixbuf_engine, &gdk_pixbuf_features},
+    {FORMAT_JPEG, "jpg:cairo", 10, &gdk_pixbuf_engine, &gdk_pixbuf_features},
+    {FORMAT_PNG, "png:cairo", 5, &gdk_pixbuf_engine, &gdk_pixbuf_features},
+    {FORMAT_TIFF, "tif:cairo", 10, &gdk_pixbuf_engine, &gdk_pixbuf_features},
+    {FORMAT_TIFF, "tiff:cairo", 10, &gdk_pixbuf_engine, &gdk_pixbuf_features},
+    {0, NULL, 0, NULL, NULL}
+};