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

« back to all changes in this revision

Viewing changes to base/gxhldevc.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
/* $Id: gxhldevc.c 8022 2007-06-05 22:23:38Z giles $ */
 
14
/* High level device color save/compare procedures */
 
15
 
 
16
/*
 
17
 * See comments at the start of gxhldevc.h for more explanation of the
 
18
 * purpose and operation of these procedures.
 
19
 */
 
20
#include "gx.h"
 
21
#include "gzstate.h"
 
22
#include "gscspace.h"
 
23
#include "gxcspace.h"
 
24
#include "gxhldevc.h"
 
25
#include "memory_.h"
 
26
#include "gxpcolor.h"
 
27
#include "gsptype2.h"
 
28
 
 
29
/*
 
30
 * Initiailze a high level saved color to null
 
31
 */
 
32
void gx_hld_saved_color_init(gx_hl_saved_color * psc)
 
33
{
 
34
    gx_device_color temp_devc;
 
35
 
 
36
    memset(psc, 0, sizeof(*psc));       /* clear the entire structure */   
 
37
    psc->color_space_id = psc->pattern_id = gs_no_id;
 
38
    color_set_null(&temp_devc);
 
39
    temp_devc.type->save_dc(&temp_devc, &(psc->saved_dev_color));
 
40
}
 
41
 
 
42
/*
 
43
 * Get graphics state pointer (from imager state pointer)
 
44
 */
 
45
const gs_state * gx_hld_get_gstate_ptr(const gs_imager_state * pis)
 
46
{
 
47
    extern_st(st_gs_state);             /* only for testing */
 
48
 
 
49
    /* Check to verify the structure type is really st_gs_state */
 
50
    if (pis == NULL || gs_object_type(pis->memory, pis) != &st_gs_state)
 
51
        return NULL;
 
52
 
 
53
    return (const gs_state *) pis;
 
54
}
 
55
 
 
56
/*
 
57
 * Save the device color information including the color space id and
 
58
 * client color data (if available).
 
59
 *
 
60
 * More description in src/gxhldevc.h
 
61
 */
 
62
bool
 
63
gx_hld_save_color(const gs_imager_state * pis, const gx_device_color * pdevc,
 
64
                gx_hl_saved_color * psc)
 
65
{
 
66
    const gs_state * pgs = gx_hld_get_gstate_ptr(pis);
 
67
    memset(psc, 0, sizeof(*psc));       /* clear the entire structure */
 
68
 
 
69
    if (pdevc == NULL) {
 
70
        /* No device color given, should not happen */
 
71
        gx_hld_saved_color_init(psc);   /* revert to unknown color */
 
72
        return false;
 
73
    } else if (pgs == NULL) {
 
74
        /* No color space, simply save device color specific info */
 
75
        psc->color_space_id = psc->pattern_id = gs_no_id;
 
76
        pdevc->type->save_dc(pdevc, &(psc->saved_dev_color));
 
77
        return false;
 
78
    } else {
 
79
        /*
 
80
         * Have color space, save id,  ccolor, & device color specific info.
 
81
         * Also save the high level colors since two gx_color_index values
 
82
         * may be the same but for differing high level colors (due to the
 
83
         * usual lower resolution of the gx_color_index values.
 
84
         */
 
85
        const gs_color_space * pcs = pgs->color_space;
 
86
        int i = gs_color_space_num_components(pcs);
 
87
 
 
88
        psc->color_space_id = pcs->id;
 
89
        pdevc->type->save_dc(pdevc, &(psc->saved_dev_color));
 
90
        if (pdevc->type == gx_dc_type_pattern2)
 
91
            i = 0;
 
92
        else if (i < 0)
 
93
            i = -i - 1; /* See gx_num_components_Pattern. */
 
94
        for (i--; i >= 0; i--)
 
95
            psc->ccolor.paint.values[i] = pdevc->ccolor.paint.values[i];
 
96
 
 
97
        /* Save the pattern id - if present */
 
98
        if ((pdevc->type == gx_dc_type_pattern 
 
99
           || pdevc->type == gx_dc_type_pattern2) && pdevc->ccolor_valid)
 
100
            psc->pattern_id = pdevc->ccolor.pattern->pattern_id;
 
101
        else
 
102
            psc->pattern_id = gs_no_id;
 
103
        return true;
 
104
    }
 
105
}
 
106
 
 
107
/*
 
108
 * Compare two saved colors to check if match.  Note this routine assumes
 
109
 * unused parts of the saved color have been zeroed.  See gx_hld_save_color()
 
110
 * for what is actually being compared.
 
111
 */
 
