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

« back to all changes in this revision

Viewing changes to src/gximage.h

  • 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: gximage.h 8868 2008-07-23 23:29:39Z mvrhel $ */
15
 
/* Default image rendering state structure */
16
 
/* Requires gxcpath.h, gxdevmem.h, gxdcolor.h, gzpath.h */
17
 
 
18
 
#ifndef gximage_INCLUDED
19
 
#  define gximage_INCLUDED
20
 
 
21
 
#include "gsiparam.h"
22
 
#include "gxcspace.h"
23
 
#include "strimpl.h"            /* for sisparam.h */
24
 
#include "sisparam.h"
25
 
#include "gxdda.h"
26
 
#include "gxiclass.h"
27
 
#include "gxiparam.h"
28
 
#include "gxsample.h"
29
 
 
30
 
/* Define the abstract type for the image enumerator state. */
31
 
/*typedef struct gx_image_enum_s gx_image_enum;*/  /* in gxiclass.h */
32
 
 
33
 
/*
34
 
 * Incoming samples may go through two different transformations:
35
 
 *
36
 
 *      - For N-bit input samples with N <= 8, N-to-8-bit expansion
37
 
 *      may involve a lookup map.  Currently this map is either an
38
 
 *      identity function or a subtraction from 1 (inversion).
39
 
 *
40
 
 *      - The 8-bit or frac expanded sample may undergo decoding (a linear
41
 
 *      transformation) before being handed off to the color mapping
42
 
 *      machinery.
43
 
 *
44
 
 * If the decoding function's range is [0..1], we fold it into the
45
 
 * expansion lookup; otherwise we must compute it separately.
46
 
 * For speed, we distinguish 3 different cases of the decoding step:
47
 
 */
48
 
typedef enum {
49
 
    sd_none,                    /* decoded during expansion */
50
 
    sd_lookup,                  /* use lookup_decode table */
51
 
    sd_compute                  /* compute using base and factor */
52
 
} sample_decoding;
53
 
struct sample_map_s {
54
 
 
55
 
    sample_lookup_t table;
56
 
 
57
 
    /*
58
 
     * If an 8-bit fraction doesn't represent the decoded value
59
 
     * accurately enough, but the samples have 4 bits or fewer,
60
 
     * we precompute the decoded values into a table.
61
 
     * Different entries are used depending on bits/sample:
62
 
     *      1,8,12 bits/sample: 0,15
63
 
     *      2 bits/sample: 0,5,10,15
64
 
     *      4 bits/sample: all
65
 
     */
66
 
 
67
 
    float decode_lookup[16];
68
 
#define decode_base decode_lookup[0]
69
 
#define decode_max decode_lookup[15]
70
 
 
71
 
    /*
72
 
     * In the worst case, we have to do the decoding on the fly.
73
 
     * The value is base + sample * factor, where the sample is
74
 
     * an 8-bit (unsigned) integer or a frac.
75
 
     */
76
 
 
77
 
    double decode_factor;
78
 
 
79
 
    sample_decoding decoding;
80
 
 
81
 
    /*
82
 
     * If decoding is sd_none for a non-mask image, we still need to know
83
 
     * whether the table includes an inversion, so that we can transform
84
 
     * mask values correctly.
85
 
     */
86
 
 
87
 
    bool inverted;
88
 
 
89
 
};
90
 
 
91
 
#ifndef sample_map_DEFINED
92
 
#define sample_map_DEFINED
93
 
typedef struct sample_map_s sample_map;
94
 
#endif
95
 
 
96
 
/* Decode an 8-bit sample into a floating point color component. */
97
 
/* penum points to the gx_image_enum structure. */
98
 
#define decode_sample(sample_value, cc, i)\
99
 
  switch ( penum->map[i].decoding )\
