⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 glmodule.c

📁 python s60 1.4.5版本的源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
	if ( !PyArg_Parse(args, "hhhhl", &x1, &y1, &x2, &y2, &hints) )
	  return 0;
	size = (long)(x2+1-x1) * (long)(y2+1-y1);
	rv = PyString_FromStringAndSize((char *)NULL, size*sizeof(long));
	if ( rv == NULL )
	  return NULL;
	parray = (unsigned long *)PyString_AsString(rv);
	size_ret = readdisplay(x1, y1, x2, y2, parray, hints);
	if ( size_ret != size ) {
	    printf("gl_readdisplay: got %ld pixels, expected %ld\n",
		   size_ret, size);
	    PyErr_SetString(PyExc_RuntimeError, "readdisplay returned unexpected length");
	    return NULL;
	}
	return rv;
}

/* Desperately needed, here are tools to compress and decompress
   the data manipulated by lrectread/lrectwrite.

   gl.packrect(width, height, packfactor, bigdata) --> smalldata
		makes 'bigdata' 4*(packfactor**2) times smaller by:
		- turning it into B/W (a factor 4)
		- replacing squares of size pacfactor by one
		  representative

   gl.unpackrect(width, height, packfactor, smalldata) --> bigdata
		is the inverse; the numeric arguments must be *the same*.

   Both work best if width and height are multiples of packfactor
   (in fact unpackrect will leave garbage bytes).
*/


static PyObject *
gl_packrect(PyObject *self, PyObject *args)
{
	long width, height, packfactor;
	char *s;
	PyObject *unpacked, *packed;
	int pixcount, packedcount, x, y, r, g, b;
	unsigned long pixel;
	unsigned char *p;
	unsigned long *parray;
	if (!PyArg_GetLong(args, 4, 0, &width))
		return NULL;
	if (!PyArg_GetLong(args, 4, 1, &height))
		return NULL;
	if (!PyArg_GetLong(args, 4, 2, &packfactor))
		return NULL;
	if (!PyArg_GetString(args, 4, 3, &s)) /* For type checking only */
		return NULL;
	if (!PyArg_GetObject(args, 4, 3, &unpacked))
		return NULL;
	if (width <= 0 || height <= 0 || packfactor <= 0) {
		PyErr_SetString(PyExc_RuntimeError, "packrect args must be > 0");
		return NULL;
	}
	pixcount = width*height;
	packedcount = ((width+packfactor-1)/packfactor) *
		((height+packfactor-1)/packfactor);
	if (PyString_Size(unpacked) != pixcount*sizeof(long)) {
		PyErr_SetString(PyExc_RuntimeError,
			   "string arg to packrect has wrong size");
		return NULL;
	}
	packed = PyString_FromStringAndSize((char *)NULL, packedcount);
	if (packed == NULL)
		return NULL;
	parray = (unsigned long *) PyString_AsString(unpacked);
	p = (unsigned char *) PyString_AsString(packed);
	for (y = 0; y < height; y += packfactor, parray += packfactor*width) {
		for (x = 0; x < width; x += packfactor) {
			pixel = parray[x];
			r = pixel & 0xff;
			g = (pixel >> 8) & 0xff;
			b = (pixel >> 16) & 0xff;
			*p++ = (30*r+59*g+11*b) / 100;
		}
	}
	return packed;
}


static unsigned long unpacktab[256];
static int unpacktab_inited = 0;

