home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume2 / pbm / Part4 / pbmenlarge.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-07  |  1.9 KB  |  91 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.     if ( argc > 3 )
  26.     {
  27.     fprintf( stderr, usage, argv[0] );
  28.     exit( 1 );
  29.     }
  30.  
  31.     n = 0;
  32.     ifd = stdin;
  33.  
  34.     for ( argn = 1; argn < argc; argn++ )
  35.     {
  36.     if ( argv[argn][0] == '-' )
  37.         {
  38.         if ( n != 0 )
  39.         {
  40.         fprintf( stderr, usage, argv[0] );
  41.         exit( 1 );
  42.         }
  43.         if ( sscanf( &(argv[argn][1]), "%d", &n ) != 1 )
  44.         {
  45.         fprintf( stderr, usage, argv[0] );
  46.         exit( 1 );
  47.         }
  48.         if ( n < 2 )
  49.         {
  50.         fprintf( stderr, usage, argv[0] );
  51.         exit( 1 );
  52.         }
  53.         }
  54.     else
  55.         {
  56.         if ( ifd != stdin )
  57.         {
  58.         fprintf( stderr, usage, argv[0] );
  59.         exit( 1 );
  60.         }
  61.         ifd = fopen( argv[argn], "r" );
  62.         if ( ifd == NULL )
  63.         {
  64.         fprintf( stderr, "%s: can't open.\n", argv[argn] );
  65.         exit( 1 );
  66.         }
  67.         }
  68.     }
  69.     
  70.     if ( n == 0 )
  71.     n = 2;    /* default to double */
  72.  
  73.     bits = pbm_readpbm( ifd, &cols, &rows );
  74.  
  75.     if ( ifd != stdin )
  76.     fclose( ifd );
  77.  
  78.     newbits = pbm_allocarray( cols * n, rows * n );
  79.  
  80.     for ( row = 0; row < rows; row++ )
  81.         for ( col = 0; col < cols; col++ )
  82.         for ( subrow = 0; subrow < n; subrow++ )
  83.         for ( subcol = 0; subcol < n; subcol++ )
  84.             newbits[row * n + subrow][col * n + subcol] =
  85.             bits[row][col];
  86.  
  87.     pbm_writepbm( stdout, newbits, cols * n, rows * n );
  88.  
  89.     exit( 0 );
  90.     }
  91.