100
 
  {\
101
 
  case sd_none:\
102
 
    cc.paint.values[i] = (sample_value) * (1.0 / 255.0);  /* faster than / */\
103
 
    break;\
104
 
  case sd_lookup:       /* <= 4 significant bits */\
105
 
    cc.paint.values[i] =\
106
 
      penum->map[i].decode_lookup[(sample_value) >> 4];\
107
 
    break;\
108
 
  case sd_compute:\
109
 
    cc.paint.values[i] =\
110
 
      penum->map[i].decode_base + (sample_value) * penum->map[i].decode_factor;\
111
 
  }
112
 
 
113
 
/* Decode a frac value similarly. */
114
 
#define decode_frac(frac_value, cc, i)\
115
 
  cc.paint.values[i] =\
116
 
    penum->map[i].decode_base + (frac_value) * penum->map[i].decode_factor
117
 
 
118
 
 
119
 
/* Decode a frac value, to our 16 bit frac form. */
120
 
#define DECODE_FRAC_FRAC(frac_value, frac_value_out, i)\
121
 
  frac_value_out =\
122
 
    gx_unit_frac(penum->map[i].decode_base + (frac_value) * penum->map[i].decode_factor)
123
 
 
124
 
/*
125
 
 * Declare the pointer that holds the 12-bit unpacking procedure
126
 
 * if 12-bit samples are supported, 0 otherwise.
127
 
 */
128
 
extern const sample_unpack_proc_t sample_unpack_12_proc;
129
 
 
130
 
/*
131
 
 * Declare the pointer that holds the 16-bit unpacking procedure
132
 
 * if 16-bit samples are supported, 0 otherwise.
133
 
 */
134
 
extern const sample_unpack_proc_t sample_unpack_16_proc;
135
 
 
136
 
/* Define the distinct postures of an image. */
137
 
/* Each posture includes its reflected variant. */
138
 
typedef enum {
139
 
    image_portrait = 0,         /* 0 or 180 degrees */
140
 
    image_landscape,            /* 90 or 270 degrees */
141
 
    image_skewed                /* any other transformation */
142
 
} image_posture;
143
 
 
144
 
/*
145
 
 * Define an entry in the image color table.  For single-source-plane
146
 
 * images, the table index is the sample value, and the key is not used;
147
 
 * for multiple-plane (color) images, the table index is a hash of the key,
148
 
 * which is the concatenation of the source pixel components.
149
 
 * "Clue" = Color LookUp Entry (by analogy with CLUT).
150
 
 */
151
 
typedef struct gx_image_clue_s {
152
 
    gx_device_color dev_color;
153
 
    bits32 key;
154
 
} gx_image_clue;
155
 
 
156
 
/* Main state structure */
157
 
 
158
 
#ifndef gx_device_clip_DEFINED
159
 
#  define gx_device_clip_DEFINED
160
 
typedef struct gx_device_clip_s gx_device_clip;
161
 
#endif
162
 
 
163
 
#ifndef gx_device_rop_texture_DEFINED
164
 
#  define gx_device_rop_texture_DEFINED
165
 
typedef struct gx_device_rop_texture_s gx_device_rop_texture;
166
 
#endif
167
 
 
168
 
struct gx_image_enum_s {
169
 
    gx_image_enum_common;
170
 
    /* We really want the map structure to be long-aligned, */
171
 
    /* so we choose shorter types for some flags. */
172
 
    /* Following are set at structure initialization */
173
 
    int Width;                  /* Full image width */
174
 
    int Height;                 /* Full image height */
175
 
    byte bps;                   /* bits per sample: 1, 2, 4, 8, 12 */
176
 
    byte unpack_bps;            /* bps for computing unpack proc, */
177
 
                                /* set to 8 if no unpacking */
178
 
    byte log2_xbytes;           /* log2(bytes per expanded sample): */
179
 
                                /* 0 if bps <= 8, log2(sizeof(frac)) */
180
 
                                /* if bps > 8 */
181
 
    byte spp;                   /* samples per pixel */
182
 
    gs_image_alpha_t alpha;     /* Alpha from image structure */
183
 
    struct mc_ {
184
 
