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

« back to all changes in this revision

Viewing changes to base/sa85d.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: sa85d.c 8250 2007-09-25 13:31:24Z giles $ */
 
15
/* ASCII85Decode filter */
 
16
#include "std.h"
 
17
#include "strimpl.h"
 
18
#include "sa85d.h"
 
19
#include "scanchar.h"
 
20
 
 
21
/* ------ ASCII85Decode ------ */
 
22
 
 
23
private_st_A85D_state();
 
24
 
 
25
/* Initialize the state */
 
26
static int
 
27
s_A85D_init(stream_state * st)
 
28
{
 
29
    stream_A85D_state *const ss = (stream_A85D_state *) st;
 
30
 
 
31
    return s_A85D_init_inline(ss);
 
32
}
 
33
 
 
34
/* Process a buffer */
 
35
static int a85d_finish(int, ulong, stream_cursor_write *);
 
36
static int
 
37
s_A85D_process(stream_state * st, stream_cursor_read * pr,
 
38
               stream_cursor_write * pw, bool last)
 
39
{
 
40
    stream_A85D_state *const ss = (stream_A85D_state *) st;
 
41
    register const byte *p = pr->ptr;
 
42
    register byte *q = pw->ptr;
 
43
    /* stop processing early unless the target is empty (last == true)  */
 
44
    /* to make sure we consume the EOD marker correctly. The EOD marker */
 
45
    /* might be as many as 6 characters after the last valid data char  */
 
46
    /* D <cr> <lf> '~' <cr> <lf> '>' where 'D' is a data character.     */
 
47
    const byte *rlimit = pr->limit - (last ? 0 : 7); /* max EOD len + 1 */
 
48
    const byte *r = max(p, rlimit);
 
49
    byte *wlimit = pw->limit;
 
50
    int ccount = ss->odd;
 
51
    ulong word = ss->word;
 
52
    int status = 0;
 
53
 
 
54
    /* scan to make sure that an EOD isn't fully contained in the */
 
55
    /* last part of the buffer (between rlimit and pr->limit).    */
 
56
    while (r < pr->limit) {
 
57
        if (*++r == '~') 
 
58
            while (r < pr->limit)
 
59
                if (*++r == '>') {
 
60
                    /* we have both characters of a complete EOD. */
 
61
                    rlimit = pr->limit; /* go ahead and process everything */
 
62
                    r = rlimit;         /* break out of the while loops */
 
63
                    break;
 
64
                }
 
65
    }
 
66
    while (p < rlimit) {
 
67
        int ch = *++p;
 
68
        uint ccode = ch - '!';
 
69
 
 
70
        if (ccode < 85) {       /* catches ch < '!' as well */
 
71
            if (ccount == 4) {
 
72
                /*
 
73
                 * We've completed a 32-bit group.  Make sure we have
 
74
                 * room for it in the output.
 
75
                 */
 
76
                if (wlimit - q < 4) {
 
77
                    p--;
 
78
                    status = 1;
 
79
                    break;
 
80
                }
 
81
                /* Check for overflow condition, throw ioerror if so */
 
82
                if (word >= 0x03030303 && ccode > 0) {
 
83
                    status = ERRC;
 
84
                    break;
 
85
                }
 
86
                word = word * 85 + ccode;
 
87
                q[1] = (byte) (word >> 24);
 
88
                q[2] = (byte) (word >> 16);
 
89
                q[3] = (byte) ((uint) word >> 8);
 
90
                q[4] = (byte) word;
 
91
                q += 4;
 
92
                word = 0;
 
93
                ccount = 0;
 
94
            } else {
 
95
                word = word * 85 + ccode;
 
96
                ++ccount;
 
97
            }
 
98
        } else if (ch == 'z' && ccount == 0) {
 
99
            if (wlimit - q < 4) {
 
100
                p--;
 
101
                status = 1;
 
102
                break;
 
103
            }
 
104
            q[1] = q[2] = q[3] = q[4] = 0,
 
105
                q += 4;
 
106
        } else if (scan_char_decoder[ch] == ctype_space)
 
107
            DO_NOTHING;
 
108
        else if (ch == '~') {
 
109
            int i = 1;
 
110
 
 
111
            rlimit = pr->limit;         /* Here we use the real "limit" */
 
112
            /* Handle odd bytes. */
 
113
            if (p == rlimit) {
 
114
                if (last)
 
115
                    status = ERRC;
 
116
                else
 
117
                    p--;
 
118
                break;
 
119
            }
 
120
            if ((int)(wlimit - q) < ccount - 1) {
 
121
                status = 1;
 
122
                p--;
 
123
                break;
 
124
            }
 
125
 
 
126
            /* According to PLRM 3rd, if the A85 filter encounters '~',
 
127
             * the next character must be '>'.
 
128
             * And any other characters should raise an ioerror.
 
129
             * But Adobe Acrobat allows CR/LF between ~ and >.
 
130
             * So we allow CR/LF between them. */
 
131
            while ((p[i] == 13 || p[i] == 10) && (p+i <= rlimit)) 
 
132
                i++;
 
133
            if (p[i] != '>') {
 
134
                if (p+i == rlimit) {
 
135
                    if (last)
 
136
                        status = ERRC;
 
137
                    else
 
138
                        p--;    /* we'll see the '~' after filling the buffer */
 
139
                }
 
140
                break;
 
141
            }
 
142
            p += i;             /* advance to the '>' */
 
143
            pw->ptr = q;
 
144
            status = a85d_finish(ccount, word, pw);
 
145
            q = pw->ptr;
 
146
            break;
 
147
        } else {                /* syntax error or exception */
 
148
            status = ERRC;
 
149
            break;
 
150
        }
 
151
    }
 
152
    pw->ptr = q;
 
153
    if (status == 0 && last) {
 
154
        if ((int)(wlimit - q) < ccount - 1)
 
155
            status = 1;
 
156
        else
 
157
            status = a85d_finish(ccount, word, pw);
 
158
    }
 
159
    pr->ptr = p;
 
160
    ss->odd = ccount;
 
161
    ss->word = word;
 
162
    return status;
 
163
}
 
164
/* Handle the end of input data. */
 
165
static int
 
166
a85d_finish(int ccount, ulong word, stream_cursor_write * pw)
 
167
{
 
168
    /* Assume there is enough room in the output buffer! */
 
169
    byte *q = pw->ptr;
 
170
    int status = EOFC;
 
171
 
 
172
    switch (ccount) {
 
173
        case 0:
 
174
            break;
 
175
        case 1:         /* syntax error */
 
176
            status = ERRC;
 
177
            break;
 
178
        case 2:         /* 1 odd byte */
 
179
            word = word * (85L * 85 * 85) + 85L * 85 * 85 - 1L;
 
180
            goto o1;
 
181
        case 3:         /* 2 odd bytes */
 
182
            word = word * (85L * 85) + 85L * 85L - 1L;
 
183
            goto o2;
 
184
        case 4:         /* 3 odd bytes */
 
185
            word = word * 85L + 84L;
 
186
            q[3] = (byte) (word >> 8);
 
187
o2:         q[2] = (byte) (word >> 16);
 
188
o1:         q[1] = (byte) (word >> 24);
 
189
            q += ccount - 1;
 
190
            pw->ptr = q;
 
191
    }
 
192
    return status;
 
193
}
 
194
 
 
195
/* Stream template */
 
196
const stream_template s_A85D_template = {
 
197
    &st_A85D_state, s_A85D_init, s_A85D_process, 2, 4
 
198
};