Skip to content

Commit

Permalink
simplify pic_16bit.t
Browse files Browse the repository at this point in the history
  • Loading branch information
mohawk2 committed Sep 26, 2024
1 parent 450f3fb commit e085a6b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 37 deletions.
5 changes: 0 additions & 5 deletions IO/FITS/FITS.pm
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,11 @@ sub PDL::rfitshdr {
}

sub PDL::rfits {

my $class = shift;

barf 'Usage: $x = rfits($file) -or- $x = PDL->rfits($file)' if (@_ < 1 || @_ > 2);

my $file = shift;

my $u_opt = ifhref(shift);
my $opt = $rfits_options->options($u_opt);

my($nbytes, $line, $name, $rest, $size, $i, $bscale, $bzero, $extnum);

$nbytes = 0;
Expand Down
52 changes: 20 additions & 32 deletions IO/Pnm/t/pic_16bit.t
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
# This tests the 16-bit image capabilities of the rpic() and wpic()
# commands. The new code works with PNM output files and PNG format
# too.

use strict;
use warnings;
use Test::More;
Expand All @@ -14,37 +10,29 @@ use PDL::IO::Pic;
my $can_png = PDL->wpiccan('PNG');

$PDL::IO::Pic::debug=20;

# test save/restore of 8-bit image
my $x = sequence(16, 16);
my $tmpdir = tempdir( CLEANUP => 1 );
my $filestub = File::Spec->catfile($tmpdir, 't byte_a');
$x->wpic("$filestub.pnm");
my $a_pnm = rpic("$filestub.pnm");
ok(sum(abs($x-$a_pnm)) == 0, 'pnm byte image save+restore');
unlink "$filestub.pnm";

if ($can_png) {
$x->wpic("$filestub.png");
my $a_png;
unless ($^O =~ /MSWin32/i) { $a_png = rpic("$filestub.png") }
else { $a_png = rpic("$filestub.png", {FORMAT => 'PNG'}) }
ok all($x == $a_png), 'png byte image save+restore';
unlink "$filestub.png";

sub roundtrip {
my ($in, $file, $label, @extra) = @_;
$file = File::Spec->catfile($tmpdir, $file);
$in->wpic($file);
my $got = rpic($file, @extra);
ok all($in == $got), "$label image save+restore";
}

# test save/restore of 8-bit image
roundtrip(my $x = sequence(16,16), 'byte_a.pnm', 'pnm byte');

roundtrip($x, 'byte_a.png', 'png byte',
$^O =~ /MSWin32/i ? {FORMAT => 'PNG'} : ()) if $can_png;

# test save/restore of 16-bit image
my $a16 = sequence(256, 255)->ushort * 231;
my $pnm_file = File::Spec->catfile($tmpdir, 'tushort_a16.pnm');
$a16->wpic($pnm_file);
my $a16_pnm = rpic($pnm_file);
ok all($a16 == $a16_pnm), 'pnm ushort image save+restore';

if ($can_png) {
my $png_file = File::Spec->catfile($tmpdir, 'tushort_a16.png');
$a16->wpic($png_file);
my $a16_png = rpic($png_file, $^O =~ /MSWin32/i ? {FORMAT => 'PNG'} : ());
ok all($a16 == $a16_png), 'png ushort image save+restore';
}
roundtrip(
my $a16 = sequence(256, 255)->ushort * 231,
'tushort_a16.pnm', 'pnm ushort',
);

roundtrip($a16, 'tushort_a16.png', 'png ushort',
$^O =~ /MSWin32/i ? {FORMAT => 'PNG'} : ()) if $can_png;

done_testing;

0 comments on commit e085a6b

Please sign in to comment.