Skip to content

Commit

Permalink
* generic/tclgdio.c: Use Tcl's ckalloc and ckfree instead of GD's
Browse files Browse the repository at this point in the history
  gdMalloc and gdFree -- it wasn't necessary to use GD's versions,
  and this keeps us from needing to access GD functions that are
  not declared in gd.h plus it lets us use Tcl's memory debugging
  capabilities to determine if we're leaking anything here.

* doc/tclgd.n:  Added an admonition of the importance of configuring
  channels for binary tranlation when loading and saving images.

* README, mapserver-patches/README: Improve docs, explain how to use
  the C function to bring a GD image structure into Tcl from a C
  program.  Better document the Mapserver patch.
  • Loading branch information
karl committed Dec 18, 2005
1 parent 4aacb0a commit 30acb21
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 15 deletions.
17 changes: 16 additions & 1 deletion ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
$Id: ChangeLog,v 1.11 2005-12-14 02:15:26 karl Exp $
$Id: ChangeLog,v 1.12 2005-12-18 23:49:37 karl Exp $

2005-12-18 Karl Lehenbauer <karl-tclgd@sc.com>

* generic/tclgdio.c: Use Tcl's ckalloc and ckfree instead of GD's
gdMalloc and gdFree -- it wasn't necessary to use GD's versions,
and this keeps us from needing to access GD functions that are
not declared in gd.h plus it lets us use Tcl's memory debugging
capabilities to determine if we're leaking anything here.

* doc/tclgd.n: Added an admonition of the importance of configuring
channels for binary tranlation when loading and saving images.

* README, mapserver-patches/README: Improve docs, explain how to use
the C function to bring a GD image structure into Tcl from a C
program. Better document the Mapserver patch.

2005-12-14 Karl Lehenbauer <karl-tclgd@sc.com>
* Update to Tcl TEA build environment version 3.4.
Expand Down
25 changes: 23 additions & 2 deletions README
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
This is tcl.gd, a new Tcl interface to GD that is significantly more feature-
complete with gd 2 than Gdtclft.

Version 0.0
Version 0.6

$Id: README,v 1.4 2005-11-21 11:38:11 karl Exp $
$Id: README,v 1.5 2005-12-18 23:49:37 karl Exp $

This package is a freely available open source package under the "Berkeley"
license, same as Tcl. You can do virtually anything you like with it, such as
Expand All @@ -21,10 +21,31 @@ package require tclgd
TCLGD QUICK REF
===============

Please see the tclgd manpage in the doc directory.

BUGS
====

Yes.

INTEGRATING TCLGD WITH EXISTING C APPLICATIONS THAT USE GD
==========================================================

You can attach an existing gd handle to a tcl.gd image manipulation command
using tclgd_newGDObjectAttach. Please see the tclgd_newGDObjectAttach manpage
for details.

MAPSERVER MAPSCRIPT PATCH
=========================

Included with tcl.gd is a patch to Mapserver's mapscript Tcl extension to
use the aforementioned capability for integrating tcl.gd with C
aplications that use gd to provide a tcl.gd capability for mapscript.

Consult the README file in the mapserver-patches subdirectory for details
on how to install the mapserver patch to add this capability to mapserver.


CONTENTS
========

Expand Down
11 changes: 11 additions & 0 deletions doc/tclgd.n
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,17 @@ data, or from a Tcl file handle (in a couple of cases where a channel
interface can't be provided due to limitations of the underlying gd library
routines).
.PP
IMPORTANT: The channel being read should be configured for binary translation
using something like
.nf
set fp [open parrots.png]
fconfigure $fp -translation binary
GD create_from_png parrots $fp
.fo
If you get corrupt image errors on images that you feel pretty sure are OK,
like you can load them into Photoshop, you probably are not setting
translation to binary.
.PP
For formats where channels are support (the majority), any type of channel
can be used, including files, sockets, and, if so equipped, alternate
channel interfaces such as reading the data directly from zip files.
Expand Down
9 changes: 4 additions & 5 deletions generic/tclgdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,10 @@
* modeled after the gd_io_file.c file in the gd package, which is documented
* as having been written/modified 1999, Philip Warner.
*
* $Id: tclgdio.c,v 1.6 2005-11-25 06:40:00 karl Exp $
* $Id: tclgdio.c,v 1.7 2005-12-18 23:49:37 karl Exp $
*/

