~ubuntu-branches/ubuntu/oneiric/ghostscript/oneiric

« back to all changes in this revision

Viewing changes to base/gsutil.c

  • Committer: Bazaar Package Importer
  • Author(s): Till Kamppeter
  • Date: 2011-07-15 16:49:55 UTC
  • mfrom: (1.1.23 upstream)
  • Revision ID: james.westby@ubuntu.com-20110715164955-uga6qibao6kez05c
Tags: 9.04~dfsg~20110715-0ubuntu1
* New upstream release
   - GIT snapshot from Jult, 12 2011.
* debian/patches/020110406~a54df2d.patch,
  debian/patches/020110408~0791cc8.patch,
  debian/patches/020110408~507cbee.patch,
  debian/patches/020110411~4509a49.patch,
  debian/patches/020110412~78bb9a6.patch,
  debian/patches/020110418~a05ab8a.patch,
  debian/patches/020110420~20b6c78.patch,
  debian/patches/020110420~4ddefa2.patch: Removed upstream patches.
* debian/rules: Generate ABI version number (variable "abi") correctly,
  cutting off repackaging and pre-release parts.
* debian/rules: Added ./lcms2/ directory to DEB_UPSTREAM_REPACKAGE_EXCLUDES.
* debian/copyright: Added lcms2/* to the list of excluded files.
* debian/symbols.common: Updated for new upstream source. Applied patch
  which dpkg-gensymbols generated for debian/libgs9.symbols to this file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* Copyright (C) 2001-2006 Artifex Software, Inc.
2
2
   All Rights Reserved.
3
 
  
 
3
 
4
4
   This software is provided AS-IS with no warranty, either express or
5
5
   implied.
6
6
 
11
11
   San Rafael, CA  94903, U.S.A., +1(415)492-9861, for further information.
12
12
*/
13
13
 
14
 
/* $Id: gsutil.c 11739 2010-09-23 19:45:27Z mvrhel $ */
 
14
/* $Id$ */
15
15
/* Utilities for Ghostscript library */
16
16
 
17
17
#include "string_.h"
26
26
#include "gzstate.h"
27
27
#include "gxdcolor.h"
28
28
 
29
 
 
30
 
 
31
29
/* ------ Unique IDs ------ */
32
30
 
33
31
ulong
50
48
    uint aceg, bdfh;
51
49
 
52
50
    {
53
 
        const byte *ptr4 = inp + (line_size << 2);
54
 
        const int ls2 = line_size << 1;
 
51
        const byte *ptr4 = inp + (line_size << 2);
 
52
        const int ls2 = line_size << 1;
55
53
 
56
 
        aceg = ((uint)*inp) | ((uint)inp[ls2] << 8) |
57
 
            ((uint)*ptr4 << 16) | ((uint)ptr4[ls2] << 24);
58
 
        inp += line_size, ptr4 += line_size;
59
 
        bdfh = ((uint)*inp) | ((uint)inp[ls2] << 8) |
60
 
            ((uint)*ptr4 << 16) | ((uint)ptr4[ls2] << 24);
 
54
        aceg = ((uint)*inp) | ((uint)inp[ls2] << 8) |
 
55
            ((uint)*ptr4 << 16) | ((uint)ptr4[ls2] << 24);
 
56
        inp += line_size, ptr4 += line_size;
 
57
        bdfh = ((uint)*inp) | ((uint)inp[ls2] << 8) |
 
58
            ((uint)*ptr4 << 16) | ((uint)ptr4[ls2] << 24);
61
59
    }
62
60
 
63
61
    /* Check for all 8 bytes being the same. */
64
62
    /* This is especially worth doing for the case where all are zero. */