        uint values[GS_IMAGE_MAX_COMPONENTS * 2]; /* MaskColor values, */
185
 
                                /* always as ranges, guaranteed in range */
186
 
                                /* and in order (v0 <= v1) */
187
 
        bits32 mask, test;      /* (if spp > 1, bps <= 8) */
188
 
                                /* mask & test value for quick filtering */
189
 
        bool exact;             /* (if spp > 1, bps <= 8) */
190
 
                                /* if true, mask/test filter is exact */
191
 
    } mask_color;               /* (if ImageType 4) */
192
 
    byte use_mask_color;        /* true if color masking is being used */
193
 
    /*byte num_planes; */       /* (in common part) */
194
 
    byte spread;                /* (spp if multi-plane, 1 if not) */
195
 
                                /* << log2_xbytes */
196
 
    byte masked;                /* 0 = [color]image, 1 = imagemask */
197
 
    byte interpolate;           /* true if Interpolate requested */
198
 
    gs_matrix matrix;           /* image space -> device space */
199
 
    struct r_ {
200
 
        int x, y, w, h;         /* subrectangle being rendered */
201
 
    } rect;
202
 
    fixed dst_height;           /* Full image height in the device space for siscale.c only;
203
 
                                   assumes posture == image_portrait. */
204
 
    fixed dst_width;            /* Full image width in the device space for siscale.c only;
205
 
                                   assumes posture == image_portrait. */
206
 
    gs_fixed_point x_extent, y_extent;  /* extent of one row of rect */
207
 
    SAMPLE_UNPACK_PROC((*unpack));
208
 
    irender_proc((*render));
209
 
    const gs_imager_state *pis;
210
 
    const gs_color_space *pcs;  /* color space of image */
211
 
    byte *buffer;               /* for expanding samples to a */
212
 
                                /* byte or frac */
213
 
    uint buffer_size;
214
 
    byte *line;                 /* buffer for an output scan line */
215
 
    uint line_size;
216
 
    uint line_width;            /* width of line in device pixels */
217
 
    image_posture posture;
218
 
    byte use_rop;               /* true if CombineWithColor requested */
219
 
    byte clip_image;            /* mask, see below */
220
 
    /* Either we are clipping to a rectangle, in which case */
221
 
    /* the individual x/y flags may be set, or we are clipping */
222
 
    /* to a general region, in which case only clip_region */
223
 
    /* is set. */
224
 
#define image_clip_xmin 1
225
 
#define image_clip_xmax 2
226
 
#define image_clip_ymin 4
227
 
#define image_clip_ymax 8
228
 
#define image_clip_region 0x10
229
 
    byte slow_loop;             /* true if must use slower loop */
230
 
                                /* (if needed) */
231
 
    byte device_color;          /* true if device color space and */
232
 
                                /* standard decoding */
233
 
    gs_fixed_rect clip_outer;   /* outer box of clip path */
234
 
    gs_fixed_rect clip_inner;   /* inner box of clip path */
235
 
    gs_logical_operation_t log_op;      /* logical operation */
236
 
    fixed adjust;               /* adjustment when rendering */
237
 
                                /* characters */
238
 
    fixed dxx, dxy;             /* fixed versions of matrix */
239
 
                                /* components (as needed) */
240
 
    gx_device_clip *clip_dev;   /* clipping device (if needed) */
241
 
    gx_device_rop_texture *rop_dev;     /* RasterOp device (if needed) */
242
 
    stream_image_scale_state *scaler;   /* scale state for Interpolate */
243
 
                                /* (if needed) */
244
 
    /* Following are updated dynamically */
245
 
    int y;                      /* next source y */
246
 
    gs_int_point used;          /* amount of data already used, if */
247
 
                                /* interrupted by error */
248
 
    gs_fixed_point cur, prev;   /* device x, y of current & */
249
 
                                /* previous row */
250
 
    struct dd_ {
251
 
        gx_dda_fixed_point row; /* DDA for row origin, has been */
252
 
                                /* advanced when render proc called */
253
 