112
bool gx_hld_saved_color_equal(const gx_hl_saved_color * psc1,
 
113
                           const gx_hl_saved_color * psc2)
 
114
{
 
115
    return (memcmp(psc1, psc2, sizeof(*psc1)) == 0);
 
116
}
 
117
 
 
118
/*
 
119
 * Check whether two saved colors have same color space.
 
120
 */
 
121
bool gx_hld_saved_color_same_cspace(const gx_hl_saved_color * psc1,
 
122
                           const gx_hl_saved_color * psc2)
 
123
{
 
124
    if (psc1->color_space_id != psc2->color_space_id)
 
125
        return false;
 
126
    if (psc1->pattern_id != psc2->pattern_id)
 
127
        return false;
 
128
    if (psc1->ccolor_valid != psc2->ccolor_valid)
 
129
        return false;
 
130
    if (psc1->color_space_id != psc2->color_space_id)
 
131
        return false;
 
132
    return true;
 
133
}
 
134
 
 
135
/*
 
136
 * Check if a high level color is availavble.
 
137
 */
 
138
bool
 
139
gx_hld_is_hl_color_available(const gs_imager_state * pis,
 
140
                const gx_device_color * pdevc)
 
141
{
 
142
    const gs_state * pgs = gx_hld_get_gstate_ptr(pis);
 
143
 
 
144
    if (pgs != NULL && pdevc != NULL && pdevc->ccolor_valid)
 
145
        return true;
 
146
    return false;
 
147
}
 
148
 
 
149
/*
 
150
 * Get pointers to the current color space and client color.
 
151
 *
 
152
 * More description in src/gxhldevc.h
 
153
 */
 
154
gx_hld_get_color_space_and_ccolor_status
 
155
gx_hld_get_color_space_and_ccolor(const gs_imager_state * pis,
 
156
                const gx_device_color * pdevc, const gs_color_space ** ppcs,
 
157
                const gs_client_color ** ppcc)
 
158
{
 
159
    /* Check if the current color space was used to build the device color */
 
160
    if (gx_hld_is_hl_color_available(pis, pdevc)) {
 
161
        const gs_state * pgs = gx_hld_get_gstate_ptr(pis);
 
162
        const gs_color_space * pcs = pgs->color_space;
 
163
 
 
164
        *ppcs = pcs;
 
165
        *ppcc = &(pdevc->ccolor);
 
166
        if (pdevc->type == gx_dc_type_pattern 
 
167
           || pdevc->type == &gx_dc_pure_masked
 
168
           || pdevc->type == gx_dc_type_pattern2)
 
169
            return pattern_color_sapce;
 
170
        else {
 
171
            return non_pattern_color_space;
 
172
        }
 
173
    }
 
174
    /* No color space */
 
175
    *ppcs = NULL;
 
176
    *ppcc = NULL;
 
177
    return use_process_color;
 
178
}
 
179
 
 
180
/*
 
181
 * Get the number of components in the current color space.
 
182
 *
 
183
 * More description in src/gxhldevc.h
 
184
 */
 
185
int
 
186
gx_hld_get_number_color_components(const gs_imager_state * pis)
 
187
{
 
188
    const gs_state * pgs = gx_hld_get_gstate_ptr(pis);
 
189
 
 
190
    if (pgs != NULL) {
 
191
        const gs_color_space * pcs = pgs->color_space;
 
192
        int n = gs_color_space_num_components(pcs);
 
193
 
 
194
        return (n >= 0 ? n : -n - 1);
 
195
    } else
 
196
        return -1;
 
197
}
 
198
 
 
199
/*
 
200
 * Get the requested high level color value.
 
201
 *
 
202
 * More description in src/gxhldevc.h
 
203
 */
 
204
gx_hld_get_color_component_status
 
205
gx_hld_get_color_component(const gs_imager_state * pis,
 
206
                          const gx_device_color * pdevc,
 
207
                          int comp_num, float * output)
 
208
{
 
209
    if (pdevc != NULL && pdevc->ccolor_valid) {
 
210
        int ncomp = gx_hld_get_number_color_components(pis);
 
211
 
 
212
        if (ncomp < 0)
 
213
            return invalid_color_info;
 
214
        if (comp_num < 0 || comp_num >= ncomp) 
 
215
            return invalid_component_requested;
 
216
        *output = pdevc->ccolor.paint.values[comp_num];
 
217
        return valid_result;
 
218
    }
 
219
    return invalid_color_info;
 
220
}
 
221