cinap_lenrekadd hg and python4bb9e2215 years agoHistory
2559 lines · 65.9 KB · C
RawDownload
	} 	list = PyList_New(bufferlength);	if (list == NULL) {		PyMem_DEL(PVbuffer);		return NULL;	} 	for (i = 0; i < bufferlength; i++) {		if (i & 1)			PyList_SetItem(list, i, PyInt_FromLong(PVbuffer[i]));		else if (PVbuffer[i] == 0) {			Py_INCREF(Py_None);			PyList_SetItem(list, i, Py_None);		} else			PyList_SetItem(list, i,				   PyString_FromString((char *) PVbuffer[i]));	} 	PyMem_DEL(PVbuffer); 	return list;} static PyObject *clm_GetMinMax(PyObject *self, PyObject *args){	int param, min, max;	float fmin, fmax; 	CheckCompressor(SELF); 	if (!PyArg_Parse(args, "i", &param))		return NULL; 	clGetMinMax(SELF->ob_compressorHdl, param, &min, &max); 	if (param_type_is_float(SELF, param) > 0) {		fmin = CL_TypeIsFloat(min);		fmax = CL_TypeIsFloat(max);		return Py_BuildValue("(ff)", fmin, fmax);	} 	return Py_BuildValue("(ii)", min, max);} static PyObject *clm_GetName(PyObject *self, PyObject *args){	int param;	char *name; 	CheckCompressor(SELF); 	if (!PyArg_Parse(args, "i", &param))		return NULL; 	error_handler_called = 0;	name = clGetName(SELF->ob_compressorHdl, param);	if (name == NULL || error_handler_called) {		if (!error_handler_called)			PyErr_SetString(ClError, "getname failed");		return NULL;	} 	return PyString_FromString(name);} static PyObject *clm_QuerySchemeFromHandle(PyObject *self){	CheckCompressor(SELF);	return PyInt_FromLong(clQuerySchemeFromHandle(SELF->ob_compressorHdl));} static PyObject *clm_ReadHeader(PyObject *self, PyObject *args){	char *header;	int headerSize; 	CheckCompressor(SELF); 	if (!PyArg_Parse(args, "s#", &header, &headerSize))		return NULL; 	return PyInt_FromLong(clReadHeader(SELF->ob_compressorHdl,					   headerSize, header));} static PyMethodDef compressor_methods[] = {	{"close",		clm_CloseCompressor, METH_NOARGS}, /* alias */	{"CloseCompressor",	clm_CloseCompressor, METH_NOARGS},	{"Compress",		clm_Compress, METH_OLDARGS},	{"GetDefault",		clm_GetDefault, METH_OLDARGS},	{"GetMinMax",		clm_GetMinMax, METH_OLDARGS},	{"GetName",		clm_GetName, METH_OLDARGS},	{"GetParam",		clm_GetParam, METH_OLDARGS},	{"GetParamID",		clm_GetParamID, METH_OLDARGS},	{"GetParams",		clm_GetParams, METH_OLDARGS},	{"QueryParams",		clm_QueryParams, METH_NOARGS},	{"QuerySchemeFromHandle",clm_QuerySchemeFromHandle, METH_NOARGS},	{"SetParam",		clm_SetParam, METH_OLDARGS},	{"SetParams",		clm_SetParams, METH_OLDARGS},	{NULL,			NULL}		/* sentinel */}; static PyMethodDef decompressor_methods[] = {	{"close",		clm_CloseDecompressor, METH_NOARGS},	/* alias */	{"CloseDecompressor",	clm_CloseDecompressor, METH_NOARGS},	{"Decompress",		clm_Decompress, METH_OLDARGS},	{"GetDefault",		clm_GetDefault, METH_OLDARGS},	{"GetMinMax",		clm_GetMinMax, METH_OLDARGS},	{"GetName",		clm_GetName, METH_OLDARGS},	{"GetParam",		clm_GetParam, METH_OLDARGS},	{"GetParamID",		clm_GetParamID, METH_OLDARGS},	{"GetParams",		clm_GetParams, METH_OLDARGS},	{"ReadHeader",		clm_ReadHeader, METH_OLDARGS},	{"QueryParams",		clm_QueryParams, METH_NOARGS},	{"QuerySchemeFromHandle",clm_QuerySchemeFromHandle, METH_NOARGS},	{"SetParam",		clm_SetParam, METH_OLDARGS},	{"SetParams",		clm_SetParams, METH_OLDARGS},	{NULL,			NULL}		/* sentinel */}; static voidcl_dealloc(PyObject *self){	if (SELF->ob_compressorHdl) {		if (SELF->ob_isCompressor)			clCloseCompressor(SELF->ob_compressorHdl);		else			clCloseDecompressor(SELF->ob_compressorHdl);	}	PyObject_Del(self);} static PyObject *cl_getattr(PyObject *self, char *name){	if (SELF->ob_isCompressor)		return Py_FindMethod(compressor_methods, self, name);	else		return Py_FindMethod(decompressor_methods, self, name);} static PyTypeObject Cltype = {	PyObject_HEAD_INIT(&PyType_Type)	0,			/*ob_size*/	"cl.cl",		/*tp_name*/	sizeof(clobject),	/*tp_size*/	0,			/*tp_itemsize*/	/* methods */	(destructor)cl_dealloc,	/*tp_dealloc*/	0,			/*tp_print*/	(getattrfunc)cl_getattr, /*tp_getattr*/	0,			/*tp_setattr*/	0,			/*tp_compare*/	0,			/*tp_repr*/	0,			/*tp_as_number*/	0,			/*tp_as_sequence*/	0,			/*tp_as_mapping*/}; static PyObject *doOpen(PyObject *self, PyObject *args, int (*open_func)(int, CL_Handle *),       int iscompressor){	int scheme;	clobject *new; 	if (!PyArg_ParseTuple(args, "i", &scheme))		return NULL; 	new = PyObject_New(clobject, &Cltype);	if (new == NULL)		return NULL; 	new->ob_compressorHdl = NULL;	new->ob_isCompressor = iscompressor;	new->ob_paramtypes = NULL; 	error_handler_called = 0;	if ((*open_func)(scheme, &new->ob_compressorHdl) == FAILURE ||	    error_handler_called) {		Py_DECREF(new);		if (!error_handler_called)			PyErr_SetString(ClError, "Open(De)Compressor failed");		return NULL;	}	return (PyObject *)new;} static PyObject *cl_OpenCompressor(PyObject *self, PyObject *args){	return doOpen(self, args, clOpenCompressor, 1);} static PyObject *cl_OpenDecompressor(PyObject *self, PyObject *args){	return doOpen(self, args, clOpenDecompressor, 0);} static PyObject *cl_QueryScheme(PyObject *self, PyObject *args){	char *header;	int headerlen;	int scheme; 	if (!PyArg_ParseTuple(args, "s#", &header, &headerlen))		return NULL; 	scheme = clQueryScheme(header);	if (scheme < 0) {		PyErr_SetString(ClError, "unknown compression scheme");		return NULL;	} 	return PyInt_FromLong(scheme);} static PyObject *cl_QueryMaxHeaderSize(PyObject *self, PyObject *args){	int scheme; 	if (!PyArg_ParseTuple(args, "i", &scheme))		return NULL; 	return PyInt_FromLong(clQueryMaxHeaderSize(scheme));} static PyObject *cl_QueryAlgorithms(PyObject *self, PyObject *args){	int algorithmMediaType;	int bufferlength;	int *PVbuffer;	PyObject *list;	int i; 	if (!PyArg_ParseTuple(args, "i", &algorithmMediaType))		return NULL; 	error_handler_called = 0;	bufferlength = clQueryAlgorithms(algorithmMediaType, 0, 0);	if (error_handler_called)		return NULL; 	PVbuffer = PyMem_NEW(int, bufferlength);	if (PVbuffer == NULL)		return PyErr_NoMemory(); 	bufferlength = clQueryAlgorithms(algorithmMediaType, PVbuffer,					 bufferlength);	if (error_handler_called) {		PyMem_DEL(PVbuffer);		return NULL;	} 	list = PyList_New(bufferlength);	if (list == NULL) {		PyMem_DEL(PVbuffer);		return NULL;	} 	for (i = 0; i < bufferlength; i++) {		if (i & 1)			PyList_SetItem(list, i, PyInt_FromLong(PVbuffer[i]));		else if (PVbuffer[i] == 0) {			Py_INCREF(Py_None);			PyList_SetItem(list, i, Py_None);		} else			PyList_SetItem(list, i,				   PyString_FromString((char *) PVbuffer[i]));	} 	PyMem_DEL(PVbuffer); 	return list;} static PyObject *cl_QuerySchemeFromName(PyObject *self, PyObject *args){	int algorithmMediaType;	char *name;	int scheme; 	if (!PyArg_ParseTuple(args, "is", &algorithmMediaType, &name))		return NULL; 	error_handler_called = 0;	scheme = clQuerySchemeFromName(algorithmMediaType, name);	if (error_handler_called) {		PyErr_SetString(ClError, "unknown compression scheme");		return NULL;	} 	return PyInt_FromLong(scheme);} static PyObject *cl_GetAlgorithmName(PyObject *self, PyObject *args){	int scheme;	char *name; 	if (!PyArg_ParseTuple(args, "i", &scheme))		return NULL; 	name = clGetAlgorithmName(scheme);	if (name == 0) {		PyErr_SetString(ClError, "unknown compression scheme");		return NULL;	} 	return PyString_FromString(name);} static PyObject *do_set(PyObject *self, PyObject *args, int (*func)(int, int, int)){	int scheme, paramID, value;	float fvalue;	int is_float = 0; 	if (!PyArg_ParseTuple(args, "iii", &scheme, &paramID, &value)) {		PyErr_Clear();		if (!PyArg_ParseTuple(args, "iif", &scheme, &paramID, &fvalue)) {			PyErr_Clear();			PyErr_SetString(PyExc_TypeError,			     "bad argument list (format '(iii)' or '(iif)')");			return NULL;		}		value = CL_TypeIsInt(fvalue);		is_float = 1;	} else {		/* check some parameters which we know to be floats */		switch (scheme) {		case CL_COMPRESSION_RATIO:		case CL_SPEED:			fvalue = value;			value = CL_TypeIsInt(fvalue);			is_float = 1;			break;		}	}  	error_handler_called = 0;	value = (*func)(scheme, paramID, value);	if (error_handler_called)		return NULL; 	if (is_float)		return PyFloat_FromDouble(CL_TypeIsFloat(value));	else		return PyInt_FromLong(value);} static PyObject *cl_SetDefault(PyObject *self, PyObject *args){	return do_set(self, args, clSetDefault);} static PyObject *cl_SetMin(PyObject *self, PyObject *args){	return do_set(self, args, clSetMin);} static PyObject *cl_SetMax(PyObject *self, PyObject *args){	return do_set(self, args, clSetMax);} #define func(name, handler)	\static PyObject *cl_##name(PyObject *self, PyObject *args) \{ \	  int x; \	  if (!PyArg_ParseTuple(args, "i", &x)) return NULL; \	  return Py##handler(CL_##name(x)); \} #define func2(name, handler)	\static PyObject *cl_##name(PyObject *self, PyObject *args) \{ \	  int a1, a2; \	  if (!PyArg_ParseTuple(args, "ii", &a1, &a2)) return NULL; \	  return Py##handler(CL_##name(a1, a2)); \} func(BytesPerSample, Int_FromLong)func(BytesPerPixel, Int_FromLong)func(AudioFormatName, String_FromString)func(VideoFormatName, String_FromString)func(AlgorithmNumber, Int_FromLong)func(AlgorithmType, Int_FromLong)func2(Algorithm, Int_FromLong)func(ParamNumber, Int_FromLong)func(ParamType, Int_FromLong)func2(ParamID, Int_FromLong) #ifdef CLDEBUG	static PyObject *cvt_type(PyObject *self, PyObject *args){	int number;	float fnumber; 	if (PyArg_Parse(args, "i", &number))		return PyFloat_FromDouble(CL_TypeIsFloat(number));	else {		PyErr_Clear();		if (PyArg_Parse(args, "f", &fnumber))			return PyInt_FromLong(CL_TypeIsInt(fnumber));		return NULL;	}}#endif static PyMethodDef cl_methods[] = {	{"CompressImage",	cl_CompressImage, METH_VARARGS},	{"DecompressImage",	cl_DecompressImage, METH_VARARGS},	{"GetAlgorithmName",	cl_GetAlgorithmName, METH_VARARGS},	{"OpenCompressor",	cl_OpenCompressor, METH_VARARGS},	{"OpenDecompressor",	cl_OpenDecompressor, METH_VARARGS},	{"QueryAlgorithms",	cl_QueryAlgorithms, METH_VARARGS},	{"QueryMaxHeaderSize",	cl_QueryMaxHeaderSize, METH_VARARGS},	{"QueryScheme",		cl_QueryScheme, METH_VARARGS},	{"QuerySchemeFromName",	cl_QuerySchemeFromName, METH_VARARGS},	{"SetDefault",		cl_SetDefault, METH_VARARGS},	{"SetMax",		cl_SetMax, METH_VARARGS},	{"SetMin",		cl_SetMin, METH_VARARGS},	{"BytesPerSample",	cl_BytesPerSample, METH_VARARGS},	{"BytesPerPixel",	cl_BytesPerPixel, METH_VARARGS},	{"AudioFormatName",	cl_AudioFormatName, METH_VARARGS},	{"VideoFormatName",	cl_VideoFormatName, METH_VARARGS},	{"AlgorithmNumber",	cl_AlgorithmNumber, METH_VARARGS},	{"AlgorithmType",	cl_AlgorithmType, METH_VARARGS},	{"Algorithm",		cl_Algorithm, METH_VARARGS},	{"ParamNumber",		cl_ParamNumber, METH_VARARGS},	{"ParamType",		cl_ParamType, METH_VARARGS},	{"ParamID",		cl_ParamID, METH_VARARGS},#ifdef CLDEBUG	{"cvt_type",		cvt_type, METH_VARARGS},#endif	{NULL,			NULL} /* Sentinel */}; #ifdef CL_JPEG_SOFTWARE#define IRIX_5_3_LIBRARY#endif voidinitcl(void){	PyObject *m, *d, *x; 	m = Py_InitModule("cl", cl_methods);	if (m == NULL)		return;	d = PyModule_GetDict(m); 	ClError = PyErr_NewException("cl.error", NULL, NULL);	(void) PyDict_SetItemString(d, "error", ClError); #ifdef CL_ADDED_ALGORITHM_ERROR	x = PyInt_FromLong(CL_ADDED_ALGORITHM_ERROR);	if (x == NULL || PyDict_SetItemString(d, "ADDED_ALGORITHM_ERROR", x) < 0)		return;	Py_DECREF(x);#endif#ifdef CL_ALAW	x = PyInt_FromLong(CL_ALAW);	if (x == NULL || PyDict_SetItemString(d, "ALAW", x) < 0)		return;	Py_DECREF(x);#endif#ifdef CL_ALGORITHM_ID	x = PyInt_FromLong(CL_ALGORITHM_ID);	if (x == NULL || PyDict_SetItemString(d, "ALGORITHM_ID", x) < 0)		return;	Py_DECREF(x);#endif#ifdef CL_ALGORITHM_TABLE_FULL	x = PyInt_FromLong(CL_ALGORITHM_TABLE_FULL);	if (x == NULL || PyDict_SetItemString(d, "ALGORITHM_TABLE_FULL", x) < 0)		return;	Py_DECREF(x);#endif#ifdef CL_ALGORITHM_VERSION	x = PyInt_FromLong(CL_ALGORITHM_VERSION);	if (x == NULL || PyDict_SetItemString(d, "ALGORITHM_VERSION", x) < 0)		return;

Lines 501–1000 of 2559. Previous lines