pnm.pd (PDL-2.081) | : | pnm.pd (PDL-2.082) | ||
---|---|---|---|---|
# REPLACE FOLLOWING BY | use strict; | |||
# | use warnings; | |||
# use PDL::PP qw/PDL::Experiment PDL::Experiment Experiment/; | ||||
# | ||||
# when using not in this package. | ||||
pp_add_exported('',"rpnm wpnm"); | pp_add_exported('',"rpnm wpnm"); | |||
pp_addpm({At=>'Top'},<<'EOD'); | pp_addpm({At=>'Top'},<<'EOD'); | |||
use strict; | use strict; | |||
use warnings; | use warnings; | |||
=head1 NAME | =head1 NAME | |||
skipping to change at line 275 | skipping to change at line 272 | |||
conditions. For details, see the file COPYING in the PDL | conditions. For details, see the file COPYING in the PDL | |||
distribution. If this file is separated from the PDL distribution, | distribution. If this file is separated from the PDL distribution, | |||
the copyright notice should be included in the file. | the copyright notice should be included in the file. | |||
=cut | =cut | |||
############################## END PM CODE ################################ | ############################## END PM CODE ################################ | |||
EOD | EOD | |||
pp_def('pnminraw', | pp_def('pnminraw', | |||
Pars => 'type(); byte+ [o] im(m,n)', | Pars => 'type(); byte+ [o] im(m,n); byte [t] buf(llen)', | |||
OtherPars => 'int ms => m; int ns => n; | OtherPars => 'int ms => m; int ns => n; | |||
int isbin; PerlIO *fp', | int isbin; PerlIO *fp', | |||
GenericTypes => [B,U,L], | GenericTypes => [qw(B U L)], | |||
Code => 'int ms, ns, i,j,k,bit,llen; | RedoDimsCode => ' | |||
PDL_Byte *buf, *bp; | $SIZE(llen) = $COMP(isbin) ? ($SIZE(m)+7) / 8 : $SIZE(m) * sizeof($GENE | |||
$GENERIC() *gbp; | RIC()); | |||
', | ||||
Code => 'int ms, ns, i,j,k,bit,llen = $SIZE(llen); | ||||
PDL_Byte *buf = $P(buf), *bp; | ||||
ms = $SIZE(m); ns = $SIZE(n); | ms = $SIZE(m); ns = $SIZE(n); | |||
llen = ($COMP(isbin) ? ((ms+7) / 8) : (ms * sizeof($GENERIC()))) | ||||
; | ||||
/* allocate a buffer of length llen */ | ||||
if ((buf = (PDL_Byte*) malloc(llen*sizeof(PDL_Byte))) | ||||
== NULL) | ||||
$CROAK("Error getting mem for line buffer"); | ||||
broadcastloop %{ /* with top to bottom inversion */ | broadcastloop %{ /* with top to bottom inversion */ | |||
for (i=ns-1; i>= 0; i--) { | for (i=ns-1; i>= 0; i--) { | |||
if (PerlIO_read($COMP(fp),buf,llen) != llen) | if (PerlIO_read($COMP(fp),buf,llen) != llen) | |||
$CROAK("Error reading pnm file"); | $CROAK("Error reading pnm file"); | |||
if ($COMP(isbin)) /* unpack buffer */ | if ($COMP(isbin)) /* unpack buffer */ | |||
for (j=0,bp=buf,bit=0; j<ms; j++, bit++) { | for (j=0,bp=buf,bit=0; j<ms; j++, bit++) { | |||
bit &= 7; | bit &= 7; | |||
if (!bit) k= *bp++; | if (!bit) k= *bp++; | |||
/* here we do the inversion */ | /* here we do the inversion */ | |||
$im(n=>i,m=>j) = (k&0x80) ? 0 : 1; | $im(n=>i,m=>j) = (k&0x80) ? 0 : 1; | |||
k = k << 1; | k = k << 1; | |||
} | } | |||
else { | else { | |||
gbp = ($GENERIC()*)buf; | $GENERIC() *gbp = ($GENERIC()*)buf; | |||
loop(m) %{ | loop(m) %{ | |||
$im(n=>i,m=>m) = *(gbp++); | $im(n=>i,m=>m) = *(gbp++); | |||
%} | %} | |||
} | } | |||
} | } | |||
%}', Doc => ' | %}', Doc => ' | |||
=for ref | =for ref | |||
Read in a raw pnm file. | Read in a raw pnm file. | |||
read a raw pnm file. The C<type> argument is only there to | read a raw pnm file. The C<type> argument is only there to | |||
determine the type of the operation when creating C<im> or trigger | determine the type of the operation when creating C<im> or trigger | |||
the appropriate type conversion (maybe we want a byte+ here so that | the appropriate type conversion (maybe we want a byte+ here so that | |||
C<im> follows I<strictly> the type of C<type>). | C<im> follows I<strictly> the type of C<type>). | |||
' | ' | |||
); | ); | |||
pp_addhdr(<<'EOH'); | pp_addhdr(<<'EOH'); | |||
#include "get.h" | #include "get.h" | |||
EOH | EOH | |||
pp_def( 'pnminascii', | pp_def( 'pnminascii', | |||
Pars => 'type(); byte+ [o] im(m,n)', | Pars => 'type(); byte+ [o] im(m,n)', | |||
OtherPars => 'int ms => m; int ns => n; | OtherPars => 'int ms => m; int ns => n; | |||
int format; PerlIO *fp', | int format; PerlIO *fp', | |||
GenericTypes => [B,U,S,L], | GenericTypes => [qw(B U S L)], | |||
Code => q? | Code => q? | |||
int ms, ns, s, i; | int ms, ns, s, i; | |||
ms = $SIZE(m); ns = $SIZE(n); | ms = $SIZE(m); ns = $SIZE(n); | |||
switch ($COMP(format)) { | switch ($COMP(format)) { | |||
case PBM: | case PBM: | |||
broadcastloop %{ /* with top to bottom inversion */ | broadcastloop %{ /* with top to bottom inversion */ | |||
for (i=ns-1; i>= 0; i--) { | for (i=ns-1; i>= 0; i--) { | |||
loop(m) %{ | loop(m) %{ | |||
while ((s = PerlIO_getc($COMP(fp))) != EOF) { | while ((s = PerlIO_getc($COMP(fp))) != EOF) { | |||
skipping to change at line 395 | skipping to change at line 388 | |||
Read in an ascii pnm file. | Read in an ascii pnm file. | |||
' | ' | |||
); | ); | |||
# write a line of data supporting broadcasting ! | # write a line of data supporting broadcasting ! | |||
pp_def( 'pnmout', | pp_def( 'pnmout', | |||
Pars => 'a(m);', | Pars => 'a(m);', | |||
'NoPthread' => 1, # Pthreading doesn't make sense for an IO function | 'NoPthread' => 1, # Pthreading doesn't make sense for an IO function | |||
OtherPars => "int israw; int isbin; PerlIO *fp", | OtherPars => "int israw; int isbin; PerlIO *fp", | |||
GenericTypes => [B,U,S,L], | GenericTypes => [qw(B U S L)], | |||
Code => ' | Code => ' | |||
if ($COMP(israw)) { | if ($COMP(israw)) { | |||
if ($COMP(isbin)) { | if ($COMP(isbin)) { | |||
broadcastloop %{ | broadcastloop %{ | |||
int k=0, bit=0; | int k=0, bit=0; | |||
loop(m) %{ | loop(m) %{ | |||
k = (k << 1) | ($a() < 1); | k = (k << 1) | ($a() < 1); | |||
bit++; | bit++; | |||
if (bit==8) { | if (bit==8) { | |||
PerlIO_putc($COMP(fp),k); | PerlIO_putc($COMP(fp),k); | |||
End of changes. 8 change blocks. | ||||
20 lines changed or deleted | 13 lines changed or added |