New built-in module "cl" (Compression Library). Only for Irix 4.0.5

and higher.  Made a few improvements to previous version.
This commit is contained in:
Sjoerd Mullender 1992-09-24 10:37:39 +00:00
parent 2b65c03603
commit d53a4f3d14
2 changed files with 129 additions and 42 deletions

View File

@ -25,6 +25,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* Cl objects */ /* Cl objects */
#include <stdarg.h>
#include <cl.h> #include <cl.h>
#include "allobjects.h" #include "allobjects.h"
#include "modsupport.h" /* For getargs() etc. */ #include "modsupport.h" /* For getargs() etc. */
@ -44,13 +45,30 @@ extern typeobject Cltype; /* Really static, forward */
#define is_clobject(v) ((v)->ob_type == &Cltype) #define is_clobject(v) ((v)->ob_type == &Cltype)
static object *ClError; /* exception cl.error */
static int error_handler_called = 0;
static void
cl_ErrorHandler(long errnum, const char *fmt, ...)
{
va_list ap;
char errbuf[BUFSIZ]; /* hopefully big enough */
error_handler_called = 1;
va_start(ap, fmt);
vsprintf(errbuf, fmt, ap);
va_end(ap);
err_setstr(ClError, errbuf);
}
static object * static object *
cl_Compress(self, args) cl_Compress(self, args)
clobject *self; clobject *self;
object *args; object *args;
{ {
object *data, *res; object *data;
long frameIndex, numberOfFrames, dataSize, result; long frameIndex, numberOfFrames, dataSize;
if (!getargs(args, "(ii)", &frameIndex, &numberOfFrames)) if (!getargs(args, "(ii)", &frameIndex, &numberOfFrames))
return NULL; return NULL;
@ -62,16 +80,20 @@ cl_Compress(self, args)
dataSize = numberOfFrames * self->ob_dataMaxSize; dataSize = numberOfFrames * self->ob_dataMaxSize;
result = clCompress(self->ob_compressorHdl, frameIndex, numberOfFrames, error_handler_called = 0;
&dataSize, (void *) getstringvalue(data)); if (clCompress(self->ob_compressorHdl, frameIndex, numberOfFrames,
&dataSize, (void *) getstringvalue(data)) == FAILURE) {
DECREF(data);
if (!error_handler_called)
err_setstr(ClError, "compress failed");
return NULL;
}
if (dataSize < numberOfFrames * self->ob_dataMaxSize) if (dataSize < numberOfFrames * self->ob_dataMaxSize)
if (resizestring(&data, dataSize)) if (resizestring(&data, dataSize))
return NULL; return NULL;
res = mkvalue("(iO)", result, data); return data;
DECREF(data);
return res;
} }
static object * static object *
@ -79,8 +101,8 @@ cl_Decompress(self, args)
clobject *self; clobject *self;
object *args; object *args;
{ {
object *data, *res; object *data;
long frameIndex, numberOfFrames, result; long frameIndex, numberOfFrames;
if (!getargs(args, "(ii)", &frameIndex, &numberOfFrames)) if (!getargs(args, "(ii)", &frameIndex, &numberOfFrames))
return NULL; return NULL;
@ -90,12 +112,16 @@ cl_Decompress(self, args)
if (data == NULL) if (data == NULL)
return NULL; return NULL;
result = clDecompress(self->ob_compressorHdl, frameIndex, error_handler_called = 0;
numberOfFrames, (void *) getstringvalue(data)); if (clDecompress(self->ob_compressorHdl, frameIndex, numberOfFrames,
(void *) getstringvalue(data)) == FAILURE) {
DECREF(data);
if (!error_handler_called)
err_setstr(ClError, "decompress failed");
return NULL;
}
res = mkvalue("(iO)", result, data); return data;
DECREF(data);
return res;
} }
static object * static object *
@ -110,13 +136,14 @@ cl_GetCompressorInfo(self, args)
if (!getnoarg(args)) if (!getnoarg(args))
return NULL; return NULL;
result = clGetCompressorInfo(self->ob_compressorHdl, &infoSize, &info); error_handler_called = 0;
if (clGetCompressorInfo(self->ob_compressorHdl, &infoSize, &info) == FAILURE) {
if (!error_handler_called)
err_setstr(ClError, "getcompressorinfo failed");
return NULL;
}
infoObject = newsizedstringobject((char *) info, infoSize); return newsizedstringobject((char *) info, infoSize);
res = mkvalue("(iO)", result, infoObject);
DECREF(infoObject);
return res;
} }
static object * static object *
@ -129,7 +156,10 @@ cl_GetDefault(self, args)
if (!getargs(args, "i", &initial)) if (!getargs(args, "i", &initial))
return NULL; return NULL;
error_handler_called = 0;
result = clGetDefault(self->ob_compressorHdl, initial); result = clGetDefault(self->ob_compressorHdl, initial);
if (error_handler_called)
return NULL;
return newintobject(result); return newintobject(result);
} }
@ -144,7 +174,10 @@ cl_GetMinMax(self, args)
if (!getargs(args, "i", &param)) if (!getargs(args, "i", &param))
return NULL; return NULL;
error_handler_called = 0;
clGetMinMax(self->ob_compressorHdl, param, &min, &max); clGetMinMax(self->ob_compressorHdl, param, &min, &max);
if (error_handler_called)
return NULL;
return mkvalue("(ii)", min, max); return mkvalue("(ii)", min, max);
} }
@ -160,7 +193,14 @@ cl_GetName(self, args)
if (!getargs(args, "i", &descriptor)) if (!getargs(args, "i", &descriptor))
return NULL; return NULL;
error_handler_called = 0;
name = clGetName(self->ob_compressorHdl, descriptor); name = clGetName(self->ob_compressorHdl, descriptor);
if (error_handler_called)
return NULL;
if (name == NULL) {
err_setstr(ClError, "getname failed");
return NULL;
}
return newstringobject(name); return newstringobject(name);
} }
@ -197,7 +237,10 @@ doParams(self, args, func, modified)
PVbuffer[i] = getintvalue(v); PVbuffer[i] = getintvalue(v);
} }
error_handler_called = 0;
(*func)(self->ob_compressorHdl, PVbuffer, length); (*func)(self->ob_compressorHdl, PVbuffer, length);
if (error_handler_called)
return NULL;
if (modified) { if (modified) {
for (i = 0; i < length; i++) for (i = 0; i < length; i++)
@ -237,7 +280,10 @@ cl_QueryParams(self, args)
if (!getnoarg(args)) if (!getnoarg(args))
return NULL; return NULL;
error_handler_called = 0;
bufferlength = clQueryParams(self->ob_compressorHdl, 0, 0); bufferlength = clQueryParams(self->ob_compressorHdl, 0, 0);
if (error_handler_called)
return NULL;
PVbuffer = NEW(long, bufferlength); PVbuffer = NEW(long, bufferlength);
if (PVbuffer == NULL) if (PVbuffer == NULL)
@ -245,6 +291,10 @@ cl_QueryParams(self, args)
bufferlength = clQueryParams(self->ob_compressorHdl, PVbuffer, bufferlength = clQueryParams(self->ob_compressorHdl, PVbuffer,
bufferlength); bufferlength);
if (error_handler_called) {
DEL(PVbuffer);
return NULL;
}
list = newlistobject(bufferlength); list = newlistobject(bufferlength);
if (list == NULL) { if (list == NULL) {
@ -252,8 +302,12 @@ cl_QueryParams(self, args)
return NULL; return NULL;
} }
for (i = 0; i < bufferlength; i++) for (i = 0; i < bufferlength; i++) {
setlistitem(list, i, newintobject(PVbuffer[i])); if (i & 1)
setlistitem(list, i, newintobject(PVbuffer[i]));
else
setlistitem(list, i, newstringobject((char *) PVbuffer[i]));
}
DEL(PVbuffer); DEL(PVbuffer);
@ -424,8 +478,6 @@ cl_OpenCompressor(self, args)
object *GetFrameCBPtr; object *GetFrameCBPtr;
object *callbackID; object *callbackID;
clobject *new; clobject *new;
long result;
object *res;
if (!getargs(args, "((iiiiiiiiii)iOO)", if (!getargs(args, "((iiiiiiiiii)iOO)",
&compressionFormat.width, &compressionFormat.width,
@ -445,8 +497,19 @@ cl_OpenCompressor(self, args)
if (new == 0) if (new == 0)
return NULL; return NULL;
result = clOpenCompressor(&compressionFormat, qualityFactor, GetFrame, new->ob_compressorHdl = NULL;
(void *) new, &new->ob_compressorHdl); new->ob_callbackFunc = NULL;
new->ob_callbackID = NULL;
new->ob_data = NULL;
error_handler_called = 0;
if (clOpenCompressor(&compressionFormat, qualityFactor, GetFrame,
(void *) new, &new->ob_compressorHdl) == FAILURE) {
DECREF(new);
if (!error_handler_called)
err_setstr(ClError, "opencompressor failed");
return NULL;
}
new->ob_isCompressor = 1; new->ob_isCompressor = 1;
new->ob_callbackFunc = GetFrameCBPtr; new->ob_callbackFunc = GetFrameCBPtr;
@ -458,9 +521,7 @@ cl_OpenCompressor(self, args)
new->ob_data = NULL; new->ob_data = NULL;
new->ob_dataMaxSize = compressionFormat.dataMaxSize; new->ob_dataMaxSize = compressionFormat.dataMaxSize;
res = mkvalue("(iO)", result, new); return new;
DECREF(new);
return res;
} }
static object * static object *
@ -473,7 +534,6 @@ cl_OpenDecompressor(self, args)
object *GetDataCBPtr; object *GetDataCBPtr;
object *callbackID; object *callbackID;
clobject *new; clobject *new;
long result;
object *res; object *res;
if (!getargs(args, "(s#OO)", &info, &infoSize, &GetDataCBPtr, if (!getargs(args, "(s#OO)", &info, &infoSize, &GetDataCBPtr,
@ -484,9 +544,19 @@ cl_OpenDecompressor(self, args)
if (new == 0) if (new == 0)
return NULL; return NULL;
result = clOpenDecompressor(&compressionFormat, infoSize, info, new->ob_compressorHdl = NULL;
GetData, (void *) new, new->ob_callbackFunc = NULL;
&new->ob_compressorHdl); new->ob_callbackID = NULL;
new->ob_data = NULL;
error_handler_called = 0;
if (clOpenDecompressor(&compressionFormat, infoSize, info, GetData,
(void *) new, &new->ob_compressorHdl) == FAILURE) {
DECREF(new);
if (!error_handler_called)
err_setstr(ClError, "opendecompressor failed");
return NULL;
}
new->ob_isCompressor = 0; new->ob_isCompressor = 0;
new->ob_callbackFunc = GetDataCBPtr; new->ob_callbackFunc = GetDataCBPtr;
@ -497,7 +567,7 @@ cl_OpenDecompressor(self, args)
XINCREF(new->ob_callbackID); XINCREF(new->ob_callbackID);
new->ob_data = NULL; new->ob_data = NULL;
res = mkvalue("(iO(iiiiiiiiii))", result, new, res = mkvalue("(O(iiiiiiiiii))", new,
compressionFormat.width, compressionFormat.width,
compressionFormat.height, compressionFormat.height,
compressionFormat.frameSize, compressionFormat.frameSize,
@ -508,10 +578,6 @@ cl_OpenDecompressor(self, args)
compressionFormat.frameRate, compressionFormat.frameRate,
compressionFormat.numberOfFrames, compressionFormat.numberOfFrames,
compressionFormat.compressionScheme); compressionFormat.compressionScheme);
if (res == NULL) {
XDECREF(new->ob_callbackFunc);
XDECREF(new->ob_callbackID);
}
DECREF(new); DECREF(new);
return res; return res;
@ -522,14 +588,19 @@ cl_AddParam(self, args)
object *self, *args; object *self, *args;
{ {
char *name; char *name;
long type, min, max, initial, paramID, result; long type, min, max, initial, paramID;
if (!getargs(args, "(siiii)", &name, &type, &min, &max, &initial)) if (!getargs(args, "(siiii)", &name, &type, &min, &max, &initial))
return NULL; return NULL;
result = clAddParam(name, type, min, max, initial, &paramID); error_handler_called = 0;
if (clAddParam(name, type, min, max, initial, &paramID) == FAILURE) {
if (!error_handler_called)
err_setstr(ClError, "addparam failed");
return NULL;
}
return mkvalue("(ii)", result, paramID); return newintobject(paramID);
} }
static struct methodlist cl_methods[] = { static struct methodlist cl_methods[] = {
@ -542,5 +613,14 @@ static struct methodlist cl_methods[] = {
void void
initcl() initcl()
{ {
(void) initmodule("cl", cl_methods); object *m, *d;
m = initmodule("cl", cl_methods);
d = getmoduledict(m);
ClError = newstringobject("cl.error");
if (ClError == NULL || dictinsert(d, "error", ClError) != 0)
fatal("can't define cl.error");
(void) clSetErrorHandler(cl_ErrorHandler);
} }

View File

@ -214,6 +214,9 @@ extern void initthread();
#ifdef USE_SV #ifdef USE_SV
extern void initsv(); extern void initsv();
#endif #endif
#ifdef USE_CL
extern void initcl();
#endif
#ifdef USE_TIME #ifdef USE_TIME
extern void inittime(); extern void inittime();
#endif #endif
@ -335,6 +338,10 @@ struct {
{"sv", initsv}, {"sv", initsv},
#endif #endif
#ifdef USE_CL
{"cl", initcl},
#endif
#ifdef USE_THREAD #ifdef USE_THREAD
{"thread", initthread}, {"thread", initthread},
#endif #endif