1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
4
This software is provided AS-IS with no warranty, either express or
7
This software is distributed under license and may not be copied, modified
8
or distributed except as expressly authorized under the terms of that
9
license. Refer to licensing information at http://www.artifex.com/
10
or contact Artifex Software, Inc., 7 Mt. Lassen Drive - Suite A-134,
11
San Rafael, CA 94903, U.S.A., +1(415)492-9861, for further information.
14
/* $Id: gdevjbig2.c 6300 2005-12-28 19:56:24Z giles $ */
15
/* JBIG2 encode filter test device */
20
#include "sjbig2_luratech.h"
23
/* Structure for the JBIG2-writing device. */
24
typedef struct gx_device_jbig2_s {
29
/* The device descriptor */
30
static dev_proc_print_page(jbig2_print_page);
32
/* ------ The device descriptors ------ */
34
/* Default X and Y resolution. */
42
static dev_proc_print_page(jbig2_print_page);
46
const gx_device_printer gs_gdevjbig2_device =
47
prn_device(prn_std_procs, "jbig2",
48
DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
49
X_DPI, Y_DPI, /* resolution */
50
0, 0, 0, 0, /* margins */
54
/* Send the page to the file. */
56
jbig2_print_page(gx_device_printer * pdev, FILE * prn_stream)
58
gx_device_jbig2 *jdev = (gx_device_jbig2 *) pdev;
59
gs_memory_t *mem = jdev->memory;
60
int line_size = gdev_mem_bytes_per_scan_line((gx_device *) pdev);
61
byte *in = gs_alloc_bytes(mem, line_size, "jbig2_print_page(in)");
68
stream_jbig2encode_state state;
72
code = gs_note_error(gs_error_VMerror);
75
/* Create the jbig2encode state. */
76
s_init_state((stream_state *)&state, &s_jbig2encode_template, 0);
77
if (state.template->set_defaults)
78
(*state.template->set_defaults) ((stream_state *) & state);
79
state.width = jdev->width;
80
state.height = jdev->height;
81
/* Set up the streams. */
82
fbuf_size = max(512 /* arbitrary */ , state.template->min_out_size);
83
jbuf_size = state.template->min_in_size;
84
if ((fbuf = gs_alloc_bytes(mem, fbuf_size, "jbig2_print_page(fbuf)")) == 0 ||
85
(jbuf = gs_alloc_bytes(mem, jbuf_size, "jbig2_print_page(jbuf)")) == 0
87
code = gs_note_error(gs_error_VMerror);
91
swrite_file(&fstrm, prn_stream, fbuf, fbuf_size);
93
s_std_init(&cstrm, jbuf, jbuf_size, &s_filter_write_procs,
95
cstrm.state = (stream_state *) & state;
96
cstrm.procs.process = state.template->process;
98
if (state.template->init)
99
(*state.template->init) (cstrm.state);
101
/* Copy the data to the output. */
102
for (lnum = 0; lnum < jdev->height; ++lnum) {
106
if (cstrm.end_status) {
107
code = gs_note_error(gs_error_ioerror);
110
gdev_prn_get_bits(pdev, lnum, in, &data);
111
sputs(&cstrm, data, state.stride, &ignore_used);
118
gs_free_object(mem, jbuf, "jbig2_print_page(jbuf)");
119
gs_free_object(mem, fbuf, "jbig2_print_page(fbuf)");
120
gs_free_object(mem, in, "jbig2_print_page(in)");
123
gs_free_object(mem, in, "jbig2_print_page(in)");