65
63
    if (aceg == bdfh && (aceg >> 8) == (aceg & 0xffffff)) {
66
 
        if (aceg == 0 || aceg == 0xffffffff)
67
 
            goto store;
68
 
        *outp = (byte)-(int)((aceg >> 7) & 1);
69
 
        outp[dist] = (byte)-(int)((aceg >> 6) & 1);
70
 
        outp += dist << 1;
71
 
        *outp = (byte)-(int)((aceg >> 5) & 1);
72
 
        outp[dist] = (byte)-(int)((aceg >> 4) & 1);
73
 
        outp += dist << 1;
74
 
        *outp = (byte)-(int)((aceg >> 3) & 1);
75
 
        outp[dist] = (byte)-(int)((aceg >> 2) & 1);
76
 
        outp += dist << 1;
77
 
        *outp = (byte)-(int)((aceg >> 1) & 1);
78
 
        outp[dist] = (byte)-(int)(aceg & 1);
79
 
        return;
 
64
        if (aceg == 0 || aceg == 0xffffffff)
 
65
            goto store;
 
66
        *outp = (byte)-(int)((aceg >> 7) & 1);
 
67
        outp[dist] = (byte)-(int)((aceg >> 6) & 1);
 
68
        outp += dist << 1;
 
69
        *outp = (byte)-(int)((aceg >> 5) & 1);
 
70
        outp[dist] = (byte)-(int)((aceg >> 4) & 1);
 
71
        outp += dist << 1;
 
72
        *outp = (byte)-(int)((aceg >> 3) & 1);
 
73
        outp[dist] = (byte)-(int)((aceg >> 2) & 1);
 
74
        outp += dist << 1;
 
75
        *outp = (byte)-(int)((aceg >> 1) & 1);
 
76
        outp[dist] = (byte)-(int)(aceg & 1);
 
77
        return;
80
78
    } {
81
 
        register uint temp;
 
79
        register uint temp;
82
80
 
83
81
/* Transpose a block of bits between registers. */
84
82
#define TRANSPOSE(r,s,mask,shift)\
86
84
   s ^= temp << shift)
87
85
 
88
86
/* Transpose blocks of 4 x 4 */
89
 
        TRANSPOSE(aceg, aceg, 0x00000f0f, 20);
90
 
        TRANSPOSE(bdfh, bdfh, 0x00000f0f, 20);
 
87
        TRANSPOSE(aceg, aceg, 0x00000f0f, 20);
 
88
        TRANSPOSE(bdfh, bdfh, 0x00000f0f, 20);
91
89
 
92
90
/* Transpose blocks of 2 x 2 */
93
 
        TRANSPOSE(aceg, aceg, 0x00330033, 10);
94
 
        TRANSPOSE(bdfh, bdfh, 0x00330033, 10);
 
91
        TRANSPOSE(aceg, aceg, 0x00330033, 10);
 
92
        TRANSPOSE(bdfh, bdfh, 0x00330033, 10);
95
93
 
96
94
/* Transpose blocks of 1 x 1 */
97
 
        TRANSPOSE(aceg, bdfh, 0x55555555, 1);
 
95
        TRANSPOSE(aceg, bdfh, 0x55555555, 1);
98
96
 
99
97
#undef TRANSPOSE
100
98
    }
131
129
    register uint len = len1;
132
130
 
133
131
    if (len2 < len)
134
 
        len = len2;
 
132
        len = len2;
135
133
    {
136
 
        register const byte *p1 = s1;
137
 
        register const byte *p2 = s2;
 
134
        register const byte *p1 = s1;
 
135
        register const byte *p2 = s2;
138
136
 
139
 
        while (len--)
140
 
            if (*p1++ != *p2++)
141
 
                return (p1[-1] < p2[-1] ? -1 : 1);
 
137
        while (len--)
 
138
            if (*p1++ != *p2++)
 
139
                return (p1[-1] < p2[-1] ? -1 : 1);
142
140
    }
143
141
    /* Now check for differing lengths */
144
142
    return (len1 == len2 ? 0 : len1 < len2 ? -1 : 1);
152
150
 
153
151
bool
154
152
string_match(const byte * str, uint len, const byte * pstr, uint plen,
155
 
             register const string_match_params * psmp)
 
153
             register const string_match_params * psmp)
