"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "IO/Pnm/pnm.pd" between
PDL-2.074.tar.gz and PDL-2.075.tar.gz

About: PDL (Perl Data Language) aims to turn perl into an efficient numerical language for scientific computing (similar to IDL and MatLab).

pnm.pd  (PDL-2.074):pnm.pd  (PDL-2.075)
skipping to change at line 288 skipping to change at line 288
GenericTypes => [B,U,L], GenericTypes => [B,U,L],
Code => 'int ms, ns, i,j,k,bit,llen; Code => 'int ms, ns, i,j,k,bit,llen;
PDL_Byte *buf, *bp; PDL_Byte *buf, *bp;
$GENERIC() *gbp; $GENERIC() *gbp;
ms = $SIZE(m); ns = $SIZE(n); ms = $SIZE(m); ns = $SIZE(n);
llen = ($COMP(isbin) ? ((ms+7) / 8) : (ms * sizeof($GENERIC()))) ; llen = ($COMP(isbin) ? ((ms+7) / 8) : (ms * sizeof($GENERIC()))) ;
/* allocate a buffer of length llen */ /* allocate a buffer of length llen */
if ((buf = (PDL_Byte*) malloc(llen*sizeof(PDL_Byte))) if ((buf = (PDL_Byte*) malloc(llen*sizeof(PDL_Byte)))
== NULL) == NULL)
$CROAK("Error getting mem for line buffer"); $CROAK("Error getting mem for line buffer");
threadloop %{ /* 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;
skipping to change at line 335 skipping to change at line 335
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 => [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:
threadloop %{ /* 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) {
switch (s) { switch (s) {
case '#': /* comment, skip rest of line */ case '#': /* comment, skip rest of line */
SWALLOWLINE($COMP(fp)); SWALLOWLINE($COMP(fp));
break; break;
case '0': case '0':
case '1': case '1':
/* invert on the fly */ /* invert on the fly */
skipping to change at line 368 skipping to change at line 368
break; break;
} }
} }
$PPSYM()next: ; $PPSYM()next: ;
%} %}
} }
%} %}
break; break;
case PGM: case PGM:
case PPM: case PPM:
threadloop %{ /* with top to bottom inversion */ broadcastloop %{ /* with top to bottom inversion */
PDL_Long j; PDL_Long j;
for (i=ns-1; i>= 0; i--) { for (i=ns-1; i>= 0; i--) {
loop(m) %{ loop(m) %{
if (getint($COMP(fp),&j) <= 0) if (getint($COMP(fp),&j) <= 0)
$CROAK("found garbage, aborting"); /* for now */ $CROAK("found garbage, aborting"); /* for now */
$im(n=>i,m=>m) = j; $im(n=>i,m=>m) = j;
%} %}
} }
%} %}
break; break;
skipping to change at line 390 skipping to change at line 390
$CROAK("unknown PNM format"); $CROAK("unknown PNM format");
break; break;
} /* end switch */ } /* end switch */
?, Doc => ' ?, Doc => '
=for ref =for ref
Read in an ascii pnm file. Read in an ascii pnm file.
' '
); );
# write a line of data supporting threading ! # 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 => [B,U,S,L],
Code => ' Code => '
if ($COMP(israw)) { if ($COMP(israw)) {
if ($COMP(isbin)) { if ($COMP(isbin)) {
threadloop %{ 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);
bit = k = 0; bit = k = 0;
} }
%} %}
if (bit) { if (bit) {
k = k << (8-bit); k = k << (8-bit);
PerlIO_putc($COMP(fp),k); PerlIO_putc($COMP(fp),k);
} }
%} %}
} else { } else {
int len = $SIZE(m) * sizeof($GENERIC()); int len = $SIZE(m) * sizeof($GENERIC());
threadloop %{ broadcastloop %{
if (PerlIO_write($COMP(fp),$P(a),len) != len) if (PerlIO_write($COMP(fp),$P(a),len) != len)
$CROAK("Error writing pnm file"); $CROAK("Error writing pnm file");
%} %}
} }
} else { } else {
int len=0; int len=0;
threadloop %{ broadcastloop %{
loop(m) %{ loop(m) %{
PerlIO_printf($COMP(fp),"%3d ",$COMP(isbin) ? PerlIO_printf($COMP(fp),"%3d ",$COMP(isbin) ?
($a() < 1) :$a()); ($a() < 1) :$a());
len +=4; len +=4;
if (len>58) { PerlIO_printf($COMP(fp),"\n"); len= 0; } if (len>58) { PerlIO_printf($COMP(fp),"\n"); len= 0; }
%} %}
if (len<=58) if (len<=58)
PerlIO_printf($COMP(fp),"\n"); PerlIO_printf($COMP(fp),"\n");
%} %}
} }
', Doc => ' ', Doc => '
=for ref =for ref
Write a line of pnm data. Write a line of pnm data.
This function is implemented this way so that threading works This function is implemented this way so that broadcasting works
naturally. naturally.
'); ');
pp_done(); pp_done();
 End of changes. 8 change blocks. 
8 lines changed or deleted 8 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)