home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / NETWORK / netpbm_src.lzh / NETPBM / PBM / pbmto10x.c.orig < prev    next >
Text File  |  1996-11-18  |  3KB  |  127 lines

  1. /* pbmto10x.c - read a portable bitmap and produce a Gemini 10X printer file
  2. **
  3. ** Copyright (C) 1990 by Ken Yap
  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 "pbm.h"
  14.  
  15. #define    LOW_RES_ROWS    8        /* printed per pass */
  16. #define    HIGH_RES_ROWS    16        /* printed per pass */
  17.  
  18. static void res_60x72 ARGS(( void ));
  19. static void res_120x144 ARGS(( void ));
  20.  
  21. static int    highres = 0;
  22. static FILE    *ifp;
  23. static int    rows, cols, format;
  24.  
  25. int
  26. main(argc, argv)
  27.     int    argc;
  28.     char    *argv[];
  29. {
  30.     pbm_init( &argc, argv );
  31.     if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'h')
  32.     {
  33.         highres = 1;
  34.         --argc;
  35.         ++argv;
  36.     }
  37.     if (argc > 2)
  38.         pm_usage("[pbmfile]");
  39.     if (argc == 2)
  40.         ifp = pm_openr(argv[1]);
  41.     else
  42.         ifp = stdin;
  43.  
  44.     pbm_readpbminit(ifp, &cols, &rows, &format);
  45.     if (highres)
  46.         res_120x144();
  47.     else
  48.         res_60x72();
  49.  
  50.     pm_close(ifp);
  51.     exit(0);
  52. }
  53.  
  54. static void
  55. res_60x72()
  56. {
  57.     register int    i, item, npins, row, col;
  58.     bit        *bitrows[LOW_RES_ROWS], *bP[LOW_RES_ROWS];
  59.  
  60.     for (i = 0; i < LOW_RES_ROWS; ++i)
  61.         bitrows[i] = pbm_allocrow(cols);
  62.     printf("\033A\010");        /* '\n' = 8/72 */
  63.     for (row = 0; row < rows; row += LOW_RES_ROWS)
  64.     {
  65.         if (row + LOW_RES_ROWS <= rows)
  66.             npins = LOW_RES_ROWS;
  67.         else
  68.             npins = rows - row;
  69.         for (i = 0; i < npins; ++i)
  70.             pbm_readpbmrow(ifp, bP[i] = bitrows[i], cols, format);
  71.         printf("\033K%c%c", cols % 256, cols / 256);
  72.         for (col = 0; col < cols; ++col)
  73.         {
  74.             item = 0;
  75.             for (i = 0; i < npins; ++i)
  76.                 if (*(bP[i]++) == PBM_BLACK)
  77.                     item |= 1 << (7 - i);
  78.             putchar(item);
  79.         }
  80.         putchar('\n');
  81.     }
  82. }
  83.  
  84. static void
  85. res_120x144()
  86. {
  87.     register int    i, pin, item, npins, row, col;
  88.     bit        *bitrows[HIGH_RES_ROWS], *bP[HIGH_RES_ROWS];
  89.  
  90.     for (i = 0; i < HIGH_RES_ROWS; ++i)
  91.         bitrows[i] = pbm_allocrow(cols);
  92.     putchar('\033'); putchar('3'); putchar('\0');
  93.     for (row = 0; row < rows; row += HIGH_RES_ROWS)
  94.     {
  95.         if (row + HIGH_RES_ROWS <= rows)
  96.             npins = HIGH_RES_ROWS;
  97.         else
  98.             npins = rows - row;
  99.         for (i = 0; i < npins; ++i)
  100.             pbm_readpbmrow(ifp, bP[i] = bitrows[i], cols, format);
  101.         printf("\033L%c%c", cols % 256, cols / 256);
  102.         for (col = 0; col < cols; ++col)
  103.         {
  104.             item = 0;
  105.             /* even rows */
  106.             for (pin = i = 0; i < npins; i += 2, ++pin)
  107.                 if (*(bP[i]++) == PBM_BLACK)
  108.                     item |= 1 << (7 - pin);
  109.             putchar(item);
  110.         }
  111.         putchar('\n');            /* flush buffer */
  112.         printf("\033J\001");        /* 1/144 down */
  113.         printf("\033L%c%c", cols % 256, cols / 256);
  114.         for (col = 0; col < cols; ++col)
  115.         {
  116.             item = 0;
  117.             /* odd rows */
  118.             for (i = 1, pin = 0; i < npins; i += 2, ++pin)
  119.                 if (*(bP[i]++) == PBM_BLACK)
  120.                     item |= 1 << (7 - pin);
  121.             putchar(item);
  122.         }
  123.         putchar('\n');            /* flush buffer */
  124.         printf("\033J\017");        /* 15/144 down */
  125.     }
  126. }
  127.