home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1996 February / PCWK0296.iso / sharewar / dos / program / gs300sr1 / gs300sr1.exe / GDEVCIF.C < prev    next >
C/C++ Source or Header  |  1994-07-27  |  4KB  |  99 lines

  1. /* Copyright (C) 1993 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of Aladdin Ghostscript.
  4.   
  5.   Aladdin Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author
  6.   or distributor accepts any responsibility for the consequences of using it,
  7.   or for whether it serves any particular purpose or works at all, unless he
  8.   or she says so in writing.  Refer to the Aladdin Ghostscript Free Public
  9.   License (the "License") for full details.
  10.   
  11.   Every copy of Aladdin Ghostscript must include a copy of the License,
  12.   normally in a plain ASCII text file named PUBLIC.  The License grants you
  13.   the right to copy, modify and redistribute Aladdin Ghostscript, but only
  14.   under certain conditions described in the License.  Among other things, the
  15.   License requires that the copyright notice and this notice be preserved on
  16.   all copies.
  17. */
  18.  
  19. /* gdevcif.c */
  20. /* The `Fake bitmapped device to estimate rendering time' 
  21.    slightly modified to produce CIF files from PostScript.
  22.    So anyone can put a nice logo free on its chip!
  23.    Frederic Petrot, petrot@masi.ibp.fr */
  24.  
  25. #include "gdevprn.h"
  26.  
  27. /* Define the device parameters. */
  28. #ifndef X_DPI
  29. #  define X_DPI 72
  30. #endif
  31. #ifndef Y_DPI
  32. #  define Y_DPI 72
  33. #endif
  34.  
  35. /* The device descriptor */
  36. private dev_proc_print_page(cif_print_page);
  37. gx_device_printer far_data gs_cif_device =
  38.   prn_device(prn_std_procs, "cif",
  39.     DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
  40.     X_DPI, Y_DPI,
  41.     0,0,0,0,
  42.     1, cif_print_page);
  43.  
  44. /* Send the page to the output. */
  45. private int
  46. cif_print_page(gx_device_printer *pdev, FILE *prn_stream)
  47. {    int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev);
  48.     int lnum;
  49.     byte *in = (byte *)gs_malloc(line_size, 1, "cif_print_page(in)");
  50.     char *s;
  51.     int scanline, scanbyte;
  52.     int length, start; /* length is the number of successive 1 bits, */
  53.                /* start is the set of 1 bit start position */
  54.  
  55.     if (in == 0)
  56.         return_error(gs_error_VMerror);
  57.  
  58.     if ((s = strchr(pdev->fname, '.')) == NULL)
  59.         length = strlen(pdev->fname) + 1;
  60.     else
  61.         length = s - pdev->fname;
  62.     s = (char *)gs_malloc(length, sizeof(char), "cif_print_page(s)");
  63.  
  64.     strncpy(s, pdev->fname, length);
  65.     *(s + length) = '\0';
  66.     fprintf(prn_stream, "DS1 25 1;\n9 %s;\nLCP;\n", s);
  67.     gs_free(s, length, 1, "cif_print_page(s)");
  68.  
  69.    for (lnum = 0; lnum < pdev->height; lnum++) {   
  70.       gdev_prn_copy_scan_lines(pdev, lnum, in, line_size);
  71.       length = 0;
  72.       for (scanline = 0; scanline < line_size; scanline++)
  73. #ifdef TILE            /* original, simple, inefficient algorithm */
  74.          for (scanbyte = 0; scanbyte < 8; scanbyte++)
  75.             if (((in[scanline] >> scanbyte) & 1) != 0)
  76.                fprintf(prn_stream, "B4 4 %d %d;\n",
  77.                   (scanline * 8 + (7 - scanbyte)) * 4,
  78.                   (pdev->height - lnum) * 4);
  79. #else                /* better algorithm */
  80.          for (scanbyte = 7; scanbyte >= 0; scanbyte--)
  81.             /* cheap linear reduction of rectangles in lines */
  82.             if (((in[scanline] >> scanbyte) & 1) != 0) {
  83.                if (length == 0)
  84.                   start = (scanline * 8 + (7 - scanbyte));
  85.                length++;
  86.             } else {
  87.                if (length != 0)
  88.                   fprintf(prn_stream, "B%d 4 %d %d;\n", length * 4,
  89.                            start * 4 + length * 2,
  90.                            (pdev->height - lnum) * 4);
  91.                length = 0;
  92.             }
  93. #endif
  94.    }
  95.     fprintf(prn_stream, "DF;\nC1;\nE\n");
  96.     gs_free(in, line_size, 1, "cif_print_page(in)");
  97.     return 0;
  98. }
  99.