Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 1 | /*********************************************************** |
Guido van Rossum | 524b588 | 1995-01-04 19:10:35 +0000 | [diff] [blame^] | 2 | Copyright 1991-1995 by Stichting Mathematisch Centrum, Amsterdam, |
| 3 | The Netherlands. |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 4 | |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Permission to use, copy, modify, and distribute this software and its |
| 8 | documentation for any purpose and without fee is hereby granted, |
| 9 | provided that the above copyright notice appear in all copies and that |
| 10 | both that copyright notice and this permission notice appear in |
| 11 | supporting documentation, and that the names of Stichting Mathematisch |
| 12 | Centrum or CWI not be used in advertising or publicity pertaining to |
| 13 | distribution of the software without specific, written prior permission. |
| 14 | |
| 15 | STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO |
| 16 | THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND |
| 17 | FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE |
| 18 | FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 19 | WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 20 | ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 21 | OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 22 | |
| 23 | ******************************************************************/ |
| 24 | |
| 25 | |
| 26 | /* Cl objects */ |
| 27 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 28 | #define CLDEBUG |
| 29 | |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 30 | #include <stdarg.h> |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 31 | #include <cl.h> |
| 32 | #include "allobjects.h" |
| 33 | #include "modsupport.h" /* For getargs() etc. */ |
| 34 | #include "ceval.h" /* For call_object() */ |
| 35 | |
| 36 | typedef struct { |
| 37 | OB_HEAD |
| 38 | int ob_isCompressor; /* Compressor or Decompressor */ |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 39 | CL_Handle ob_compressorHdl; |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 40 | int *ob_paramtypes; |
| 41 | int ob_nparams; |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 42 | } clobject; |
| 43 | |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 44 | static object *ClError; /* exception cl.error */ |
| 45 | |
| 46 | static int error_handler_called = 0; |
| 47 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 48 | /* |
| 49 | * We want to use the function prototypes that are available in the C |
| 50 | * compiler on the SGI. Because of that, we need to declare the first |
| 51 | * argument of the compressor and decompressor methods as "object *", |
| 52 | * even though they are really "clobject *". Therefore we cast the |
| 53 | * argument to the proper type using this macro. |
| 54 | */ |
| 55 | #define SELF ((clobject *) self) |
| 56 | |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 57 | /******************************************************************** |
| 58 | Utility routines. |
| 59 | ********************************************************************/ |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 60 | static void |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 61 | cl_ErrorHandler(CL_Handle handle, int code, const char *fmt, ...) |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 62 | { |
| 63 | va_list ap; |
| 64 | char errbuf[BUFSIZ]; /* hopefully big enough */ |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 65 | char *p; |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 66 | |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 67 | if (err_occurred()) /* don't change existing error */ |
| 68 | return; |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 69 | error_handler_called = 1; |
| 70 | va_start(ap, fmt); |
| 71 | vsprintf(errbuf, fmt, ap); |
| 72 | va_end(ap); |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 73 | p = &errbuf[strlen(errbuf) - 1]; /* swat the line feed */ |
| 74 | if (*p == '\n') |
| 75 | *p = 0; |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 76 | err_setstr(ClError, errbuf); |
| 77 | } |
| 78 | |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 79 | /* |
| 80 | * This assumes that params are always in the range 0 to some maximum. |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 81 | */ |
| 82 | static int |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 83 | param_type_is_float(clobject *self, int param) |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 84 | { |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 85 | int bufferlength; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 86 | int ret; |
| 87 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 88 | if (self->ob_paramtypes == NULL) { |
| 89 | error_handler_called = 0; |
| 90 | bufferlength = clQueryParams(self->ob_compressorHdl, 0, 0); |
| 91 | if (error_handler_called) |
| 92 | return -1; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 93 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 94 | self->ob_paramtypes = NEW(int, bufferlength); |
| 95 | if (self->ob_paramtypes == NULL) |
| 96 | return -1; |
| 97 | self->ob_nparams = bufferlength / 2; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 98 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 99 | (void) clQueryParams(self->ob_compressorHdl, self->ob_paramtypes, bufferlength); |
| 100 | if (error_handler_called) { |
| 101 | DEL(self->ob_paramtypes); |
| 102 | self->ob_paramtypes = NULL; |
| 103 | return -1; |
| 104 | } |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 105 | } |
| 106 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 107 | if (param < 0 || param >= self->ob_nparams) |
| 108 | return -1; |
| 109 | |
| 110 | if (self->ob_paramtypes[param*2 + 1] == CL_FLOATING_ENUM_VALUE || |
| 111 | self->ob_paramtypes[param*2 + 1] == CL_FLOATING_RANGE_VALUE) |
| 112 | return 1; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 113 | else |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 114 | return 0; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /******************************************************************** |
| 118 | Single image compression/decompression. |
| 119 | ********************************************************************/ |
| 120 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 121 | cl_CompressImage(object *self, object *args) |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 122 | { |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 123 | int compressionScheme, width, height, originalFormat; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 124 | float compressionRatio; |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 125 | int frameBufferSize, compressedBufferSize; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 126 | char *frameBuffer; |
| 127 | object *compressedBuffer; |
| 128 | |
| 129 | if (!getargs(args, "(iiiifs#)", &compressionScheme, &width, &height, |
| 130 | &originalFormat, &compressionRatio, &frameBuffer, |
| 131 | &frameBufferSize)) |
| 132 | return NULL; |
| 133 | |
| 134 | retry: |
| 135 | compressedBuffer = newsizedstringobject(NULL, frameBufferSize); |
| 136 | if (compressedBuffer == NULL) |
| 137 | return NULL; |
| 138 | |
| 139 | compressedBufferSize = frameBufferSize; |
| 140 | error_handler_called = 0; |
| 141 | if (clCompressImage(compressionScheme, width, height, originalFormat, |
| 142 | compressionRatio, (void *) frameBuffer, |
| 143 | &compressedBufferSize, |
| 144 | (void *) getstringvalue(compressedBuffer)) |
| 145 | == FAILURE) { |
| 146 | DECREF(compressedBuffer); |
| 147 | if (!error_handler_called) |
| 148 | err_setstr(ClError, "clCompressImage failed"); |
| 149 | return NULL; |
| 150 | } |
| 151 | |
| 152 | if (compressedBufferSize > frameBufferSize) { |
| 153 | frameBufferSize = compressedBufferSize; |
| 154 | DECREF(compressedBuffer); |
| 155 | goto retry; |
| 156 | } |
| 157 | |
| 158 | if (compressedBufferSize < frameBufferSize) |
| 159 | if (resizestring(&compressedBuffer, compressedBufferSize)) |
| 160 | return NULL; |
| 161 | |
| 162 | return compressedBuffer; |
| 163 | } |
| 164 | |
| 165 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 166 | cl_DecompressImage(object *self, object *args) |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 167 | { |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 168 | int compressionScheme, width, height, originalFormat; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 169 | char *compressedBuffer; |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 170 | int compressedBufferSize, frameBufferSize; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 171 | object *frameBuffer; |
| 172 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 173 | if (!getargs(args, "(iiiis#)", &compressionScheme, &width, &height, |
| 174 | &originalFormat, &compressedBuffer, |
| 175 | &compressedBufferSize)) |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 176 | return NULL; |
| 177 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 178 | frameBufferSize = width * height * CL_BytesPerPixel(originalFormat); |
| 179 | |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 180 | frameBuffer = newsizedstringobject(NULL, frameBufferSize); |
| 181 | if (frameBuffer == NULL) |
| 182 | return NULL; |
| 183 | |
| 184 | error_handler_called = 0; |
| 185 | if (clDecompressImage(compressionScheme, width, height, originalFormat, |
| 186 | compressedBufferSize, compressedBuffer, |
| 187 | (void *) getstringvalue(frameBuffer)) == FAILURE) { |
| 188 | DECREF(frameBuffer); |
| 189 | if (!error_handler_called) |
| 190 | err_setstr(ClError, "clDecompressImage failed"); |
| 191 | return NULL; |
| 192 | } |
| 193 | |
| 194 | return frameBuffer; |
| 195 | } |
| 196 | |
| 197 | /******************************************************************** |
| 198 | Sequential compression/decompression. |
| 199 | ********************************************************************/ |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 200 | #define CheckCompressor(self) if ((self)->ob_compressorHdl == NULL) { \ |
| 201 | err_setstr(RuntimeError, "(de)compressor not active"); \ |
| 202 | return NULL; \ |
| 203 | } |
| 204 | |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 205 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 206 | doClose(clobject *self, object *args, int (*close_func)(CL_Handle)) |
Sjoerd Mullender | 37f17b7 | 1992-09-25 10:28:20 +0000 | [diff] [blame] | 207 | { |
| 208 | CheckCompressor(self); |
| 209 | |
| 210 | if (!getnoarg(args)) |
| 211 | return NULL; |
| 212 | |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 213 | error_handler_called = 0; |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 214 | if ((*close_func)(self->ob_compressorHdl) == FAILURE) { |
Sjoerd Mullender | 37f17b7 | 1992-09-25 10:28:20 +0000 | [diff] [blame] | 215 | if (!error_handler_called) |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 216 | err_setstr(ClError, "close failed"); |
Sjoerd Mullender | 37f17b7 | 1992-09-25 10:28:20 +0000 | [diff] [blame] | 217 | return NULL; |
| 218 | } |
| 219 | |
| 220 | self->ob_compressorHdl = NULL; |
| 221 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 222 | if (self->ob_paramtypes) |
| 223 | DEL(self->ob_paramtypes); |
| 224 | self->ob_paramtypes = NULL; |
| 225 | |
Sjoerd Mullender | 37f17b7 | 1992-09-25 10:28:20 +0000 | [diff] [blame] | 226 | INCREF(None); |
| 227 | return None; |
| 228 | } |
| 229 | |
| 230 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 231 | clm_CloseCompressor(object *self, object *args) |
Sjoerd Mullender | 37f17b7 | 1992-09-25 10:28:20 +0000 | [diff] [blame] | 232 | { |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 233 | return doClose(SELF, args, clCloseCompressor); |
Sjoerd Mullender | 37f17b7 | 1992-09-25 10:28:20 +0000 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 237 | clm_CloseDecompressor(object *self, object *args) |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 238 | { |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 239 | return doClose(SELF, args, clCloseDecompressor); |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 243 | clm_Compress(object *self, object *args) |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 244 | { |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 245 | int numberOfFrames; |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 246 | int frameBufferSize, compressedBufferSize, size; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 247 | char *frameBuffer; |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 248 | object *data; |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 249 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 250 | CheckCompressor(SELF); |
Sjoerd Mullender | 37f17b7 | 1992-09-25 10:28:20 +0000 | [diff] [blame] | 251 | |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 252 | if (!getargs(args, "(is#)", &numberOfFrames, &frameBuffer, &frameBufferSize)) |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 253 | return NULL; |
| 254 | |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 255 | error_handler_called = 0; |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 256 | size = clGetParam(SELF->ob_compressorHdl, CL_COMPRESSED_BUFFER_SIZE); |
| 257 | compressedBufferSize = size; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 258 | if (error_handler_called) |
| 259 | return NULL; |
| 260 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 261 | data = newsizedstringobject(NULL, size); |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 262 | if (data == NULL) |
| 263 | return NULL; |
| 264 | |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 265 | error_handler_called = 0; |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 266 | if (clCompress(SELF->ob_compressorHdl, numberOfFrames, |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 267 | (void *) frameBuffer, &compressedBufferSize, |
| 268 | (void *) getstringvalue(data)) == FAILURE) { |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 269 | DECREF(data); |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 270 | if (!error_handler_called) |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 271 | err_setstr(ClError, "compress failed"); |
| 272 | return NULL; |
| 273 | } |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 274 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 275 | if (compressedBufferSize < size) |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 276 | if (resizestring(&data, compressedBufferSize)) |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 277 | return NULL; |
| 278 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 279 | if (compressedBufferSize > size) { |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 280 | /* we didn't get all "compressed" data */ |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 281 | DECREF(data); |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 282 | err_setstr(ClError, "compressed data is more than fitted"); |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 283 | return NULL; |
| 284 | } |
| 285 | |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 286 | return data; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 287 | } |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 288 | |
| 289 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 290 | clm_Decompress(object *self, object *args) |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 291 | { |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 292 | object *data; |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 293 | int numberOfFrames; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 294 | char *compressedData; |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 295 | int compressedDataSize, dataSize; |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 296 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 297 | CheckCompressor(SELF); |
Sjoerd Mullender | 37f17b7 | 1992-09-25 10:28:20 +0000 | [diff] [blame] | 298 | |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 299 | if (!getargs(args, "(is#)", &numberOfFrames, &compressedData, |
| 300 | &compressedDataSize)) |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 301 | return NULL; |
| 302 | |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 303 | error_handler_called = 0; |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 304 | dataSize = clGetParam(SELF->ob_compressorHdl, CL_FRAME_BUFFER_SIZE); |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 305 | if (error_handler_called) |
| 306 | return NULL; |
| 307 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 308 | data = newsizedstringobject(NULL, dataSize); |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 309 | if (data == NULL) |
| 310 | return NULL; |
| 311 | |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 312 | error_handler_called = 0; |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 313 | if (clDecompress(SELF->ob_compressorHdl, numberOfFrames, |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 314 | compressedDataSize, (void *) compressedData, |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 315 | (void *) getstringvalue(data)) == FAILURE) { |
| 316 | DECREF(data); |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 317 | if (!error_handler_called) |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 318 | err_setstr(ClError, "decompress failed"); |
| 319 | return NULL; |
| 320 | } |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 321 | |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 322 | return data; |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 326 | doParams(clobject *self, object *args, int (*func)(CL_Handle, int *, int), |
| 327 | int modified) |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 328 | { |
| 329 | object *list, *v; |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 330 | int *PVbuffer; |
| 331 | int length; |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 332 | int i; |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 333 | float number; |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 334 | |
Sjoerd Mullender | 37f17b7 | 1992-09-25 10:28:20 +0000 | [diff] [blame] | 335 | CheckCompressor(self); |
| 336 | |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 337 | if (!getargs(args, "O", &list)) |
| 338 | return NULL; |
| 339 | if (!is_listobject(list)) { |
| 340 | err_badarg(); |
| 341 | return NULL; |
| 342 | } |
| 343 | length = getlistsize(list); |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 344 | PVbuffer = NEW(int, length); |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 345 | if (PVbuffer == NULL) |
| 346 | return err_nomem(); |
| 347 | for (i = 0; i < length; i++) { |
| 348 | v = getlistitem(list, i); |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 349 | if (is_floatobject(v)) { |
| 350 | number = getfloatvalue(v); |
| 351 | PVbuffer[i] = CL_TypeIsInt(number); |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 352 | } else if (is_intobject(v)) { |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 353 | PVbuffer[i] = getintvalue(v); |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 354 | if ((i & 1) && |
| 355 | param_type_is_float(self, PVbuffer[i-1]) > 0) { |
| 356 | number = PVbuffer[i]; |
| 357 | PVbuffer[i] = CL_TypeIsInt(number); |
| 358 | } |
| 359 | } else { |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 360 | DEL(PVbuffer); |
| 361 | err_badarg(); |
| 362 | return NULL; |
| 363 | } |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 364 | } |
| 365 | |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 366 | error_handler_called = 0; |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 367 | (*func)(self->ob_compressorHdl, PVbuffer, length); |
Sjoerd Mullender | f64992e | 1993-08-03 15:11:36 +0000 | [diff] [blame] | 368 | if (error_handler_called) { |
| 369 | DEL(PVbuffer); |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 370 | return NULL; |
Sjoerd Mullender | f64992e | 1993-08-03 15:11:36 +0000 | [diff] [blame] | 371 | } |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 372 | |
| 373 | if (modified) { |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 374 | for (i = 0; i < length; i++) { |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 375 | if ((i & 1) && |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 376 | param_type_is_float(self, PVbuffer[i-1]) > 0) { |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 377 | number = CL_TypeIsFloat(PVbuffer[i]); |
| 378 | v = newfloatobject(number); |
| 379 | } else |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 380 | v = newintobject(PVbuffer[i]); |
| 381 | setlistitem(list, i, v); |
| 382 | } |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | DEL(PVbuffer); |
| 386 | |
| 387 | INCREF(None); |
| 388 | return None; |
| 389 | } |
| 390 | |
| 391 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 392 | clm_GetParams(object *self, object *args) |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 393 | { |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 394 | return doParams(SELF, args, clGetParams, 1); |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 398 | clm_SetParams(object *self, object *args) |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 399 | { |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 400 | return doParams(SELF, args, clSetParams, 0); |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 404 | do_get(clobject *self, object *args, int (*func)(CL_Handle, int)) |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 405 | { |
| 406 | int paramID, value; |
| 407 | float fvalue; |
| 408 | |
| 409 | CheckCompressor(self); |
| 410 | |
| 411 | if (!getargs(args, "i", ¶mID)) |
| 412 | return NULL; |
| 413 | |
| 414 | error_handler_called = 0; |
| 415 | value = (*func)(self->ob_compressorHdl, paramID); |
| 416 | if (error_handler_called) |
| 417 | return NULL; |
| 418 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 419 | if (param_type_is_float(self, paramID) > 0) { |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 420 | fvalue = CL_TypeIsFloat(value); |
| 421 | return newfloatobject(fvalue); |
| 422 | } |
| 423 | |
| 424 | return newintobject(value); |
| 425 | } |
| 426 | |
| 427 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 428 | clm_GetParam(object *self, object *args) |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 429 | { |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 430 | return do_get(SELF, args, clGetParam); |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 434 | clm_GetDefault(object *self, object *args) |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 435 | { |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 436 | return do_get(SELF, args, clGetDefault); |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 440 | clm_SetParam(object *self, object *args) |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 441 | { |
| 442 | int paramID, value; |
| 443 | float fvalue; |
| 444 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 445 | CheckCompressor(SELF); |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 446 | |
| 447 | if (!getargs(args, "(ii)", ¶mID, &value)) { |
| 448 | err_clear(); |
| 449 | if (!getargs(args, "(if)", ¶mID, &fvalue)) { |
| 450 | err_clear(); |
| 451 | err_setstr(TypeError, "bad argument list (format '(ii)' or '(if)')"); |
| 452 | return NULL; |
| 453 | } |
| 454 | value = CL_TypeIsInt(fvalue); |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 455 | } else { |
| 456 | if (param_type_is_float(SELF, paramID) > 0) { |
| 457 | fvalue = value; |
| 458 | value = CL_TypeIsInt(fvalue); |
| 459 | } |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 460 | } |
| 461 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 462 | error_handler_called = 0; |
| 463 | value = clSetParam(SELF->ob_compressorHdl, paramID, value); |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 464 | if (error_handler_called) |
| 465 | return NULL; |
| 466 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 467 | if (param_type_is_float(SELF, paramID) > 0) |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 468 | return newfloatobject(CL_TypeIsFloat(value)); |
| 469 | else |
| 470 | return newintobject(value); |
| 471 | } |
| 472 | |
| 473 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 474 | clm_GetParamID(object *self, object *args) |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 475 | { |
| 476 | char *name; |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 477 | int value; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 478 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 479 | CheckCompressor(SELF); |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 480 | |
| 481 | if (!getargs(args, "s", &name)) |
| 482 | return NULL; |
| 483 | |
| 484 | error_handler_called = 0; |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 485 | value = clGetParamID(SELF->ob_compressorHdl, name); |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 486 | if (value == FAILURE) { |
| 487 | if (!error_handler_called) |
| 488 | err_setstr(ClError, "getparamid failed"); |
| 489 | return NULL; |
| 490 | } |
| 491 | |
| 492 | return newintobject(value); |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 493 | } |
| 494 | |
| 495 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 496 | clm_QueryParams(object *self, object *args) |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 497 | { |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 498 | int bufferlength; |
| 499 | int *PVbuffer; |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 500 | object *list; |
| 501 | int i; |
| 502 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 503 | CheckCompressor(SELF); |
Sjoerd Mullender | 37f17b7 | 1992-09-25 10:28:20 +0000 | [diff] [blame] | 504 | |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 505 | if (!getnoarg(args)) |
| 506 | return NULL; |
| 507 | |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 508 | error_handler_called = 0; |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 509 | bufferlength = clQueryParams(SELF->ob_compressorHdl, 0, 0); |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 510 | if (error_handler_called) |
| 511 | return NULL; |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 512 | |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 513 | PVbuffer = NEW(int, bufferlength); |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 514 | if (PVbuffer == NULL) |
| 515 | return err_nomem(); |
| 516 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 517 | bufferlength = clQueryParams(SELF->ob_compressorHdl, PVbuffer, |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 518 | bufferlength); |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 519 | if (error_handler_called) { |
| 520 | DEL(PVbuffer); |
| 521 | return NULL; |
| 522 | } |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 523 | |
| 524 | list = newlistobject(bufferlength); |
| 525 | if (list == NULL) { |
| 526 | DEL(PVbuffer); |
| 527 | return NULL; |
| 528 | } |
| 529 | |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 530 | for (i = 0; i < bufferlength; i++) { |
| 531 | if (i & 1) |
| 532 | setlistitem(list, i, newintobject(PVbuffer[i])); |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 533 | else if (PVbuffer[i] == 0) { |
| 534 | INCREF(None); |
| 535 | setlistitem(list, i, None); |
| 536 | } else |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 537 | setlistitem(list, i, newstringobject((char *) PVbuffer[i])); |
| 538 | } |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 539 | |
| 540 | DEL(PVbuffer); |
| 541 | |
| 542 | return list; |
| 543 | } |
| 544 | |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 545 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 546 | clm_GetMinMax(object *self, object *args) |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 547 | { |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 548 | int param, min, max; |
| 549 | float fmin, fmax; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 550 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 551 | CheckCompressor(SELF); |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 552 | |
| 553 | if (!getargs(args, "i", ¶m)) |
| 554 | return NULL; |
| 555 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 556 | clGetMinMax(SELF->ob_compressorHdl, param, &min, &max); |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 557 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 558 | if (param_type_is_float(SELF, param) > 0) { |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 559 | fmin = CL_TypeIsFloat(min); |
| 560 | fmax = CL_TypeIsFloat(max); |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 561 | return mkvalue("(ff)", fmin, fmax); |
| 562 | } |
| 563 | |
| 564 | return mkvalue("(ii)", min, max); |
| 565 | } |
| 566 | |
| 567 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 568 | clm_GetName(object *self, object *args) |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 569 | { |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 570 | int param; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 571 | char *name; |
| 572 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 573 | CheckCompressor(SELF); |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 574 | |
| 575 | if (!getargs(args, "i", ¶m)) |
| 576 | return NULL; |
| 577 | |
| 578 | error_handler_called = 0; |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 579 | name = clGetName(SELF->ob_compressorHdl, param); |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 580 | if (name == NULL || error_handler_called) { |
| 581 | if (!error_handler_called) |
| 582 | err_setstr(ClError, "getname failed"); |
| 583 | return NULL; |
| 584 | } |
| 585 | |
| 586 | return newstringobject(name); |
| 587 | } |
| 588 | |
| 589 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 590 | clm_QuerySchemeFromHandle(object *self, object *args) |
| 591 | { |
| 592 | CheckCompressor(SELF); |
| 593 | |
| 594 | if (!getnoarg(args)) |
| 595 | return NULL; |
| 596 | |
| 597 | return newintobject(clQuerySchemeFromHandle(SELF->ob_compressorHdl)); |
| 598 | } |
| 599 | |
| 600 | static object * |
| 601 | clm_ReadHeader(object *self, object *args) |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 602 | { |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 603 | char *header; |
| 604 | int headerSize; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 605 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 606 | CheckCompressor(SELF); |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 607 | |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 608 | if (!getargs(args, "s#", &header, &headerSize)) |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 609 | return NULL; |
| 610 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 611 | return newintobject(clReadHeader(SELF->ob_compressorHdl, |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 612 | headerSize, header)); |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 613 | } |
| 614 | |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 615 | static struct methodlist compressor_methods[] = { |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 616 | {"close", clm_CloseCompressor}, /* alias */ |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 617 | {"CloseCompressor", clm_CloseCompressor}, |
| 618 | {"Compress", clm_Compress}, |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 619 | {"GetDefault", clm_GetDefault}, |
| 620 | {"GetMinMax", clm_GetMinMax}, |
| 621 | {"GetName", clm_GetName}, |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 622 | {"GetParam", clm_GetParam}, |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 623 | {"GetParamID", clm_GetParamID}, |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 624 | {"GetParams", clm_GetParams}, |
| 625 | {"QueryParams", clm_QueryParams}, |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 626 | {"QuerySchemeFromHandle",clm_QuerySchemeFromHandle}, |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 627 | {"SetParam", clm_SetParam}, |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 628 | {"SetParams", clm_SetParams}, |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 629 | {NULL, NULL} /* sentinel */ |
| 630 | }; |
| 631 | |
| 632 | static struct methodlist decompressor_methods[] = { |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 633 | {"close", clm_CloseDecompressor}, /* alias */ |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 634 | {"CloseDecompressor", clm_CloseDecompressor}, |
| 635 | {"Decompress", clm_Decompress}, |
| 636 | {"GetDefault", clm_GetDefault}, |
| 637 | {"GetMinMax", clm_GetMinMax}, |
| 638 | {"GetName", clm_GetName}, |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 639 | {"GetParam", clm_GetParam}, |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 640 | {"GetParamID", clm_GetParamID}, |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 641 | {"GetParams", clm_GetParams}, |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 642 | {"ReadHeader", clm_ReadHeader}, |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 643 | {"QueryParams", clm_QueryParams}, |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 644 | {"QuerySchemeFromHandle",clm_QuerySchemeFromHandle}, |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 645 | {"SetParam", clm_SetParam}, |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 646 | {"SetParams", clm_SetParams}, |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 647 | {NULL, NULL} /* sentinel */ |
| 648 | }; |
| 649 | |
| 650 | static void |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 651 | cl_dealloc(object *self) |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 652 | { |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 653 | if (SELF->ob_compressorHdl) { |
| 654 | if (SELF->ob_isCompressor) |
| 655 | clCloseCompressor(SELF->ob_compressorHdl); |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 656 | else |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 657 | clCloseDecompressor(SELF->ob_compressorHdl); |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 658 | } |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 659 | DEL(self); |
| 660 | } |
| 661 | |
| 662 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 663 | cl_getattr(object *self, char *name) |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 664 | { |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 665 | if (SELF->ob_isCompressor) |
| 666 | return findmethod(compressor_methods, self, name); |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 667 | else |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 668 | return findmethod(decompressor_methods, self, name); |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 669 | } |
| 670 | |
| 671 | static typeobject Cltype = { |
| 672 | OB_HEAD_INIT(&Typetype) |
| 673 | 0, /*ob_size*/ |
| 674 | "cl", /*tp_name*/ |
| 675 | sizeof(clobject), /*tp_size*/ |
| 676 | 0, /*tp_itemsize*/ |
| 677 | /* methods */ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 678 | (destructor)cl_dealloc, /*tp_dealloc*/ |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 679 | 0, /*tp_print*/ |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 680 | (getattrfunc)cl_getattr, /*tp_getattr*/ |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 681 | 0, /*tp_setattr*/ |
| 682 | 0, /*tp_compare*/ |
| 683 | 0, /*tp_repr*/ |
| 684 | 0, /*tp_as_number*/ |
| 685 | 0, /*tp_as_sequence*/ |
| 686 | 0, /*tp_as_mapping*/ |
| 687 | }; |
| 688 | |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 689 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 690 | doOpen(object *self, object *args, int (*open_func)(int, CL_Handle *), |
| 691 | int iscompressor) |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 692 | { |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 693 | int scheme; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 694 | clobject *new; |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 695 | |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 696 | if (!getargs(args, "i", &scheme)) |
| 697 | return NULL; |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 698 | |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 699 | new = NEWOBJ(clobject, &Cltype); |
| 700 | if (new == NULL) |
| 701 | return NULL; |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 702 | |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 703 | new->ob_compressorHdl = NULL; |
| 704 | new->ob_isCompressor = iscompressor; |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 705 | new->ob_paramtypes = NULL; |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 706 | |
| 707 | error_handler_called = 0; |
| 708 | if ((*open_func)(scheme, &new->ob_compressorHdl) == FAILURE) { |
| 709 | DECREF(new); |
| 710 | if (!error_handler_called) |
| 711 | err_setstr(ClError, "Open(De)Compressor failed"); |
| 712 | return NULL; |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 713 | } |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 714 | return (object *)new; |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 715 | } |
| 716 | |
| 717 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 718 | cl_OpenCompressor(object *self, object *args) |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 719 | { |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 720 | return doOpen(self, args, clOpenCompressor, 1); |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 721 | } |
| 722 | |
| 723 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 724 | cl_OpenDecompressor(object *self, object *args) |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 725 | { |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 726 | return doOpen(self, args, clOpenDecompressor, 0); |
Sjoerd Mullender | 384f248 | 1992-09-29 16:43:43 +0000 | [diff] [blame] | 727 | } |
| 728 | |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 729 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 730 | cl_QueryScheme(object *self, object *args) |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 731 | { |
| 732 | char *header; |
| 733 | int headerlen; |
| 734 | int scheme; |
| 735 | |
| 736 | if (!getargs(args, "s#", &header, &headerlen)) |
| 737 | return NULL; |
| 738 | |
| 739 | scheme = clQueryScheme(header); |
| 740 | if (scheme < 0) { |
| 741 | err_setstr(ClError, "unknown compression scheme"); |
| 742 | return NULL; |
| 743 | } |
| 744 | |
| 745 | return newintobject(scheme); |
| 746 | } |
| 747 | |
| 748 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 749 | cl_QueryMaxHeaderSize(object *self, object *args) |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 750 | { |
| 751 | int scheme; |
| 752 | |
| 753 | if (!getargs(args, "i", &scheme)) |
| 754 | return NULL; |
| 755 | |
| 756 | return newintobject(clQueryMaxHeaderSize(scheme)); |
| 757 | } |
| 758 | |
| 759 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 760 | cl_QueryAlgorithms(object *self, object *args) |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 761 | { |
| 762 | int algorithmMediaType; |
| 763 | int bufferlength; |
| 764 | int *PVbuffer; |
| 765 | object *list; |
| 766 | int i; |
| 767 | |
| 768 | if (!getargs(args, "i", &algorithmMediaType)) |
| 769 | return NULL; |
| 770 | |
| 771 | error_handler_called = 0; |
| 772 | bufferlength = clQueryAlgorithms(algorithmMediaType, 0, 0); |
| 773 | if (error_handler_called) |
| 774 | return NULL; |
| 775 | |
| 776 | PVbuffer = NEW(int, bufferlength); |
| 777 | if (PVbuffer == NULL) |
| 778 | return err_nomem(); |
| 779 | |
| 780 | bufferlength = clQueryAlgorithms(algorithmMediaType, PVbuffer, |
| 781 | bufferlength); |
| 782 | if (error_handler_called) { |
| 783 | DEL(PVbuffer); |
| 784 | return NULL; |
| 785 | } |
| 786 | |
| 787 | list = newlistobject(bufferlength); |
| 788 | if (list == NULL) { |
| 789 | DEL(PVbuffer); |
| 790 | return NULL; |
| 791 | } |
| 792 | |
| 793 | for (i = 0; i < bufferlength; i++) { |
| 794 | if (i & 1) |
| 795 | setlistitem(list, i, newintobject(PVbuffer[i])); |
| 796 | else if (PVbuffer[i] == 0) { |
| 797 | INCREF(None); |
| 798 | setlistitem(list, i, None); |
| 799 | } else |
| 800 | setlistitem(list, i, newstringobject((char *) PVbuffer[i])); |
| 801 | } |
| 802 | |
| 803 | DEL(PVbuffer); |
| 804 | |
| 805 | return list; |
| 806 | } |
| 807 | |
| 808 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 809 | cl_QuerySchemeFromName(object *self, object *args) |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 810 | { |
| 811 | int algorithmMediaType; |
| 812 | char *name; |
| 813 | int scheme; |
| 814 | |
| 815 | if (!getargs(args, "(is)", &algorithmMediaType, &name)) |
| 816 | return NULL; |
| 817 | |
| 818 | error_handler_called = 0; |
| 819 | scheme = clQuerySchemeFromName(algorithmMediaType, name); |
| 820 | if (error_handler_called) { |
| 821 | err_setstr(ClError, "unknown compression scheme"); |
| 822 | return NULL; |
| 823 | } |
| 824 | |
| 825 | return newintobject(scheme); |
| 826 | } |
| 827 | |
| 828 | static object * |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 829 | cl_GetAlgorithmName(object *self, object *args) |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 830 | { |
| 831 | int scheme; |
| 832 | char *name; |
| 833 | |
| 834 | if (!getargs(args, "i", &scheme)) |
| 835 | return NULL; |
| 836 | |
| 837 | name = clGetAlgorithmName(scheme); |
| 838 | if (name == 0) { |
| 839 | err_setstr(ClError, "unknown compression scheme"); |
| 840 | return NULL; |
| 841 | } |
| 842 | |
| 843 | return newstringobject(name); |
| 844 | } |
| 845 | |
Sjoerd Mullender | 22e44cd | 1993-02-17 09:11:14 +0000 | [diff] [blame] | 846 | static object * |
| 847 | do_set(object *self, object *args, int (*func)(int, int, int)) |
| 848 | { |
| 849 | int scheme, paramID, value; |
| 850 | float fvalue; |
| 851 | int is_float = 0; |
| 852 | |
| 853 | if (!getargs(args, "(iii)", &scheme, ¶mID, &value)) { |
| 854 | err_clear(); |
| 855 | if (!getargs(args, "(iif)", &scheme, ¶mID, &fvalue)) { |
| 856 | err_clear(); |
| 857 | err_setstr(TypeError, "bad argument list (format '(iii)' or '(iif)')"); |
| 858 | return NULL; |
| 859 | } |
| 860 | value = CL_TypeIsInt(fvalue); |
| 861 | is_float = 1; |
| 862 | } else { |
| 863 | /* check some parameters which we know to be floats */ |
| 864 | switch (scheme) { |
| 865 | case CL_COMPRESSION_RATIO: |
| 866 | case CL_SPEED: |
| 867 | fvalue = value; |
| 868 | value = CL_TypeIsInt(fvalue); |
| 869 | is_float = 1; |
| 870 | break; |
| 871 | } |
| 872 | } |
| 873 | |
| 874 | error_handler_called = 0; |
| 875 | value = (*func)(scheme, paramID, value); |
| 876 | if (error_handler_called) |
| 877 | return NULL; |
| 878 | |
| 879 | if (is_float) |
| 880 | return newfloatobject(CL_TypeIsFloat(value)); |
| 881 | else |
| 882 | return newintobject(value); |
| 883 | } |
| 884 | |
| 885 | static object * |
| 886 | cl_SetDefault(object *self, object *args) |
| 887 | { |
| 888 | return do_set(self, args, clSetDefault); |
| 889 | } |
| 890 | |
| 891 | static object * |
| 892 | cl_SetMin(object *self, object *args) |
| 893 | { |
| 894 | return do_set(self, args, clSetMin); |
| 895 | } |
| 896 | |
| 897 | static object * |
| 898 | cl_SetMax(object *self, object *args) |
| 899 | { |
| 900 | return do_set(self, args, clSetMax); |
| 901 | } |
| 902 | |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 903 | #ifdef CLDEBUG |
| 904 | static object * |
| 905 | cvt_type(object *self, object *args) |
| 906 | { |
| 907 | int number; |
| 908 | float fnumber; |
| 909 | |
| 910 | if (getargs(args, "i", &number)) |
| 911 | return newfloatobject(CL_TypeIsFloat(number)); |
| 912 | else { |
| 913 | err_clear(); |
| 914 | if (getargs(args, "f", &fnumber)) |
| 915 | return newintobject(CL_TypeIsInt(fnumber)); |
| 916 | return NULL; |
| 917 | } |
| 918 | } |
| 919 | #endif |
| 920 | |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 921 | static struct methodlist cl_methods[] = { |
Sjoerd Mullender | 8dd054d | 1992-12-14 13:17:29 +0000 | [diff] [blame] | 922 | {"CompressImage", cl_CompressImage}, |
| 923 | {"DecompressImage", cl_DecompressImage}, |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 924 | {"GetAlgorithmName", cl_GetAlgorithmName}, |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 925 | {"OpenCompressor", cl_OpenCompressor}, |
| 926 | {"OpenDecompressor", cl_OpenDecompressor}, |
Sjoerd Mullender | 3a99727 | 1993-02-04 16:43:28 +0000 | [diff] [blame] | 927 | {"QueryAlgorithms", cl_QueryAlgorithms}, |
| 928 | {"QueryMaxHeaderSize", cl_QueryMaxHeaderSize}, |
| 929 | {"QueryScheme", cl_QueryScheme}, |
| 930 | {"QuerySchemeFromName", cl_QuerySchemeFromName}, |
Sjoerd Mullender | 22e44cd | 1993-02-17 09:11:14 +0000 | [diff] [blame] | 931 | {"SetDefault", cl_SetDefault}, |
| 932 | {"SetMax", cl_SetMax}, |
| 933 | {"SetMin", cl_SetMin}, |
Sjoerd Mullender | 4e2a427 | 1993-02-16 11:55:17 +0000 | [diff] [blame] | 934 | #ifdef CLDEBUG |
| 935 | {"cvt_type", cvt_type}, |
| 936 | #endif |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 937 | {NULL, NULL} /* Sentinel */ |
| 938 | }; |
| 939 | |
| 940 | void |
| 941 | initcl() |
| 942 | { |
Sjoerd Mullender | d53a4f3 | 1992-09-24 10:37:39 +0000 | [diff] [blame] | 943 | object *m, *d; |
| 944 | |
| 945 | m = initmodule("cl", cl_methods); |
| 946 | d = getmoduledict(m); |
| 947 | |
| 948 | ClError = newstringobject("cl.error"); |
| 949 | if (ClError == NULL || dictinsert(d, "error", ClError) != 0) |
| 950 | fatal("can't define cl.error"); |
| 951 | |
| 952 | (void) clSetErrorHandler(cl_ErrorHandler); |
Sjoerd Mullender | c431549 | 1992-09-23 14:53:00 +0000 | [diff] [blame] | 953 | } |