Exemple #1
0
// Set screenresolution
static PyObject* pympav_set_resolution(PyObject *self, PyObject *args) {

	if (!PyArg_ParseTuple(args, "iii", &width, &height, &cinema))
		return (PyObject*)NULL;

	if(init == 1) {
		goom_set_resolution(width, height, cinema);
	}

	// See http://sdldoc.csn.ul.ie/sdlcreatergbsurface.php
	SDL_Surface* s = SDL_CreateRGBSurface(0, width, height, 32, 0, 0, 0, 0);

	if (s) {
		// deallocate if there is one already
		if (pysurf) {
			Py_XDECREF(pysurf);
		}

		pysurf = (PySurfaceObject*) PySurface_New(s);
		Py_XINCREF(pysurf);
		
		if (pysurf) {
			RETURN_NONE;
		} 
		else {
			RAISE(PyExc_ValueError, "Error creating pygame surface");
		}
	}
	RAISE(PyExc_ValueError, "Error creating sdl surface");
}
Exemple #2
0
static PyObject *
PyGoom_getsurface(PyGoomObject *self, void *closure)
{
    if (debug >= 3) {
        printf("PyGoom_getsurface()\n"); fflush(stdout);
    }
    return Py_BuildValue("O", PySurface_New(self->surface));
}
Exemple #3
0
// our main method for processing images
// should  return a surface no matter what in the future
static PyObject* pygoom_process(PyObject *self, PyObject *args)
{
    if (init == 0) {
        if (data_import_init() == 0) {
            goomInfo = goom_init(width, height);
            init     = 1;
        }
        else {
            data_import_clean();
            return RAISE(PyExc_ValueError, "Error initializing mmap");
        }
    }

    if (mmap_area->count > counter || mmap_area->count < counter) {
        counter = mmap_area->count;

#ifdef USE_FASTMEMCPY
        fast_memcpy(data, mmap_area + sizeof(data_t), 2048);
#else
        memcpy(data, mmap_area + sizeof(data_t), 2048);
#endif
#ifdef VERBOSE
        printf ("goomInfo=%p, data=%p, FXMODE=%d, fps=%.1f, songtitle=%s, message=%s\n", 
            goomInfo, data, FXMODE, fps, songtitle, message);
#endif
        render_data = goom_update(goomInfo, data, FXMODE, fps, songtitle, message);

        if (!render_data) {
            data_import_clean();
            return RAISE(PyExc_ValueError, "Goom didn't give any result!");
        }

        if (!surf) {
            return RAISE(PyExc_ValueError, "Resolution not set");
        }

#ifdef USE_FASTMEMCPY
        fast_memcpy(surf->pixels, render_data, width * height * sizeof(uint32_t));
#else
        memcpy(surf->pixels, render_data, width * height * sizeof(uint32_t));
#endif
    }
    return Py_BuildValue("O", PySurface_New(surf));
}
Exemple #4
0
static PyObject *
PyGoom_process(PyGoomObject *self, PyObject *args)
{
    int i, j;
    gint16 data[2][512];
    char *songtitle, *message;

    if (debug >= 4) {
        printf("*"); fflush(stdout);
    }
	if (!PyArg_ParseTuple(args, ":process")) {
		return NULL;
	}

    if (!self->surface) {
        return RAISE(PyExc_ValueError, "Surface not initialized");
    }

    if (self->mmap_area) {
        if (self->mmap_area->count != self->mmap_area_count) {
            if (debug >= 4) {
                printf("mmap_area->count=%llu, self->mmap_area_count=%llu\n", 
                    self->mmap_area->count, self->mmap_area_count);
            }
            if (debug >= 3) {
                printf("memcpy(data=%p, self->mmap_area=%p + sizeof(data_t)=%u, sizeof(gint16)=%u * 2 * 512)\n",
                    data, self->mmap_area, (unsigned)sizeof(data_t), (unsigned)sizeof(gint16));
            }
            self->mmap_area_count = self->mmap_area->count;
            //memcpy(data, self->mmap_area + sizeof(data_t), sizeof(gint16) * 2 * 512);
            memcpy(data, self->mmap_area + sizeof(data_t), sizeof(gint16) * 1 * 512);
        }
    }
    else {
        // generate some random data if export file is NULL
        for (i = 0; i < 2; i++) {
            for (j = 0; j < 512; j++) {
                data[i][j] = (gint16)rand();
            }
        }
    }

    songtitle = PyString_AsString(self->songtitle);
    if (songtitle && strcmp(songtitle, "") == 0) {
        songtitle = 0;
    } 
    message = PyString_AsString(self->message);
    if (message && strcmp(message, "") == 0) {
        message = 0;
    }
    if (songtitle || message) {
        if (debug >= 1) {
            printf ("songtitle=%s, message=%s\n", songtitle, message);
        }
    }
    
    self->render_data = goom_update(self->goominfo, data, self->fxmode, self->fps, songtitle, message);

    self->songtitle = PyString_FromString("");
    self->message = PyString_FromString("");

    if (!self->render_data) {
        return RAISE(PyExc_ValueError, "Goom didn't give any result!");
    }

    memcpy(self->surface->pixels, self->render_data, self->width * self->height * sizeof(uint32_t));
    // fast memcpy make very little differenc so lets not use it
    //fast_memcpy(self->surface->pixels, self->render_data, self->width * self->height * sizeof(uint32_t));

    return Py_BuildValue("O", PySurface_New(self->surface));
}