From 2ea4aa428d116eddcef1d44385550a4c23b308c7 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Sat, 31 Jan 2015 09:57:24 +1100 Subject: [PATCH] zero unfilled channels in color returned by getpixel() --- Imager.xs | 2 ++ t/100-base/010-introvert.t | 14 +++++++------- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Imager.xs b/Imager.xs index 5fe6b4dc..99e41738 100644 --- a/Imager.xs +++ b/Imager.xs @@ -3100,6 +3100,7 @@ i_get_pixel(im, x, y) i_img_dim y; CODE: RETVAL = (i_color *)mymalloc(sizeof(i_color)); + memset(RETVAL, 0, sizeof(*RETVAL)); if (i_gpix(im, x, y, RETVAL) != 0) { myfree(RETVAL); XSRETURN_UNDEF; @@ -3693,6 +3694,7 @@ i_gpixf(im, x, y) i_img_dim y; CODE: RETVAL = (i_fcolor *)mymalloc(sizeof(i_fcolor)); + memset(RETVAL, 0, sizeof(*RETVAL)); if (i_gpixf(im, x, y, RETVAL) != 0) { myfree(RETVAL); XSRETURN_UNDEF; diff --git a/t/100-base/010-introvert.t b/t/100-base/010-introvert.t index e13d57b6..8e46f58f 100644 --- a/t/100-base/010-introvert.t +++ b/t/100-base/010-introvert.t @@ -934,11 +934,11 @@ my $psamp_outside_error = "Image position outside of image"; } # simple calls - is_color3($im->getpixel(x => 1, y => 0), 255, 0, 0, + is_color4($im->getpixel(x => 1, y => 0), 255, 0, 0, 0, "getpixel(1, 0)"); - is_color3($im->getpixel(x => 8, y => 1), 0, 255, 255, + is_color4($im->getpixel(x => 8, y => 1), 0, 255, 255, 0, "getpixel(8, 1)"); - is_color3($im->getpixel(x => 8, y => 7), 255, 0, 255, + is_color4($im->getpixel(x => 8, y => 7), 255, 0, 255, 0, "getpixel(8, 7)"); { @@ -970,10 +970,10 @@ my $psamp_outside_error = "Image position outside of image"; { # float is_fcolor3($im->getpixel(x => 1, y => 0, type => 'float'), 1.0, 0, 0, "getpixel(1,0) float"); - is_fcolor3($im->getpixel(x => 8, y => 1, type => 'float'), - 0, 1.0, 1.0, "getpixel(8,1) float"); - is_fcolor3($im->getpixel(x => 8, y => 7, type => 'float'), - 1.0, 0, 1.0, "getpixel(8,7) float"); + is_fcolor4($im->getpixel(x => 8, y => 1, type => 'float'), + 0, 1.0, 1.0, 0, "getpixel(8,1) float"); + is_fcolor4($im->getpixel(x => 8, y => 7, type => 'float'), + 1.0, 0, 1.0, 0, "getpixel(8,7) float"); my @colors = $im->getpixel(x => [ 0, 8, 7 ], y => [ 0, 7, 3 ], type => 'float'); is(@colors, 3, "getpixel 2 3 element array refs (float)"); -- 2.39.5