home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / netpbma.zip / pnm / pnmenlarge.c < prev    next >
C/C++ Source or Header  |  1993-10-04  |  2KB  |  78 lines

  1. /* pnmenlarge.c - read a portable anymap and enlarge it N times
  2. **
  3. ** Copyright (C) 1989 by Jef Poskanzer.
  4. **
  5. ** Permission to use, copy, modify, and distribute this software and its
  6. ** documentation for any purpose and without fee is hereby granted, provided
  7. ** that the above copyright notice appear in all copies and that both that
  8. ** copyright notice and this permission notice appear in supporting
  9. ** documentation.  This software is provided "as is" without express or
  10. ** implied warranty.
  11. */
  12.  
  13. #include "pnm.h"
  14.  
  15. int
  16. main( argc, argv )
  17.     int argc;
  18.     char* argv[];
  19.     {
  20.     FILE* ifp;
  21.     xel* xelrow;
  22.     xel* newxelrow;
  23.     register xel *xP;
  24.     register xel *nxP;
  25.     int argn, n, rows, cols, format, row;
  26.     register int col, subrow, subcol;
  27.     xelval maxval;
  28.     char* usage = "N [pnmfile]";
  29.  
  30.     pnm_init( &argc, argv );
  31.  
  32.     argn = 1;
  33.  
  34.     if ( argn == argc )
  35.     pm_usage( usage );
  36.     if ( sscanf( argv[argn], "%d", &n ) != 1 )
  37.     pm_usage( usage );
  38.     if ( n < 2 )
  39.     pm_error( "N must be greater than 1" );
  40.     ++argn;
  41.  
  42.     if ( argn != argc )
  43.     {
  44.     ifp = pm_openr( argv[argn] );
  45.     ++argn;
  46.     }
  47.     else
  48.     ifp = stdin;
  49.  
  50.     if ( argn != argc )
  51.     pm_usage( usage );
  52.  
  53.     pnm_readpnminit( ifp, &cols, &rows, &maxval, &format );
  54.     xelrow = pnm_allocrow( cols );
  55.     pnm_writepnminit( stdout, cols * n, rows * n, maxval, format, 0 );
  56.     newxelrow = pnm_allocrow( cols * n );
  57.  
  58.     for ( row = 0; row < rows; ++row )
  59.     {
  60.     pnm_readpnmrow( ifp, xelrow, cols, maxval, format );
  61.     for ( subrow = 0; subrow < n; ++subrow )
  62.         {
  63.         for ( col = 0, xP = xelrow; col < cols; ++col, ++xP )
  64.         {
  65.         for ( subcol = 0, nxP = &(newxelrow[col * n]);
  66.               subcol < n; ++subcol, ++nxP )
  67.             *nxP = *xP;
  68.         }
  69.         pnm_writepnmrow( stdout, newxelrow, cols * n, maxval, format, 0 );
  70.         }
  71.     }
  72.  
  73.     pm_close( ifp );
  74.     pm_close( stdout );
  75.  
  76.     exit( 0 );
  77.     }
  78.