]> granicus.if.org Git - graphviz/commitdiff
Add a GIF formatter for cairo in the GD plugin.
authorellson <devnull@localhost>
Wed, 22 Aug 2007 21:38:34 +0000 (21:38 +0000)
committerellson <devnull@localhost>
Wed, 22 Aug 2007 21:38:34 +0000 (21:38 +0000)
Now GIFs are antialiased and use pango fonts.

-Tgif:cairo is now the default, but -Tgif:gd is still available.

Currently transparency is not provided in -Tgif:cairo

plugin/gd/gvformatter_gd.c
plugin/gdk_pixbuf/gvformatter_gdk_pixbuf.c
plugin/pango/gvrender_pango.c

index cfbdf7e3b4794c0c29406bba8255140d3ce5b646..d32410da0838da715b2d1d1be38c0ed5b3be3656 100644 (file)
@@ -18,6 +18,7 @@
 #include "config.h"
 #endif
 
+#include <stdlib.h>
 #include "gvplugin_formatter.h"
 
 #ifdef HAVE_LIBGD
 #include "gd.h"
 
 typedef enum {
-       FORMAT_GD,
-       FORMAT_GD2,
        FORMAT_GIF,
        FORMAT_JPEG,
+#if 0
        FORMAT_PNG,
        FORMAT_WBMP,
+       FORMAT_GD,
+       FORMAT_GD2,
        FORMAT_XBM,
+#endif
 } format_type;
 
 static void
