1 /* Copyright (C) 2001-2019 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,
8    modified or distributed except as expressly authorized under the terms
9    of the license contained in the file LICENSE in this distribution.
10 
11    Refer to licensing information at http://www.artifex.com or contact
12    Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
13    CA 94945, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 
17 /* Client interface to PatternType 1 Patterns */
18 
19 #ifndef gsptype1_INCLUDED
20 #  define gsptype1_INCLUDED
21 
22 #include "gspcolor.h"
23 #include "gxbitmap.h"
24 #include "gsdcolor.h"
25 #include "gscspace.h"
26 
27 /* ---------------- Types and structures ---------------- */
28 
29 /* PatternType 1 template */
30 
31 typedef struct gs_pattern1_template_s {
32     /*
33      * The common template must come first.  It defines type, uid,
34      * PatternType, and client_data.
35      */
36     gs_pattern_template_common;
37     int PaintType;
38     int TilingType;
39     bool uses_transparency;
40     gs_rect BBox;
41     float XStep;
42     float YStep;
43     int (*PaintProc) (const gs_client_color *, gs_gstate *);
44 } gs_pattern1_template_t;
45 
46 #define private_st_pattern1_template() /* in gspcolor.c */\
47   gs_private_st_suffix_add0(st_pattern1_template,\
48     gs_pattern1_template_t, "gs_pattern1_template_t",\
49     pattern1_template_enum_ptrs, pattern1_template_reloc_ptrs,\
50     st_pattern_template)
51 #define st_pattern1_template_max_ptrs st_pattern_template_max_ptrs
52 
53 /* Backward compatibility */
54 typedef gs_pattern1_template_t gs_client_pattern;
55 
56 /* ---------------- Procedures ---------------- */
57 
58 /*
59  * Construct a PatternType 1 Pattern color space.  If the base space is
60  * NULL, the color space can only be used with colored patterns.
61  */
62 extern int gs_cspace_build_Pattern1(
63                                     gs_color_space ** ppcspace,
64                                     gs_color_space * pbase_cspace,
65                                     gs_memory_t * pmem
66                                     );
67 
68 /* Initialize a PatternType 1 pattern. */
69 void gs_pattern1_init(gs_pattern1_template_t *);
70 
71 /* Backward compatibility */
72 #define gs_client_pattern_init(ppat) gs_pattern1_init(ppat)
73 
74 /*
75  * Define versions of make_pattern and get_pattern specifically for
76  * PatternType 1 patterns.
77  *
78  * The gs_memory_t argument for gs_makepattern may be NULL, meaning use the
79  * same allocator as for the gs_gstate argument.  Note that gs_makepattern
80  * uses rc_alloc_struct_1 to allocate pattern instances.
81  */
82 int gs_makepattern(gs_client_color *, const gs_client_pattern *,
83                    const gs_matrix *, gs_gstate *, gs_memory_t *);
84 const gs_client_pattern *gs_getpattern(const gs_client_color *);
85 
86 /* Check device color for Pattern Type 1. */
87 bool gx_dc_is_pattern1_color(const gx_device_color *pdevc);
88 
89 /* Check device color for Pattern Type 1 with transparency involved */
90 bool gx_dc_is_pattern1_color_with_trans(const gx_device_color *pdevc);
91 
92 /* Get transparency pointer */
93 void * gx_pattern1_get_transptr(const gx_device_color *pdevc);
94 /* pattern is clist with transparency */
95 int gx_pattern1_clist_has_trans(const gx_device_color *pdevc);
96 
97 /* For changing the device color procs when we have a transparency situation */
98 
99 void gx_set_pattern_procs_trans(gx_device_color *pdevc);
100 void gx_set_pattern_procs_standard(gx_device_color *pdevc);
101 bool gx_pattern_procs_istrans(gx_device_color *pdevc);
102 
103 /* Check device color for clist-based Pattern Type 1. */
104 bool gx_dc_is_pattern1_color_clist_based(const gx_device_color *pdevc);
105 
106 /* Get pattern id (type 1 pattern only) */
107 gs_id gs_dc_get_pattern_id(const gx_device_color *pdevc);
108 
109 /*
110  * Make a pattern from a bitmap or pixmap. The pattern may be colored or
111  * uncolored, as determined by the mask operand. This code is intended
112  * primarily for use by PCL.
113  *
114  * By convention, if pmat is null the identity matrix will be used, and if
115  * id is no_UniqueID the code will assign a unique id. Thes conventions allow
116  * gs_makebitmappattern to be implemented as a macro. Also, if mem is a
117  * null pointer, the memory allocator for the graphic state is used.
118  *
119  * For mask patterns, pix_depth must be 1, while pcspace and white_index are
120  * ignored; the polarity of the mask considers ones part of the mask, while
121  * zeros are not. For colored patterns pspace must point to an indexed color
122  * space and the image must used the canoncial Decode array for this color
123  * space. For both cases no interpolation or adjustment is provided.
124  *
125  * For backwards compatibility, if mask is false, pcspace is null, and
126  * pix_depth is 1, the pattern will be rendered with a color space that maps
127  * 0 to white and 1 to black.
128  *
129  * The image must be described by a gx_tile_bitmap structure (this is actually
130  * somewhat awkward, but the only option available at the moment), and the
131  * pattern step will exactly match the image size. The client need not maintain
132  * the gx_tile_bitmap structure after the completion of this call, but the
133  * raw image data itself must be kept until the pattern is no longer needed.
134  *
135  * NB: For proper handling of transparency in PCL, there must be only a single
136  *     white value accessed by the pattern image. If the palette contains
137  *     multiple white values, the PCL component must remap the image data to
138  *     ensure that all white indices are mapped to the single, given white
139  *     index.
140  */
141 extern int gs_makepixmappattern(
142                                 gs_client_color * pcc,
143                                 const gs_depth_bitmap * pbitmap,
144                                 bool mask,
145                                 const gs_matrix * pmat,
146                                 long id,
147                                 gs_color_space * pcspace,
148                                 uint white_index,
149                                 gs_gstate * pgs,
150                                 gs_memory_t * mem
151                                 );
152 
153 /*
154  *  Backwards compatibility feature, to allow the existing
155  *  gs_makebitmappattern operation to still function.
156  */
157 extern int gs_makebitmappattern_xform(
158                                       gs_client_color * pcc,
159                                       const gx_tile_bitmap * ptile,
160                                       bool mask,
161                                       const gs_matrix * pmat,
162                                       long id,
163                                       gs_gstate * pgs,
164                                       gs_memory_t * mem
165                                       );
166 
167 /*
168  * High level pattern support for pixmap patterns, if the interpreter supports them.
169  */
170 extern int pixmap_high_level_pattern(gs_gstate * pgs);
171 
172 #define gs_makebitmappattern(pcc, tile, mask, pgs, mem)                 \
173     gs_makebitmappattern_xform(pcc, tile, mask, 0, no_UniqueID, pgs, mem)
174 
175 #endif /* gsptype1_INCLUDED */
176