Skip to content

Commit

Permalink
Merge 73a3ef3 into 70d538f
Browse files Browse the repository at this point in the history
  • Loading branch information
zmughal committed Jan 27, 2023
2 parents 70d538f + 73a3ef3 commit a62b175
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ MANIFEST.SKIP
README.pod
t/pdfcairo-output.t
t/plot.t
t/aa.t
12 changes: 10 additions & 2 deletions lib/PDL/Graphics/Gnuplot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,7 @@ FOO
}

### Terminals that support anti-aliasing all broadcast their format so that rpic can handle them.
if( defined $termTab->{terminal}->{image_format}) {
if( defined $termTab->{$terminal}->{image_format}) {
$this->{image_format}= $termTab->{$terminal}->{image_format};
} else {
delete($this->{image_format});
Expand Down Expand Up @@ -2448,13 +2448,18 @@ sub close
restart($this);
if(defined $this->{aa} && $this->{aa} && $this->{aa} != 1 && $this->{aa_ready}) {
eval "use PDL::Transform; use PDL::IO::Pic;"; # load when needed
unless( rpiccan($this->{image_format}) and wpiccan($this->{image_format}) ) {
carp "Can not read/write $this->{image_format} for anti-aliasing. Skipping aa operation.";
return;
}
my $im = rpic($this->{options}->{output},{FORMAT=>$this->{image_format}});
if($im->ndims==3) {
$im = $im->mv(0,-1);
}
# gamma-correct before scaling, and put back after.
my $imf = ((float $im)/255.0)->clip(0,1) ** 2.2;
$imf = $imf->match( [ $im->dim(0)/$this->{aa}, $im->dim(1)/$this->{aa} ], {method=>'h',blur=>0.5});
$imf->check_badflag;
$im = byte(($imf ** (1/2.2)) * 255);
if($im->ndims==3){
$im = $im->mv(-1,0);
Expand Down Expand Up @@ -7065,7 +7070,10 @@ for my $k(keys %$termTabSource) {
undef, # This gets filled in on first use in the constructor.
"$k terminal options"
],
default_output=> $v->{default_output}
default_output=> $v->{default_output},
( exists $v->{image_format}
? ( image_format => $v->{image_format} )
: () ),
};
}

Expand Down
42 changes: 42 additions & 0 deletions t/aa.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
use strict;
use warnings;
use Test::More;

use PDL::Graphics::Gnuplot qw(gpwin);
use File::Temp qw(tempfile);
use PDL;


my @terms_with_aa = map {
my $tab = $_;
grep exists $tab->{$_}{opt}[0]{aa}, keys %$tab
} $PDL::Graphics::Gnuplot::termTab;

my @valid_terms = grep $PDL::Graphics::Gnuplot::valid_terms->{$_}, @terms_with_aa;

if( @valid_terms ) {
plan tests => scalar @valid_terms;
} else {
plan skip_all => 'No terminals with anti-aliasing';
}

for my $term (sort @valid_terms) {
subtest "Terminal $term" => sub {
my ($suffix) = $PDL::Graphics::Gnuplot::termTab->{$term}{default_output} =~ /(\.[^.]+)$/;

ok $suffix, 'have suffix';

my (undef, $testoutput) = tempfile('pdl_graphics_gnuplot_test_aa_XXXXXXX',
SUFFIX => $suffix);

my $x = zeroes(50)->xlinvals(0, 7);
my $w = gpwin($term, output => $testoutput, aa => 2);
$w->plot(with => 'lines', $x, $x->sin);
$w->close;
ok -s $testoutput, 'File has size';

unlink($testoutput) or warn "\$!: $!";
};
}

done_testing;

0 comments on commit a62b175

Please sign in to comment.