From 743d0551e35255b1947985f028c5cc8aa0939dbb Mon Sep 17 00:00:00 2001 From: Ed J Date: Thu, 25 Jul 2024 21:14:52 +0100 Subject: [PATCH] fix with=>"fits" RGB images --- lib/PDL/Graphics/Gnuplot.pm | 29 +++++------------------------ t/plot.t | 4 ++++ 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/lib/PDL/Graphics/Gnuplot.pm b/lib/PDL/Graphics/Gnuplot.pm index e544291..38344e7 100644 --- a/lib/PDL/Graphics/Gnuplot.pm +++ b/lib/PDL/Graphics/Gnuplot.pm @@ -7764,10 +7764,9 @@ sub _with_fits_prefrobnicator { barf "PDL::Graphics::Gnuplot: 'with fits' special option requires a single FITS image\n" if(@data != 1); my $data = $data[0]; - my $h = $data->gethdr(); + barf "PDL::Graphics::Gnuplot: 'with fits' needs an image, RGB triplet, or RGBA quad\n" unless $data->ndims==2 || ($data->ndims==3 && ($data->dim(2)==4 || $data->dim(2)==3 || $data->dim(2)==1)); + my $h = $data->gethdr; unless($h and ref $h eq 'HASH' and $h->{NAXIS} and $h->{NAXIS1} and $h->{NAXIS2}) { - barf "PDL::Graphics::Gnuplot: 'with fits' got a (non-image) ".join("x",$data->dims)." PDL with no FITS header.\n" - unless $data->ndims==2 or ($data->ndims==3 && ($data->dim(3)==3 || $data->dim(3)==1)); warn "PDL::Graphics::Gnuplot: 'with fits' expected a FITS header. Using pixel coordinates...\n"; $h = { NAXIS=>2, @@ -7837,27 +7836,9 @@ sub _with_fits_prefrobnicator { )]; } - ## - # Debugging Gnuplot's horrible indexing problem - # $PDL::Graphics::Gnuplot::prefrobnicated = [$ndc->mv(0,-1)->dog, $d2]; - - if($d2->ndims == 2) { - $with->[0] = 'image'; - $chunk->{options}{with} = [@$with]; - return ($ndc->mv(0,-1)->dog, $d2); - } - - if($data->ndims == 3 and $data->dim(2)==3) { - $with->[0] = 'rgbimage'; - return ($ndc->mv(0,-1)->dog, $d2->dog); - } - - if($data->ndims == 3 and $data->dim(2)==4) { - $with->[0] = 'rgbalpha'; - return ($ndc->mv(0,-1)->dog, $d2->dog); - } - - barf "PDL::Graphics::Gnuplot: 'with fits' needs an image, RGB triplet, or RGBA quad\n"; + $with->[0] = 'image'; + $chunk->{options}{with} = [@$with]; + ($ndc->mv(0,-1)->dog, $d2); } ########## diff --git a/t/plot.t b/t/plot.t index 67baf6b..8042eac 100644 --- a/t/plot.t +++ b/t/plot.t @@ -160,6 +160,10 @@ unlink($testoutput) or warn "\$!: $! for '$testoutput'"; is($@, '', "with 'fits', resample"); eval {$w->plot({with => 'fits', resample=>[100,100]},$r9)}; is($@, '', "with 'fits', resample [100,100]"); + my $r9_rgb = pdl(0,$r9,$r9); + $r9_rgb->slice(',,0') .= 6; + eval {$w->plot({with => 'fits'},$r9_rgb*20)}; + is($@, '', "with 'fits', rgb"); } {