From 18714652832ec384c75d63bfebb79ea8a79d6389 Mon Sep 17 00:00:00 2001 From: sam Date: Mon, 28 Jul 2008 23:01:17 +0000 Subject: [PATCH] * pixels.c: do not return a white pixel when calling getpixel() outside the image boundaries; instead, return the closest pixel in the image. git-svn-id: file:///srv/caca.zoy.org/var/lib/svn/libpipi/trunk@2602 92316355-f0b4-4df1-b90c-862c8a59935f --- pipi/pixels.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pipi/pixels.c b/pipi/pixels.c index fed1662..257be69 100644 --- a/pipi/pixels.c +++ b/pipi/pixels.c @@ -49,11 +49,11 @@ int pipi_getpixel(pipi_image_t const *img, { uint8_t *pixel; - if(x < 0 || y < 0 || x >= img->width || y >= img->height) - { - *r = *g = *b = 1.; - return -1; - } + if(x < 0) x = 0; + else if(x >= img->width) x = img->width - 1; + + if(y < 0) y = 0; + else if(y >= img->height) y = img->height - 1; pixel = img->pixels + y * img->pitch + x * img->channels;