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 < prev    next >
C/C++ Source or Header  |  1996-11-18  |  4KB  |  157 lines

  1. /* pbmto10x.c - read a portable bitmap and produce a Gemini 10X printer file
  2. **
  3. ** Copyright (C) 1990, 1994 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. ** Modified to shorten stripes and eliminate blank stripes. Dec 1994.
  13. */
  14.  
  15. #include "pbm.h"
  16.  
  17. #define    LOW_RES_ROWS    8        /* printed per pass */
  18. #define    HIGH_RES_ROWS    16        /* printed per pass */
  19.  
  20. static void res_60x72 ARGS(( void ));
  21. static void res_120x144 ARGS(( void ));
  22.  
  23. static int    highres = 0;
  24. static FILE    *ifp;
  25. static int    rows, cols, format;
  26.  
  27. int
  28. main(argc, argv)
  29.     int    argc;
  30.     char    *argv[];
  31. {
  32.     pbm_init( &argc, argv );
  33.     if (argc > 1 && argv[1][0] == '-' && argv[1][1] == 'h')
  34.     {
  35.         highres = 1;
  36.         --argc;
  37.         ++argv;
  38.     }
  39.     if (argc > 2)
  40.         pm_usage("[pbmfile]");
  41.     if (argc == 2)
  42.         ifp = pm_openr(argv[1]);
  43.     else
  44.         ifp = stdin;
  45.  
  46.     pbm_readpbminit(ifp, &cols, &rows, &format);
  47.     if (highres)
  48.         res_120x144();
  49.     else
  50.         res_60x72();
  51.  
  52.     pm_close(ifp);
  53.     exit(0);
  54. }
  55.  
  56. static void
  57. outstripe(stripe, sP, reschar)
  58.     register char    *stripe, *sP;
  59.     register int    reschar;
  60. {
  61.     register int    ncols;
  62.  
  63.     /* scan backwards, removing empty columns */
  64.     while (sP != stripe)
  65.         if (*--sP != 0)
  66.         {
  67.             ++sP;
  68.             break;
  69.         }
  70.     ncols = sP - stripe;
  71.     if (ncols > 0)
  72.     {
  73.         printf("\033%c%c%c", reschar, ncols % 256, ncols / 256);
  74.         fwrite(stripe, sizeof(char), ncols, stdout);
  75.     }
  76.     putchar('\n');            /* flush buffer */
  77. }
  78.  
  79. static void
  80. res_60x72()
  81. {
  82.     register int    i, item, npins, row, col;
  83.     bit        *bitrows[LOW_RES_ROWS], *bP[LOW_RES_ROWS];
  84.     char        *stripe, *sP;
  85.  
  86.     stripe = malloc(cols);
  87.     for (i = 0; i < LOW_RES_ROWS; ++i)
  88.         bitrows[i] = pbm_allocrow(cols);
  89.     printf("\033A\010");        /* '\n' = 8/72 */
  90.     for (row = 0, sP = stripe; row < rows; row += LOW_RES_ROWS, sP = stripe)
  91.     {
  92.         if (row + LOW_RES_ROWS <= rows)
  93.             npins = LOW_RES_ROWS;
  94.         else
  95.             npins = rows - row;
  96.         for (i = 0; i < npins; ++i)
  97.             pbm_readpbmrow(ifp, bP[i] = bitrows[i], cols, format);
  98.         for (col = 0; col < cols; ++col)
  99.         {
  100.             item = 0;
  101.             for (i = 0; i < npins; ++i)
  102.                 if (*(bP[i]++) == PBM_BLACK)
  103.                     item |= 1 << (7 - i);
  104.             *sP++ = item;
  105.         }
  106.         outstripe(stripe, sP, 'K');
  107.     }
  108.     printf("\033@");
  109.     free(stripe);
  110. }
  111.  
  112. static void
  113. res_120x144()
  114. {
  115.     register int    i, pin, item, npins, row, col;
  116.     bit        *bitrows[HIGH_RES_ROWS], *bP[HIGH_RES_ROWS];
  117.     char        *stripe, *sP;
  118.  
  119.     stripe = malloc(cols);
  120.     for (i = 0; i < HIGH_RES_ROWS; ++i)
  121.         bitrows[i] = pbm_allocrow(cols);
  122.     printf("\0333\001");            /* \n = 1/144" */
  123.     for (row = 0, sP = stripe; row < rows; row += HIGH_RES_ROWS, sP = stripe)
  124.     {
  125.         if (row + HIGH_RES_ROWS <= rows)
  126.             npins = HIGH_RES_ROWS;
  127.         else
  128.             npins = rows - row;
  129.         for (i = 0; i < npins; ++i)
  130.             pbm_readpbmrow(ifp, bP[i] = bitrows[i], cols, format);
  131.         for (col = 0; col < cols; ++col)
  132.         {
  133.             item = 0;
  134.             /* even rows */
  135.             for (pin = i = 0; i < npins; i += 2, ++pin)
  136.                 if (*(bP[i]++) == PBM_BLACK)
  137.                     item |= 1 << (7 - pin);
  138.             *sP++ = item;
  139.         }
  140.         outstripe(stripe, sP, 'L');
  141.         sP = stripe;
  142.         for (col = 0; col < cols; ++col)
  143.         {
  144.             item = 0;
  145.             /* odd rows */
  146.             for (i = 1, pin = 0; i < npins; i += 2, ++pin)
  147.                 if (*(bP[i]++) == PBM_BLACK)
  148.                     item |= 1 << (7 - pin);
  149.             *sP++ = item;
  150.         }
  151.         outstripe(stripe, sP, 'L');
  152.         printf("\033J\016");        /* 14/144 down, \n did 1/144 */
  153.     }
  154.     printf("\033@");
  155.     free(stripe);
  156. }
  157.