equal
deleted
inserted
replaced
5 * |
5 * |
6 * Radek Brich, 2006 |
6 * Radek Brich, 2006 |
7 */ |
7 */ |
8 |
8 |
9 #include <Python.h> |
9 #include <Python.h> |
|
10 |
10 #include <vector> |
11 #include <vector> |
11 #include "scene.h" |
12 #include "scene.h" |
12 #include "raytracer.h" |
13 #include "raytracer.h" |
13 |
14 |
14 //=========================== Light Source Object =========================== |
15 //=========================== Light Source Object =========================== |
444 PyObject *o; |
445 PyObject *o; |
445 |
446 |
446 if (!PyArg_ParseTuple(args, "(ii)", &w, &h)) |
447 if (!PyArg_ParseTuple(args, "(ii)", &w, &h)) |
447 return NULL; |
448 return NULL; |
448 |
449 |
449 printf("[PyRit] Raytracing...\n"); |
450 printf("[pyrit] Raytracing...\n"); |
450 data = ((RaytracerObject *)self)->raytracer->render(w, h); |
451 data = ((RaytracerObject *)self)->raytracer->render(w, h); |
451 if (!data) { |
452 if (!data) { |
452 Py_INCREF(Py_None); |
453 Py_INCREF(Py_None); |
453 return Py_None; |
454 return Py_None; |
454 } |
455 } |
455 |
456 |
456 // convert data to char |
457 // convert data to char |
457 printf("[PyRit] Converting image data (float to char)...\n"); |
458 printf("[pyrit] Converting image data (float to char)...\n"); |
458 chardata = (char *) malloc(w*h*3); |
459 chardata = (char *) malloc(w*h*3); |
459 float *d = data; |
460 float *d = data; |
460 for (char *c = chardata; c != chardata + w*h*3; c++, d++) { |
461 for (char *c = chardata; c != chardata + w*h*3; c++, d++) { |
461 if (*d > 1.0) |
462 if (*d > 1.0) |
462 *c = 255; |
463 *c = 255; |
464 *c = (unsigned char)(*d * 255.0); |
465 *c = (unsigned char)(*d * 255.0); |
465 } |
466 } |
466 free(data); |
467 free(data); |
467 o = Py_BuildValue("s#", chardata, w*h*3); |
468 o = Py_BuildValue("s#", chardata, w*h*3); |
468 free(chardata); |
469 free(chardata); |
469 printf("[PyRit] Done.\n"); |
470 printf("[pyrit] Done.\n"); |
470 return o; |
471 return o; |
471 } |
472 } |
472 |
473 |
473 static PyObject* Raytracer_addshape(PyObject* self, PyObject* args) |
474 static PyObject* Raytracer_addshape(PyObject* self, PyObject* args) |
474 { |
475 { |