File: init.c

package info (click to toggle)
libtk-img 1%3A2.0.1%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 47,852 kB
  • sloc: ansic: 224,696; sh: 20,589; tcl: 8,921; makefile: 2,272; cpp: 1,933; ada: 1,681; pascal: 1,139; cs: 879; awk: 794; asm: 587; python: 542; xml: 95
file content (238 lines) | stat: -rwxr-xr-x 7,474 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
 * init.c --
 *
 *  Generic photo image type initialization, Tcl/Tk package
 *
 * Copyright (c) 2002 Andreas Kupries <andreas_kupries@users.sourceforge.net>
 *
 */

#include "tkimg.h"

#ifndef MORE_INITIALIZATION
#define MORE_INITIALIZATION
#endif

/*
 * Functions exported for package management.
 */


extern DLLEXPORT int @CPACKAGE@_Init(Tcl_Interp *interp);
extern DLLEXPORT int @CPACKAGE@_SafeInit(Tcl_Interp *interp);

/*
 * Declarations of internal functions.
 */

#if defined(USE_FORMAT_VERSION3) && HAVE_FORMAT_VERSION3 == 1

static int FileMatchVersion3(Tcl_Interp *interp,
        Tcl_Channel chan, const char *fileName, Tcl_Obj *format,
        Tcl_Obj *metadataIn, int *widthPtr, int *heightPtr,
        Tcl_Obj *metadataOut);

static int StringMatchVersion3(Tcl_Interp *interp,
        Tcl_Obj *dataObj, Tcl_Obj *format, Tcl_Obj *metadataIn, int *widthPtr,
        int *heightPtr, Tcl_Obj *metadataOut);

static int FileReadVersion3(Tcl_Interp *interp,
        Tcl_Channel chan,
        const char *fileName, Tcl_Obj *format, Tcl_Obj *metadataIn,
        Tk_PhotoHandle imageHandle,
        int destX, int destY, int width, int height, int srcX, int srcY,
        Tcl_Obj *metadataOut);

static int StringReadVersion3(Tcl_Interp *interp,
        Tcl_Obj *dataObj, Tcl_Obj *format, Tcl_Obj *metadataIn,
        Tk_PhotoHandle imageHandle, int destX, int destY, int width, int height,
        int srcX, int srcY, Tcl_Obj *metadataOut);

static int FileWriteVersion3(Tcl_Interp *interp,
        const char *fileName, Tcl_Obj *format, Tcl_Obj *metadataIn,
        Tk_PhotoImageBlock *blockPtr);

static int StringWriteVersion3(Tcl_Interp *interp,
        Tcl_Obj *format, Tcl_Obj *metadataIn, Tk_PhotoImageBlock *blockPtr);

static Tk_PhotoImageFormatVersion3 sImageFormatVersion3 = {
    (char *) "%PHIMGTYPE%",  /* name */
    FileMatchVersion3,       /* fileMatchProc */
    StringMatchVersion3,     /* stringMatchProc */
    FileReadVersion3,        /* fileReadProc */
    StringReadVersion3,      /* stringReadProc */
    FileWriteVersion3,       /* fileWriteProc */
    StringWriteVersion3,     /* stringWriteProc */
    NULL
};

#else

static int FileMatch(Tcl_Channel chan, const char *fileName,
        Tcl_Obj *format, int *widthPtr, int *heightPtr, Tcl_Interp *interp);

static int StringMatch(Tcl_Obj *dataObj, Tcl_Obj *format,
        int *widthPtr, int *heightPtr, Tcl_Interp *interp);

static int FileRead(Tcl_Interp *interp, Tcl_Channel chan,
        const char *fileName, Tcl_Obj *format, Tk_PhotoHandle imageHandle,
        int destX, int destY, int width, int height, int srcX, int srcY);

static int StringRead(Tcl_Interp *interp, Tcl_Obj *dataObj,
        Tcl_Obj *format, Tk_PhotoHandle imageHandle,
        int destX, int destY, int width, int height, int srcX, int srcY);

static int FileWrite(Tcl_Interp *interp, const char *filename,
        Tcl_Obj *format, Tk_PhotoImageBlock *blockPtr);

static int StringWrite(Tcl_Interp *interp, Tcl_Obj *format,
        Tk_PhotoImageBlock *blockPtr);

static Tk_PhotoImageFormat sImageFormat = {
    (char *) "%PHIMGTYPE%",  /* name */
    FileMatch,               /* fileMatchProc */
    StringMatch,             /* stringMatchProc */
    FileRead,                /* fileReadProc */
    StringRead,              /* stringReadProc */
    FileWrite,               /* fileWriteProc */
    StringWrite,             /* stringWriteProc */
    NULL
};
#endif /* USE_FORMAT_VERSION3 && HAVE_FORMAT_VERSION3 */

