Skip to content

Commit

Permalink
extract out image-regularising func
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Jul 1, 2024
1 parent 20f6220 commit 1d19687
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
41 changes: 21 additions & 20 deletions lib/PDL/Graphics/Gnuplot.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3534,26 +3534,10 @@ EOF
if ( $cdims==2 ) {
if ($chunk{options}{with}[0] eq 'image') {
my $dp = $dataPiddles[-1];
if ($dp->ndims==3) {
if ($dp->dim(1) >= 5) {
if ($dp->dim(0) ==3 && $dp->dim(1) >= 5 && $dp->dim(2) >= 5) {
$chunk{options}{with}[0] = 'rgbimage';
pop @dataPiddles;
push @dataPiddles,$dp->using(0,1,2);
} elsif ($dp->dim(2)==3 && $dp->dim(1)>=5 && $dp->dim(0) >= 5) {
$chunk{options}{with}[0] = 'rgbimage';
pop @dataPiddles;
push @dataPiddles,$dp->mv(2,0)->using(0,1,2);
} elsif ($dp->dim(0)==4 && $dp->dim(1) >= 5 && $dp->dim(2) >= 5) {
$chunk{options}{with}[0] = 'rgbalpha';
pop @dataPiddles;
push @dataPiddles,$dp->using(0,1,2,3);
} elsif ($dp->dim(2)==4 && $dp->dim(0) >= 5 && $dp->dim(1) >= 5) {
$chunk{options}{with}[0] = 'rgbalpha';
pop @dataPiddles;
push @dataPiddles, $dp->mv(2,0)->using(0,1,2,3);
}
}
if ($dp->ndims==3 and $dp->dim(1) >= 5) {
my ($with, @ndarrays) = _regularise_image($dp);
$chunk{options}{with}[0] = $with;
splice @dataPiddles, -1, 1, @ndarrays;
}
}
}
Expand Down Expand Up @@ -3677,6 +3661,23 @@ FOO
return (\@chunks, $Ncurves);
}

sub _regularise_image {
my ($dp) = @_;
my $with = $dp->dim(0) == 3 || $dp->dim(2) == 3 ? 'rgbimage' :
$dp->dim(0) == 4 || $dp->dim(2) == 4 ? 'rgbalpha' : undef;
my @ndarrays;
if ($dp->dim(0) == 3 && $dp->dim(2) >= 5) {
@ndarrays = $dp->using(0..2);
} elsif ($dp->dim(2) == 3 && $dp->dim(0) >= 5) {
@ndarrays = $dp->mv(2,0)->using(0..2);
} elsif ($dp->dim(0) == 4 && $dp->dim(2) >= 5) {
@ndarrays = $dp->using(0..3);
} elsif ($dp->dim(2) == 4 && $dp->dim(0) >= 5) {
@ndarrays = $dp->mv(2,0)->using(0..3);
}
($with, @ndarrays);
}

##########
# matchDims: nested sub inside plot - kludge up thread style matching across
# the data arguments to a given chunk.
Expand Down
4 changes: 4 additions & 0 deletions t/plot.t
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ unlink($testoutput) or warn "\$!: $! for '$testoutput'";
my $r9 = rvals(9,9);
eval {$w->plot({colorbox => 1},{with => 'image'},$r9->xvals,$r9->yvals,$r9)};
is($@, '', "colorbox succeeded");
for my $dims ([3,9,9],[4,9,9],[9,9,3],[9,9,4]) {
eval {$w->plot({colorbox => 1},{with => 'image'},$r9->xvals,$r9->yvals,rvals(@$dims))};
is($@, '', "regularising image succeeded (@$dims)");
}
}

{
Expand Down

0 comments on commit 1d19687

Please sign in to comment.