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

« back to all changes in this revision

Viewing changes to src/gspcolor.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: gspcolor.c 8250 2007-09-25 13:31:24Z giles $ */
15
 
/* Pattern color operators and procedures for Ghostscript library */
16
 
#include "math_.h"
17
 
#include "gx.h"
18
 
#include "gserrors.h"
19
 
#include "gsrop.h"
20
 
#include "gsstruct.h"
21
 
#include "gsutil.h"             /* for gs_next_ids */
22
 
#include "gxarith.h"
23
 
#include "gxfixed.h"
24
 
#include "gxmatrix.h"
25
 
#include "gxcoord.h"            /* for gs_concat, gx_tr'_to_fixed */
26
 
#include "gxcspace.h"           /* for gscolor2.h */
27
 
#include "gxcolor2.h"
28
 
#include "gxdcolor.h"
29
 
#include "gxdevice.h"
30
 
#include "gxdevmem.h"
31
 
#include "gxclip2.h"
32
 
#include "gspath.h"
33
 
#include "gxpath.h"
34
 
#include "gxpcolor.h"
35
 
#include "gzstate.h"
36
 
#include "gsimage.h"
37
 
#include "gsiparm4.h"
38
 
#include "stream.h"
39
 
 
40
 
/* GC descriptors */
41
 
public_st_pattern_template();
42
 
public_st_pattern_instance();
43
 
 
44
 
/* Define the Pattern color space. */
45
 
gs_private_st_composite(st_color_space_Pattern, gs_color_space,
46
 
     "gs_color_space_Pattern", cs_Pattern_enum_ptrs, cs_Pattern_reloc_ptrs);
47
 
static cs_proc_num_components(gx_num_components_Pattern);
48
 
static cs_proc_remap_color(gx_remap_Pattern);
49
 
static cs_proc_init_color(gx_init_Pattern);
50
 
static cs_proc_restrict_color(gx_restrict_Pattern);
51
 
static cs_proc_install_cspace(gx_install_Pattern);
52
 
static cs_proc_set_overprint(gx_set_overprint_Pattern);
53
 
static cs_proc_final(gx_final_Pattern);
54
 
static cs_proc_adjust_color_count(gx_adjust_color_Pattern);
55
 
static cs_proc_serialize(gx_serialize_Pattern);
56
 
const gs_color_space_type gs_color_space_type_Pattern = {
57
 
    gs_color_space_index_Pattern, false, false,
58
 
    &st_color_space_Pattern, gx_num_components_Pattern,
59
 
    gx_init_Pattern, gx_restrict_Pattern,
60
 
    gx_no_concrete_space,
61
 
    gx_no_concretize_color, NULL,
62
 
    gx_remap_Pattern, gx_install_Pattern,
63
 
    gx_set_overprint_Pattern,
64
 
    gx_final_Pattern, gx_adjust_color_Pattern,
65
 
    gx_serialize_Pattern,
66
 
    gx_cspace_no_linear
67
 
};
68
 
 
69
 
/* Initialize a generic pattern template. */
70
 
void
71
 
gs_pattern_common_init(gs_pattern_template_t * ppat,
72
 
                       const gs_pattern_type_t *type)
73
 
{
74
 
    ppat->type = type;
75
 
    ppat->PatternType = type->PatternType;
76
 
    uid_set_invalid(&ppat->uid);
77
 
    ppat->client_data = 0;      /* for GC */
78
 
}
79
 
 
80
 
/* Generic makepattern */
81
 
int
82
 
gs_make_pattern(gs_client_color * pcc, const gs_pattern_template_t * pcp,
83
 
                const gs_matrix * pmat, gs_state * pgs, gs_memory_t * mem)
84
 
{
85
 
    return pcp->type->procs.make_pattern(pcc, pcp, pmat, pgs, mem);
86
 
}
87
 
 
88
 
/*
89
 
 * Do the generic work for makepattern: allocate the instance and the
90
 
 * saved graphics state, and fill in the common members.
91
 
 */
92
 
int
93
 
gs_make_pattern_common(gs_client_color *pcc,
94
 
                       const gs_pattern_template_t *ptemp,
95
 
                       const gs_matrix *pmat, gs_state *pgs, gs_memory_t *mem,
96
 
                       gs_memory_type_ptr_t pstype)
97
 
