From:	Ulrich Lauther <lauther@inf21.zfe.siemens.de>
To:	gert@greenie.muc.de (Gert Doering)

> > Ich habe jetzt pnmtops so geaendert, dass man in x- und y-Richtung
> > unabhaengig scalen kann. (Das geht schneller und erzeugt sehr viel kleinere
> > output-Files als wenn man pnmscale benutzen wuerde.)
[..]

*** pnmtops.c-	Wed Dec 29 11:47:55 1993
--- pnmtops.c	Wed Jan  5 10:15:22 1994
***************
*** 14,20 ****
  
  #define MARGIN 0.95
  
! static void putinit ARGS(( char* name, int cols, int rows, int padright, int bps, float scale, int dpi, int pagewid, int pagehgt, int format, int turnflag, int turnokflag, int rleflag ));
  static void putitem ARGS(( void ));
  static void putxelval ARGS(( xelval xv ));
  static void putrest ARGS(( void ));
--- 14,25 ----
  
  #define MARGIN 0.95
  
! static void putinit ARGS(( char* name, int cols, int rows,\
!                          int padright, int bps,\
!                          float scale, float xscale, float yscale,\
!                          float xoff, float yoff,\
!                          int dpi, int pagewid, int pagehgt, int format,\
!                          int turnflag, int turnokflag, int rleflag, int norescaleflag));
  static void putitem ARGS(( void ));
  static void putxelval ARGS(( xelval xv ));
  static void putrest ARGS(( void ));
***************
*** 32,56 ****
      FILE* ifp;
      xel* xelrow;
      register xel* xP;
!     int argn, turnflag, turnokflag, rleflag;
      int rows, cols, format, bps, padright, row, col;
      xelval maxval, nmaxval;
!     float scale, f;
      int dpi, pagewid, pagehgt;
      char name[100];
      char* cp;
!     char* usage = "[-scale <x>] [-turn|-noturn] [-rle|-runlength] [-dpi <n>] [-width <n>] [-height <n>] [-rle|-runlength] [pnmfile]";
  
      pnm_init( &argc, argv );
  
!     argn = 1;
!     scale = 1.0;
      turnflag = 0;
      turnokflag = 1;
      rleflag = 0;
      /* LaserWriter defaults. */
      dpi = 300;
!     pagewid = 612;
      pagehgt = 762;
  
      /* Check for flags. */
--- 37,75 ----
      FILE* ifp;
      xel* xelrow;
      register xel* xP;
!     int argn, turnflag, turnokflag, rleflag, norescaleflag;
      int rows, cols, format, bps, padright, row, col;
      xelval maxval, nmaxval;
!     float scale,
!           xscale,
!           yscale,
!           xoff,
!           yoff,
!           f;
      int dpi, pagewid, pagehgt;
      char name[100];
      char* cp;
!     char* usage = "\
! [-scale <x>] [-xscale <x>] [-yscale <x>]\n\
! [-xoff <x>] [-yoff <x>]\n\
! [-turn|-noturn] [-norescale] [-rle|-runlength]\n\
! [-dpi <n>] [-width <n>] [-height <n>] [pnmfile]";
  
      pnm_init( &argc, argv );
  
!     argn   = 1;
!     scale  = 1.0;
!     xscale = 1.0;
!     yscale = 1.0;
!     xoff   = -1000.0;
!     yoff   = -1000.0;
!     norescaleflag = 0;
      turnflag = 0;
      turnokflag = 1;
      rleflag = 0;
      /* LaserWriter defaults. */
      dpi = 300;
!     pagewid = 612; /* points (i.e., 1/72 inch ) */
      pagehgt = 762;
  
      /* Check for flags. */
***************
*** 62,71 ****
  	    if ( argn == argc || sscanf( argv[argn], "%f", &scale ) != 1 )
  		pm_usage( usage );
  	    }
  	else if ( pm_keymatch( argv[argn], "-turn", 2 ) )
  	    turnflag = 1;
! 	else if ( pm_keymatch( argv[argn], "-noturn", 2 ) )
  	    turnokflag = 0;
  	else if ( pm_keymatch( argv[argn], "-rle", 2 ) ||
  	          pm_keymatch( argv[argn], "-runlength", 2 ) )
  	    rleflag = 1;
--- 81,116 ----
  	    if ( argn == argc || sscanf( argv[argn], "%f", &scale ) != 1 )
  		pm_usage( usage );
  	    }
