blob: 31f2691a2faf7f8e1c0d169098403f46e700d1b9 [file] [log] [blame]
Sjoerd Mullenderc4315491992-09-23 14:53:00 +00001/***********************************************************
2Copyright 1991, 1992 by Stichting Mathematisch Centrum, Amsterdam, The
3Netherlands.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this software and its
8documentation for any purpose and without fee is hereby granted,
9provided that the above copyright notice appear in all copies and that
10both that copyright notice and this permission notice appear in
11supporting documentation, and that the names of Stichting Mathematisch
12Centrum or CWI not be used in advertising or publicity pertaining to
13distribution of the software without specific, written prior permission.
14
15STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
16THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
17FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
18FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
20ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
21OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
22
23******************************************************************/
24
25
26/* Cl objects */
27
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +000028#include <stdarg.h>
Sjoerd Mullenderc4315491992-09-23 14:53:00 +000029#include <cl.h>
30#include "allobjects.h"
31#include "modsupport.h" /* For getargs() etc. */
32#include "ceval.h" /* For call_object() */
33
34typedef struct {
35 OB_HEAD
36 int ob_isCompressor; /* Compressor or Decompressor */
37 CL_CompressorHdl ob_compressorHdl;
38 long ob_dataMaxSize;
39 object *ob_callbackFunc;
40 object *ob_callbackID;
41 object *ob_data;
42} clobject;
43
Sjoerd Mullender37f17b71992-09-25 10:28:20 +000044#define CheckCompressor(self) if ((self)->ob_compressorHdl == NULL) { \
45 err_setstr(RuntimeError, "(de)compressor not active"); \
46 return NULL; \
47 }
48
Sjoerd Mullenderc4315491992-09-23 14:53:00 +000049extern typeobject Cltype; /* Really static, forward */
50
51#define is_clobject(v) ((v)->ob_type == &Cltype)
52
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +000053static object *ClError; /* exception cl.error */
54
55static int error_handler_called = 0;
56
57static void
58cl_ErrorHandler(long errnum, const char *fmt, ...)
59{
60 va_list ap;
61 char errbuf[BUFSIZ]; /* hopefully big enough */
62
63 error_handler_called = 1;
64 va_start(ap, fmt);
65 vsprintf(errbuf, fmt, ap);
66 va_end(ap);
67 err_setstr(ClError, errbuf);
68}
69
Sjoerd Mullenderc4315491992-09-23 14:53:00 +000070static object *
Sjoerd Mullender37f17b71992-09-25 10:28:20 +000071cl_CloseCompressor(self, args)
72 clobject *self;
73 object *args;
74{
75 CheckCompressor(self);
76
77 if (!getnoarg(args))
78 return NULL;
79
80 if (clCloseCompressor(self->ob_compressorHdl) == FAILURE) {
81 if (!error_handler_called)
82 err_setstr(ClError, "CloseCompressor failed");
83 return NULL;
84 }
85
86 self->ob_compressorHdl = NULL;
87
88 INCREF(None);
89 return None;
90}
91
92static object *
93cl_CloseDecompressor(self, args)
94 clobject *self;
95 object *args;
96{
97 CheckCompressor(self);
98
99 if (!getnoarg(args))
100 return NULL;
101
102 if (clCloseDecompressor(self->ob_compressorHdl) == FAILURE) {
103 if (!error_handler_called)
104 err_setstr(ClError, "CloseDecompressor failed");
105 return NULL;
106 }
107
108 self->ob_compressorHdl = NULL;
109
110 INCREF(None);
111 return None;
112}
113
114static object *
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000115cl_Compress(self, args)
116 clobject *self;
117 object *args;
118{
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000119 object *data;
120 long frameIndex, numberOfFrames, dataSize;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000121
Sjoerd Mullender37f17b71992-09-25 10:28:20 +0000122 CheckCompressor(self);
123
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000124 if (!getargs(args, "(ii)", &frameIndex, &numberOfFrames))
125 return NULL;
126
127 data = newsizedstringobject(NULL,
128 numberOfFrames * self->ob_dataMaxSize);
129 if (data == NULL)
130 return NULL;
131
132 dataSize = numberOfFrames * self->ob_dataMaxSize;
133
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000134 error_handler_called = 0;
135 if (clCompress(self->ob_compressorHdl, frameIndex, numberOfFrames,
136 &dataSize, (void *) getstringvalue(data)) == FAILURE) {
137 DECREF(data);
138 if (!error_handler_called)
139 err_setstr(ClError, "compress failed");
140 return NULL;
141 }
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000142
143 if (dataSize < numberOfFrames * self->ob_dataMaxSize)
144 if (resizestring(&data, dataSize))
145 return NULL;
146
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000147 return data;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000148}
149
150static object *
151cl_Decompress(self, args)
152 clobject *self;
153 object *args;
154{
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000155 object *data;
156 long frameIndex, numberOfFrames;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000157
Sjoerd Mullender37f17b71992-09-25 10:28:20 +0000158 CheckCompressor(self);
159
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000160 if (!getargs(args, "(ii)", &frameIndex, &numberOfFrames))
161 return NULL;
162
163 data = newsizedstringobject(NULL,
164 numberOfFrames * self->ob_dataMaxSize);
165 if (data == NULL)
166 return NULL;
167
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000168 error_handler_called = 0;
169 if (clDecompress(self->ob_compressorHdl, frameIndex, numberOfFrames,
170 (void *) getstringvalue(data)) == FAILURE) {
171 DECREF(data);
172 if (!error_handler_called)
173 err_setstr(ClError, "decompress failed");
174 return NULL;
175 }
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000176
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000177 return data;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000178}
179
180static object *
181cl_GetCompressorInfo(self, args)
182 clobject *self;
183 object *args;
184{
185 long result, infoSize;
186 void *info;
187 object *infoObject, *res;
188
Sjoerd Mullender37f17b71992-09-25 10:28:20 +0000189 CheckCompressor(self);
190
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000191 if (!getnoarg(args))
192 return NULL;
193
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000194 error_handler_called = 0;
195 if (clGetCompressorInfo(self->ob_compressorHdl, &infoSize, &info) == FAILURE) {
196 if (!error_handler_called)
197 err_setstr(ClError, "getcompressorinfo failed");
198 return NULL;
199 }
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000200
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000201 return newsizedstringobject((char *) info, infoSize);
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000202}
203
204static object *
205cl_GetDefault(self, args)
206 clobject *self;
207 object *args;
208{
209 long initial, result;
210
Sjoerd Mullender37f17b71992-09-25 10:28:20 +0000211 CheckCompressor(self);
212
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000213 if (!getargs(args, "i", &initial))
214 return NULL;
215
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000216 error_handler_called = 0;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000217 result = clGetDefault(self->ob_compressorHdl, initial);
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000218 if (error_handler_called)
219 return NULL;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000220
221 return newintobject(result);
222}
223
224static object *
225cl_GetMinMax(self, args)
226 clobject *self;
227 object *args;
228{
229 long param, min, max;
230
Sjoerd Mullender37f17b71992-09-25 10:28:20 +0000231 CheckCompressor(self);
232
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000233 if (!getargs(args, "i", &param))
234 return NULL;
235
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000236 error_handler_called = 0;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000237 clGetMinMax(self->ob_compressorHdl, param, &min, &max);
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000238 if (error_handler_called)
239 return NULL;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000240
241 return mkvalue("(ii)", min, max);
242}
243
244static object *
245cl_GetName(self, args)
246 clobject *self;
247 object *args;
248{
249 long descriptor;
250 char *name;
251
Sjoerd Mullender37f17b71992-09-25 10:28:20 +0000252 CheckCompressor(self);
253
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000254 if (!getargs(args, "i", &descriptor))
255 return NULL;
256
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000257 error_handler_called = 0;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000258 name = clGetName(self->ob_compressorHdl, descriptor);
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000259 if (error_handler_called)
260 return NULL;
261 if (name == NULL) {
262 err_setstr(ClError, "getname failed");
263 return NULL;
264 }
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000265
266 return newstringobject(name);
267}
268
269static object *
270doParams(self, args, func, modified)
271 clobject *self;
272 object *args;
273 void (*func)(CL_CompressorHdl, long *, long);
274 int modified;
275{
276 object *list, *v;
277 long *PVbuffer;
278 long length;
279 int i;
280
Sjoerd Mullender37f17b71992-09-25 10:28:20 +0000281 CheckCompressor(self);
282
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000283 if (!getargs(args, "O", &list))
284 return NULL;
285 if (!is_listobject(list)) {
286 err_badarg();
287 return NULL;
288 }
289 length = getlistsize(list);
290 PVbuffer = NEW(long, length);
291 if (PVbuffer == NULL)
292 return err_nomem();
293 for (i = 0; i < length; i++) {
294 v = getlistitem(list, i);
295 if (!is_intobject(v)) {
296 DEL(PVbuffer);
297 err_badarg();
298 return NULL;
299 }
300 PVbuffer[i] = getintvalue(v);
301 }
302
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000303 error_handler_called = 0;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000304 (*func)(self->ob_compressorHdl, PVbuffer, length);
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000305 if (error_handler_called)
306 return NULL;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000307
308 if (modified) {
309 for (i = 0; i < length; i++)
310 setlistitem(list, i, newintobject(PVbuffer[i]));
311 }
312
313 DEL(PVbuffer);
314
315 INCREF(None);
316 return None;
317}
318
319static object *
320cl_GetParams(self, args)
321 object *self, *args;
322{
323 return doParams(self, args, clGetParams, 1);
324}
325
326static object *
327cl_SetParams(self, args)
328 object *self, *args;
329{
330 return doParams(self, args, clSetParams, 0);
331}
332
333static object *
334cl_QueryParams(self, args)
335 clobject *self;
336 object *args;
337{
338 long bufferlength;
339 long *PVbuffer;
340 object *list;
341 int i;
342
Sjoerd Mullender37f17b71992-09-25 10:28:20 +0000343 CheckCompressor(self);
344
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000345 if (!getnoarg(args))
346 return NULL;
347
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000348 error_handler_called = 0;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000349 bufferlength = clQueryParams(self->ob_compressorHdl, 0, 0);
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000350 if (error_handler_called)
351 return NULL;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000352
353 PVbuffer = NEW(long, bufferlength);
354 if (PVbuffer == NULL)
355 return err_nomem();
356
357 bufferlength = clQueryParams(self->ob_compressorHdl, PVbuffer,
358 bufferlength);
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000359 if (error_handler_called) {
360 DEL(PVbuffer);
361 return NULL;
362 }
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000363
364 list = newlistobject(bufferlength);
365 if (list == NULL) {
366 DEL(PVbuffer);
367 return NULL;
368 }
369
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000370 for (i = 0; i < bufferlength; i++) {
371 if (i & 1)
372 setlistitem(list, i, newintobject(PVbuffer[i]));
373 else
374 setlistitem(list, i, newstringobject((char *) PVbuffer[i]));
375 }
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000376
377 DEL(PVbuffer);
378
379 return list;
380}
381
382static struct methodlist compressor_methods[] = {
Sjoerd Mullender37f17b71992-09-25 10:28:20 +0000383 {"CloseCompressor", cl_CloseCompressor},
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000384 {"Compress", cl_Compress},
385 {"GetCompressorInfo", cl_GetCompressorInfo},
386 {"GetDefault", cl_GetDefault},
387 {"GetMinMax", cl_GetMinMax},
388 {"GetName", cl_GetName},
389 {"GetParams", cl_GetParams},
390 {"QueryParams", cl_QueryParams},
391 {"SetParams", cl_SetParams},
392 {NULL, NULL} /* sentinel */
393};
394
395static struct methodlist decompressor_methods[] = {
Sjoerd Mullender37f17b71992-09-25 10:28:20 +0000396 {"CloseDecompressor", cl_CloseDecompressor},
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000397 {"Decompress", cl_Decompress},
398 {"GetDefault", cl_GetDefault},
399 {"GetMinMax", cl_GetMinMax},
400 {"GetName", cl_GetName},
401 {"GetParams", cl_GetParams},
402 {"QueryParams", cl_QueryParams},
403 {"SetParams", cl_SetParams},
404 {NULL, NULL} /* sentinel */
405};
406
407static void
408cl_dealloc(self)
409 clobject *self;
410{
411 if (self->ob_compressorHdl) {
412 if (self->ob_isCompressor)
413 clCloseCompressor(self->ob_compressorHdl);
414 else
415 clCloseDecompressor(self->ob_compressorHdl);
416 }
417 XDECREF(self->ob_callbackFunc);
418 XDECREF(self->ob_callbackID);
419 XDECREF(self->ob_data);
420 DEL(self);
421}
422
423static object *
424cl_getattr(self, name)
425 clobject *self;
426 char *name;
427{
428 if (self->ob_isCompressor)
429 return findmethod(compressor_methods, (object *)self, name);
430 else
431 return findmethod(decompressor_methods, (object *) self, name);
432}
433
434static typeobject Cltype = {
435 OB_HEAD_INIT(&Typetype)
436 0, /*ob_size*/
437 "cl", /*tp_name*/
438 sizeof(clobject), /*tp_size*/
439 0, /*tp_itemsize*/
440 /* methods */
441 cl_dealloc, /*tp_dealloc*/
442 0, /*tp_print*/
443 cl_getattr, /*tp_getattr*/
444 0, /*tp_setattr*/
445 0, /*tp_compare*/
446 0, /*tp_repr*/
447 0, /*tp_as_number*/
448 0, /*tp_as_sequence*/
449 0, /*tp_as_mapping*/
450};
451
452static long
453GetFrame(callbackID, frameIndex, numberOfFrames, data)
454 void *callbackID;
455 long frameIndex;
456 long numberOfFrames;
457 void **data;
458{
459 object *args;
460 clobject *self = (clobject *) callbackID;
461 object *result;
462
463 args = newtupleobject(3);
464 if (args == NULL)
465 return FAILURE;
466
467 XINCREF(self->ob_callbackID);
468 settupleitem(args, 0, self->ob_callbackID);
469 settupleitem(args, 1, newintobject(frameIndex));
470 settupleitem(args, 2, newintobject(numberOfFrames));
471
472 if (err_occurred()) {
473 XDECREF(self->ob_callbackID);
474 return FAILURE;
475 }
476
477 result = call_object(self->ob_callbackFunc, args);
478 DECREF(args);
479 if (result == NULL)
480 return FAILURE;
481
482 if (!is_stringobject(result)) {
483 DECREF(result);
484 return FAILURE;
485 }
486
487 XDECREF(self->ob_data);
488 self->ob_data = result;
489
490 *data = (void *) getstringvalue(result);
491
492 return SUCCESS;
493}
494
495static long
496GetData(callbackID, frameIndex, numberOfFrames, dataSize, data)
497 void *callbackID;
498 long frameIndex;
499 long numberOfFrames;
500 long *dataSize;
501 void **data;
502{
503 object *args, *result;
504 clobject *self = (clobject *) callbackID;
505
506 args = newtupleobject(3);
507 if (args == NULL)
508 return FAILURE;
509
510 XINCREF(self->ob_callbackID);
511 settupleitem(args, 0, self->ob_callbackID);
512 settupleitem(args, 1, newintobject(frameIndex));
513 settupleitem(args, 2, newintobject(numberOfFrames));
514
515 if (err_occurred()) {
516 XDECREF(self->ob_callbackID);
517 return FAILURE;
518 }
519
520 result = call_object(self->ob_callbackFunc, args);
521 DECREF(args);
522 if (result == NULL)
523 return FAILURE;
524
525 if (!is_stringobject(result)) {
526 DECREF(result);
527 return FAILURE;
528 }
529
530 XDECREF(self->ob_data);
531 self->ob_data = result;
532
533 *dataSize = getstringsize(result);
534 *data = (void *) getstringvalue(result);
535
536 return SUCCESS;
537}
538
539static object *
540cl_OpenCompressor(self, args)
541 object *self, *args;
542{
543 CL_CompressionFormat compressionFormat;
544 long qualityFactor;
545 object *GetFrameCBPtr;
546 object *callbackID;
547 clobject *new;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000548
549 if (!getargs(args, "((iiiiiiiiii)iOO)",
550 &compressionFormat.width,
551 &compressionFormat.height,
552 &compressionFormat.frameSize,
553 &compressionFormat.dataMaxSize,
554 &compressionFormat.originalFormat,
555 &compressionFormat.components,
556 &compressionFormat.bitsPerComponent,
557 &compressionFormat.frameRate,
558 &compressionFormat.numberOfFrames,
559 &compressionFormat.compressionScheme,
560 &qualityFactor, &GetFrameCBPtr, &callbackID))
561 return NULL;
562
563 new = NEWOBJ(clobject, &Cltype);
564 if (new == 0)
565 return NULL;
566
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000567 new->ob_compressorHdl = NULL;
568 new->ob_callbackFunc = NULL;
569 new->ob_callbackID = NULL;
570 new->ob_data = NULL;
571
572 error_handler_called = 0;
573 if (clOpenCompressor(&compressionFormat, qualityFactor, GetFrame,
574 (void *) new, &new->ob_compressorHdl) == FAILURE) {
575 DECREF(new);
576 if (!error_handler_called)
577 err_setstr(ClError, "opencompressor failed");
578 return NULL;
579 }
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000580
581 new->ob_isCompressor = 1;
582 new->ob_callbackFunc = GetFrameCBPtr;
583 XINCREF(new->ob_callbackFunc);
584 if (callbackID == NULL)
585 callbackID = None;
586 new->ob_callbackID = callbackID;
587 INCREF(new->ob_callbackID);
588 new->ob_data = NULL;
589 new->ob_dataMaxSize = compressionFormat.dataMaxSize;
590
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000591 return new;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000592}
593
594static object *
595cl_OpenDecompressor(self, args)
596 object *self, *args;
597{
598 CL_CompressionFormat compressionFormat;
599 long infoSize;
600 void *info;
601 object *GetDataCBPtr;
602 object *callbackID;
603 clobject *new;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000604 object *res;
605
Sjoerd Mullender37f17b71992-09-25 10:28:20 +0000606 if (!getargs(args, "((iiiiiiiiii)s#OO)",
607 &compressionFormat.width,
608 &compressionFormat.height,
609 &compressionFormat.frameSize,
610 &compressionFormat.dataMaxSize,
611 &compressionFormat.originalFormat,
612 &compressionFormat.components,
613 &compressionFormat.bitsPerComponent,
614 &compressionFormat.frameRate,
615 &compressionFormat.numberOfFrames,
616 &compressionFormat.compressionScheme,
617 &info, &infoSize, &GetDataCBPtr, &callbackID))
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000618 return NULL;
619
620 new = NEWOBJ(clobject, &Cltype);
621 if (new == 0)
622 return NULL;
623
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000624 new->ob_compressorHdl = NULL;
625 new->ob_callbackFunc = NULL;
626 new->ob_callbackID = NULL;
627 new->ob_data = NULL;
628
629 error_handler_called = 0;
630 if (clOpenDecompressor(&compressionFormat, infoSize, info, GetData,
631 (void *) new, &new->ob_compressorHdl) == FAILURE) {
Sjoerd Mullender37f17b71992-09-25 10:28:20 +0000632 new->ob_compressorHdl = NULL; /* just in case... */
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000633 DECREF(new);
634 if (!error_handler_called)
635 err_setstr(ClError, "opendecompressor failed");
636 return NULL;
637 }
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000638
639 new->ob_isCompressor = 0;
640 new->ob_callbackFunc = GetDataCBPtr;
641 XINCREF(new->ob_callbackFunc);
642 if (callbackID == NULL)
643 callbackID = None;
644 new->ob_callbackID = callbackID;
645 XINCREF(new->ob_callbackID);
646 new->ob_data = NULL;
Sjoerd Mullender37f17b71992-09-25 10:28:20 +0000647 new->ob_dataMaxSize = compressionFormat.dataMaxSize;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000648
Sjoerd Mullender37f17b71992-09-25 10:28:20 +0000649 return new;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000650}
651
652static object *
653cl_AddParam(self, args)
654 object *self, *args;
655{
656 char *name;
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000657 long type, min, max, initial, paramID;
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000658
659 if (!getargs(args, "(siiii)", &name, &type, &min, &max, &initial))
660 return NULL;
661
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000662 error_handler_called = 0;
663 if (clAddParam(name, type, min, max, initial, &paramID) == FAILURE) {
664 if (!error_handler_called)
665 err_setstr(ClError, "addparam failed");
666 return NULL;
667 }
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000668
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000669 return newintobject(paramID);
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000670}
671
672static struct methodlist cl_methods[] = {
673 {"AddParam", cl_AddParam},
674 {"OpenCompressor", cl_OpenCompressor},
675 {"OpenDecompressor", cl_OpenDecompressor},
676 {NULL, NULL} /* Sentinel */
677};
678
679void
680initcl()
681{
Sjoerd Mullenderd53a4f31992-09-24 10:37:39 +0000682 object *m, *d;
683
684 m = initmodule("cl", cl_methods);
685 d = getmoduledict(m);
686
687 ClError = newstringobject("cl.error");
688 if (ClError == NULL || dictinsert(d, "error", ClError) != 0)
689 fatal("can't define cl.error");
690
691 (void) clSetErrorHandler(cl_ErrorHandler);
Sjoerd Mullenderc4315491992-09-23 14:53:00 +0000692}