/*
 * tcl.gd include file
 *
 * Copyright (C) 2005 -2013 by Karl Lehenbauer, All Rights Reserved
 *
 * Redistributable under the terms of the Berkeley copyright
 */

#include <tcl.h>
#include <gd.h>

/* Check, if Tcl version supports Tcl_Size,
   which was introduced in Tcl 8.7 and 9.
*/
#ifndef TCL_SIZE_MAX
    #include <limits.h>
    #define TCL_SIZE_MAX INT_MAX

    #ifndef Tcl_Size
        typedef int Tcl_Size;
    #endif

    #define TCL_SIZE_MODIFIER ""
    #define Tcl_GetSizeIntFromObj Tcl_GetIntFromObj
#endif 

extern int
tclgd_GDObjCmd(ClientData dummy, Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);

extern int
tclgd_newGDObject (Tcl_Interp *interp, Tcl_Obj *nameObj, gdImagePtr im, int destroyOnDelete);

extern int
tclgd_newGDObjectAttach (Tcl_Interp *interp, char *name, gdImagePtr im);

typedef struct tclgd_channelIOCtx
{
    gdIOCtx      ctx;
    Tcl_Channel  channel;
} tclgd_channelIOCtx;

typedef struct tclgd_clientData
{
    gdImagePtr   im;
    int          destroyOnDelete;
    Tcl_Command  cmdToken;
} tclgd_clientData;

gdIOCtx *tclgd_newChannelCtx (Tcl_Channel channel);

gdIOCtx *
tclgd_channelNameToIOCtx (Tcl_Interp *interp, char *channelName, int modeFlag);