{
98
 
    gs_pattern_instance_t *pinst;
99
 
    gs_state *saved;
100
 
 
101
 
    if (mem == 0)
102
 
        mem = gs_state_memory(pgs);
103
 
    rc_alloc_struct_1(pinst, gs_pattern_instance_t, pstype, mem,
104
 
                      return_error(gs_error_VMerror),
105
 
                      "gs_make_pattern_common");
106
 
    pinst->rc.free = rc_free_pattern_instance;
107
 
    pinst->type = ptemp->type;
108
 
    saved = gs_state_copy(pgs, mem);
109
 
    if (saved == 0) {
110
 
        gs_free_object(mem, pinst, "gs_make_pattern_common");
111
 
        return_error(gs_error_VMerror);
112
 
    }
113
 
    gs_concat(saved, pmat);
114
 
    gs_newpath(saved);
115
 
    pinst->saved = saved;
116
 
    pcc->pattern = pinst;
117
 
    pcc->pattern->pattern_id = gs_next_ids(mem, 1);
118
 
    return 0;
119
 
}
120
 
 
121
 
/* Free the saved gstate when freeing a Pattern instance. */
122
 
void
123
 
rc_free_pattern_instance(gs_memory_t * mem, void *pinst_void,
124
 
                         client_name_t cname)
125
 
{
126
 
    gs_pattern_instance_t *pinst = pinst_void;
127
 
 
128
 
    gs_state_free(pinst->saved);
129
 
    rc_free_struct_only(mem, pinst_void, cname);
130
 
}
131
 
 
132
 
/* setpattern */
133
 
int
134
 
gs_setpattern(gs_state * pgs, const gs_client_color * pcc)
135
 
{
136
 
    int code = gs_setpatternspace(pgs);
137
 
 
138
 
    if (code < 0)
139
 
        return code;
140
 
    return gs_setcolor(pgs, pcc);
141
 
}
142
 
 
143
 
/* setpatternspace */
144
 
/* This does all the work of setpattern except for the final setcolor. */
145
 
int
146
 
gs_setpatternspace(gs_state * pgs)
147
 
{
148
 
    int code = 0;
149
 
 
150
 
    if (pgs->in_cachedevice)
151
 
        return_error(gs_error_undefined);
152
 
    if (pgs->color_space->type->index != gs_color_space_index_Pattern) {
153
 
        gs_color_space *pcs;
154
 
 
155
 
        pcs = gs_cspace_alloc(pgs->memory, &gs_color_space_type_Pattern);
156
 
        if (pcs == NULL)
157
 
            return_error(gs_error_VMerror);
158
 
        /* reference to base space shifts from pgs to pcs with no net change */
159
 
        pcs->base_space = pgs->color_space;
160
 
        pcs->params.pattern.has_base_space = true;
161
 
        pgs->color_space = pcs;
162
 
        cs_full_init_color(pgs->ccolor, pcs);
163
 
        gx_unset_dev_color(pgs);
164
 
    }
165
 
    return code;
166
 
}
167
 
 
168
 
/*
169
 
 * Adjust the reference count of a pattern. This is intended to support
170
 
 * applications (such as PCL) which maintain client colors outside of the
171
 
 * graphic state. Since the pattern instance structure is opaque to these
172
 
 * applications, they need some way to release or retain the instances as
173
 
 * needed.
174
 
 */
175
 
void
176
 
gs_pattern_reference(gs_client_color * pcc, int delta)
177
 
{
178
 
    if (pcc->pattern != 0)
179
 
        rc_adjust(pcc->pattern, delta, "gs_pattern_reference");
180
 
}
181
 
 
182
 
/* getpattern */
183
 
/* This is only intended for the benefit of pattern PaintProcs. */
184
 
const gs_pattern_template_t *
185
 
gs_get_pattern(const gs_client_color * pcc)
186
 
{
187
 
    const gs_pattern_instance_t *pinst = pcc->pattern;
188
 
 
189
 
    return (pinst == 0 ? 0 : pinst->type->procs.get_pattern(pinst));
190
 
}
191
 
 
192
 
/*
193
 
 * Get the number of components in a Pattern color.
194
 
 * For backward compatibility, and to distinguish Pattern color spaces
195
 
 * from all others, we negate the result.
196
 
 */
197
 
static int
198
 
gx_num_components_Pattern(const gs_color_space * pcs)
199
 
{
200
 
    return
201
 
        (pcs->params.pattern.has_base_space ?
202
 
         -1 - cs_num_components(pcs->base_space) :
203
 
         -1 /* Pattern dictionary only */ );
204
 
}
205
 
 
206
 
/* Remap a Pattern color. */
207
 
static int
208
 
gx_remap_Pattern(const gs_client_color * pc, const gs_color_space * pcs,
209
 
                 gx_device_color * pdc, const gs_imager_state * pis,
210
 
                 gx_device * dev, gs_color_select_t select)
211
 
