diff options
Diffstat (limited to 'libdimension/canvas_pigment.c')
-rw-r--r-- | libdimension/canvas_pigment.c | 41 |
1 files changed, 21 insertions, 20 deletions
diff --git a/libdimension/canvas_pigment.c b/libdimension/canvas_pigment.c index c86fc66..a1820c4 100644 --- a/libdimension/canvas_pigment.c +++ b/libdimension/canvas_pigment.c @@ -18,25 +18,14 @@ * <http://www.gnu.org/licenses/>. * *************************************************************************/ -#include "dimension.h" - -/* Canvas color pigment callback */ -static dmnsn_color dmnsn_canvas_pigment_fn(const dmnsn_pigment *pigment, - dmnsn_vector v); -static void dmnsn_canvas_pigment_free_fn(void *ptr); +/** + * @file + * Image maps. + */ -/* Create a canvas color */ -dmnsn_pigment * -dmnsn_new_canvas_pigment(dmnsn_canvas *canvas) -{ - dmnsn_pigment *pigment = dmnsn_new_pigment(); - pigment->pigment_fn = &dmnsn_canvas_pigment_fn; - pigment->free_fn = &dmnsn_canvas_pigment_free_fn; - pigment->ptr = canvas; - return pigment; -} +#include "dimension.h" -/* Canvas color callback */ +/** Canvas pigment color callback. */ static dmnsn_color dmnsn_canvas_pigment_fn(const dmnsn_pigment *pigment, dmnsn_vector v) { @@ -44,14 +33,26 @@ dmnsn_canvas_pigment_fn(const dmnsn_pigment *pigment, dmnsn_vector v) dmnsn_canvas *canvas = pigment->ptr; - int x = (fmod(v.x, 1.0) + 1.0)*(canvas->x - 1) + 0.5; - int y = (fmod(v.y, 1.0) + 1.0)*(canvas->y - 1) + 0.5; - dmnsn_color c = dmnsn_get_pixel(canvas, x%canvas->x, y%canvas->y); + int x = (fmod(v.x, 1.0) + 1.0)*(canvas->width - 1) + 0.5; + int y = (fmod(v.y, 1.0) + 1.0)*(canvas->height - 1) + 0.5; + dmnsn_color c = dmnsn_get_pixel(canvas, x%canvas->width, y%canvas->height); return c; } +/** Canvas pigment destructor. */ static void dmnsn_canvas_pigment_free_fn(void *ptr) { dmnsn_delete_canvas(ptr); } + +/* Create a canvas color */ +dmnsn_pigment * +dmnsn_new_canvas_pigment(dmnsn_canvas *canvas) +{ + dmnsn_pigment *pigment = dmnsn_new_pigment(); + pigment->pigment_fn = &dmnsn_canvas_pigment_fn; + pigment->free_fn = &dmnsn_canvas_pigment_free_fn; + pigment->ptr = canvas; + return pigment; +} |