#ifdef SECOND_FORMAT
/*
 * Declare procedures of the second format as needed. The macro we
 * check for allow us to share code between first and second
 * format. Current user of this feature: The PS/PDF combo handler
 */

#ifndef SECOND_FILEMATCH
#define SECOND_FILEMATCH FileMatchBeta
static int FileMatchBeta(Tcl_Channel chan, const char *fileName,
        Tcl_Obj *format, int *widthPtr, int *heightPtr, Tcl_Interp *interp);
#endif

#ifndef SECOND_STRINGMATCH
#define SECOND_STRINGMATCH StringMatchBeta
static int StringMatchBeta(Tcl_Obj *dataObj, Tcl_Obj *format,
        int *widthPtr, int *heightPtr, Tcl_Interp *interp);
#endif

#ifndef SECOND_FILEREAD
#define SECOND_FILEREAD FileReadBeta
static int FileReadBeta(Tcl_Interp *interp, Tcl_Channel chan,
        const char *fileName, Tcl_Obj *format, Tk_PhotoHandle imageHandle,
        int destX, int destY, int width, int height, int srcX, int srcY);
#endif

#ifndef SECOND_STRINGREAD
#define SECOND_STRINGREAD StringReadBeta
static int StringReadBeta(Tcl_Interp *interp, Tcl_Obj *dataObj,
        Tcl_Obj *format, Tk_PhotoHandle imageHandle,
        int destX, int destY, int width, int height, int srcX, int srcY);
#endif

#ifndef SECOND_FILEWRITE
#define SECOND_FILEWRITE FileWriteBeta
static int FileWriteBeta(Tcl_Interp *interp, const char *filename,
        Tcl_Obj *format, Tk_PhotoImageBlock *blockPtr);
#endif

#ifndef SECOND_STRINGWRITE
#define SECOND_STRINGWRITE StringWriteBeta
static int StringWriteBeta(Tcl_Interp *interp, Tcl_Obj *format,
        Tk_PhotoImageBlock *blockPtr);
#endif

static Tk_PhotoImageFormat sImageFormatBeta = {
    (char *) "%PHIMGTYPE_BETA%",  /* name */
    SECOND_FILEMATCH,             /* fileMatchProc */
    SECOND_STRINGMATCH,           /* stringMatchProc */
    SECOND_FILEREAD,              /* fileReadProc */
    SECOND_STRINGREAD,            /* stringReadProc */
    SECOND_FILEWRITE,             /* fileWriteProc */
    SECOND_STRINGWRITE,           /* stringWriteProc */
    NULL
};

#endif /* SECOND_FORMAT */


/*
 *----------------------------------------------------------------------------
 *
 * @CPACKAGE@_Init --
 *
 *  Initialisation routine for loadable module
 *
 * Results:
 *  None.
 *
 * Side effects:
 *  Creates commands in the interpreter, loads package.
 *
 *----------------------------------------------------------------------------
 */

int
@CPACKAGE@_Init(
    Tcl_Interp *interp /* Interpreter to initialise. */
) {
    if (!Tcl_InitStubs(interp, "8.6-", 0)) {
        return TCL_ERROR;
    }
#if defined(USE_FORMAT_VERSION3) && HAVE_FORMAT_VERSION3 == 1
    if (!Tk_InitStubs(interp, "8.7-", 0)) {
        return TCL_ERROR;
    }
#else
    if (!Tk_InitStubs(interp, "8.6-", 0)) {
        return TCL_ERROR;
    }
#endif
    if (!Tkimg_InitStubs(interp, TKIMG_VERSION, 0)) {
        return TCL_ERROR;
    }

    MORE_INITIALIZATION;

#if defined(USE_FORMAT_VERSION3) && HAVE_FORMAT_VERSION3 == 1
    Tk_CreatePhotoImageFormatVersion3(&sImageFormatVersion3);
#else
    Tk_CreatePhotoImageFormat(&sImageFormat);
#endif

#ifdef SECOND_FORMAT
    Tk_CreatePhotoImageFormat(&sImageFormatBeta);
#endif

    if (Tcl_PkgProvide(interp, PACKAGE_TCLNAME, TKIMG_VERSION) != TCL_OK) {
        return TCL_ERROR;
    }
    return TCL_OK;
}

/*
 *----------------------------------------------------------------------------
 *
 * @CPACKAGE@_SafeInit --
 *
 *  Initialisation routine for loadable module in a safe interpreter.
 *
 * Results:
 *  None.
 *
 * Side effects:
 *  Creates commands in the interpreter, loads package.
 *
 *----------------------------------------------------------------------------
 */

int
@CPACKAGE@_SafeInit(
    Tcl_Interp *interp /* Interpreter to initialise. */
) {
    return @CPACKAGE@_Init(interp);
}