static PyObject *
gl_unpackrect(PyObject *self, PyObject *args)
{
	long width, height, packfactor;
	char *s;
	PyObject *unpacked, *packed;
	int pixcount, packedcount;
	register unsigned char *p;
	register unsigned long *parray;
	if (!unpacktab_inited) {
		register int white;
		for (white = 256; --white >= 0; )
			unpacktab[white] = white * 0x010101L;
		unpacktab_inited++;
	}
	if (!PyArg_GetLong(args, 4, 0, &width))
		return NULL;
	if (!PyArg_GetLong(args, 4, 1, &height))
		return NULL;
	if (!PyArg_GetLong(args, 4, 2, &packfactor))
		return NULL;
	if (!PyArg_GetString(args, 4, 3, &s)) /* For type checking only */
		return NULL;
	if (!PyArg_GetObject(args, 4, 3, &packed))
		return NULL;
	if (width <= 0 || height <= 0 || packfactor <= 0) {
		PyErr_SetString(PyExc_RuntimeError, "packrect args must be > 0");
		return NULL;
	}
	pixcount = width*height;
	packedcount = ((width+packfactor-1)/packfactor) *
		((height+packfactor-1)/packfactor);
	if (PyString_Size(packed) != packedcount) {
		PyErr_SetString(PyExc_RuntimeError,
			   "string arg to unpackrect has wrong size");
		return NULL;
	}
	unpacked = PyString_FromStringAndSize((char *)NULL, pixcount*sizeof(long));
	if (unpacked == NULL)
		return NULL;
	parray = (unsigned long *) PyString_AsString(unpacked);
	p = (unsigned char *) PyString_AsString(packed);
	if (packfactor == 1 && width*height > 0) {
		/* Just expand bytes to longs */
		register int x = width * height;
		do {
			*parray++ = unpacktab[*p++];
		} while (--x >= 0);
	}
	else {
		register int y;
		for (y = 0; y < height-packfactor+1;
		     y += packfactor, parray += packfactor*width) {
			register int x;
			for (x = 0; x < width-packfactor+1; x += packfactor) {
				register unsigned long pixel = unpacktab[*p++];
				register int i;
				for (i = packfactor*width; (i-=width) >= 0;) {
					register int j;
					for (j = packfactor; --j >= 0; )
						parray[i+x+j] = pixel;
				}
			}
		}
	}
	return unpacked;
}

static PyObject *
gl_gversion(PyObject *self, PyObject *args)
{
	char buf[20];
	gversion(buf);
	return PyString_FromString(buf);
}