#include "tclgd.h"
#include "gdhelpers.h"

static int tclgd_channelGetbuf (gdIOCtx *, void *, int);
static int tclgd_channelPutbuf (gdIOCtx *, const void *, int);
Expand All @@ -28,7 +27,7 @@ BGD_DECLARE(gdIOCtx *) tclgd_newChannelCtx (Tcl_Channel channel)
{
tclgd_channelIOCtx *ctx;

ctx = (tclgd_channelIOCtx *) gdMalloc (sizeof (tclgd_channelIOCtx));
ctx = (tclgd_channelIOCtx *) ckalloc (sizeof (tclgd_channelIOCtx));
if (ctx == NULL) {
return NULL;
}
Expand All @@ -53,7 +52,7 @@ static void
tclgd_FreeChannelCtx (gdIOCtx * ctx)
{
/* printf("tclgd_FreeChannelCtx %lx\n", ctx); */
gdFree (ctx);
ckfree ((char *) ctx);
}


Expand Down Expand Up @@ -95,7 +94,7 @@ tclgd_channelGetbuf (gdIOCtx * ctx, void *buf, int size)
static void
tclgd_channelPutchar (gdIOCtx * ctx, int a)
{
unsigned char b;
char b;
tclgd_channelIOCtx *tctx;

tctx = (tclgd_channelIOCtx *) ctx;
Expand Down
25 changes: 18 additions & 7 deletions mapserver-patches/README
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

$Id: README,v 1.4 2005-11-27 07:03:31 karl Exp $
$Id: README,v 1.5 2005-12-18 23:49:37 karl Exp $

MAPSERVER/MAPSCRIPT
===================
Expand All @@ -18,12 +18,18 @@ and you then have an additional method for mapscript image objects.
HOW TO PATCH
============

cd to your mapserver directory, cd to mapscript
cd to your mapserver build directory, then cd to the mapscript directory within
it.

patch -p0 <.../mapserver-patches/mapscript-image.i.patch

patch -p0 <.../mapserver-patches/pkgIndex.tcl.patch

cd to the tcl subdirectory and run the configure script. FreeBSD users will
need to alter the configure script to be able to find the Tcl libraries and
includes in the slightly different places where Tcl, when built from the ports
tree or installed from pacakges, is installed.

HOW TO USE
==========

Expand All @@ -35,16 +41,21 @@ Eventually you get a mapImage handle by doing something like...

set mapImage [$map draw]

Now you're ready to attach the gd buffer out of the map image and manipulate
At this point, you normally write out the mapImage, but instead,
now you're ready to attach the gd buffer out of the map image and manipulate
it using tcl.gd...

$mapImage gdHandle newCommandName

You can now use newCommandName to do all of the usual tclgd magic, and you
are operating on the gd buffer that's part of the Mapserver/Mapscript
image object. For instance, you can draw lines, write text into the buffer,
merge images into the buffer, and write it to a channel or to memory.

If you delete the new command (rename newCommandName "") it will not free the
gd buffer out from underneath Mapscript -- we're too smart for that ;-)
merge images into the buffer, and write the GD image it to a channel (for
instance, a file or a socket, but it could be something more exotic like a
file in a zip archive or anything else there's a channel driver for), or to
memory.

If you delete the new tcl.gd manipulation command (rename newCommandName "") it
will not free the gd buffer out from underneath Mapscript -- we're too smart
for that, at least since verison 0.6 or so ;-)

0 comments on commit 30acb21

Please sign in to comment.