home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume5 / pbm3 / part3 / pbmenlarge.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-03  |  1.7 KB  |  82 lines

  1. /* pbmenlarge.c - read a portable bitmap and enlarge it N times
  2. **
  3. ** Copyright (C) 1988 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 <stdio.h>
  14. #include "pbm.h"
  15.  
  16. main( argc, argv )
  17. int argc;
  18. char *argv[];
  19.     {
  20.     FILE *ifd;
  21.     bit **bits, **newbits;
  22.     int argn, n, rows, cols, row, col, subrow, subcol;
  23.     char *usage = "usage:  %s [-N] [pbmfile]\n";
  24.  
  25.     argn = 1;
  26.     n = 2;
  27.  
  28.     if ( argn < argc )
  29.     {
  30.     if ( argv[argn][0] == '-' )
  31.         {
  32.         if ( sscanf( &(argv[argn][1]), "%d", &n ) != 1 )
  33.         {
  34.         fprintf( stderr, usage, argv[0] );
  35.         exit( 1 );
  36.         }
  37.         if ( n < 2 )
  38.         {
  39.         fprintf( stderr, usage, argv[0] );
  40.         exit( 1 );
  41.         }
  42.         argn++;
  43.         }
  44.     }
  45.  
  46.     if ( argn == argc )
  47.     ifd = stdin;
  48.     else
  49.     {
  50.     ifd = fopen( argv[argn], "r" );
  51.     if ( ifd == NULL )
  52.         {
  53.         fprintf( stderr, "%s: can't open.\n", argv[argn] );
  54.         exit( 1 );
  55.         }
  56.     argn++;
  57.     }
  58.  
  59.     if ( argn != argc )
  60.     {
  61.     fprintf( stderr, usage, argv[0] );
  62.     exit( 1 );
  63.     }
  64.  
  65.     bits = pbm_readpbm( ifd, &cols, &rows );
  66.     if ( ifd != stdin )
  67.     fclose( ifd );
  68.  
  69.     newbits = pbm_allocarray( cols * n, rows * n );
  70.  
  71.     for ( row = 0; row < rows; row++ )
  72.         for ( col = 0; col < cols; col++ )
  73.         for ( subrow = 0; subrow < n; subrow++ )
  74.         for ( subcol = 0; subcol < n; subcol++ )
  75.             newbits[row * n + subrow][col * n + subcol] =
  76.             bits[row][col];
  77.  
  78.     pbm_writepbm( stdout, newbits, cols * n, rows * n );
  79.  
  80.     exit( 0 );
  81.     }
  82.