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

« back to all changes in this revision

Viewing changes to src/gsfunc.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: gsfunc.c 8022 2007-06-05 22:23:38Z giles $ */
15
 
/* Generic Function support */
16
 
#include "memory_.h"
17
 
#include "gx.h"
18
 
#include "gserrors.h"
19
 
#include "gsparam.h"
20
 
#include "gxfunc.h"
21
 
#include "stream.h"
22
 
 
23
 
/* GC descriptors */
24
 
public_st_function();
25
 
gs_private_st_ptr(st_function_ptr, gs_function_t *, "gs_function_t *",
26
 
                  function_ptr_enum_ptrs, function_ptr_reloc_ptrs);
27
 
gs_private_st_element(st_function_ptr_element, gs_function_t *,
28
 
                      "gs_function_t *[]", function_ptr_element_enum_ptrs,
29
 
                      function_ptr_element_reloc_ptrs, st_function_ptr);
30
 
 
31
 
/* Allocate an array of function pointers. */
32
 
int
33
 
alloc_function_array(uint count, gs_function_t *** pFunctions,
34
 
                     gs_memory_t *mem)
35
 
{
36
 
    gs_function_t **ptr;
37
 
 
38
 
    if (count == 0)
39
 
        return_error(gs_error_rangecheck);
40
 
    ptr = gs_alloc_struct_array(mem, count, gs_function_t *,
41
 
                                &st_function_ptr_element, "Functions");
42
 
    if (ptr == 0)
43
 
        return_error(gs_error_VMerror);
44
 
    memset(ptr, 0, sizeof(*ptr) * count);
45
 
    *pFunctions = ptr;
46
 
    return 0;
47
 
}
48
 
 
49
 
/* Generic free_params implementation. */
50
 
void
51
 
fn_common_free_params(gs_function_params_t * params, gs_memory_t * mem)
52
 
{
53
 
    gs_free_const_object(mem, params->Range, "Range");
54
 
    gs_free_const_object(mem, params->Domain, "Domain");
55
 
}
56
 
 
57
 
/* Generic free implementation. */
58
 
void
59
 
fn_common_free(gs_function_t * pfn, bool free_params, gs_memory_t * mem)
60
 
{
61
 
    if (free_params)
62
 
        gs_function_free_params(pfn, mem);
63
 
    gs_free_object(mem, pfn, "fn_common_free");
64
 
}
65
 
 
66
 
/* Check the values of m, n, Domain, and (if supplied) Range. */
67
 
int
68
 
fn_check_mnDR(const gs_function_params_t * params, int m, int n)
69
 
{
70
 
    int i;
71
 
 
72
 
    if (m <= 0 || n <= 0)
73
 
        return_error(gs_error_rangecheck);
74
 
    for (i = 0; i < m; ++i)
75
 
        if (params->Domain[2 * i] > params->Domain[2 * i + 1])
76
 
            return_error(gs_error_rangecheck);
77
 
    if (params->Range != 0)
78
 
        for (i = 0; i < n; ++i)
79
 
            if (params->Range[2 * i] > params->Range[2 * i + 1])
80
 
                return_error(gs_error_rangecheck);
81
 
    return 0;
82
 
}
83
 
 
84
 
/* Return default function information. */
85
 
void
86
 
gs_function_get_info_default(const gs_function_t *pfn, gs_function_info_t *pfi)
87
 
{
88
 
    pfi->DataSource = 0;
89
 
    pfi->Functions = 0;
90
 
}
91
 
 
92
 
/*
93
 
 * Write generic parameters (FunctionType, Domain, Range) on a parameter list.
94
 
 */
95
 
int
96
 
fn_common_get_params(const gs_function_t *pfn, gs_param_list *plist)
97
 
{
98
 
    int ecode = param_write_int(plist, "FunctionType", &FunctionType(pfn));
99
 
    int code;
100
 
 
101
 
    if (pfn->params.Domain) {
102
 
        code = param_write_float_values(plist, "Domain", pfn->params.Domain,
103
 
                                        2 * pfn->params.m, false);
104
 
        if (code < 0)
105
 
            ecode = code;
106
 
    }
107
 
    if (pfn->params.Range) {
108
 
        code = param_write_float_values(plist, "Range", pfn->params.Range,
109
 
                                        2 * pfn->params.n, false);
110
 
        if (code < 0)
111
 
            ecode = code;
112
 
    }
113
 
    return ecode;
114
 
}
115
 
 
116
 
