g3topbm patch for s-t-r-e-t-c-h-i-n-g vertically

Steven Work (steve@work.bellingham.wa.us)
Tue, 8 Mar 1994 23:43:00 +0100


Hi all--

Here is an unapproved patch for Gert's g3topbm to double the rows of a
g3 file -- giving a normal resolution fax the same aspect ratio as a
fine res fax.  Why?

vgetty is running my phone line here, so I want vgetty's process tied
down as little as possible.  vgetty can't answer the next call until
$FAX_DIR/new_fax finishes its processing, so new_fax must be as
efficient as possible for me (this is a slow machine).  I found it
good to avoid pnmscale in new_fax, but the dumbest "pbmdoublerows"
program I wrote--read a row of bits, write it twice-- made print
queuing go from 11 seconds to 55 seconds per page (this is a _very_
slow machine--`pnmscale|pgmtopbm' took about three minutes).

By moving the row doubling to Gert's g3topbm.c program, the time
increase I measured was 1 second (12 seconds per page total to convert
to pbm & pipe to `lpr -d', whose filter is a hacked-up
auto-discriminator).  That seems significant enough to share.

Two patches follow: one for tools/g3topbm.c, and one for
doc/g3topbm.1.

---------------------- g3topbm.c.diff ---------------------
*** g3topbm-orig.c	Mon Nov 29 02:48:53 1993
--- g3topbm.c	Tue Mar  8 13:49:20 1994
***************
*** 25,30 ****
--- 25,31 ----
  #endif
  
  static int byte_tab[ 256 ];
+ static int opt_dblhigh;			/* -2 to stretch normal-res */
  
  struct g3_tree * black, * white;
  
***************
*** 67,72 ****
--- 68,75 ----
  	{
  	    init_byte_tab( 1, byte_tab );
  	}
+ 	else if (argv[i][1] == '2')
+ 	  opt_dblhigh++;		/* -2: stretch this normal-res g3 */
  	i++;
      }
  
***************
*** 255,266 ****
      sprintf( rbuf, "P4\n%d %d\n", hcol, row );
      write( 1, rbuf, strlen( rbuf ));
  
!     if ( hcol == MAX_COLS )
          write( 1, bitmap, (MAX_COLS/8) * row );
      else
      {
  	for ( i=0; i<row; i++ )
  	  write( 1, &bitmap[ i*(MAX_COLS/8) ], (hcol+7)/8 );
      }
  
      return 0;
--- 258,276 ----
      sprintf( rbuf, "P4\n%d %d\n", hcol, row );
      write( 1, rbuf, strlen( rbuf ));
  
!     if ( hcol == MAX_COLS && !opt_dblhigh)
          write( 1, bitmap, (MAX_COLS/8) * row );
      else
      {
+       if ( !opt_dblhigh)
  	for ( i=0; i<row; i++ )
  	  write( 1, &bitmap[ i*(MAX_COLS/8) ], (hcol+7)/8 );
+       else				/* Double each row */
+ 	for ( i=0; i<row; i++ )
+ 	  {
+ 	    write( 1, &bitmap[ i*(MAX_COLS/8) ], (hcol+7)/8 );
+ 	    write( 1, &bitmap[ i*(MAX_COLS/8) ], (hcol+7)/8 );
+ 	  }
      }
  
      return 0;
--------------------- end g3topbm.c.diff -------------------

And the man page:

--------------------- g3topbm.1.diff -----------------------
*** g3topbm-orig.1	Tue Mar  8 14:33:13 1994
--- g3topbm.1	Tue Mar  8 14:39:24 1994
***************
*** 5,10 ****
--- 5,11 ----
  .SH SYNOPSIS
  .B g3topbm
  .RB [ -reversebits ]
+ .RB [ -2 ]
  .RI [ g3file ]
  .SH DESCRIPTION
  Reads a Group 3 fax file (raw or digifax) as input. If no filename is
***************
*** 22,27 ****
--- 23,36 ----
  Apparently some fax modems do it one way and others do it the other way.
  If you get a whole bunch of "invalid code" messages, try using this
  flag.
+ .TP
+ .B -2
+ Repeat each horizontal row of the fax file in the pbm file.  You can
+ use this to adjust the aspect ratio of a "normal resolution" fax file
+ to match that of a "fine resolution" fax file.  This might not seem
+ like it belongs here, but it's 
+ .I much
+ faster than using pnmscale|pgmtopbm later.
  .SH REFERENCES
  The standard for Group 3 fax is defined in CCITT Recommendation T.4.
  .SH BUGS

--------------------- end g3topbm.1.diff -------------------


Steven Work
Renaissance Labs
Bellingham, WA
+1 206 647-1833
steve@work.bellingham.wa.us