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;