~ubuntu-branches/ubuntu/jaunty/ghostscript/jaunty-updates

« back to all changes in this revision

Viewing changes to base/gdevjpx.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2009-01-20 16:40:45 UTC
  • mfrom: (1.1.10 upstream)
  • Revision ID: james.westby@ubuntu.com-20090120164045-lnfhi0n30o5lwhwa
Tags: 8.64.dfsg.1~svn9377-0ubuntu1
* New upstream release (SVN rev 9377)
   o Fixes many bugs concerning PDF rendering, to make the PDF printing
     workflow correctly working.
   o Fixes long-standing bugs in many drivers, like input paper tray and
     duplex options not working for the built-in PCL 4, 5, 5c, 5e, and
     6/XL drivers, PDF input not working for bjc600, bjc800, and cups
     output devices, several options not working and uninitialized
     memory with cups output device.
   o Merged nearly all patches of the Ubuntu and Debian packages upstream.
   o Fixes LP: #317810, LP: #314439, LP: #314018.
* debian/patches/03_libpaper_support.dpatch,
  debian/patches/11_gs-cjk_font_glyph_handling_fix.dpatch,
  debian/patches/12_gs-cjk_vertical_writing_metrics_fix.dpatch,
  debian/patches/13_gs-cjk_cjkps_examples.dpatch,
  debian/patches/20_bbox_segv_fix.dpatch,
  debian/patches/21_brother_7x0_gdi_fix.dpatch,
  debian/patches/22_epsn_margin_workaround.dpatch,
  debian/patches/24_gs_man_fix.dpatch,
  debian/patches/25_toolbin_insecure_tmp_usage_fix.dpatch,
  debian/patches/26_assorted_script_fixes.dpatch,
  debian/patches/29_gs_css_fix.dpatch,
  debian/patches/30_ps2pdf_man_improvement.dpatch,
  debian/patches/31_fix-gc-sigbus.dpatch,
  debian/patches/34_ftbfs-on-hurd-fix.dpatch,
  debian/patches/35_disable_libcairo.dpatch,
  debian/patches/38_pxl-duplex.dpatch,
  debian/patches/39_pxl-resolution.dpatch,
  debian/patches/42_gs-init-ps-delaybind-fix.dpatch,
  debian/patches/45_bjc600-bjc800-pdf-input.dpatch,
  debian/patches/48_cups-output-device-pdf-duplex-uninitialized-memory-fix.dpatch,
  debian/patches/50_lips4-floating-point-exception.dpatch,
  debian/patches/52_cups-device-logging.dpatch,
  debian/patches/55_pcl-input-slot-fix.dpatch,
  debian/patches/57_pxl-input-slot-fix.dpatch,
  debian/patches/60_pxl-cups-driver-pdf.dpatch,
  debian/patches/62_onebitcmyk-pdf.dpatch,
  debian/patches/65_too-big-temp-files-1.dpatch,
  debian/patches/67_too-big-temp-files-2.dpatch,
  debian/patches/70_take-into-account-data-in-stream-buffer-before-refill.dpatch:
  Removed, applied upstream.
* debian/patches/01_docdir_fix_for_debian.dpatch,
  debian/patches/02_gs_man_fix_debian.dpatch,
  debian/patches/01_docdir-fix-for-debian.dpatch,
  debian/patches/02_docdir-fix-for-debian.dpatch: Renamed patches to
  make merging with Debian easier.
* debian/patches/32_improve-handling-of-media-size-changes-from-gv.dpatch, 
  debian/patches/33_bad-params-to-xinitimage-on-large-bitmaps.dpatch:
  regenerated for new source directory structure.
* debian/rules: Corrected paths to remove cidfmap (it is in Resource/Init/
  in GS 8.64) and to install headers (source paths are psi/ and base/ now).
* debian/rules: Remove all fontmaps, as DeFoMa replaces them.
* debian/local/pdftoraster/pdftoraster.c,
  debian/local/pdftoraster/pdftoraster.convs, debian/rules: Removed
  added pdftoraster filter and use the one which comes with Ghostscript.
* debian/ghostscript.links: s/8.63/8.64/

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (C) 2001-2006 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, 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.
 
12
*/
 
13
 
 
14
/* $Id: gdevjpx.c 6300 2005-12-28 19:56:24Z giles $ */
 
15
/* JPX encode filter test device */
 
16
 
 
17
#include "gdevprn.h"
 
18
#include "stream.h"
 
19
#include "strimpl.h"
 
20
#include "sjpx_luratech.h"
 
21
 
 
22
 
 
23
/* Structure for the JPX-writing device. */
 
24
typedef struct gx_device_jpx_s {
 
25
    gx_device_common;
 
26
    gx_prn_device_common;
 
27
} gx_device_jpx;
 
28
 
 
29
/* The device descriptor */
 
30
static dev_proc_print_page(jpx_print_page);
 
31
 
 
32
/* ------ The device descriptors ------ */
 
33
 
 
34
/* Default X and Y resolution. */
 
35
#ifndef X_DPI
 
36
#  define X_DPI 72
 
37
#endif
 
38
#ifndef Y_DPI
 
39
#  define Y_DPI 72
 
40
#endif
 
41
 
 
42
static dev_proc_print_page(jpx_print_page);
 
43
 
 
44
/* 24 bit RGB default */
 
45
static const gx_device_procs jpxrgb_procs =
 
46
prn_color_procs(gdev_prn_open, gdev_prn_output_page, gdev_prn_close,
 
47
                       gx_default_rgb_map_rgb_color,
 
48
                       gx_default_rgb_map_color_rgb);
 
49
const gx_device_printer gs_jpxrgb_device = {
 
50
    prn_device_std_body(gx_device_jpx, jpxrgb_procs, "jpx",
 
51
        DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
 
52
        X_DPI, Y_DPI,   /* resolution */
 
53
        0, 0, 0, 0,     /* margins */
 
54
        24,             /* bits per pixel */
 
55
        jpx_print_page)
 
56
};
 
57
 
 
58
/* 8 bit Grayscale */
 
59
static const gx_device_procs jpxgray_procs =
 
60
prn_color_procs(gdev_prn_open, gdev_prn_output_page, gdev_prn_close,
 
61
                       gx_default_gray_map_rgb_color,
 
62
                       gx_default_gray_map_color_rgb);
 
63
const gx_device_printer gs_jpxgray_device = {
 
64
    prn_device_body(gx_device_jpx, jpxgray_procs, "jpxgray",
 
65
        DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
 
66
        X_DPI, Y_DPI,   /* resolution */
 
67
        0, 0, 0, 0,     /* margins */
 
68
        1, 8, 255, 0, 256, 0, /* components, depth and min/max values */
 
69
        jpx_print_page)
 
70
};
 
71
 
 
72
/* 32 bit CMKY */
 
73
static dev_proc_map_color_rgb(jpx_cmyk_map_color_rgb);
 
74
static dev_proc_map_cmyk_color(jpx_cmyk_map_cmyk_color);
 
75
static const gx_device_procs jpxcmyk_procs = 
 
76
{       gdev_prn_open,
 
77
        gx_default_get_initial_matrix,
 
78
        NULL,   /* sync_output */
 
79
        gdev_prn_output_page,
 
80
        gdev_prn_close,
 
81
        NULL,
 
82
        jpx_cmyk_map_color_rgb,
 
83
        NULL,   /* fill_rectangle */
 
84
        NULL,   /* tile_rectangle */
 
85
        NULL,   /* copy_mono */
 
86
        NULL,   /* copy_color */
 
87
        NULL,   /* draw_line */
 
88
        NULL,   /* get_bits */
 
89
        gdev_prn_get_params,
 
90
        gdev_prn_put_params,
 
91
        jpx_cmyk_map_cmyk_color,
 
92
        NULL,   /* get_xfont_procs */
 
93
        NULL,   /* get_xfont_device */
 
94
        NULL,   /* map_rgb_alpha_color */
 
95
        gx_page_device_get_page_device  /* get_page_device */
 
96
};
 
97
const gx_device_printer gs_jpxcmyk_device = {
 
98
    prn_device_std_body(gx_device_jpx, jpxcmyk_procs, "jpxcmyk",
 
99
        DEFAULT_WIDTH_10THS, DEFAULT_HEIGHT_10THS,
 
100
        X_DPI, Y_DPI,   /* resolution */
 
101
        0, 0, 0, 0,     /* margins */
 
102
        32,             /* bits per pixel */
 
103
        jpx_print_page)
 
104
};
 
105
 
 
106
/* private color conversion routines; 
 
107
   we don't seem to have defaults for cmyk. */
 
108
static int
 
109
jpx_cmyk_map_color_rgb(gx_device * dev, gx_color_index color,
 
110
                        gx_color_value prgb[3])
 
111
{
 
112
    int not_k = color & 0xff,
 
113
        r = not_k - ~(color >> 24),
 
114
        g = not_k - ~((color >> 16) & 0xff),
 
115
        b = not_k - ~((color >> 8) & 0xff);
 
116
 
 
117
    prgb[0] = (r < 0 ? 0 : gx_color_value_from_byte(r));
 
118
    prgb[1] = (g < 0 ? 0 : gx_color_value_from_byte(g));
 
119
    prgb[2] = (b < 0 ? 0 : gx_color_value_from_byte(b));
 
120
    return 0;
 
121
}
 
122
 
 
123
static gx_color_index
 
124
jpx_cmyk_map_cmyk_color(gx_device * dev, const gx_color_value cv[])
 
125
{
 
126
    gx_color_index color = ~(
 
127
        gx_color_value_to_byte(cv[3]) +
 
128
        ((uint)gx_color_value_to_byte(cv[2]) << 8) +
 
129
        ((uint)gx_color_value_to_byte(cv[1]) << 16) +
 
130
        ((uint)gx_color_value_to_byte(cv[0]) << 24));
 
131
 
 
132
    return (color == gx_no_color_index ? color ^ 1 : color);
 
133
}
 
134
 
 
135
 
 
136
/* Send the page to the file. */
 
137
static int
 
138
jpx_print_page(gx_device_printer * pdev, FILE * prn_stream)
 
139
{
 
140
    gx_device_jpx *jdev = (gx_device_jpx *) pdev;
 
141
    gs_memory_t *mem = jdev->memory;
 
142
    int line_size = gdev_mem_bytes_per_scan_line((gx_device *) pdev);
 
143
    byte *in = gs_alloc_bytes(mem, line_size, "jpx_print_page(in)");
 
144
    byte *fbuf = 0;
 
145
    uint fbuf_size;
 
146
    byte *jbuf = 0;
 
147
    uint jbuf_size;
 
148
    int lnum;
 
149
    int code = 0;
 
150
    stream_jpxe_state state;
 
151
    stream fstrm, cstrm;
 
152
 
 
153
    if (in == 0) {
 
154
        code = gs_note_error(gs_error_VMerror);
 
155
        goto fail;
 
156
    }
 
157
    /* Create the jpx encoder state. */
 
158
    s_init_state((stream_state *)&state, &s_jpxe_template, 0);
 
159
    if (state.template->set_defaults)
 
160
        (*state.template->set_defaults) ((stream_state *) & state);
 
161
    state.width = jdev->width;
 
162
    state.height = jdev->height;
 
163
    switch (jdev->color_info.depth) {
 
164
        case 32: state.colorspace = gs_jpx_cs_cmyk; break;
 
165
        case 24: state.colorspace = gs_jpx_cs_rgb; break;
 
166
        case  8: state.colorspace = gs_jpx_cs_gray; break;
 
167
        default:
 
168
            state.colorspace = gs_jpx_cs_gray; /* safest option */
 
169
            dlprintf1("unexpected color_info depth %d\n",
 
170
                                        jdev->color_info.depth);
 
171
    }
 
172
    state.bpc = 8; /* currently only 8 bits per component is supported */
 
173
 
 
174
    /* ask for lossless encoding */
 
175
    /* state.lossless = 1; */
 
176
    /* or, set the quality level different from the default */
 
177
    /* state.quality = 35; */
 
178
 
 
179
    /* Set up the streams. */
 
180
    fbuf_size = max(512 /* arbitrary */ , state.template->min_out_size);
 
181
    jbuf_size = state.template->min_in_size;
 
182
    if ((fbuf = gs_alloc_bytes(mem, fbuf_size, "jpx_print_page(fbuf)")) == 0 ||
 
183
        (jbuf = gs_alloc_bytes(mem, jbuf_size, "jpx_print_page(jbuf)")) == 0
 
184
        ) {
 
185
        code = gs_note_error(gs_error_VMerror);
 
186
        goto done;
 
187
    }
 
188
    s_init(&fstrm, mem);
 
189
    swrite_file(&fstrm, prn_stream, fbuf, fbuf_size);
 
190
    s_init(&cstrm, mem);
 
191
    s_std_init(&cstrm, jbuf, jbuf_size, &s_filter_write_procs,
 
192
               s_mode_write);
 
193
    cstrm.state = (stream_state *) & state;
 
194
    cstrm.procs.process = state.template->process;
 
195
    cstrm.strm = &fstrm;
 
196
    if (state.template->init)
 
197
        (*state.template->init) (cstrm.state);
 
198
 
 
199
    /* Copy the data to the output. */
 
200
    for (lnum = 0; lnum < jdev->height; ++lnum) {
 
201
        byte *data;
 
202
        uint ignore_used;
 
203
 
 
204
        if (cstrm.end_status) {
 
205
            code = gs_note_error(gs_error_ioerror);
 
206
            goto done;
 
207
        }
 
208
        gdev_prn_get_bits(pdev, lnum, in, &data);
 
209
        sputs(&cstrm, data, state.stride, &ignore_used);
 
210
    }
 
211
 
 
212
    /* Wrap up. */
 
213
    sclose(&cstrm);
 
214
    sflush(&fstrm);
 
215
  done:
 
216
    gs_free_object(mem, jbuf, "jpx_print_page(jbuf)");
 
217
    gs_free_object(mem, fbuf, "jpx_print_page(fbuf)");
 
218
    gs_free_object(mem, in, "jpx_print_page(in)");
 
219
    return code;
 
220
  fail:
 
221
    gs_free_object(mem, in, "jpx_print_page(in)");
 
222
    return code;
 
223
}