/*
117
 
 * Copy an array of numeric values when scaling a function.
118
 
 */
119
 
void *
120
 
fn_copy_values(const void *pvalues, int count, int size, gs_memory_t *mem)
121
 
{
122
 
    if (pvalues) {
123
 
        void *values = gs_alloc_byte_array(mem, count, size, "fn_copy_values");
124
 
 
125
 
        if (values)
126
 
            memcpy(values, pvalues, count * size);
127
 
        return values;
128
 
    } else
129
 
        return 0;               /* caller must check */
130
 
}
131
 
 
132
 
/*
133
 
 * If necessary, scale the Range or Decode array for fn_make_scaled.
134
 
 * Note that we must always allocate a new array.
135
 
 */
136
 
int
137
 
fn_scale_pairs(const float **ppvalues, const float *pvalues, int npairs,
138
 
               const gs_range_t *pranges, gs_memory_t *mem)
139
 
{
140
 
    if (pvalues == 0)
141
 
        *ppvalues = 0;
142
 
    else {
143
 
        float *out = (float *)
144
 
            gs_alloc_byte_array(mem, 2 * npairs, sizeof(*pvalues),
145
 
                                "fn_scale_pairs");
146
 
 
147
 
        *ppvalues = out;
148
 
        if (out == 0)
149
 
            return_error(gs_error_VMerror);
150
 
        if (pranges) {
151
 
            /* Allocate and compute scaled ranges. */
152
 
            int i;
153
 
            for (i = 0; i < npairs; ++i) {
154
 
                double base = pranges[i].rmin, factor = pranges[i].rmax - base;
155
 
 
156
 
                out[2 * i] = pvalues[2 * i] * factor + base;
157
 
                out[2 * i + 1] = pvalues[2 * i + 1] * factor + base;
158
 
            }
159
 
        } else
160
 
            memcpy(out, pvalues, 2 * sizeof(*pvalues) * npairs);
161
 
    }
162
 
    return 0;
163
 
}
164
 
 
165
 
/*
166
 
 * Scale the generic part of a function (Domain and Range).
167
 
 * The client must have copied the parameters already.
168
 
 */
169
 
int
170
 
fn_common_scale(gs_function_t *psfn, const gs_function_t *pfn,
171
 
                const gs_range_t *pranges, gs_memory_t *mem)
172
 
{
173
 
    int code;
174
 
 
175
 
    psfn->head = pfn->head;
176
 
    psfn->params.Domain = 0;            /* in case of failure */
177
 
    psfn->params.Range = 0;
178
 
    if ((code = fn_scale_pairs(&psfn->params.Domain, pfn->params.Domain,
179
 
                               pfn->params.m, NULL, mem)) < 0 ||
180
 
        (code = fn_scale_pairs(&psfn->params.Range, pfn->params.Range,
181
 
                               pfn->params.n, pranges, mem)) < 0)
182
 
        return code;
183
 
    return 0;
184
 
}
185
 
 
186
 
/* Serialize. */
187
 
int
188
 
fn_common_serialize(const gs_function_t * pfn, stream *s)
189
 
{
190
 
    uint n;
191
 
    const gs_function_params_t * p = &pfn->params;
192
 
    int code = sputs(s, (const byte *)&pfn->head.type, sizeof(pfn->head.type), &n);
193
 
    const float dummy[8] = {0, 0, 0, 0,  0, 0, 0, 0};
194
 
 
195
 
    if (code < 0)
196
 
        return code;
197
 
    code = sputs(s, (const byte *)&p->m, sizeof(p->m), &n);
198
 
    if (code < 0)
199
 
        return code;
200
 
    code = sputs(s, (const byte *)&p->Domain[0], sizeof(p->Domain[0]) * p->m * 2, &n);
201
 
    if (code < 0)
202
 
        return code;
203
 
    code = sputs(s, (const byte *)&p->n, sizeof(p->n), &n);
204
 
    if (code < 0)
205
 
        return code;
206
 
    if (p->Range == NULL && p->n * 2 > count_of(dummy))
207
 
        return_error(gs_error_unregistered); /* Unimplemented. */
208
 
    return sputs(s, (const byte *)(p->Range != NULL ? &p->Range[0] : dummy), 
209
 
            sizeof(p->Range[0]) * p->n * 2, &n);
210
 
}
211