+ 	else if ( pm_keymatch( argv[argn], "-xscale", 3 ) )
+ 	    {
+ 	    ++argn;
+ 	    if ( argn == argc || sscanf( argv[argn], "%f", &xscale ) != 1 )
+ 		pm_usage( usage );
+ 	    }
+ 	else if ( pm_keymatch( argv[argn], "-yscale", 3 ) )
+ 	    {
+ 	    ++argn;
+ 	    if ( argn == argc || sscanf( argv[argn], "%f", &yscale ) != 1 )
+ 		pm_usage( usage );
+ 	    }
+ 	else if ( pm_keymatch( argv[argn], "-xoff", 3 ) )
+ 	    {
+ 	    ++argn;
+ 	    if ( argn == argc || sscanf( argv[argn], "%f", &xoff ) != 1 )
+ 		pm_usage( usage );
+ 	    }
+ 	else if ( pm_keymatch( argv[argn], "-yoff", 3 ) )
+ 	    {
+ 	    ++argn;
+ 	    if ( argn == argc || sscanf( argv[argn], "%f", &yoff ) != 1 )
+ 		pm_usage( usage );
+ 	    }
  	else if ( pm_keymatch( argv[argn], "-turn", 2 ) )
  	    turnflag = 1;
! 	else if ( pm_keymatch( argv[argn], "-noturn", 4 ) )
  	    turnokflag = 0;
+ 	else if ( pm_keymatch( argv[argn], "-norescale", 4 ) )
+ 	    norescaleflag = 1;
  	else if ( pm_keymatch( argv[argn], "-rle", 2 ) ||
  	          pm_keymatch( argv[argn], "-runlength", 2 ) )
  	    rleflag = 1;
