src/raytracermodule.cc
branchpyrit
changeset 60 a23b5089b9c3
parent 59 64e456ab823d
child 69 303583d2fb97
equal deleted inserted replaced
59:64e456ab823d 60:a23b5089b9c3
   734 }
   734 }
   735 
   735 
   736 static PyObject* Raytracer_render(PyObject* self, PyObject* args)
   736 static PyObject* Raytracer_render(PyObject* self, PyObject* args)
   737 {
   737 {
   738 	int w = 0, h = 0;
   738 	int w = 0, h = 0;
   739 	char *chardata;
   739 	unsigned char *chardata;
   740 	Float *data;
   740 	Float *data;
   741 	PyObject *o;
   741 	PyObject *o;
   742 
   742 
   743 	if (!PyArg_ParseTuple(args, "(ii)", &w, &h))
   743 	if (!PyArg_ParseTuple(args, "(ii)", &w, &h))
   744 		return NULL;
   744 		return NULL;
   754 		return Py_None;
   754 		return Py_None;
   755 	}
   755 	}
   756 
   756 
   757 	// convert data to char
   757 	// convert data to char
   758 	printf("[pyrit] Converting image data (float to char)\n");
   758 	printf("[pyrit] Converting image data (float to char)\n");
   759 	chardata = (char *) malloc(w*h*3);
   759 	chardata = (unsigned char *) malloc(w*h*3);
   760 	Float *d = data;
   760 	Float *d = data;
   761 	for (char *c = chardata; c != chardata + w*h*3; c++, d++) {
   761 	for (unsigned char *c = chardata; c != chardata + w*h*3; c++, d++) {
   762 		if (*d > 1.0)
   762 		if (*d > 1.0)
   763 			*c = 255;
   763 			*c = 255;
   764 		else
   764 		else
   765 			*c = (unsigned char)(*d * 255.0);
   765 			*c = (unsigned char)(*d * 255.0);
   766 	}
   766 	}