From 04f85f6384631a5a685c403025dabd2621cb5bb6 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Tue, 22 Apr 2008 04:10:06 +0000 Subject: [PATCH] - Regression: filling a greyscale image with a hatch used the wrong color channels from the supplied fg/bg colors. https://rt.cpan.org/Ticket/Display.html?id=35278 --- Changes | 4 ++++ fills.c | 23 +++++++++++++++++++---- t/t20fill.t | 24 +++++++++++++++++++++++- 3 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Changes b/Changes index e6ef2bfd..e9eb06fe 100644 --- a/Changes +++ b/Changes @@ -18,6 +18,10 @@ Bug fixes: scale size parameters are a reference. http://rt.cpan.org/Ticket/Display.html?id=35172 + - Regression: filling a greyscale image with a hatch used the wrong + color channels from the supplied fg/bg colors. + https://rt.cpan.org/Ticket/Display.html?id=35278 + Imager 0.63 - 7 April 2008 =========== diff --git a/fills.c b/fills.c index 55139ed0..973b2f96 100644 --- a/fills.c +++ b/fills.c @@ -650,12 +650,20 @@ static void fill_hatch(i_fill_t *fill, int x, int y, int width, int channels, int byte = f->hatch[(y + f->dy) & 7]; int xpos = (x + f->dx) & 7; int mask = 128 >> xpos; + i_color fg = f->fg; + i_color bg = f->bg; + int want_channels = channels > 2 ? 4 : 2; + + if (channels < 3) { + i_adapt_colors(2, 4, &fg, 1); + i_adapt_colors(2, 4, &bg, 1); + } while (width-- > 0) { if (byte & mask) - *data++ = f->fg; + *data++ = fg; else - *data++ = f->bg; + *data++ = bg; if ((mask >>= 1) == 0) mask = 128; @@ -675,12 +683,19 @@ static void fill_hatchf(i_fill_t *fill, int x, int y, int width, int channels, int byte = f->hatch[(y + f->dy) & 7]; int xpos = (x + f->dx) & 7; int mask = 128 >> xpos; + i_fcolor fg = f->ffg; + i_fcolor bg = f->fbg; + + if (channels < 3) { + i_adapt_fcolors(2, 4, &fg, 1); + i_adapt_fcolors(2, 4, &bg, 1); + } while (width-- > 0) { if (byte & mask) - *data++ = f->ffg; + *data++ = fg; else - *data++ = f->fbg; + *data++ = bg; if ((mask >>= 1) == 0) mask = 128; diff --git a/t/t20fill.t b/t/t20fill.t index 5cc253ec..f42dc49a 100644 --- a/t/t20fill.t +++ b/t/t20fill.t @@ -1,10 +1,11 @@ #!perl -w use strict; -use Test::More tests => 121; +use Test::More tests => 123; use Imager ':handy'; use Imager::Fill; use Imager::Color::Float; +use Imager::Test qw(is_image); use Config; Imager::init_log("testout/t20fill.log", 1); @@ -413,6 +414,27 @@ SKIP: cmp_ok(Imager->errstr, '=~', 'No color named', "check error message"); } +{ # RT #35278 + # hatch fills on a grey scale image don't adapt colors + for my $bits (8, 'double') { + my $im_g = Imager->new(xsize => 10, ysize => 10, channels => 1, bits => $bits); + $im_g->box(filled => 1, color => 'FFFFFF'); + my $fill = Imager::Fill->new + ( + combine => 'normal', + hatch => 'weave', + fg => '000000', + bg => 'FFFFFF' + ); + $im_g->box(fill => $fill); + my $im_c = Imager->new(xsize => 10, ysize => 10, channels => 3, bits => $bits); + $im_c->box(filled => 1, color => 'FFFFFF'); + $im_c->box(fill => $fill); + my $im_cg = $im_g->convert(preset => 'rgb'); + is_image($im_c, $im_cg, "check hatch is the same between color and greyscale"); + } +} + sub color_close { my ($c1, $c2) = @_; -- 2.39.5