{
212
 
    if (pc->pattern == 0) {
213
 
        pdc->ccolor_valid = false;
214
 
        pdc->ccolor.pattern = 0; /* for GC */
215
 
        color_set_null_pattern(pdc);
216
 
        return 0;
217
 
    }
218
 
    return
219
 
        pc->pattern->type->procs.remap_color(pc, pcs, pdc, pis, dev, select);
220
 
}
221
 
 
222
 
/* Initialize a Pattern color. */
223
 
static void
224
 
gx_init_Pattern(gs_client_color * pcc, const gs_color_space * pcs)
225
 
{
226
 
    if (pcs->params.pattern.has_base_space) {
227
 
        const gs_color_space *pbcs = pcs->base_space;
228
 
 
229
 
        cs_init_color(pcc, pbcs);
230
 
    }
231
 
    /*pcc->pattern = 0; *//* cs_full_init_color handles this */
232
 
}
233
 
 
234
 
/* Force a Pattern color into legal range. */
235
 
/* Note that if the pattern is uncolored (PaintType = 2), */
236
 
/* the color space must have a base space: we check this here only */
237
 
/* to prevent accessing uninitialized data, but if there is no base space, */
238
 
/* it is an error that we count on being detected elsewhere. */
239
 
static void
240
 
gx_restrict_Pattern(gs_client_color * pcc, const gs_color_space * pcs)
241
 
{
242
 
    /* We need a special check for the null pattern. */
243
 
    if (pcc->pattern &&
244
 
        pcc->pattern->type->procs.uses_base_space(gs_get_pattern(pcc)) &&
245
 
        pcs->params.pattern.has_base_space
246
 
        ) {
247
 
        const gs_color_space *pbcs = pcs->base_space;
248
 
 
249
 
        (*pbcs->type->restrict_color) (pcc, pbcs);
250
 
    }
251
 
}
252
 
 
253
 
/* Install a Pattern color space. */
254
 
static int
255
 
gx_install_Pattern(gs_color_space * pcs, gs_state * pgs)
256
 
{
257
 
    if (!pcs->params.pattern.has_base_space)
258
 
        return 0;
259
 
    return (pcs->base_space->type->install_cspace)(pcs->base_space, pgs);
260
 
}
261
 
 
262
 
/*
263
 
 * Set the overprint compositor for a Pattern color space. This does nothing;
264
 
 * for patterns the overprint compositor is set at set_device_color time.
265
 
*/
266
 
static int
267
 
gx_set_overprint_Pattern(const gs_color_space * pcs, gs_state * pgs)
268
 
{
269
 
    return 0;
270
 
}
271
 
 
272
 
/* Adjust the reference counts for Pattern color spaces or colors. */
273
 
static void
274
 
gx_final_Pattern(const gs_color_space * pcs)
275
 
{
276
 
    /* {csrc} really do nothing? */
277
 
}
278
 
 
279
 
static void
280
 
gx_adjust_color_Pattern(const gs_client_color * pcc,
281
 
                        const gs_color_space * pcs, int delta)
282
 
{
283
 
    gs_pattern_instance_t *pinst = pcc->pattern;
284
 
 
285
 
    rc_adjust_only(pinst, delta, "gx_adjust_color_Pattern");
286
 
    if (pcs && pcs->params.pattern.has_base_space)
287
 
        (pcs->base_space->type->adjust_color_count)
288
 
            (pcc, pcs->base_space, delta);
289
 
}
290
 
 
291
 
/* GC procedures */
292
 
 
293
 
static 
294
 
ENUM_PTRS_BEGIN_PROC(cs_Pattern_enum_ptrs)
295
 
{
296
 
    return 0;
297
 
    /* {csrc} may change to st_base_color_space */
298
 
}
299
 
ENUM_PTRS_END_PROC
300
 
static RELOC_PTRS_BEGIN(cs_Pattern_reloc_ptrs)
301
 
{
302
 
    return;
303
 
}
304
 
RELOC_PTRS_END
305
 
 
306
 
/* ---------------- Serialization. -------------------------------- */
307
 
 
308
 
static int 
309
 
gx_serialize_Pattern(const gs_color_space * pcs, stream * s)
310
 
{
311
 
    const gs_pattern_params * p = &pcs->params.pattern;
312
 
    uint n;
313
 
    int code = gx_serialize_cspace_type(pcs, s);
314
 
 
315
 
    if (code < 0)
316
 
        return code;
317
 
    code = sputs(s, (const byte *)&p->has_base_space, sizeof(p->has_base_space), &n);
318
 
    if (code < 0)
319
 
        return code;
320
 
    if (!p->has_base_space)
321
 
        return 0;
322
 
    return cs_serialize(pcs->base_space, s);
323
 
}