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

  1. /* pnmtile.c - replicate a portable anymap into a specified size
  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** xels;
  22.     register xel* xelrow;
  23.     xelval maxval;
  24.     int rows, cols, format, width, height, row, col;
  25.     char* usage = "width height [pnmfile]";
  26.  
  27.     pnm_init( &argc, argv );
  28.  
  29.     if ( argc < 3 || argc > 4 )
  30.     pm_usage( usage );
  31.  
  32.     if ( sscanf( argv[1], "%d", &width ) != 1 )
  33.     pm_usage( usage );
  34.     if ( sscanf( argv[2], "%d", &height ) != 1 )
  35.     pm_usage( usage );
  36.  
  37.     if ( width < 1 )
  38.     pm_error( "width is less than 1" );
  39.     if ( height < 1 )
  40.     pm_error( "height is less than 1" );
  41.  
  42.     if ( argc == 4 )
  43.     ifp = pm_openr( argv[3] );
  44.     else
  45.     ifp = stdin;
  46.  
  47.     xels = pnm_readpnm( ifp, &cols, &rows, &maxval, &format );
  48.     pm_close( ifp );
  49.  
  50.     xelrow = pnm_allocrow( width );
  51.  
  52.     pnm_writepnminit( stdout, width, height, maxval, format, 0 );
  53.     for ( row = 0; row < height; ++row )
  54.     {
  55.     for ( col = 0; col < width; ++col )
  56.         xelrow[col] = xels[row % rows][col % cols];
  57.     pnm_writepnmrow( stdout, xelrow, width, maxval, format, 0 );
  58.     }
  59.  
  60.     pm_close( stdout );
  61.  
  62.     exit( 0 );
  63.     }
  64.