        gx_dda_fixed_point strip;  /* row + rect.x */
254
 
        gx_dda_fixed_point pixel0;      /* DDA for first pixel to render, */
255
 
                                /* strip + used.x */
256
 
    } dda;
257
 
    int line_xy;                /* x or y value at start of buffered line */
258
 
    int xi_next;                /* expected xci of next row */
259
 
                                /* (landscape only) */
260
 
    gs_int_point xyi;           /* integer origin of row */
261
 
                                /* (Interpolate only) */
262
 
    int yi0;                    /* integer y of entire image origin. */
263
 
    int yci, hci;               /* integer y & h of row (portrait) */
264
 
    int xci, wci;               /* integer x & w of row (landscape) */
265
 
    /* The maps are set at initialization.  We put them here */
266
 
    /* so that the scalars will have smaller offsets. */
267
 
    sample_map map[GS_IMAGE_MAX_COMPONENTS];
268
 
    /* Entries 0 and 255 of the following are set at initialization */
269
 
    /* for monochrome images; other entries are updated dynamically. */
270
 
    gx_image_clue clues[256];
271
 
#define icolor0 clues[0].dev_color
272
 
#define icolor1 clues[255].dev_color
273
 
};
274
 
 
275
 
/* Enumerate the pointers in an image enumerator. */
276
 
#define gx_image_enum_do_ptrs(m)\
277
 
  m(0,pis) m(1,pcs) m(2,dev) m(3,buffer) m(4,line)\
278
 
  m(5,clip_dev) m(6,rop_dev) m(7,scaler)
279
 
#define gx_image_enum_num_ptrs 8
280
 
#define private_st_gx_image_enum() /* in gsimage.c */\
281
 
  gs_private_st_composite(st_gx_image_enum, gx_image_enum, "gx_image_enum",\
282
 
    image_enum_enum_ptrs, image_enum_reloc_ptrs)
283
 
 
284
 
/* Compare two device colors for equality. */
285
 
/* We can special-case this for speed later if we care. */
286
 
#define dev_color_eq(devc1, devc2)\
287
 
  gx_device_color_equal(&(devc1), &(devc2))
288
 
 
289
 
/*
290
 
 * Scale a pair of mask_color values to match the scaling of each sample to
291
 
 * a full byte, and complement and swap them if the map incorporates
292
 
 * a Decode = [1 0] inversion.
293
 
 */
294
 
void gx_image_scale_mask_colors(gx_image_enum *penum,
295
 
                                int component_index);
296
 
 
297
 
/*
298
 
 * Do common initialization for processing an ImageType 1 or 4 image.
299
 
 * Allocate the enumerator and fill in the following members:
300
 
 *      rect
301
 
 */
302
 
int
303
 
gx_image_enum_alloc(const gs_image_common_t * pic,
304
 
                    const gs_int_rect * prect,
305
 
                    gs_memory_t * mem, gx_image_enum **ppenum);
306
 
 
307
 
/*
308
 
 * Finish initialization for processing an ImageType 1 or 4 image.
309
 
 * Assumes the following members of *penum are set in addition to those
310
 
 * set by gx_image_enum_alloc:
311
 
 *      alpha, use_mask_color, mask_color (if use_mask_color is true),
312
 
 *      masked, adjust
313
 
 */
314
 
int
315
 
gx_image_enum_begin(gx_device * dev, const gs_imager_state * pis,
316
 
                    const gs_matrix *pmat, const gs_image_common_t * pic,
317
 
                    const gx_drawing_color * pdcolor,
318
 
                    const gx_clip_path * pcpath,
319
 
                    gs_memory_t * mem, gx_image_enum *penum);
320
 
 
321
 
/*
322
 
 * Clear the relevant clues. Exported for use by image_render_*
323
 
 * when ht_tile cache is invalidated.
324
 
 */
325
 
void
326
 
image_init_clues(gx_image_enum * penum, int bps, int spp);
327
 
 
328
 
#endif /* gximage_INCLUDED */