/src/libspectre/ghostscript/devices/gdevcif.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright (C) 2001-2020 Artifex Software, Inc. |
2 | | All Rights Reserved. |
3 | | |
4 | | This software is provided AS-IS with no warranty, either express or |
5 | | implied. |
6 | | |
7 | | This software is distributed under license and may not be copied, |
8 | | modified or distributed except as expressly authorized under the terms |
9 | | of the license contained in the file LICENSE in this distribution. |
10 | | |
11 | | Refer to licensing information at http://www.artifex.com or contact |
12 | | Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato, |
13 | | CA 94945, U.S.A., +1(415)492-9861, for further information. |
14 | | */ |
15 | | |
16 | | /* |
17 | | CIF output driver |
18 | | |
19 | | The `Fake bitmapped device to estimate rendering time' |
20 | | slightly modified to produce CIF files from PostScript. |
21 | | So anyone can put a nice logo free on its chip! |
22 | | Frederic Petrot, petrot@masi.ibp.fr */ |
23 | | |
24 | | #include "gdevprn.h" |
25 | | |
26 | | /* Define the device parameters. */ |
27 | | #ifndef X_DPI |
28 | | # define X_DPI 72 |
29 | | #endif |
30 | | #ifndef Y_DPI |
31 | | # define Y_DPI 72 |
32 | | #endif |
33 | | |
34 | | /* The device descriptor */ |
35 | | static dev_proc_print_page(cif_print_page); |
36 | | const gx_device_printer far_data gs_cif_device = |
37 | | prn_device(prn_bg_procs, "cif", /* The print_page proc is compatible with allowing bg printing */ |
38 | | DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS, |
39 | | X_DPI, Y_DPI, |
40 | | 0,0,0,0, |
41 | | 1, cif_print_page); |
42 | | |
43 | | /* Send the page to the output. */ |
44 | | static int |
45 | | cif_print_page(gx_device_printer *pdev, gp_file *prn_stream) |
46 | 0 | { int line_size = gdev_mem_bytes_per_scan_line((gx_device *)pdev); |
47 | 0 | int lnum; |
48 | 0 | byte *in = (byte *)gs_malloc(pdev->memory, line_size, 1, "cif_print_page(in)"); |
49 | 0 | char *s; |
50 | 0 | const char *fname; |
51 | 0 | int scanline, scanbyte; |
52 | 0 | int length, start; /* length is the number of successive 1 bits, */ |
53 | | /* start is the set of 1 bit start position */ |
54 | 0 | int code = 0; |
55 | |
|
56 | 0 | if (in == 0) |
57 | 0 | return_error(gs_error_VMerror); |
58 | | |
59 | | #ifdef CLUSTER |
60 | | fname = "clusterout"; |
61 | | #else |
62 | 0 | fname = (const char *)(pdev->fname); |
63 | 0 | #endif |
64 | 0 | if ((s = strchr(fname, '.')) == NULL) |
65 | 0 | length = strlen(fname) + 1; |
66 | 0 | else |
67 | 0 | length = s - fname; |
68 | 0 | s = (char *)gs_malloc(pdev->memory, length+1, sizeof(char), "cif_print_page(s)"); |
69 | 0 | if (s == NULL) |
70 | 0 | return_error(gs_error_VMerror); |
71 | 0 | strncpy(s, fname, length); |
72 | 0 | *(s + length) = '\0'; |
73 | 0 | gp_fprintf(prn_stream, "DS1 25 1;\n9 %s;\nLCP;\n", s); |
74 | 0 | gs_free(pdev->memory, s, length+1, 1, "cif_print_page(s)"); |
75 | |
|
76 | 0 | for (lnum = 0; lnum < pdev->height; lnum++) { |
77 | 0 | code = gdev_prn_copy_scan_lines(pdev, lnum, in, line_size); |
78 | 0 | if (code < 0) |
79 | 0 | goto xit; |
80 | 0 | length = 0; |
81 | 0 | for (scanline = 0; scanline < line_size; scanline++) |
82 | | #ifdef TILE /* original, simple, inefficient algorithm */ |
83 | | for (scanbyte = 0; scanbyte < 8; scanbyte++) |
84 | | if (((in[scanline] >> scanbyte) & 1) != 0) |
85 | | gp_fprintf(prn_stream, "B4 4 %d %d;\n", |
86 | | (scanline * 8 + (7 - scanbyte)) * 4, |
87 | | (pdev->height - lnum) * 4); |
88 | | #else /* better algorithm */ |
89 | 0 | for (scanbyte = 7; scanbyte >= 0; scanbyte--) |
90 | | /* cheap linear reduction of rectangles in lines */ |
91 | 0 | if (((in[scanline] >> scanbyte) & 1) != 0) { |
92 | 0 | if (length == 0) |
93 | 0 | start = (scanline * 8 + (7 - scanbyte)); |
94 | 0 | length++; |
95 | 0 | } else { |
96 | 0 | if (length != 0) |
97 | 0 | gp_fprintf(prn_stream, "B%d 4 %d %d;\n", length * 4, |
98 | 0 | start * 4 + length * 2, |
99 | 0 | (pdev->height - lnum) * 4); |
100 | 0 | length = 0; |
101 | 0 | } |
102 | 0 | #endif |
103 | 0 | } |
104 | 0 | gp_fprintf(prn_stream, "DF;\nC1;\nE\n"); |
105 | 0 | xit: |
106 | 0 | gs_free(pdev->memory, in, line_size, 1, "cif_print_page(in)"); |
107 | 0 | return code; |
108 | 0 | } |