/* void clear - Manual because of clash with termcap */
static PyObject *
gl_clear(PyObject *self, PyObject *args)
{
	__GLclear( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* End of manually written stubs */


/* long getshade */

static PyObject *
gl_getshade(PyObject *self, PyObject *args)
{
	long retval;
	retval = getshade( );
	return mknewlongobject(retval);
}

/* void devport short s long s */

static PyObject *
gl_devport(PyObject *self, PyObject *args)
{
	short arg1 ;
	long arg2 ;
	if (!getishortarg(args, 2, 0, &arg1))
		return NULL;
	if (!getilongarg(args, 2, 1, &arg2))
		return NULL;
	devport( arg1 , arg2 );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void rdr2i long s long s */

static PyObject *
gl_rdr2i(PyObject *self, PyObject *args)
{
	long arg1 ;
	long arg2 ;
	if (!getilongarg(args, 2, 0, &arg1))
		return NULL;
	if (!getilongarg(args, 2, 1, &arg2))
		return NULL;
	rdr2i( arg1 , arg2 );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void rectfs short s short s short s short s */

static PyObject *
gl_rectfs(PyObject *self, PyObject *args)
{
	short arg1 ;
	short arg2 ;
	short arg3 ;
	short arg4 ;
	if (!getishortarg(args, 4, 0, &arg1))
		return NULL;
	if (!getishortarg(args, 4, 1, &arg2))
		return NULL;
	if (!getishortarg(args, 4, 2, &arg3))
		return NULL;
	if (!getishortarg(args, 4, 3, &arg4))
		return NULL;
	rectfs( arg1 , arg2 , arg3 , arg4 );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void rects short s short s short s short s */

static PyObject *
gl_rects(PyObject *self, PyObject *args)
{
	short arg1 ;
	short arg2 ;
	short arg3 ;
	short arg4 ;
	if (!getishortarg(args, 4, 0, &arg1))
		return NULL;
	if (!getishortarg(args, 4, 1, &arg2))
		return NULL;
	if (!getishortarg(args, 4, 2, &arg3))
		return NULL;
	if (!getishortarg(args, 4, 3, &arg4))
		return NULL;
	rects( arg1 , arg2 , arg3 , arg4 );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void rmv2i long s long s */

static PyObject *
gl_rmv2i(PyObject *self, PyObject *args)
{
	long arg1 ;
	long arg2 ;
	if (!getilongarg(args, 2, 0, &arg1))
		return NULL;
	if (!getilongarg(args, 2, 1, &arg2))
		return NULL;
	rmv2i( arg1 , arg2 );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void noport */

static PyObject *
gl_noport(PyObject *self, PyObject *args)
{
	noport( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void popviewport */

static PyObject *
gl_popviewport(PyObject *self, PyObject *args)
{
	popviewport( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void clearhitcode */

static PyObject *
gl_clearhitcode(PyObject *self, PyObject *args)
{
	clearhitcode( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void closeobj */

static PyObject *
gl_closeobj(PyObject *self, PyObject *args)
{
	closeobj( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void cursoff */

static PyObject *
gl_cursoff(PyObject *self, PyObject *args)
{
	cursoff( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void curson */

static PyObject *
gl_curson(PyObject *self, PyObject *args)
{
	curson( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void doublebuffer */

static PyObject *
gl_doublebuffer(PyObject *self, PyObject *args)
{
	doublebuffer( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void finish */

static PyObject *
gl_finish(PyObject *self, PyObject *args)
{
	finish( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void gconfig */

static PyObject *
gl_gconfig(PyObject *self, PyObject *args)
{
	gconfig( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void ginit */

static PyObject *
gl_ginit(PyObject *self, PyObject *args)
{
	ginit( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void greset */

static PyObject *
gl_greset(PyObject *self, PyObject *args)
{
	greset( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void multimap */

static PyObject *
gl_multimap(PyObject *self, PyObject *args)
{
	multimap( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void onemap */

static PyObject *
gl_onemap(PyObject *self, PyObject *args)
{
	onemap( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void popattributes */

static PyObject *
gl_popattributes(PyObject *self, PyObject *args)
{
	popattributes( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void popmatrix */

static PyObject *
gl_popmatrix(PyObject *self, PyObject *args)
{
	popmatrix( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void pushattributes */

static PyObject *
gl_pushattributes(PyObject *self, PyObject *args)
{
	pushattributes( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void pushmatrix */

static PyObject *
gl_pushmatrix(PyObject *self, PyObject *args)
{
	pushmatrix( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void pushviewport */

static PyObject *
gl_pushviewport(PyObject *self, PyObject *args)
{
	pushviewport( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void qreset */

static PyObject *
gl_qreset(PyObject *self, PyObject *args)
{
	qreset( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void RGBmode */

static PyObject *
gl_RGBmode(PyObject *self, PyObject *args)
{
	RGBmode( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void singlebuffer */

static PyObject *
gl_singlebuffer(PyObject *self, PyObject *args)
{
	singlebuffer( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void swapbuffers */

static PyObject *
gl_swapbuffers(PyObject *self, PyObject *args)
{
	swapbuffers( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void gsync */

static PyObject *
gl_gsync(PyObject *self, PyObject *args)
{
	gsync( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void gflush */

static PyObject *
gl_gflush(PyObject *self, PyObject *args)
{
	gflush( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void tpon */

static PyObject *
gl_tpon(PyObject *self, PyObject *args)
{
	tpon( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void tpoff */

static PyObject *
gl_tpoff(PyObject *self, PyObject *args)
{
	tpoff( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void clkon */

static PyObject *
gl_clkon(PyObject *self, PyObject *args)
{
	clkon( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void clkoff */

static PyObject *
gl_clkoff(PyObject *self, PyObject *args)
{
	clkoff( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void ringbell */

static PyObject *
gl_ringbell(PyObject *self, PyObject *args)
{
	ringbell( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void gbegin */

static PyObject *
gl_gbegin(PyObject *self, PyObject *args)
{
	gbegin( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void textinit */

static PyObject *
gl_textinit(PyObject *self, PyObject *args)
{
	textinit( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void initnames */

static PyObject *
gl_initnames(PyObject *self, PyObject *args)
{
	initnames( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void pclos */

static PyObject *
gl_pclos(PyObject *self, PyObject *args)
{
	pclos( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void popname */

static PyObject *
gl_popname(PyObject *self, PyObject *args)
{
	popname( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void spclos */

static PyObject *
gl_spclos(PyObject *self, PyObject *args)
{
	spclos( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void zclear */

static PyObject *
gl_zclear(PyObject *self, PyObject *args)
{
	zclear( );
	Py_INCREF(Py_None);
	return Py_None;
}

/* void screenspace */

static PyObject *
gl_screenspace(PyObject *self, PyObject *args)
{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -