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

« back to all changes in this revision

Viewing changes to base/sjpegc.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: sjpegc.c 8250 2007-09-25 13:31:24Z giles $ */
 
15
/* Interface routines for IJG code, common to encode/decode. */
 
16
#include "stdio_.h"
 
17
#include "string_.h"
 
18
#include "jpeglib_.h"
 
19
#include "jerror_.h"
 
20
#include "gx.h"
 
21
#include "gserrors.h"
 
22
#include "strimpl.h"
 
23
#include "sdct.h"
 
24
#include "sjpeg.h"
 
25
 
 
26
/*
 
27
  Ghostscript uses a non-public interface to libjpeg in order to
 
28
  override the library's default memory manager implementation.
 
29
  Since many users will want to compile Ghostscript using the
 
30
  shared jpeg library, we provide these prototypes so that a copy
 
31
  of the libjpeg source distribution is not needed.
 
32
 
 
33
  The presence of the jmemsys.h header file is detected in
 
34
  unix-aux.mak, and written to gconfig_.h
 
35
 */
 
36
 
 
37
#include "gconfig_.h"
 
38
#ifdef DONT_HAVE_JMEMSYS_H
 
39
 
 
40
void *
 
41
jpeg_get_small(j_common_ptr cinfo, size_t size);
 
42
 
 
43
void
 
44
jpeg_free_small(j_common_ptr cinfo, void *object, size_t size);
 
45
 
 
46
void FAR *
 
47
jpeg_get_large(j_common_ptr cinfo, size_t size);
 
48
 
 
49
void
 
50
jpeg_free_large(j_common_ptr cinfo, void FAR * object, size_t size);
 
51
typedef void *backing_store_ptr;
 
52
 
 
53
long
 
54
jpeg_mem_available(j_common_ptr cinfo, long min_bytes_needed,
 
55
                   long max_bytes_needed, long already_allocated);
 
56
 
 
57
void
 
58
jpeg_open_backing_store(j_common_ptr cinfo, backing_store_ptr info,
 
59
                        long total_bytes_needed);
 
60
 
 
61
long
 
62
jpeg_mem_init(j_common_ptr cinfo);
 
63
 
 
64
void
 
65
jpeg_mem_term(j_common_ptr cinfo);
 
66
 
 
67
#else
 
68
#include "jmemsys.h"            /* for prototypes */
 
69
#endif
 
70
 
 
71
private_st_jpeg_block();
 
72
 
 
73
/*
 
74
 * Error handling routines (these replace corresponding IJG routines from
 
75
 * jpeg/jerror.c).  These are used for both compression and decompression.
 
76
 * We assume
 
77
 * offset_of(jpeg_compress_data, cinfo)==offset_of(jpeg_decompress_data, dinfo)
 
78
 */
 
79
 
 
80
static void
 
81
gs_jpeg_error_exit(j_common_ptr cinfo)
 
82
{
 
83
    jpeg_stream_data *jcomdp =
 
84
    (jpeg_stream_data *) ((char *)cinfo -
 
85
                          offset_of(jpeg_compress_data, cinfo));
 
86
 
 
87
    longjmp(find_jmp_buf(jcomdp->exit_jmpbuf), 1);
 
88
}
 
89
 
 
90
static void
 
91
gs_jpeg_emit_message(j_common_ptr cinfo, int msg_level)
 
92
{
 
93
    if (msg_level < 0) {        /* GS policy is to ignore IJG warnings when Picky=0,
 
94
                                 * treat them as errors when Picky=1.
 
95
                                 */
 
96
        jpeg_stream_data *jcomdp =
 
97
        (jpeg_stream_data *) ((char *)cinfo -
 
98
                              offset_of(jpeg_compress_data, cinfo));
 
99
 
 
100
        if (jcomdp->Picky)
 
101
            gs_jpeg_error_exit(cinfo);
 
102
    }
 
103
    /* Trace messages are always ignored. */
 
104
}
 
105
 
 
106
/*
 
107
 * This routine initializes the error manager fields in the JPEG object.
 
108
 * It is based on jpeg_std_error from jpeg/jerror.c.
 
109
 */
 
110
 
 
111
void
 
112
gs_jpeg_error_setup(stream_DCT_state * st)
 
113
{
 
114
    struct jpeg_error_mgr *err = &st->data.common->err;
 
115
 
 
116
    /* Initialize the JPEG compression object with default error handling */
 
117
    jpeg_std_error(err);
 
118
 
 
119
    /* Replace some methods with our own versions */
 
120
    err->error_exit = gs_jpeg_error_exit;
 
121
    err->emit_message = gs_jpeg_emit_message;
 
122
 
 
123
    st->data.compress->cinfo.err = err;         /* works for decompress case too */
 
124
}
 
125
 
 
126
/* Stuff the IJG error message into errorinfo after an error exit. */
 
127
 
 
128
int
 
129
gs_jpeg_log_error(stream_DCT_state * st)
 
130
{
 
131
    j_common_ptr cinfo = (j_common_ptr) & st->data.compress->cinfo;
 
132
    char buffer[JMSG_LENGTH_MAX];
 
133
 
 
134
    /* Format the error message */
 
135
    (*cinfo->err->format_message) (cinfo, buffer);
 
136
    (*st->report_error) ((stream_state *) st, buffer);
 
137
    return gs_error_ioerror;    /* caller will do return_error() */
 
138
}
 
139
 
 
140
 
 
141
/*
 
142
 * Interface routines.  This layer of routines exists solely to limit
 
143
 * side-effects from using setjmp.
 
144
 */
 
145
 
 
146
 
 
147
JQUANT_TBL *
 
148
gs_jpeg_alloc_quant_table(stream_DCT_state * st)
 
149
{
 
150
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) {
 
151
        gs_jpeg_log_error(st);
 
152
        return NULL;
 
153
    }
 
154
    return jpeg_alloc_quant_table((j_common_ptr)
 
155
                                  & st->data.compress->cinfo);
 
156
}
 
157
 
 
158
JHUFF_TBL *
 
159
gs_jpeg_alloc_huff_table(stream_DCT_state * st)
 
160
{
 
161
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf))) {
 
162
        gs_jpeg_log_error(st);
 
163
        return NULL;
 
164
    }
 
165
    return jpeg_alloc_huff_table((j_common_ptr)
 
166
                                 & st->data.compress->cinfo);
 
167
}
 
168
 
 
169
int
 
170
gs_jpeg_destroy(stream_DCT_state * st)
 
171
{
 
172
    if (setjmp(find_jmp_buf(st->data.common->exit_jmpbuf)))
 
173
        return_error(gs_jpeg_log_error(st));
 
174
    jpeg_destroy((j_common_ptr) & st->data.compress->cinfo);
 
175
    return 0;
 
176
}
 
177
 
 
178
 
 
179
/*
 
180
 * These routines replace the low-level memory manager of the IJG library.
 
181
 * They pass malloc/free calls to the Ghostscript memory manager.
 
182
 * Note we do not need these to be declared in any GS header file.
 
183
 */
 
184
 
 
185
static inline jpeg_compress_data *
 
186
cinfo2jcd(j_common_ptr cinfo)
 
187
{   /* We use the offset of cinfo in jpeg_compress data here, but we */
 
188
    /* could equally well have used jpeg_decompress_data.            */
 
189
    return (jpeg_compress_data *)
 
190
      ((byte *)cinfo - offset_of(jpeg_compress_data, cinfo));
 
191
}
 
192
 
 
193
static void *
 
194
jpeg_alloc(j_common_ptr cinfo, size_t size, const char *info)
 
195
{
 
196
    jpeg_compress_data *jcd = cinfo2jcd(cinfo);
 
197
    gs_memory_t *mem = jcd->memory;
 
198
    
 
199
    jpeg_block_t *p = gs_alloc_struct_immovable(mem, jpeg_block_t,
 
200
                        &st_jpeg_block, "jpeg_alloc(block)");
 
201
    void *data = gs_alloc_bytes_immovable(mem, size, info);
 
202
 
 
203
    if (p == 0 || data == 0) {
 
204
        gs_free_object(mem, data, info);
 
205
        gs_free_object(mem, p, "jpeg_alloc(block)");
 
206
        return 0;
 
207
    }
 
208
    p->data = data;
 
209
    p->next = jcd->blocks;
 
210
    jcd->blocks = p;
 
211
    return data;
 
212
}
 
213
 
 
214
static void
 
215
jpeg_free(j_common_ptr cinfo, void *data, const char *info)
 
216
{
 
217
    jpeg_compress_data *jcd = cinfo2jcd(cinfo);
 
218
    gs_memory_t *mem = jcd->memory;
 
219
    jpeg_block_t  *p  =  jcd->blocks;
 
220
    jpeg_block_t **pp = &jcd->blocks;
 
221
 
 
222
    gs_free_object(mem, data, info);
 
223
    while(p && p->data != data)
 
224
      { pp = &p->next;
 
225
        p = p->next;
 
226
      }
 
227
    if(p == 0)
 
228
      lprintf1("Freeing unrecorded JPEG data 0x%lx!\n", (ulong)data);
 
229
    else
 
230
      *pp = p->next;
 
231
    gs_free_object(mem, p, "jpeg_free(block)");
 
232
}
 
233
 
 
234
void *
 
235
jpeg_get_small(j_common_ptr cinfo, size_t size)
 
236
{
 
237
    return jpeg_alloc(cinfo, size, "JPEG small internal data allocation");
 
238
}
 
239
 
 
240
void
 
241
jpeg_free_small(j_common_ptr cinfo, void *object, size_t size)
 
242
{
 
243
    jpeg_free(cinfo, object, "Freeing JPEG small internal data");
 
244
}
 
245
 
 
246
void FAR *
 
247
jpeg_get_large(j_common_ptr cinfo, size_t size)
 
248
{
 
249
    return jpeg_alloc(cinfo, size, "JPEG large internal data allocation");
 
250
}
 
251
 
 
252
void
 
253
jpeg_free_large(j_common_ptr cinfo, void FAR * object, size_t size)
 
254
{
 
255
    jpeg_free(cinfo, object, "Freeing JPEG large internal data");
 
256
}
 
257
 
 
258
long
 
259
jpeg_mem_available(j_common_ptr cinfo, long min_bytes_needed,
 
260
                   long max_bytes_needed, long already_allocated)
 
261
{
 
262
    return max_bytes_needed;
 
263
}
 
264
 
 
265
void
 
266
jpeg_open_backing_store(j_common_ptr cinfo, backing_store_ptr info,
 
267
                        long total_bytes_needed)
 
268
{
 
269
    ERREXIT(cinfo, JERR_NO_BACKING_STORE);
 
270
}
 
271
 
 
272
long
 
273
jpeg_mem_init(j_common_ptr cinfo)
 
274
{
 
275
    return 0;                   /* just set max_memory_to_use to 0 */
 
276
}
 
277
 
 
278
void
 
279
jpeg_mem_term(j_common_ptr cinfo)
 
280
{
 
281
    /* no work */
 
282
}