***************
*** 131,138 ****
      padright = ( ( ( cols * bps + 7 ) / 8 ) * 8 - cols * bps ) / bps;
  
      putinit(
! 	name, cols, rows, padright, bps, scale, dpi, pagewid, pagehgt, format,
! 	turnflag, turnokflag, rleflag );
      for ( row = 0; row < rows; ++row )
  	{
  	pnm_readpnmrow( ifp, xelrow, cols, maxval, format );
--- 176,185 ----
      padright = ( ( ( cols * bps + 7 ) / 8 ) * 8 - cols * bps ) / bps;
  
      putinit(
! 	name, cols, rows, padright, bps, scale, xscale, yscale,
! 	xoff, yoff,
! 	dpi, pagewid, pagehgt, format,
! 	turnflag, turnokflag, rleflag, norescaleflag );
      for ( row = 0; row < rows; ++row )
  	{
  	pnm_readpnmrow( ifp, xelrow, cols, maxval, format );
***************
*** 221,237 ****
  
  #if __STDC__
  static void
! putinit( char* name, int cols, int rows, int padright, int bps, float scale,
  	 int dpi, int pagewid, int pagehgt, int format, int turnflag,
! 	 int turnokflag, int rleflag )
  #else /*__STDC__*/
  static void
! putinit( name, cols, rows, padright, bps, scale, dpi, pagewid, pagehgt, format,
! 	 turnflag, turnokflag, rleflag )
      char* name;
      int cols, rows, padright, bps;
!     float scale;
!     int dpi, pagewid, pagehgt, format, turnflag, turnokflag, rleflag;
  #endif /*__STDC__*/
      {
      int icols, irows, devpix;
--- 268,288 ----
  
  #if __STDC__
  static void
! putinit( char* name, int cols, int rows, int padright, int bps,
!          float scale, float xscale, float yscale,
!          float xoff, float yoff,
  	 int dpi, int pagewid, int pagehgt, int format, int turnflag,
! 	 int turnokflag, int rleflag, int norescaleflag)
  #else /*__STDC__*/
  static void
! putinit( name, cols, rows, padright, bps, scale, xscale, yscale,
!          xoff, yoff, dpi, pagewid, pagehgt, format,
! 	 turnflag, turnokflag, rleflag, norescaleflag )
      char* name;
      int cols, rows, padright, bps;
!     float scale, xscale, yscale;
!     float xoff, yoff;
!     int dpi, pagewid, pagehgt, format, turnflag, turnokflag, rleflag, norescaleflag;
  #endif /*__STDC__*/
      {
      int icols, irows, devpix;
***************
*** 250,276 ****
      /* Figure out size. */
      devpix = dpi / 72.0 + 0.5;		/* device pixels per unit, approx. */
      pixfac = 72.0 / dpi * devpix;	/* 1, approx. */
!     scols = scale * cols * pixfac;
!     srows = scale * rows * pixfac;
      if ( scols > pagewid * MARGIN || srows > pagehgt * MARGIN )
  	{
  	if ( scols > pagewid * MARGIN )
  	    {
  	    scale *= pagewid / scols * MARGIN;
! 	    scols = scale * cols * pixfac;
! 	    srows = scale * rows * pixfac;
  	    }
  	if ( srows > pagehgt * MARGIN )
  	    {
  	    scale *= pagehgt / srows * MARGIN;
! 	    scols = scale * cols * pixfac;
! 	    srows = scale * rows * pixfac;
  	    }
  	pm_message(
  	    "warning, image too large for page, rescaling to %g", scale );
  	}
!     llx = ( pagewid - scols ) / 2;
!     lly = ( pagehgt - srows ) / 2;
  
      printf( "%%!PS-Adobe-2.0 EPSF-2.0\n" );
      printf( "%%%%Creator: pnmtops\n" );
--- 301,329 ----
      /* Figure out size. */
      devpix = dpi / 72.0 + 0.5;		/* device pixels per unit, approx. */
      pixfac = 72.0 / dpi * devpix;	/* 1, approx. */
!     scols = scale * xscale * cols * pixfac;
!     srows = scale * yscale * rows * pixfac;
!     if (! norescaleflag) {
      if ( scols > pagewid * MARGIN || srows > pagehgt * MARGIN )
  	{
  	if ( scols > pagewid * MARGIN )
  	    {
  	    scale *= pagewid / scols * MARGIN;
! 	    scols = scale * cols * xscale * pixfac;
! 	    srows = scale * rows * yscale * pixfac;
  	    }
  	if ( srows > pagehgt * MARGIN )
  	    {
  	    scale *= pagehgt / srows * MARGIN;
! 	    scols = scale * cols * xscale * pixfac;
! 	    srows = scale * rows * yscale * pixfac;
  	    }
  	pm_message(
  	    "warning, image too large for page, rescaling to %g", scale );
  	}
!     }
!     if (xoff == -1000.0) llx = ( pagewid - scols ) / 2; else llx = xoff*72;
!     if (yoff == -1000.0) lly = ( pagehgt - srows ) / 2; else lly = yoff*72;
  
      printf( "%%!PS-Adobe-2.0 EPSF-2.0\n" );
      printf( "%%%%Creator: pnmtops\n" );
*** pnmtops.1-	Wed Jan  5 09:53:28 1994
--- pnmtops.1	Wed Jan  5 10:11:35 1994
***************
*** 6,13 ****
--- 6,22 ----
  .B pnmtops
  .RB [ -scale
  .IR s ]
+ .RB [ -xscale
+ .IR x ]
+ .RB [ -yscale
+ .IR y ]
+ .RB [ -xoff
+ .IR xoff ]
+ .RB [ -yoff
+ .IR yoff ]
  .RB [ -turn | -noturn ]
  .RB [ -rle | -runlength ]
+ .RB [ -norescale ]
  .RB [ -dpi
  .IR n ]
  .RB [ -width
***************
*** 47,52 ****
--- 56,85 ----
  To get one PNM pixel per 300 dpi printer pixel, use "-scale 0.25".
  .PP
  The
+ .B -xscale
+ and
+ .B -yscale
+ flags allow for independent scaling of the x- or y-coordinate.
+ The default x- and y-scales are 1.
+ scale, xscale, and yscale accumulate: the effective scale-factors are
+ scale*xscale and scale*yscale, respectively.
+ .PP
+ The
+ .B -xoff
+ and
+ .B -yoff
+ flags allow for positioning of the result.
+ By default, the picture is centered based on its size and the specified
+ or default values of width and height.
+ These flags supress centering.
+ .PP
+ The
+ .B -norescale
+ flag controls whether the image gets rescaled if it does not fit onto the
+ page (specified by width and heights).
+ By default, rescaling is on.
+ .PP
+ The
  .B -turn
  and
  .B -noturn
***************
*** 88,93 ****
--- 121,128 ----
  The default is 8.5 inches by 11 inches.
  .PP
  All flags can be abbreviated to their shortest unique prefix.
+ .PP
+ Use the -[xy]off and -norescale flags only if you know what you are doing!
  .SH "SEE ALSO"
  pnm(5), psidtopgm(1)
  .SH AUTHOR

-- 
----------------------------------------------------------------------------
Ulrich Lauther          ph: +49 89 636 48834 fx: ... 636 42284
Siemens ZFE BT SE 14    Internet: lauther@ztivax.zfe.siemens.de
                        from ems: lauther@ztivax:tcp-636-18:Mch P Siemens AG

