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 /* Definitions for implementing compositing functions */ 18 19 #ifndef gxcomp_INCLUDED 20 # define gxcomp_INCLUDED 21 22 #include "gscompt.h" 23 #include "gsrefct.h" 24 #include "gxbitfmt.h" 25 #include "gsdevice.h" 26 27 /* 28 * Because compositor information is passed through the command list, 29 * individual compositors must be identified by some means that is 30 * independent of address space. The address of the compositor method 31 * array, gs_composite_type_t (see below), cannot be used, as it is 32 * meaningful only within a single address space. 33 * 34 * In addition, it is desirable the keep the compositor identifier 35 * size as small as possible, as this identifier must be passed through 36 * the command list for all bands whenever the compositor is invoked. 37 * Fortunately, compositor invocation is not so frequent as to warrant 38 * byte-sharing techniques, which most likely would store the identifier 39 * in some unused bits of a command code byte. Hence, the smallest 40 * reasonable size for the identifier is one byte. This allows for up 41 * to 255 compositors, which should be ample (as of this writing, there 42 * are only two compositors, only one of which can be passed through 43 * the command list). 44 * 45 * The following list is intended to enumerate all compositors. We 46 * use definitions rather than an encoding to ensure a one-byte size. 47 */ 48 #define GX_COMPOSITOR_ALPHA 0x01 /* DPS/Next alpha compositor */ 49 #define GX_COMPOSITOR_OVERPRINT 0x02 /* overprint/overprintmode compositor */ 50 #define GX_COMPOSITOR_PDF14_TRANS 0x03 /* PDF 1.4 transparency compositor */ 51 52 /* 53 * Define the abstract superclass for all compositing function types. 54 */ 55 /*typedef struct gs_composite_s gs_composite_t; *//* in gscompt.h */ 56 57 typedef struct gx_device_clist_writer_s gx_device_clist_writer; 58 59 typedef struct gs_composite_type_procs_s { 60 61 /* 62 * Create the default compositor for a compositing function. 63 */ 64 #define composite_create_default_compositor_proc(proc)\ 65 int proc(const gs_composite_t *pcte, gx_device **pcdev,\ 66 gx_device *dev, gs_gstate *pgs, gs_memory_t *mem) 67 composite_create_default_compositor_proc((*create_default_compositor)); 68 69 /* 70 * Test whether this function is equal to another one. 71 */ 72 #define composite_equal_proc(proc)\ 73 bool proc(const gs_composite_t *pcte, const gs_composite_t *pcte2) 74 composite_equal_proc((*equal)); 75 76 /* 77 * Convert the representation of this function to a string 78 * for writing in a command list. *psize is the amount of space 79 * available. If it is large enough, the procedure sets *psize 80 * to the amount used and returns 0; if it is not large enough, 81 * the procedure sets *psize to the amount needed and returns a 82 * rangecheck error; in the case of any other error, *psize is 83 * not changed. 84 */ 85 #define composite_write_proc(proc)\ 86 int proc(const gs_composite_t *pcte, byte *data, uint *psize, gx_device_clist_writer *cdev) 87 composite_write_proc((*write)); 88 89 /* 90 * Convert the string representation of a function back to 91 * a structure, allocating the structure. Return the number of 92 * bytes read, or < 0 in the event of an error. 93 */ 94 #define composite_read_proc(proc)\ 95 int proc(gs_composite_t **ppcte, const byte *data, uint size,\ 96 gs_memory_t *mem) 97 composite_read_proc((*read)); 98 99 /* 100 * Adjust CTM before applying the compositor. Used with banding. 101 */ 102 #define composite_adjust_ctm_proc(proc)\ 103 int proc(gs_composite_t *pcte, int x0, int y0, gs_gstate *pgs) 104 composite_adjust_ctm_proc((*adjust_ctm)); 105 106 /* 107 * Checks whether a next compositor operation closes this one. 108 * Must set the 2nd argument with a pointer to the opening compositor operation. 109 * Return coides : <0 - error, 0 - not closing, 110 * 1 - closing with annihilation, 2 - execute immediately, 111 * 3 - closing and replacing, 4 - replace one, 5 - drop queue. 112 */ 113 #define composite_is_closing_proc(proc)\ 114 gs_compositor_closing_state proc(const gs_composite_t *this, gs_composite_t **pcte, gx_device *dev) 115 composite_is_closing_proc((*is_closing)); 116 117 /* 118 * Checks whether a next operation is friendly to the compositor 119 * so that it may commutate with the compositor operation. 120 */ 121 #define composite_is_friendly_proc(proc)\ 122 bool proc(const gs_composite_t *this, byte cmd0, byte cmd1) 123 composite_is_friendly_proc((*is_friendly)); 124 125 /* 126 * Update the clist write device when a compositor device is created. 127 */ 128 #define composite_clist_write_update(proc)\ 129 int proc(const gs_composite_t * pcte, gx_device * dev, gx_device ** pcdev,\ 130 gs_gstate * pgs, gs_memory_t * mem) 131 composite_clist_write_update((*clist_compositor_write_update)); 132 133 /* 134 * Update the clist read device when a compositor device is created. 135 */ 136 #define composite_clist_read_update(proc)\ 137 int proc(gs_composite_t * pcte, gx_device * cdev, gx_device * tdev,\ 138 gs_gstate * pgs, gs_memory_t * mem) 139 composite_clist_read_update((*clist_compositor_read_update)); 140 141 /* 142 * Get compositor cropping. 143 */ 144 #define composite_get_cropping_proc(proc)\ 145 int proc(const gs_composite_t * pcte, int *ry, int *rheight, int cropping_min, int cropping_max) 146 composite_get_cropping_proc((*get_cropping)); 147 148 } gs_composite_type_procs_t; 149 150 typedef struct gs_composite_type_s { 151 byte comp_id; /* to identify compositor passed through command list */ 152 gs_composite_type_procs_t procs; 153 } gs_composite_type_t; 154 155 /* 156 * Default implementation for creating a compositor for clist writing. 157 * The default does nothing. 158 */ 159 composite_clist_write_update(gx_default_composite_clist_write_update); 160 161 /* Default handler for adjusting a compositor's CTM. */ 162 composite_adjust_ctm_proc(gx_default_composite_adjust_ctm); 163 164 /* Default check for closing compositor. */ 165 composite_is_closing_proc(gx_default_composite_is_closing); 166 167 /* Default check for a friendly command to a compositor. */ 168 composite_is_friendly_proc(gx_default_composite_is_friendly); 169 170 /* 171 * Default implementation for adjusting the clist reader when a compositor 172 * device is added. The default does nothing. 173 */ 174 composite_clist_read_update(gx_default_composite_clist_read_update); 175 176 /* 177 * Default implementation for get_cropping doesn't return a cropping. 178 */ 179 composite_get_cropping_proc(gx_default_composite_get_cropping); 180 181 /* 182 * Compositing objects are reference-counted, because graphics states will 183 * eventually reference them. Note that the common part has no 184 * garbage-collectible pointers and is never actually instantiated, so no 185 * structure type is needed for it. 186 */ 187 #define gs_composite_common\ 188 const gs_composite_type_t *type;\ 189 gs_id id; /* see gscompt.h */\ 190 bool idle; /* Doesn't paint anything. */\ 191 struct gs_composite_s *prev, *next /* Queue links for clist_playback_band. */ 192 193 struct gs_composite_s { 194 gs_composite_common; 195 }; 196 197 /* Replace a procedure with a macro. */ 198 #define gs_composite_id(pcte) ((pcte)->id) 199 200 #endif /* gxcomp_INCLUDED */ 201