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

  1. /* pbmtoplot.c - read a portable bitmap and produce a UNIX-format plot file.
  2. **
  3. ** Copyright (C) 1990 by Arthur David Olson.
  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. static void puttwo ARGS((int i));
  17. static void
  18. puttwo( i )
  19.     int i;
  20.     {
  21.     (void) putchar(i);
  22.     (void) putchar(i >> 8);
  23.     }
  24.  
  25. int
  26. main( argc, argv )
  27.     int argc;
  28.     char* argv[];
  29.     {
  30.     FILE* ifp;
  31.     register bit** bits;
  32.     register int row, col, scol;
  33.     int    rows, cols;
  34.  
  35.  
  36.     pbm_init( &argc, argv );
  37.  
  38.     if ( argc > 2 )
  39.     pm_usage( "[pbmfile]" );
  40.  
  41.     ifp = (argc == 2) ? pm_openr( argv[1] ) : stdin;
  42.  
  43.     bits = pbm_readpbm( ifp, &cols, &rows );
  44.  
  45.     pm_close( ifp );
  46.  
  47.     (void) putchar( 's' );
  48.     puttwo( 0 );
  49.     puttwo( 0 );
  50.     puttwo( rows - 1 );
  51.     puttwo( cols - 1 );
  52.     for ( row = 0; row < rows; ++row )
  53.     {
  54.     for ( col = 0; col < cols; ++col )
  55.         {
  56.         if ( bits[row][col] == PBM_WHITE )
  57.         continue;
  58.         scol = col;
  59.         while ( ++col < cols && bits[row][col] == PBM_BLACK )
  60.         ; /* nothing */
  61.         --col;
  62.         if ( col == scol )
  63.         (void) putchar( 'p' );
  64.         else
  65.         {
  66.         (void) putchar( 'l' );
  67.         puttwo( scol );
  68.         puttwo( rows - 1 - row );
  69.         }
  70.         puttwo( col );
  71.         puttwo( rows - 1 - row );
  72.         }
  73.     }
  74.  
  75.     exit( 0 );
  76.     }
  77.