-cairo_surface_write_to_gdk_pixbuf(cairo_surface_t *surface, format_type format, FILE *f)
+cairo_surface_write_to_gd(cairo_surface_t *surface, format_type format, FILE *f)
 {
     gdImagePtr im;
-    unsigned int width, height;
-    unsigned char *data;
+    unsigned char *data, r, g, b, a;
+    unsigned int width, height, x, y;
 
     width = cairo_image_surface_get_width(surface);
     height = cairo_image_surface_get_height(surface);
     data = cairo_image_surface_get_data(surface);
 
     im = gdImageCreateTrueColor(width, height);
+    for (y = 0; y < height; y++) {
+        for (x = 0; x < width; x++) {
+           b = *data++;
+           g = *data++;
+           r = *data++;
+           a = *data++;
+           gdImageSetPixel (im, x, y, ((((255 - a) >> 1) << 24) | (r << 16) | (g << 8) | b) );
+       }
+    }
 
-    /*
-     * Only save the alpha channel in outputs that support it if
-     * the base color was transparent.   Otherwise everything
-     * was blended so there is no useful alpha info.
-     */
-//FIXME        gdImageSaveAlpha(im, (basecolor == transparent));
     switch (format) {
-#if 0
-    case FORMAT_GD:
-       gdImageGd(im, f);
-       break;
-    case FORMAT_GD2:
-#define GD2_CHUNKSIZE 128
-#define GD2_RAW 1
-#define GD2_COMPRESSED 2
-    gdImageGd2(im, f, GD2_CHUNKSIZE, GD2_COMPRESSED);
-    break;
-#endif
 #ifdef HAVE_GD_GIF
     case FORMAT_GIF:
        gdImageTrueColorToPalette(im, 0, 256);
        gdImageGif(im, f);
         break;
 #endif
+
 #ifdef HAVE_GD_JPEG
     case FORMAT_JPEG:
        /*
@@ -87,28 +83,45 @@ cairo_surface_write_to_gdk_pixbuf(cairo_surface_t *surface, format_type format,
        gdImageJpeg(im, f, JPEG_QUALITY);
        break;
 #endif
+
+#if 0
+
 #ifdef HAVE_GD_PNG
     case FORMAT_PNG:
        gdImagePng(im, f);
         break;
 #endif
-#if 0
+
+    case FORMAT_GD:
+       gdImageGd(im, f);
+       break;
+
+    case FORMAT_GD2:
+#define GD2_CHUNKSIZE 128
+#define GD2_RAW 1
+#define GD2_COMPRESSED 2
+       gdImageGd2(im, f, 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, f);
        break;
 #endif
-#if 0
+
 #ifdef HAVE_GD_XPM
     case FORMAT_XBM:
        gdImageXbm(im, f);
 #endif
+
 #endif
        break;
     default:
        break;
     }
+
     gdImageDestroy(im);
 }
 
@@ -128,7 +141,7 @@ static void gd_formatter(GVJ_t * job)
 #endif
 #endif
 
-    cairo_surface_write_to_gdk_pixbuf(surface, job->formatter.id, job->output_file);
+    cairo_surface_write_to_gd(surface, job->formatter.id, job->output_file);
 }
 
 static gvformatter_engine_t gd_engine = {
@@ -145,23 +158,33 @@ static gvformatter_features_t gd_features = {
 gvplugin_installed_t gvformatter_gd_types[] = {
 #ifdef HAVE_PANGOCAIRO
 #ifdef HAVE_LIBGD
-//    {FORMAT_GD, "cairo2gd", -1, &gd_engine, &gd_features},
-//    {FORMAT_GD2, "cairo2gd2", -1, &gd_engine, &gd_features},
+
 #ifdef HAVE_GD_GIF
-    {FORMAT_GIF, "cairo2gif", -1, &gd_engine, &gd_features},
+    {FORMAT_GIF, "cairo2gif", 10, &gd_engine, &gd_features},
 #endif
+
 #ifdef HAVE_GD_JPEG
     {FORMAT_JPEG, "cairo2jpe", -1, &gd_engine, &gd_features},
     {FORMAT_JPEG, "cairo2jpeg", -1, &gd_engine, &gd_features},
     {FORMAT_JPEG, "cairo2jpg", -1, &gd_engine, &gd_features},
 #endif
+
+#if 0
+
 #ifdef HAVE_GD_PNG
     {FORMAT_PNG, "cairo2png", -1, &gd_engine, &gd_features},
 #endif
-//    {FORMAT_WBMP, "cairo2wbmp", -1, &gd_engine, &gd_features},
+
+    {FORMAT_GD, "cairo2gd", -1, &gd_engine, &gd_features},
+    {FORMAT_GD2, "cairo2gd2", -1, &gd_engine, &gd_features},
+#ifdef HAVE_GD_GIF
+    {FORMAT_WBMP, "cairo2wbmp", -1, &gd_engine, &gd_features},
+#endif
 #ifdef HAVE_GD_XPM
-//    {FORMAT_XBM, "cairo2xbm", -1, &gd_engine, &gd_features},
+    {FORMAT_XBM, "cairo2xbm", -1, &gd_engine, &gd_features},
+#endif
 #endif
+
 #endif
 #endif
     {0, NULL, 0, NULL, NULL}
index bade8476afac77e7a078a8ef171e868e4683566d..0b43c691028b792690065d7d5fe404e478746b1c 100644 (file)
@@ -49,7 +49,7 @@ argb2rgba ( unsigned int width, unsigned int height, unsigned char *data)
 #define Bb 2
 #define Ab 3
 
-    for (y = 0; y < height/2; y++) {
+    for (y = 0; y < height; y++) {
         for (x = 0; x < width; x++) {
             r = data[Ra];
             g = data[Ga];
index 72547864ab801ada27c2faba9f1ad5bd20194ba1..873255dad873df2fe384da5f9500601ff52a7586 100644 (file)
@@ -58,6 +58,7 @@
 
 typedef enum {
                FORMAT_BMP,
+               FORMAT_GIF,
                FORMAT_GLITZ,
                FORMAT_GTK,
                FORMAT_ICO,
@@ -68,6 +69,7 @@ typedef enum {
                FORMAT_QUARTZ,
                FORMAT_SDL,
                FORMAT_SVG,
+               FORMAT_TGA,
                FORMAT_TIFF,
                FORMAT_WIN32,
                FORMAT_XLIB,
@@ -139,10 +141,12 @@ static void cairogen_begin_page(GVJ_t * job)
         cr = (cairo_t *) job->surface;
 
     switch (job->render.id) {
-#ifdef CAIRO_HAS_PNG_FUNCTIONS
-    case FORMAT_PNG:
-#endif
+    case FORMAT_BMP:
+    case FORMAT_GIF:
+    case FORMAT_ICO:
     case FORMAT_JPEG:
+    case FORMAT_PNG:
+    case FORMAT_TIFF:
        if (!cr) {
            surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
                        job->width, job->height);
@@ -559,9 +563,18 @@ gvplugin_installed_t gvrender_pango_types[] = {
     {FORMAT_GTK, "gtk", 0, &cairogen_engine, &cairogen_features_gtk},
     {FORMAT_XLIB, "xlib", 0, &cairogen_engine, &cairogen_features_x},
 #endif
+    {FORMAT_BMP, "bmp", 10, &cairogen_engine, &cairogen_features_formatter},
+    {FORMAT_GIF, "gif", 10, &cairogen_engine, &cairogen_features_formatter},
+    {FORMAT_ICO, "ico", 10, &cairogen_engine, &cairogen_features_formatter},
     {FORMAT_JPEG, "jpe", 10, &cairogen_engine, &cairogen_features_formatter},
     {FORMAT_JPEG, "jpeg", 10, &cairogen_engine, &cairogen_features_formatter},
     {FORMAT_JPEG, "jpg", 10, &cairogen_engine, &cairogen_features_formatter},
+#ifndef CAIRO_HAS_PNG_FUNCTIONS
+    {FORMAT_PNG, "png", 10, &cairogen_engine, &cairogen_features_formatter},
+#endif
+    {FORMAT_TIFF, "tif", 10, &cairogen_engine, &cairogen_features_formatter},
+    {FORMAT_TIFF, "tiff", 10, &cairogen_engine, &cairogen_features_formatter},
+//    {FORMAT_TGA, "tga", 10, &cairogen_engine, &cairogen_features_formatter},
 #endif
     {0, NULL, 0, NULL, NULL}
 };