156
154
{
157
155
    const byte *pback = 0;
158
156
    const byte *spback = 0;     /* initialized only to pacify gcc */
160
158
    const byte *sp = str, *spend = str + len;
161
159
 
162
160
    if (psmp == 0)
163
 
        psmp = &string_match_params_default;
 
161
        psmp = &string_match_params_default;
164
162
  again:while (p < pend) {
165
 
        register byte ch = *p;
 
163
        register byte ch = *p;
166
164
 
167
 
        if (ch == psmp->any_substring) {
168
 
            pback = ++p, spback = sp;
169
 
            continue;
170
 
        } else if (ch == psmp->any_char) {
171
 
            if (sp == spend)
172
 
                return false;   /* str too short */
173
 
            p++, sp++;
174
 
            continue;
175
 
        } else if (ch == psmp->quote_next) {
176
 
            if (++p == pend)
177
 
                return true;    /* bad pattern */
178
 
            ch = *p;
179
 
        }
180
 
        if (sp == spend)
181
 
            return false;       /* str too short */
182
 
        if (*sp == ch ||
183
 
            (psmp->ignore_case && (*sp ^ ch) == 0x20 &&
184
 
             (ch &= ~0x20) >= 0x41 && ch <= 0x5a) ||
185
 
             (psmp->slash_equiv && ((ch == '\\' && *sp == '/') ||
186
 
             (ch == '/' && *sp == '\\')))
187
 
            )
188
 
            p++, sp++;
189
 
        else if (pback == 0)
190
 
            return false;       /* no * to back up to */
191
 
        else {
192
 
            sp = ++spback;
193
 
            p = pback;
194
 
        }
 
165
        if (ch == psmp->any_substring) {
 
166
            pback = ++p, spback = sp;
 
167
            continue;
 
168
        } else if (ch == psmp->any_char) {
 
169
            if (sp == spend)
 
170
                return false;   /* str too short */
 
171
            p++, sp++;
 
172
            continue;
 
173
        } else if (ch == psmp->quote_next) {
 
174
            if (++p == pend)
 
175
                return true;    /* bad pattern */
 
176
            ch = *p;
 
177
        }
 
178
        if (sp == spend)
 
179
            return false;       /* str too short */
 
180
        if (*sp == ch ||
 
181
            (psmp->ignore_case && (*sp ^ ch) == 0x20 &&
 
182
             (ch &= ~0x20) >= 0x41 && ch <= 0x5a) ||
 
183
             (psmp->slash_equiv && ((ch == '\\' && *sp == '/') ||
 
184
             (ch == '/' && *sp == '\\')))
 
185
            )
 
186
            p++, sp++;
 
187
        else if (pback == 0)
 
188
            return false;       /* no * to back up to */
 
189
        else {
 
190
            sp = ++spback;
 
191
            p = pback;
 
192
        }
195
193
    }
196
194
    if (sp < spend) {           /* We got a match, but there are chars left over. */
197
 
        /* If we can back up, back up to the only place that */
198
 
        /* could produce a complete match, otherwise fail. */
199
 
        if (pback == 0)
200
 
            return false;
201
 
        p = pback;
202
 
        pback = 0;
203
 
        sp = spend - (pend - p);
204
 
        goto again;
 
195
        /* If we can back up, back up to the only place that */
 
196
        /* could produce a complete match, otherwise fail. */
 
197
        if (pback == 0)
 
198
            return false;
 
199
        p = pback;
 
200
        pback = 0;
 
201
        sp = spend - (pend - p);
 
202
        goto again;
205
203
    }
206
204
    return true;
207
205
}
214
212
uid_equal(register const gs_uid * puid1, register const gs_uid * puid2)
215
213
{
216
214
    if (puid1->id != puid2->id)
217
 
        return false;
 
215
        return false;
218
216
    if (puid1->id >= 0)
219
 
        return true;            /* UniqueID */
 
217
        return true;            /* UniqueID */
220
218
    return
221
 
        !memcmp((const char *)puid1->xvalues,
222
 
                (const char *)puid2->xvalues,
223
 
                (uint) - (puid1->id) * sizeof(long));
 
219
        !memcmp((const char *)puid1->xvalues,
 
220
                (const char *)puid2->xvalues,
 
221
                (uint) - (puid1->id) * sizeof(long));
224
222
}
225
223
 
226
224
/* Copy the XUID data for a uid, if needed, updating the uid in place. */
228
226
uid_copy(gs_uid *puid, gs_memory_t *mem, client_name_t cname)
229
227
{
230
228
    if (uid_is_XUID(puid)) {
231
 
        uint xsize = uid_XUID_size(puid);
232
 
        long *xvalues = (long *)
233
 
            gs_alloc_byte_array(mem, xsize, sizeof(long), cname);
 
229
        uint xsize = uid_XUID_size(puid);
 
230
        long *xvalues = (long *)
 
231
            gs_alloc_byte_array(mem, xsize, sizeof(long), cname);
234
232
 
235
 
        if (xvalues == 0)
236
 
            return_error(gs_error_VMerror);
237
 
        memcpy(xvalues, uid_XUID_values(puid), xsize * sizeof(long));
238
 
        puid->xvalues = xvalues;
 
233
        if (xvalues == 0)
 
234
            return_error(gs_error_VMerror);
 
235
        memcpy(xvalues, uid_XUID_values(puid), xsize * sizeof(long));
 
236
        puid->xvalues = xvalues;
239
237
    }
240
238
    return 0;
241
239
}
249
247
 */
