Here's a quick overview of the package.
Spencer W. Thomas
This package provides a simple Tcl interface to the gd (GIF drawing)
package, version 1.1. It includes an interface to all the gd
functions and data structures from Tcl commands.
Detailed documentation for GD
is available at the CSHL site.
Credits and license terms
Gdtcl is copyright, 1994, The Regents of the University of Michigan. Permission is granted to copy and distribute this work provided that this notice remains intact.
gd 1.1 is copyright 1994, Quest Protein Database Center, Cold Spring Harbor Labs. Permission granted to copy and distribute this work provided that this notice remains intact. Credit for the library must be given to the Quest Protein Database Center, Cold Spring Harbor Labs, in all derived works. ("Derived works" includes all programs that utilize the library. Credit must be given in user-visible documentation.)
If you wish to release modified versions of gd, please clear them through Quest first by sending email to [email protected]; if this is not done, any modified version of the gd library must be clearly labeled as such.
The Quest Protein Database Center is funded under Grant P41-RR02188 by the National Institutes of Health.
Written by Thomas Boutell, 2/94 - 11/94.
The GIF compression and decompression is based on that found in the pbmplus utilities, which in turn is based on GIFENCOD by David Rowley. See the notice below:
/* ** Based on GIFENCOD by David Rowley.A ** Lempel-Zim compression based on "compress". ** ** Modified by Marcel Wijkstra ** ** Copyright (C) 1989 by Jef Poskanzer. ** ** Permission to use, copy, modify, and distribute this software and its ** documentation for any purpose and without fee is hereby granted, provided ** that the above copyright notice appear in all copies and that both that ** copyright notice and this permission notice appear in supporting ** documentation. This software is provided "as is" without express or ** implied warranty. ** ** The Graphics Interchange Format(c) is the Copyright property of ** CompuServe Incorporated. GIF(sm) is a Service Mark property of ** CompuServe Incorporated. */
Place gdCmd.c in your gd1.1 directory.
If you have installed tclX, see below. Copy tclAppInit.c from the tcl source directory, and add
Gdtcl_Init(interp);right after
/* * Call Tcl_CreateCommand for application-specific commands, if * they weren't already created by the init procedures called above. */
Then add these lines to the Makefile in the gd1.1 directory (modifying TCL_DIR appropriately for your installation)
TCL_DIR = /usr/hgp/tcl/tcl7.3 TCL_INCLUDE = -I$(TCL_DIR) TCL_LIB = $(TCL_DIR)/libtcl.a CC = gcc CFLAGS = -g $(TCL_INCLUDE) gdtcl: tclAppInit.o gdCmd.o libgd.a gcc -o gdtcl $(CFLAGS) tclAppInit.o gdCmd.o libgd.a $(TCL_LIB) -lm
Alternatively, you can modify tclAppInit.c in place, and add references
to the gd '.o' files into the tcl makefile (read the instructions
with the tcl distribution for details).
Installing with TclX
If you have installed tclX, edit gdCmd.c and uncomment the line
/* #define TCLX_SUPPORT */The gd interface uses the Handles package from tclX, so you need tcl and tclX. Copy tclXAppInit.c from the tclX/src directory, and add
Gdtcl_Init(interp);right after
/* * Call Tcl_CreateCommand for application-specific commands, if * they weren't already created by the init procedures called above. */
Then add these lines to the Makefile in the gd1.1 directory (modifying TCL_DIR appropriately for your installation)
TCL_DIR = /usr/hgp/tcl/tclX/7.3b TCL_INCLUDE = -I$(TCL_DIR)/include TCL_LIB = $(TCL_DIR)/lib/libtclx.a $(TCL_DIR)/lib/libtcl.a CC = gcc CFLAGS = -g $(TCL_INCLUDE) gdtcl: tclXAppInit.o gdCmd.o libgd.a gcc -o gdtcl $(CFLAGS) tclXAppInit.o gdCmd.o libgd.a $(TCL_LIB) -lm
Alternatively, you can modify tclXAppInit.c in place, and add references
to the gd '.o' files into the tclX makefile (read the instructions
with the tclX distribution for details).
Reference
One Tcl command, 'gd', is added. All gd package actions are sub-commands (or "options" in Tcl terminology) of this command.
Each active gd image is referred to with a "handle". The handle is a name of the form gd# (e.g., gd0) returned by the gd create options.
Almost all the gd commands take a handle as the first argument (after the option). All the drawing commands take a color index as the next argument. The color index is a number, or may be one of the strings styled, brushed, tiled, "styled brushed" or "brushed styled". The style, brush, or tile currently in effect will be used. Brushing and styling apply to lines, tiling to filled areas.
################################################################ # Sample gdtcl program # # Create a 64 x 64 image set im [gd create 64 64] # Get black and white as colors. Black is the background color because # it is allocated first from a new image. set black [gd color new $im 0 0 0] set white [gd color new $im 255 255 255] # Draw a line from upper left to lower right gd line $im $white 0 0 63 63 # Open a file for writing (Tcl on Unix, at least, doesn't support 'wb' mode) set out [open test.gif w] # Output the image to the disk file gd writeGIF $im $out # Close the file close $out # Destroy the image in memory gd destroy $im
Here's the gddemo.c program translated to tcl.
################################################################ # # gddemo in tcl # # Create output image 128 x 128 set im_out [gd create 128 128] # First color is background set white [gd color new $im_out 255 255 255] # Set transparent gd color transparent $im_out $white # Load demoin.gif and paste part of it into the output image. if {[catch {set in [open demoin.gif]}]} { puts stderr "Can't load source image; this demo is much"; puts stderr "more impressive if demoin.gif is available"; set im_in ""; } else { set im_in [gd createFromGIF $in] close $in # Copy and shrink gd copy $im_out $im_in 16 16 0 0 96 96 128 128 } # Get some colors set red [gd color new $im_out 255 0 0] set green [gd color new $im_out 0 255 0] set blue [gd color new $im_out 0 0 255] # Draw a rectangle gd line $im_out $green 8 8 120 8 gd line $im_out $green 120 8 120 120 gd line $im_out $green 120 120 8 120 gd line $im_out $green 8 120 8 8 # Text gd text $im_out $red large 16 16 hi gd textup $im_out $red small 23 23 hi # Circle gd arc $im_out $blue 64 64 30 10 0 360 # Arc gd arc $im_out $blue 64 64 20 20 45 135 # Flood fill gd fill $im_out $blue 4 4 # Polygon gd fillpolygon $im_out $green 32 0 0 64 64 64 # Brush. A fairly wild example also involving a line style! if {$im_in != ""} { set brush [gd create 8 8]; eval [concat gd copy $brush $im_in 0 0 0 0 [gd size $brush] [gd size $im_in]] gd brush $im_out $brush # Style so they won't overprint each other. gd style $im_out [concat [replicate "0 " 7] 1] gd line $im_out "styled brushed" 0 0 128 128 } # Interlace the result for "fade in" in viewers that support it gd interlace $im_out true # Write GIF set out [open demoout.gif w] gd writeGIF $im_out $out close $out gd destroy $im_out
################################################################ # gdshow -- use xv to display an image. # # Waits until xv quits to return. # proc gdshow {gd} { set f [open "|xv -" w] catch {gd writeGIF $gd $f} catch {close $f} xx if {$xx != {}} { error "XV error: $xx" } }
The major change in this release is that you can now install the extension without tclX. I've written emulation functions for the tclX "handle" routines that the extension uses. If you do have tclX, be sure to see the installation instructions above.
It's also updated to remain compatible with the changes in gd 1.1.1.
Changes from Version 1.0 to 1.1
Most of the changes involve adding new functionality to support the new
functionality in gd1.1. These are:
The dash command has been deleted, as this functionality is now available through the use of line styles.
This page last changed on 9 February, 1995.