250
248
int
251
249
int_rect_difference(gs_int_rect * outer, const gs_int_rect * inner,
252
 
                    gs_int_rect * diffs /*[4] */ )
 
250
                    gs_int_rect * diffs /*[4] */ )
253
251
{
254
252
    int x0 = outer->p.x, y0 = outer->p.y;
255
253
    int x1 = outer->q.x, y1 = outer->q.y;
256
254
    int count = 0;
257
255
 
258
256
    if (y0 < inner->p.y) {
259
 
        diffs[0].p.x = x0, diffs[0].p.y = y0;
260
 
        diffs[0].q.x = x1, diffs[0].q.y = min(y1, inner->p.y);
261
 
        outer->p.y = y0 = diffs[0].q.y;
262
 
        ++count;
 
257
        diffs[0].p.x = x0, diffs[0].p.y = y0;
 
258
        diffs[0].q.x = x1, diffs[0].q.y = min(y1, inner->p.y);
 
259
        outer->p.y = y0 = diffs[0].q.y;
 
260
        ++count;
263
261
    }
264
262
    if (y1 > inner->q.y) {
265
 
        diffs[count].p.x = x0, diffs[count].p.y = max(y0, inner->q.y);
266
 
        diffs[count].q.x = x1, diffs[count].q.y = y1;
267
 
        outer->q.y = y1 = diffs[count].p.y;
268
 
        ++count;
 
263
        diffs[count].p.x = x0, diffs[count].p.y = max(y0, inner->q.y);
 
264
        diffs[count].q.x = x1, diffs[count].q.y = y1;
 
265
        outer->q.y = y1 = diffs[count].p.y;
 
266
        ++count;
269
267
    }
270
268
    if (x0 < inner->p.x) {
271
 
        diffs[0].p.x = x0, diffs[0].p.y = y0;
272
 
        diffs[0].q.x = min(x1, inner->p.x), diffs[0].q.y = y1;
273
 
        outer->p.x = x0 = diffs[count].q.x;
274
 
        ++count;
 
269
        diffs[0].p.x = x0, diffs[0].p.y = y0;
 
270
        diffs[0].q.x = min(x1, inner->p.x), diffs[0].q.y = y1;
 
271
        outer->p.x = x0 = diffs[count].q.x;
 
272
        ++count;
275
273
    }
276
274
    if (x1 > inner->q.x) {
277
 
        diffs[count].p.x = max(x0, inner->q.x), diffs[count].p.y = y0;
278
 
        diffs[count].q.x = x1, diffs[count].q.y = y1;
279
 
        outer->q.x = x1 = diffs[count].p.x;
280
 
        ++count;
 
275
        diffs[count].p.x = max(x0, inner->q.x), diffs[count].p.y = y0;
 
276
        diffs[count].q.x = x1, diffs[count].q.y = y1;
 
277
        outer->q.x = x1 = diffs[count].p.x;
 
278
        ++count;
281
279
    }
282
280
    return count;
283
281
}
284
 
 
285
 
void
286
 
gs_enable_object_tagging(gs_memory_t * mem)
287
 
{
288
 
    if (mem->gs_lib_ctx->BITTAG == GS_DEVICE_DOESNT_SUPPORT_TAGS)
289
 
        mem->gs_lib_ctx->BITTAG = GS_UNKNOWN_TAG;
290
 
}
291
 
 
292
 
void
293
 
gs_set_object_tag(gs_imager_state * pis, const gs_object_tag_type_t tag)
294
 
{
295
 
    if (pis->memory->gs_lib_ctx->BITTAG != GS_DEVICE_DOESNT_SUPPORT_TAGS) {
296
 
        pis->object_tag = tag;
297
 
        /* mkromfs breaks this dependance 
298
 
           NB: needs to be fixed.
299
 
           gx_unset_dev_color(pgs);
300
 
         **/
301
 
        pis->memory->gs_lib_ctx->BITTAG = tag;
302
 
        /* the assumption is made that the caller will:
303
 
         * gx_set_dev_color(pgs);
304
 
         */
305
 
    }
306
 
}
307
 
 
308
 
gs_object_tag_type_t
309
 
gs_current_object_tag(gs_memory_t * mem)
310
 
{
311
 
    return mem->gs_lib_ctx->BITTAG;
312
 
}
313