gxdevcli.h 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612
  1. /* Copyright (C) 1997, 2000 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: gxdevcli.h,v 1.41 2005/10/12 17:59:55 leonardo Exp $ */
  14. /* Definitions for device clients */
  15. #ifndef gxdevcli_INCLUDED
  16. # define gxdevcli_INCLUDED
  17. #include "std.h" /* for FILE */
  18. #include "stdint_.h"
  19. #include "gscompt.h"
  20. #include "gsdcolor.h"
  21. #include "gsmatrix.h"
  22. #include "gsiparam.h" /* requires gsmatrix.h */
  23. #include "gsrefct.h"
  24. #include "gsropt.h"
  25. #include "gsstruct.h"
  26. #include "gstparam.h"
  27. #include "gsxfont.h"
  28. #include "gxbitmap.h"
  29. #include "gxcindex.h"
  30. #include "gxcvalue.h"
  31. #include "gxfixed.h"
  32. #include "gxtext.h"
  33. #include "gxcmap.h"
  34. /* See Drivers.htm for documentation of the driver interface. */
  35. #ifndef gx_device_DEFINED
  36. # define gx_device_DEFINED
  37. typedef struct gx_device_s gx_device;
  38. #endif
  39. /* ---------------- Memory management ---------------- */
  40. /*
  41. * NOTE: if you write code that creates device instances (either with
  42. * gs_copydevice or by allocating them explicitly), allocates device
  43. * instances as either local or static variables (actual instances, not
  44. * pointers to instances), or sets the target of forwarding devices, please
  45. * read the following documentation carefully. The rules for doing these
  46. * things changed substantially in release 5.68, in a
  47. * non-backward-compatible way, and unfortunately we could not find a way to
  48. * make the compiler give an error at places that need changing.
  49. */
  50. /*
  51. * Device instances are managed with reference counting: when the last
  52. * reference to a device from a graphics state or the target field of a
  53. * forwarding device is removed, the device is normally freed. However,
  54. * some device instances are referenced in other ways (for example, from
  55. * objects in the PostScript interpreter, or from library client code) and
  56. * will be freed by the garbage collector (if any) or explicitly: they
  57. * should not be freed by reference counting. These are called "retained"
  58. * device instances. Every device instance remembers whether or not it is
  59. * retained, and an instance is freed iff its reference count is zero and it
  60. * is not retained.
  61. *
  62. * Normally devices are initialized as not retained. However, devices
  63. * initialized by calling gx_device_init(pdev, proto, memory, false), or
  64. * created by gs_copydevice are marked as retained. You can also set the
  65. * retention status of a device explicitly with gx_device_retain(pdev,
  66. * true-or-false). Note that if you change a retained device to
  67. * non-retained, if there are no references to it from graphics states or
  68. * targets, it will be freed immediately.
  69. *
  70. * The preferred technique for creating a new device is now gs_copydevice.
  71. * There are a number of places in the code where memory is explicitly
  72. * allocated, then initialized with gx_device_init. These should gradually
  73. * be replaced.
  74. *
  75. * There are 3 ways that a device structure might be allocated:
  76. * 1) Allocated dynamically, e.g.,
  77. * gx_device *pdev_new;
  78. * gs_copydevice(&pdev_new, pdev_old, memory);
  79. * 2) Declared as a local or static variable, e.g.,
  80. * gx_device devv;
  81. * or
  82. * const gx_device devc = ...;
  83. * 3) Embedded in an object allocated in one of the above ways.
  84. * If you allocate a device using #2 or #3, you must either mark it as
  85. * retained by calling gx_device_retain(pdev, true) or initialize it with a
  86. * NULL memory. If you do not do this, an attempt will be made to free the
  87. * device, corrupting memory. Note that when memory is NULL, the finalize
  88. * method of the device will not be called when it is freed, so you cannot
  89. * use it for cleanup. */
  90. /*
  91. * Do not set the target of a forwarding device with an assignment like
  92. * fdev->target = tdev;
  93. * You must use the procedure
  94. * gx_device_set_target(fdev, tdev);
  95. * Note that the first argument is a gx_device_forward *, not a gx_device *.
  96. *
  97. * We could have changed the member name "target" when this became
  98. * necessary, so the compiler would flag places that needed editing, but
  99. * there were literally hundreds of places that only read the target member
  100. * that we would have had to change, so we decided to leave the name alone.
  101. */
  102. /* ---------------- Auxiliary types and structures ---------------- */
  103. /* We need at least an abstract type for a graphics state, */
  104. /* which is passed to the page device procedures. */
  105. #ifndef gs_state_DEFINED
  106. # define gs_state_DEFINED
  107. typedef struct gs_state_s gs_state;
  108. #endif
  109. /* We need abstract types for paths and fill/stroke parameters, */
  110. /* for the path-oriented device procedures. */
  111. #ifndef gx_path_DEFINED
  112. # define gx_path_DEFINED
  113. typedef struct gx_path_s gx_path;
  114. #endif
  115. #ifndef gx_clip_path_DEFINED
  116. # define gx_clip_path_DEFINED
  117. typedef struct gx_clip_path_s gx_clip_path;
  118. #endif
  119. #ifndef gx_fill_params_DEFINED
  120. # define gx_fill_params_DEFINED
  121. typedef struct gx_fill_params_s gx_fill_params;
  122. #endif
  123. #ifndef gx_stroke_params_DEFINED
  124. # define gx_stroke_params_DEFINED
  125. typedef struct gx_stroke_params_s gx_stroke_params;
  126. #endif
  127. #ifndef gs_imager_state_DEFINED
  128. # define gs_imager_state_DEFINED
  129. typedef struct gs_imager_state_s gs_imager_state;
  130. #endif
  131. /* We need an abstract type for the image enumeration state, */
  132. /* for begin[_typed]_image. */
  133. #ifndef gx_image_enum_common_t_DEFINED
  134. # define gx_image_enum_common_t_DEFINED
  135. typedef struct gx_image_enum_common_s gx_image_enum_common_t;
  136. #endif
  137. /* We need an abstract type for the pattern instance, */
  138. /* for pattern_manage. */
  139. #ifndef gs_pattern1_instance_t_DEFINED
  140. # define gs_pattern1_instance_t_DEFINED
  141. typedef struct gs_pattern1_instance_s gs_pattern1_instance_t;
  142. #endif
  143. /* Define the type for colors passed to the higher-level procedures. */
  144. typedef gx_device_color gx_drawing_color;
  145. /* Define a type for telling get_alpha_bits what kind of object */
  146. /* is being rendered. */
  147. typedef enum {
  148. go_text,
  149. go_graphics
  150. } graphics_object_type;
  151. /* Define an edge of a trapezoid. Requirement: end.y >= start.y. */
  152. typedef struct gs_fixed_edge_s {
  153. gs_fixed_point start;
  154. gs_fixed_point end;
  155. } gs_fixed_edge;
  156. /* Define the parameters passed to get_bits_rectangle. */
  157. #ifndef gs_get_bits_params_DEFINED
  158. # define gs_get_bits_params_DEFINED
  159. typedef struct gs_get_bits_params_s gs_get_bits_params_t;
  160. #endif
  161. /* Define the structure for device color capabilities. */
  162. typedef struct gx_device_anti_alias_info_s {
  163. int text_bits; /* 1,2,4 */
  164. int graphics_bits; /* ditto */
  165. } gx_device_anti_alias_info;
  166. typedef int32_t frac31; /* A fraction value in [-1,1].
  167. Represents a color (in [0,1])
  168. or a color difference (in [-1,1]) in shadings. */
  169. /* Define an edge of a linear color trapezoid. Requirement: end.y >= start.y. */
  170. typedef struct gs_linear_color_edge_s {
  171. gs_fixed_point start;
  172. gs_fixed_point end;
  173. const frac31 *c0, *c1;
  174. fixed clip_x;
  175. } gs_linear_color_edge;
  176. /*
  177. * Possible values for the separable_and_linear flag in the
  178. * gx_device_color_info structure. These form an order, with lower
  179. * values having weaker properties.
  180. *
  181. * GX_CINFO_SEP_LIN_UNKNOWN
  182. * The properties of the color encoding are not yet known. This is
  183. * always a safe default value.
  184. *
  185. * GX_CINFO_SEP_LIN_NONE
  186. * The encoding is not separable and linear. If this value is set,
  187. * the device must provide an encode_color method, either directly
  188. * or via map_rgb_color/map_cmyk_color methods. This setting is
  189. * only legitimate for color models with 4 or fewer components.
  190. *
  191. * GX_CINFO_SEP_LIN
  192. * A separable and linear encoding has the separability and
  193. * linearity properties.
  194. *
  195. * Encodings with this property are completely characterized
  196. * by the comp_shift array. Hence, there is no need to provide
  197. * an encode_color procedure for such devices, though the device
  198. * creator may choose to do so for performance reasons (e.g.: when
  199. * each color component is assigned a byte).
  200. */
  201. typedef enum {
  202. GX_CINFO_UNKNOWN_SEP_LIN = -1,
  203. GX_CINFO_SEP_LIN_NONE = 0,
  204. GX_CINFO_SEP_LIN
  205. } gx_color_enc_sep_lin_t;
  206. /*
  207. * Color model component polarity. An "unknown" value has been added to
  208. * this enumeration.
  209. */
  210. typedef enum {
  211. GX_CINFO_POLARITY_UNKNOWN = -1,
  212. GX_CINFO_POLARITY_SUBTRACTIVE = 0,
  213. GX_CINFO_POLARITY_ADDITIVE
  214. } gx_color_polarity_t;
  215. /*
  216. * Enumerator to indicate if a color model will support overprint mode.
  217. *
  218. * Only "DeviceCMYK" color space support this option, but we interpret
  219. * this designation some broadly: a DeviceCMYK color model is any sub-
  220. * tractive color model that provides the components Cyan, Magenta,
  221. * Yellow, and Black, and maps the DeviceCMYK space directly to these
  222. * components. This includes DeviceCMYK color models with spot colors,
  223. * and DeviceN color models that support the requisite components (the
  224. * latter may vary from Adobe's implementations; this is not easily
  225. * tested).
  226. *
  227. * In principle this parameter could be a boolean set at initialization
  228. * time. Primarily for historical reasons, the determination of whether
  229. * or not a color model supports overprint is delayed until this
  230. * information is required, hence the use of an enumeration with an
  231. * "unknown" setting.
  232. */
  233. typedef enum {
  234. GX_CINFO_OPMODE_UNKNOWN = -1,
  235. GX_CINFO_OPMODE_NOT = 0,
  236. GX_CINFO_OPMODE
  237. } gx_cm_opmode_t;
  238. /* component index value used to indicate no color component. */
  239. #define GX_CINFO_COMP_NO_INDEX 0xff
  240. /*
  241. * Additional possible value for cinfo.gray_index, to indicate which
  242. * component, if any, qualifies as the "gray" component.
  243. */
  244. #define GX_CINFO_COMP_INDEX_UNKNOWN 0xfe
  245. /*
  246. * The enlarged color model information structure: Some of the
  247. * information that was implicit in the component number in
  248. * the earlier conventions (component names, polarity, mapping
  249. * functions) are now explicitly provided.
  250. *
  251. * Also included is some information regarding the encoding of
  252. * color information into gx_color_index. Some of this information
  253. * was previously gathered indirectly from the mapping
  254. * functions in the existing code, specifically to speed up the
  255. * halftoned color rendering operator (see
  256. * gx_dc_ht_colored_fill_rectangle in gxcht.c). The information
  257. * is now provided explicitly because such optimizations are
  258. * more critical when the number of color components is large.
  259. *
  260. * Note: no pointers have been added to this structure, so there
  261. * is no requirement for a structure descriptor.
  262. */
  263. typedef struct gx_device_color_info_s {
  264. /*
  265. * max_components is the maximum number of components for all
  266. * color models supported by this device. This does not include
  267. * any alpha components.
  268. */
  269. int max_components;
  270. /*
  271. * The number of color components. This does not include any
  272. * alpha-channel information, which may be integrated into
  273. * the gx_color_index but is otherwise passed as a separate
  274. * component.
  275. */
  276. int num_components;
  277. /*
  278. * Polarity of the components of the color space, either
  279. * additive or subtractive. This is used to interpret transfer
  280. * functions and halftone threshold arrays. Possible values
  281. * are GX_CM_POLARITY_ADDITIVE or GX_CM_POLARITY_SUBTRACTIVE
  282. */
  283. gx_color_polarity_t polarity;
  284. /*
  285. * The number of bits of gx_color_index actually used.
  286. * This must be <= arch_sizeof_color_index, which is usually 64.
  287. */
  288. byte depth;
  289. /*
  290. * Index of the gray color component, if any. The max_gray and
  291. * dither_gray values apply to this component only; all other
  292. * components use the max_color and dither_color values.
  293. *
  294. * Note: This field refers to a 'gray' colorant because of the
  295. * past use of the max_gray/color and dither_grays/colors fields.
  296. * Prior to 8.00, the 'gray' values were used for monochrome
  297. * devices and the 'color' values for RGB and CMYK devices.
  298. * Ideally we would like to have the flexibiiity of allowing
  299. * different numbers of intensity levels for each colorant.
  300. * However this is not compatible with the pre 8.00 devices.
  301. * With post 8.00 devices, we can have two different numbers of
  302. * intensity levels. For one colorant (which is specified by
  303. * the gray_index) we will use the max_gray/dither_grays values.
  304. * The remaining colorants will use the max_color/dither_colors
  305. * values. The colorant which is specified by the gray_index
  306. * value does not have to be gray or black. For example if we
  307. * have an RGB device and we want 32 intensity levels for red and
  308. * blue and 64 levels for green, then we can set gray_index to
  309. * 1 (the green colorant), set max_gray to 63 and dither_grays to
  310. * 64, and set max_color to 31 and dither_colors to 32.
  311. *
  312. * This will be GX_CINFO_COMP_NO_INDEX if there is no 'gray'
  313. * component.
  314. */
  315. byte gray_index;
  316. /*
  317. * max_gray and max_color are the number of distinct native
  318. * intensity levels, less 1, for the 'gray' and all other color
  319. * components, respectively. For nearly all current devices
  320. * that support both 'gray' and non-'gray' components, the two
  321. * parameters have the same value. (See comment for gray_index.)
  322. *
  323. * dither_grays and dither_colors are the number of intensity
  324. * levels between which halftoning can occur, for the 'gra'y and
  325. * all other color components, respectively. This is
  326. * essentially redundant information: in all reasonable cases,
  327. * dither_grays = max_gray + 1 and dither_colors = max_color + 1.
  328. * These parameters are, however, extensively used in the
  329. * current code, and thus have been retained.
  330. *
  331. * Note that the non-'gray' values may now be relevant even if
  332. * num_components == 1. This simplifies the handling of devices
  333. * with configurable color models which may be set for a single
  334. * non-'gray' color model.
  335. */
  336. uint max_gray; /* # of distinct color levels -1 */
  337. uint max_color;
  338. uint dither_grays;
  339. uint dither_colors;
  340. /*
  341. * Information to control super-sampling of objects to support
  342. * anti-aliasing.
  343. */
  344. gx_device_anti_alias_info anti_alias;
  345. /*
  346. * Flag to indicate if gx_color_index for this device may be divided
  347. * into individual fields for each component. This is almost always
  348. * the case for printers, and is the case for most modern displays
  349. * as well. When this is the case, halftoning may be performed
  350. * separately for each component, which greatly simplifies processing
  351. * when the number of color components is large.
  352. *
  353. * If the gx_color_index is separable in this manner, the comp_shift
  354. * array provides the location of the low-order bit for each
  355. * component. This may be filled in by the client, but need not be.
  356. * If it is not provided, it will be calculated based on the values
  357. * in the max_gray and max_color fields as follows:
  358. *
  359. * comp_shift[num_components - 1] = 0,
  360. * comp_shift[i] = comp_shift[i + 1]
  361. * + ( i == gray_index ? ceil(log2(max_gray + 1))
  362. * : ceil(log2(max_color + 1)) )
  363. *
  364. * The comp_mask and comp_bits fields should be left empty by the client.
  365. * They will be filled in during initialization using the following
  366. * mechanism:
  367. *
  368. * comp_bits[i] = ( i == gray_index ? ceil(log2(max_gray + 1))
  369. * : ceil(log2(max_color + 1)) )
  370. *
  371. * comp_mask[i] = (((gx_color_index)1 << comp_bits[i]) - 1)
  372. * << comp_shift[i]
  373. *
  374. * (For current devices, it is almost always the case that
  375. * max_gray == max_color, if the color model contains both gray and
  376. * non-gray components.)
  377. *
  378. * If separable_and_linear is not set, the data in the other fields
  379. * is unpredictable and should be ignored.
  380. */
  381. gx_color_enc_sep_lin_t separable_and_linear;
  382. byte comp_shift[GX_DEVICE_COLOR_MAX_COMPONENTS];
  383. byte comp_bits[GX_DEVICE_COLOR_MAX_COMPONENTS];
  384. gx_color_index comp_mask[GX_DEVICE_COLOR_MAX_COMPONENTS];
  385. /*
  386. * Pointer to name for the process color model.
  387. */
  388. const char * cm_name;
  389. /*
  390. * Indicate if overprint mode is supported. This is only supported
  391. * for color models that have "DeviceCMYK" like behaivor: they support
  392. * the cyan, magenta, yellow, and black color components, and map the
  393. * components of a DeviceCMYK color space directly to these compoents.
  394. * Most such color spaces will have the name DeviceCMYK, but it is
  395. * also possible for DeviceN color models this behavior.
  396. *
  397. * If opmode has the value GX_CINFO_OPMODE, the process_comps will
  398. * be a bit mask, with the (1 << i) bit set if i'th component is the
  399. * cyan, magenta, yellow, or black component.
  400. */
  401. gx_cm_opmode_t opmode;
  402. gx_color_index process_comps;
  403. } gx_device_color_info;
  404. /* NB encoding flag ignored */
  405. #define dci_extended_alpha_values(mcmp, nc, p, d, gi, mg, \
  406. mc, dg, dc, ta, ga, sl, cn) \
  407. {mcmp /* max components */, \
  408. nc /* number components */, \
  409. p /* polarity */, \
  410. d /* depth */, \
  411. gi /* gray index */, \
  412. mg /* max gray */, \
  413. mc /* max color */, \
  414. dg /* dither grays */, \
  415. dc /* dither colors */, \
  416. { ta, ga } /* antialias info text, graphics */, \
  417. sl /* separable_and_linear */, \
  418. { 0 } /* component shift */, \
  419. { 0 } /* component bits */, \
  420. { 0 } /* component mask */, \
  421. cn /* process color name */,\
  422. GX_CINFO_OPMODE_UNKNOWN /* opmode */,\
  423. 0 /* process_cmps */ }
  424. /*
  425. * The "has color" macro requires a slightly different definition
  426. * with the more general color models.
  427. */
  428. #define gx_device_has_color(dev) \
  429. ( (dev)->color_info.num_components > 1 || \
  430. (dev)->color_info.gray_index == GX_CINFO_COMP_NO_INDEX )
  431. /* parameter initialization macros for backwards compatibility */
  432. /*
  433. * These macros are needed to define values for fields added when
  434. * DeviceN compatibility was added. Previously the graphics
  435. * library and the much of the device code examined the number of
  436. * components and assume that 1 --> DeviceGray, 3-->DeviceRGB,
  437. * and 4--> DeviceCMYK. Since the old device code does not
  438. * specify a color model, these macros make the same assumption.
  439. * This assumption is incorrect for a DeviceN device and thus
  440. * the following macros should not be used. The previously
  441. * defined macros should be used for new devices.
  442. */
  443. #define dci_std_cm_name(nc) \
  444. ( (nc) == 1 ? "DeviceGray" \
  445. : ((nc) == 3 ? "DeviceRGB" \
  446. : "DeviceCMYK") )
  447. #define dci_std_polarity(nc) \
  448. ( (nc) == 4 ? GX_CINFO_POLARITY_SUBTRACTIVE \
  449. : GX_CINFO_POLARITY_ADDITIVE )
  450. /*
  451. * Get the default gray_index value, based on the number of color
  452. * components. Note that this must be consistent with the index
  453. * implicitly used by the get_color_comp_index method and the
  454. * procedures in the structure returned by the
  455. * get_color_mapping_procs method.
  456. */
  457. #define dci_std_gray_index(nc) \
  458. ((nc) == 3 ? GX_CINFO_COMP_NO_INDEX : (nc) - 1)
  459. #define dci_alpha_values(nc, depth, mg, mc, dg, dc, ta, ga) \
  460. dci_extended_alpha_values(nc, nc, \
  461. dci_std_polarity(nc), \
  462. depth, \
  463. dci_std_gray_index(nc), \
  464. mg, mc, dg, dc, ta, ga, \
  465. GX_CINFO_UNKNOWN_SEP_LIN, \
  466. dci_std_cm_name(nc) )
  467. /*
  468. * Determine the depth corresponding to a color_bits specification.
  469. * Note that color_bits == 0 ==> depth == 0; surprisingly this
  470. * case is used.
  471. */
  472. #define dci_std_color_depth(color_bits) \
  473. ((color_bits) == 1 ? 1 : ((color_bits) + 7) & ~7)
  474. /*
  475. * Determine the number of components corresponding to a color_bits
  476. * specification. A device is monochrome only if it is bi-level;
  477. * the 4 and 8 bit cases are handled as mapped color displays (for
  478. * compatibility with existing code). The peculiar color_bits = 0
  479. * case is considered monochrome, for no apparent reason.
  480. */
  481. #define dci_std_color_num_components(color_bits) \
  482. ( (color_bits) <= 1 ? 1 \
  483. : ((color_bits) % 3 == 0 || \
  484. (color_bits) == 4 || \
  485. (color_bits) == 8 ) ? 3 : 4 )
  486. /*
  487. * The number of bits assigned to the gray/black color component,
  488. * assuming there is such a component. The underlying assumption
  489. * is that any extra bits are assigned to this component.
  490. */
  491. #define dci_std_gray_bits(nc, color_bits) \
  492. ((color_bits) - ((nc) - 1) * ((color_bits) / (nc)))
  493. /*
  494. * The number of bits assigned to a color component. The underlying
  495. * assumptions are that there is a gray component if nc != 3, and
  496. * that the gray component uses any extra bits.
  497. */
  498. #define dci_std_color_bits(nc, color_bits) \
  499. ( (nc) == 3 \
  500. ? (color_bits) / (nc) \
  501. : ( (nc) == 1 \
  502. ? 0 \
  503. : ((color_bits) - dci_std_gray_bits(nc, color_bits))\
  504. / ((nc) == 1 ? (1) : (nc) - 1) ) )
  505. /*
  506. * Determine the max_gray and max_color values based on the number
  507. * of components and the color_bits value. See the comments above
  508. * for information on the underlying assumptions.
  509. */
  510. #define dci_std_color_max_gray(nc, color_bits) \
  511. ( (nc) == 3 \
  512. ? 0 \
  513. : (1 << dci_std_gray_bits(nc, color_bits)) - 1 )
  514. #define dci_std_color_max_color(nc, color_bits) \
  515. ( (nc) == 1 \
  516. ? 0 \
  517. : (1 << dci_std_color_bits(nc, color_bits)) - 1 )
  518. /*
  519. * Define a color model based strictly on the number of bits
  520. * available for color representation. Please note, this is only
  521. * intended to work for a limited set of devices.
  522. */
  523. #define dci_std_color_(nc, color_bits) \
  524. dci_values( nc, \
  525. dci_std_color_depth(color_bits), \
  526. dci_std_color_max_gray(nc, color_bits), \
  527. dci_std_color_max_color(nc, color_bits), \
  528. dci_std_color_max_gray(nc, color_bits) + 1, \
  529. dci_std_color_max_color(nc, color_bits) + 1 )
  530. #define dci_std_color(color_bits) \
  531. dci_std_color_( dci_std_color_num_components(color_bits), \
  532. color_bits )
  533. #define dci_values(nc,depth,mg,mc,dg,dc)\
  534. dci_alpha_values(nc, depth, mg, mc, dg, dc, 1, 1)
  535. #define dci_black_and_white dci_std_color(1)
  536. #define dci_black_and_white_() dci_black_and_white
  537. #define dci_color(depth,maxv,dither)\
  538. dci_values(3, depth, maxv, maxv, dither, dither)
  539. /*
  540. * Macro to access the name of the process color model.
  541. */
  542. #define get_process_color_model_name(dev) \
  543. ((dev)->color_info.cm_name)
  544. /* Structure for device procedures. */
  545. typedef struct gx_device_procs_s gx_device_procs;
  546. /* Structure for page device procedures. */
  547. /* Note that these take the graphics state as a parameter. */
  548. typedef struct gx_page_device_procs_s {
  549. #define dev_page_proc_install(proc)\
  550. int proc(gx_device *dev, gs_state *pgs)
  551. dev_page_proc_install((*install));
  552. #define dev_page_proc_begin_page(proc)\
  553. int proc(gx_device *dev, gs_state *pgs)
  554. dev_page_proc_begin_page((*begin_page));
  555. #define dev_page_proc_end_page(proc)\
  556. int proc(gx_device *dev, int reason, gs_state *pgs)
  557. dev_page_proc_end_page((*end_page));
  558. } gx_page_device_procs;
  559. /* Default procedures */
  560. dev_page_proc_install(gx_default_install);
  561. dev_page_proc_begin_page(gx_default_begin_page);
  562. dev_page_proc_end_page(gx_default_end_page);
  563. /* ---------------- Device structure ---------------- */
  564. /*
  565. * Define the generic device structure. The device procedures can
  566. * have two different configurations:
  567. *
  568. * - Statically initialized devices predating release 2.8.1
  569. * set the static_procs pointer to point to a separate procedure record,
  570. * and do not initialize procs.
  571. *
  572. * - Statically initialized devices starting with release 2.8.1,
  573. * and all dynamically created device instances,
  574. * set the static_procs pointer to 0, and initialize procs.
  575. *
  576. * The gx_device_set_procs procedure converts the first of these to
  577. * the second, which is what all client code starting in 2.8.1 expects
  578. * (using the procs record, not the static_procs pointer, to call the
  579. * driver procedures).
  580. *
  581. * The choice of the name Margins (rather than, say, HWOffset), and the
  582. * specification in terms of a default device resolution rather than
  583. * 1/72" units, are due to Adobe.
  584. *
  585. * ****** NOTE: If you define any subclasses of gx_device, you *must* define
  586. * ****** the finalization procedure as gx_device_finalize. Finalization
  587. * ****** procedures are not automatically inherited.
  588. */
  589. typedef struct gx_device_cached_colors_s {
  590. gx_color_index black, white;
  591. } gx_device_cached_colors_t;
  592. #define gx_device_common\
  593. int params_size; /* OBSOLETE if stype != 0: */\
  594. /* size of this structure */\
  595. const gx_device_procs *static_procs; /* OBSOLETE */\
  596. /* pointer to procs */\
  597. const char *dname; /* the device name */\
  598. gs_memory_t *memory; /* (0 iff static prototype) */\
  599. gs_memory_type_ptr_t stype; /* memory manager structure type, */\
  600. /* may be 0 if static prototype */\
  601. bool stype_is_dynamic; /* if true, free the stype when */\
  602. /* freeing the device */\
  603. void (*finalize)(gx_device *); /* finalization to execute */\
  604. /* before closing device, if any */\
  605. rc_header rc; /* reference count from gstates */\
  606. /* and targets, +1 if retained */\
  607. bool retained; /* true if retained */\
  608. bool is_open; /* true if device has been opened */\
  609. int max_fill_band; /* limit on band size for fill, */\
  610. /* must be 0 or a power of 2 */\
  611. /* (see gdevabuf.c for more info) */\
  612. gx_device_color_info color_info; /* color information */\
  613. gx_device_cached_colors_t cached_colors;\
  614. int width; /* width in pixels */\
  615. int height; /* height in pixels */\
  616. int TrayOrientation; /* default 0 ( 90 180 270 ) if device supports */\
  617. float MediaSize[2]; /* media dimensions in points */\
  618. float ImagingBBox[4]; /* imageable region in points */\
  619. bool ImagingBBox_set;\
  620. float HWResolution[2]; /* resolution, dots per inch */\
  621. float MarginsHWResolution[2]; /* resolution for Margins */\
  622. float Margins[2]; /* offset of physical page corner */\
  623. /* from device coordinate (0,0), */\
  624. /* in units given by MarginsHWResolution */\
  625. float HWMargins[4]; /* margins around imageable area, */\
  626. /* in default user units ("points") */\
  627. long PageCount; /* number of pages written */\
  628. long ShowpageCount; /* number of calls on showpage */\
  629. int NumCopies;\
  630. bool NumCopies_set;\
  631. bool IgnoreNumCopies; /* if true, force num_copies = 1 */\
  632. bool UseCIEColor; /* for PS LL3 */\
  633. bool LockSafetyParams; /* If true, prevent unsafe changes */\
  634. gx_page_device_procs page_procs; /* must be last */\
  635. /* end of std_device_body */\
  636. gx_device_procs procs /* object procedures */
  637. /*
  638. * Note: x/y_pixels_per_inch are here only for backward compatibility.
  639. * They should not be used in new code.
  640. */
  641. #define x_pixels_per_inch HWResolution[0]
  642. #define y_pixels_per_inch HWResolution[1]
  643. #define offset_margin_values(x, y, left, bot, right, top)\
  644. {x, y}, {left, bot, right, top}
  645. #define margin_values(left, bot, right, top)\
  646. offset_margin_values(0, 0, left, bot, right, top)
  647. #define no_margins margin_values(0, 0, 0, 0)
  648. #define no_margins_() no_margins
  649. /* Define macros that give the page offset ("Margins") in inches. */
  650. #define dev_x_offset(dev) ((dev)->Margins[0] / (dev)->MarginsHWResolution[0])
  651. #define dev_y_offset(dev) ((dev)->Margins[1] / (dev)->MarginsHWResolution[1])
  652. #define dev_y_offset_points(dev) (dev_y_offset(dev) * 72.0)
  653. /* Note that left/right/top/bottom are defined relative to */
  654. /* the physical paper, not the coordinate system. */
  655. /* For backward compatibility, we define macros that give */
  656. /* the margins in inches. */
  657. #define dev_l_margin(dev) ((dev)->HWMargins[0] / 72.0)
  658. #define dev_b_margin(dev) ((dev)->HWMargins[1] / 72.0)
  659. #define dev_b_margin_points(dev) ((dev)->HWMargins[1])
  660. #define dev_r_margin(dev) ((dev)->HWMargins[2] / 72.0)
  661. #define dev_t_margin(dev) ((dev)->HWMargins[3] / 72.0)
  662. #define dev_t_margin_points(dev) ((dev)->HWMargins[3])
  663. /* The extra () are to prevent premature expansion. */
  664. #define open_init_closed() 0 /*false*/, 0 /* max_fill_band */
  665. #define open_init_open() 1 /*true*/, 0 /* max_fill_band */
  666. /* Accessors for device procedures */
  667. #define dev_proc(dev, p) ((dev)->procs.p)
  668. #define set_dev_proc(dev, p, proc) ((dev)->procs.p = (proc))
  669. #define fill_dev_proc(dev, p, dproc)\
  670. if ( dev_proc(dev, p) == 0 ) set_dev_proc(dev, p, dproc)
  671. #define assign_dev_procs(todev, fromdev)\
  672. ((todev)->procs = (fromdev)->procs)
  673. /* ---------------- Device procedures ---------------- */
  674. /* Define an opaque type for parameter lists. */
  675. #ifndef gs_param_list_DEFINED
  676. # define gs_param_list_DEFINED
  677. typedef struct gs_param_list_s gs_param_list;
  678. #endif
  679. /*
  680. * Definition of device procedures.
  681. * Note that the gx_device * argument is not declared const,
  682. * because many drivers maintain dynamic state in the device structure.
  683. * Note also that the structure is defined as a template, so that
  684. * we can instantiate it with device subclasses.
  685. * Because C doesn't have real templates, we must do this with macros.
  686. */
  687. /* Define macros for declaring device procedures. */
  688. #define dev_t_proc_open_device(proc, dev_t)\
  689. int proc(dev_t *dev)
  690. #define dev_proc_open_device(proc)\
  691. dev_t_proc_open_device(proc, gx_device)
  692. #define dev_t_proc_get_initial_matrix(proc, dev_t)\
  693. void proc(dev_t *dev, gs_matrix *pmat)
  694. #define dev_proc_get_initial_matrix(proc)\
  695. dev_t_proc_get_initial_matrix(proc, gx_device)
  696. #define dev_t_proc_sync_output(proc, dev_t)\
  697. int proc(dev_t *dev)
  698. #define dev_proc_sync_output(proc)\
  699. dev_t_proc_sync_output(proc, gx_device)
  700. #define dev_t_proc_output_page(proc, dev_t)\
  701. int proc(dev_t *dev, int num_copies, int flush)
  702. #define dev_proc_output_page(proc)\
  703. dev_t_proc_output_page(proc, gx_device)
  704. #define dev_t_proc_close_device(proc, dev_t)\
  705. int proc(dev_t *dev)
  706. #define dev_proc_close_device(proc)\
  707. dev_t_proc_close_device(proc, gx_device)
  708. #define dev_t_proc_map_rgb_color(proc, dev_t)\
  709. gx_color_index proc(dev_t *dev, const gx_color_value cv[])
  710. #define dev_proc_map_rgb_color(proc)\
  711. dev_t_proc_map_rgb_color(proc, gx_device)
  712. #define dev_t_proc_map_color_rgb(proc, dev_t)\
  713. int proc(dev_t *dev,\
  714. gx_color_index color, gx_color_value rgb[3])
  715. #define dev_proc_map_color_rgb(proc)\
  716. dev_t_proc_map_color_rgb(proc, gx_device)
  717. #define dev_t_proc_fill_rectangle(proc, dev_t)\
  718. int proc(dev_t *dev,\
  719. int x, int y, int width, int height, gx_color_index color)
  720. #define dev_proc_fill_rectangle(proc)\
  721. dev_t_proc_fill_rectangle(proc, gx_device)
  722. #define dev_t_proc_tile_rectangle(proc, dev_t)\
  723. int proc(dev_t *dev,\
  724. const gx_tile_bitmap *tile, int x, int y, int width, int height,\
  725. gx_color_index color0, gx_color_index color1,\
  726. int phase_x, int phase_y)
  727. #define dev_proc_tile_rectangle(proc)\
  728. dev_t_proc_tile_rectangle(proc, gx_device)
  729. #define dev_t_proc_copy_mono(proc, dev_t)\
  730. int proc(dev_t *dev,\
  731. const byte *data, int data_x, int raster, gx_bitmap_id id,\
  732. int x, int y, int width, int height,\
  733. gx_color_index color0, gx_color_index color1)
  734. #define dev_proc_copy_mono(proc)\
  735. dev_t_proc_copy_mono(proc, gx_device)
  736. #define dev_t_proc_copy_color(proc, dev_t)\
  737. int proc(dev_t *dev,\
  738. const byte *data, int data_x, int raster, gx_bitmap_id id,\
  739. int x, int y, int width, int height)
  740. #define dev_proc_copy_color(proc)\
  741. dev_t_proc_copy_color(proc, gx_device)
  742. /* OBSOLETED in release 3.66 */
  743. #define dev_t_proc_draw_line(proc, dev_t)\
  744. int proc(dev_t *dev,\
  745. int x0, int y0, int x1, int y1, gx_color_index color)
  746. #define dev_proc_draw_line(proc)\
  747. dev_t_proc_draw_line(proc, gx_device)
  748. /* Added in release 2.4 */
  749. #define dev_t_proc_get_bits(proc, dev_t)\
  750. int proc(dev_t *dev,\
  751. int y, byte *data, byte **actual_data)
  752. #define dev_proc_get_bits(proc)\
  753. dev_t_proc_get_bits(proc, gx_device)
  754. /* Added in release 2.4, changed in 2.8, */
  755. /* renamed in 2.9.6 */
  756. #define dev_t_proc_get_params(proc, dev_t)\
  757. int proc(dev_t *dev, gs_param_list *plist)
  758. #define dev_proc_get_params(proc)\
  759. dev_t_proc_get_params(proc, gx_device)
  760. #define dev_t_proc_put_params(proc, dev_t)\
  761. int proc(dev_t *dev, gs_param_list *plist)
  762. #define dev_proc_put_params(proc)\
  763. dev_t_proc_put_params(proc, gx_device)
  764. /* Added in release 2.6 */
  765. #define dev_t_proc_map_cmyk_color(proc, dev_t)\
  766. gx_color_index proc(dev_t *dev, const gx_color_value cv[])
  767. #define dev_proc_map_cmyk_color(proc)\
  768. dev_t_proc_map_cmyk_color(proc, gx_device)
  769. #define dev_t_proc_get_xfont_procs(proc, dev_t)\
  770. const gx_xfont_procs *proc(dev_t *dev)
  771. #define dev_proc_get_xfont_procs(proc)\
  772. dev_t_proc_get_xfont_procs(proc, gx_device)
  773. /* Added in release 2.6.1 */
  774. #define dev_t_proc_get_xfont_device(proc, dev_t)\
  775. gx_device *proc(dev_t *dev)
  776. #define dev_proc_get_xfont_device(proc)\
  777. dev_t_proc_get_xfont_device(proc, gx_device)
  778. /* Added in release 2.7.1 */
  779. #define dev_t_proc_map_rgb_alpha_color(proc, dev_t)\
  780. gx_color_index proc(dev_t *dev,\
  781. gx_color_value red, gx_color_value green, gx_color_value blue,\
  782. gx_color_value alpha)
  783. #define dev_proc_map_rgb_alpha_color(proc)\
  784. dev_t_proc_map_rgb_alpha_color(proc, gx_device)
  785. /* Added in release 2.8.1 */
  786. #define dev_t_proc_get_page_device(proc, dev_t)\
  787. gx_device *proc(dev_t *dev)
  788. #define dev_proc_get_page_device(proc)\
  789. dev_t_proc_get_page_device(proc, gx_device)
  790. /* Added in release 3.20, OBSOLETED in 5.65 */
  791. #define dev_t_proc_get_alpha_bits(proc, dev_t)\
  792. int proc(dev_t *dev, graphics_object_type type)
  793. #define dev_proc_get_alpha_bits(proc)\
  794. dev_t_proc_get_alpha_bits(proc, gx_device)
  795. /* Added in release 3.20 */
  796. #define dev_t_proc_copy_alpha(proc, dev_t)\
  797. int proc(dev_t *dev, const byte *data, int data_x,\
  798. int raster, gx_bitmap_id id, int x, int y, int width, int height,\
  799. gx_color_index color, int depth)
  800. #define dev_proc_copy_alpha(proc)\
  801. dev_t_proc_copy_alpha(proc, gx_device)
  802. /* Added in release 3.38 */
  803. #define dev_t_proc_get_band(proc, dev_t)\
  804. int proc(dev_t *dev, int y, int *band_start)
  805. #define dev_proc_get_band(proc)\
  806. dev_t_proc_get_band(proc, gx_device)
  807. /* Added in release 3.44 */
  808. #define dev_t_proc_copy_rop(proc, dev_t)\
  809. int proc(dev_t *dev,\
  810. const byte *sdata, int sourcex, uint sraster, gx_bitmap_id id,\
  811. const gx_color_index *scolors,\
  812. const gx_tile_bitmap *texture, const gx_color_index *tcolors,\
  813. int x, int y, int width, int height,\
  814. int phase_x, int phase_y, gs_logical_operation_t lop)
  815. #define dev_proc_copy_rop(proc)\
  816. dev_t_proc_copy_rop(proc, gx_device)
  817. /* Added in release 3.60, changed in 3.68. */
  818. #define dev_t_proc_fill_path(proc, dev_t)\
  819. int proc(dev_t *dev,\
  820. const gs_imager_state *pis, gx_path *ppath,\
  821. const gx_fill_params *params,\
  822. const gx_drawing_color *pdcolor, const gx_clip_path *pcpath)
  823. #define dev_proc_fill_path(proc)\
  824. dev_t_proc_fill_path(proc, gx_device)
  825. #define dev_t_proc_stroke_path(proc, dev_t)\
  826. int proc(dev_t *dev,\
  827. const gs_imager_state *pis, gx_path *ppath,\
  828. const gx_stroke_params *params,\
  829. const gx_drawing_color *pdcolor, const gx_clip_path *pcpath)
  830. #define dev_proc_stroke_path(proc)\
  831. dev_t_proc_stroke_path(proc, gx_device)
  832. /* Added in release 3.60 */
  833. #define dev_t_proc_fill_mask(proc, dev_t)\
  834. int proc(dev_t *dev,\
  835. const byte *data, int data_x, int raster, gx_bitmap_id id,\
  836. int x, int y, int width, int height,\
  837. const gx_drawing_color *pdcolor, int depth,\
  838. gs_logical_operation_t lop, const gx_clip_path *pcpath)
  839. #define dev_proc_fill_mask(proc)\
  840. dev_t_proc_fill_mask(proc, gx_device)
  841. /* Added in release 3.66, changed in 3.69 */
  842. #define dev_t_proc_fill_trapezoid(proc, dev_t)\
  843. int proc(dev_t *dev,\
  844. const gs_fixed_edge *left, const gs_fixed_edge *right,\
  845. fixed ybot, fixed ytop, bool swap_axes,\
  846. const gx_drawing_color *pdcolor, gs_logical_operation_t lop)
  847. #define dev_proc_fill_trapezoid(proc)\
  848. dev_t_proc_fill_trapezoid(proc, gx_device)
  849. #define dev_t_proc_fill_parallelogram(proc, dev_t)\
  850. int proc(dev_t *dev,\
  851. fixed px, fixed py, fixed ax, fixed ay, fixed bx, fixed by,\
  852. const gx_drawing_color *pdcolor, gs_logical_operation_t lop)
  853. #define dev_proc_fill_parallelogram(proc)\
  854. dev_t_proc_fill_parallelogram(proc, gx_device)
  855. #define dev_t_proc_fill_triangle(proc, dev_t)\
  856. int proc(dev_t *dev,\
  857. fixed px, fixed py, fixed ax, fixed ay, fixed bx, fixed by,\
  858. const gx_drawing_color *pdcolor, gs_logical_operation_t lop)
  859. #define dev_proc_fill_triangle(proc)\
  860. dev_t_proc_fill_triangle(proc, gx_device)
  861. #define dev_t_proc_draw_thin_line(proc, dev_t)\
  862. int proc(dev_t *dev,\
  863. fixed fx0, fixed fy0, fixed fx1, fixed fy1,\
  864. const gx_drawing_color *pdcolor, gs_logical_operation_t lop)
  865. #define dev_proc_draw_thin_line(proc)\
  866. dev_t_proc_draw_thin_line(proc, gx_device)
  867. /* Added in release 3.66 (as stubs); */
  868. /* changed in 3.68; */
  869. /* begin_image and image_data changed in 4.30, */
  870. /* begin_image changed in 5.23. */
  871. #define dev_t_proc_begin_image(proc, dev_t)\
  872. int proc(dev_t *dev,\
  873. const gs_imager_state *pis, const gs_image_t *pim,\
  874. gs_image_format_t format, const gs_int_rect *prect,\
  875. const gx_drawing_color *pdcolor, const gx_clip_path *pcpath,\
  876. gs_memory_t *memory, gx_image_enum_common_t **pinfo)
  877. #define dev_proc_begin_image(proc)\
  878. dev_t_proc_begin_image(proc, gx_device)
  879. /* OBSOLETED in release 5.23 */
  880. #define dev_t_proc_image_data(proc, dev_t)\
  881. int proc(dev_t *dev,\
  882. gx_image_enum_common_t *info, const byte **planes, int data_x,\
  883. uint raster, int height)
  884. #define dev_proc_image_data(proc)\
  885. dev_t_proc_image_data(proc, gx_device)
  886. /* OBSOLETED in release 5.23 */
  887. #define dev_t_proc_end_image(proc, dev_t)\
  888. int proc(dev_t *dev,\
  889. gx_image_enum_common_t *info, bool draw_last)
  890. #define dev_proc_end_image(proc)\
  891. dev_t_proc_end_image(proc, gx_device)
  892. /* Added in release 3.68 */
  893. #define dev_t_proc_strip_tile_rectangle(proc, dev_t)\
  894. int proc(dev_t *dev,\
  895. const gx_strip_bitmap *tiles, int x, int y, int width, int height,\
  896. gx_color_index color0, gx_color_index color1,\
  897. int phase_x, int phase_y)
  898. #define dev_proc_strip_tile_rectangle(proc)\
  899. dev_t_proc_strip_tile_rectangle(proc, gx_device)
  900. #define dev_t_proc_strip_copy_rop(proc, dev_t)\
  901. int proc(dev_t *dev,\
  902. const byte *sdata, int sourcex, uint sraster, gx_bitmap_id id,\
  903. const gx_color_index *scolors,\
  904. const gx_strip_bitmap *textures, const gx_color_index *tcolors,\
  905. int x, int y, int width, int height,\
  906. int phase_x, int phase_y, gs_logical_operation_t lop)
  907. #define dev_proc_strip_copy_rop(proc)\
  908. dev_t_proc_strip_copy_rop(proc, gx_device)
  909. /* Added in release 4.20 */
  910. #define dev_t_proc_get_clipping_box(proc, dev_t)\
  911. void proc(dev_t *dev, gs_fixed_rect *pbox)
  912. #define dev_proc_get_clipping_box(proc)\
  913. dev_t_proc_get_clipping_box(proc, gx_device)
  914. /* Added in release 5.20, changed in 5.23 */
  915. #define dev_t_proc_begin_typed_image(proc, dev_t)\
  916. int proc(dev_t *dev,\
  917. const gs_imager_state *pis, const gs_matrix *pmat,\
  918. const gs_image_common_t *pim, const gs_int_rect *prect,\
  919. const gx_drawing_color *pdcolor, const gx_clip_path *pcpath,\
  920. gs_memory_t *memory, gx_image_enum_common_t **pinfo)
  921. #define dev_proc_begin_typed_image(proc)\
  922. dev_t_proc_begin_typed_image(proc, gx_device)
  923. /* Added in release 5.20 */
  924. #define dev_t_proc_get_bits_rectangle(proc, dev_t)\
  925. int proc(dev_t *dev, const gs_int_rect *prect,\
  926. gs_get_bits_params_t *params, gs_int_rect **unread)
  927. #define dev_proc_get_bits_rectangle(proc)\
  928. dev_t_proc_get_bits_rectangle(proc, gx_device)
  929. #define dev_t_proc_map_color_rgb_alpha(proc, dev_t)\
  930. int proc(dev_t *dev,\
  931. gx_color_index color, gx_color_value rgba[4])
  932. #define dev_proc_map_color_rgb_alpha(proc)\
  933. dev_t_proc_map_color_rgb_alpha(proc, gx_device)
  934. #define dev_t_proc_create_compositor(proc, dev_t)\
  935. int proc(dev_t *dev,\
  936. gx_device **pcdev, const gs_composite_t *pcte,\
  937. gs_imager_state *pis, gs_memory_t *memory)
  938. #define dev_proc_create_compositor(proc)\
  939. dev_t_proc_create_compositor(proc, gx_device)\
  940. /* Added in release 5.23 */
  941. #define dev_t_proc_get_hardware_params(proc, dev_t)\
  942. int proc(dev_t *dev, gs_param_list *plist)
  943. #define dev_proc_get_hardware_params(proc)\
  944. dev_t_proc_get_hardware_params(proc, gx_device)
  945. /* Added in release 5.24 */
  946. /* ... text_begin ... see gxtext.h for definition */
  947. /* Added in release 6.23 */
  948. #define dev_t_proc_finish_copydevice(proc, dev_t)\
  949. int proc(dev_t *dev, const gx_device *from_dev)
  950. #define dev_proc_finish_copydevice(proc)\
  951. dev_t_proc_finish_copydevice(proc, gx_device)
  952. /* Added in release 6.61 (raph) */
  953. /*
  954. This area of the transparency facilities is in flux. Here is a proposal
  955. for extending the driver interface.
  956. */
  957. /*
  958. Push the current transparency state (*ppts) onto the associated stack,
  959. and set *ppts to a new transparency state of the given dimension. The
  960. transparency state may copy some or all of the imager state, such as the
  961. current alpha and/or transparency mask values, and definitely copies the
  962. parameters.
  963. */
  964. #define dev_t_proc_begin_transparency_group(proc, dev_t)\
  965. int proc(gx_device *dev,\
  966. const gs_transparency_group_params_t *ptgp,\
  967. const gs_rect *pbbox,\
  968. gs_imager_state *pis,\
  969. gs_transparency_state_t **ppts,\
  970. gs_memory_t *mem)
  971. #define dev_proc_begin_transparency_group(proc)\
  972. dev_t_proc_begin_transparency_group(proc, gx_device)
  973. /*
  974. End a transparency group: blend the top element of the transparency
  975. stack, which must be a group, into the next-to-top element, popping the
  976. stack. If the stack only had a single element, blend into the device
  977. output. Set *ppts to 0 iff the stack is now empty. If end_group fails,
  978. the stack is *not* popped.
  979. */
  980. #define dev_t_proc_end_transparency_group(proc, dev_t)\
  981. int proc(gx_device *dev,\
  982. gs_imager_state *pis,\
  983. gs_transparency_state_t **ppts)
  984. #define dev_proc_end_transparency_group(proc)\
  985. dev_t_proc_end_transparency_group(proc, gx_device)
  986. /*
  987. Push the transparency state and prepare to render a transparency mask.
  988. This is similar to begin_transparency_group except that it only
  989. accumulates coverage values, not full pixel values.
  990. */
  991. #define dev_t_proc_begin_transparency_mask(proc, dev_t)\
  992. int proc(gx_device *dev,\
  993. const gx_transparency_mask_params_t *ptmp,\
  994. const gs_rect *pbbox,\
  995. gs_imager_state *pis,\
  996. gs_transparency_state_t **ppts,\
  997. gs_memory_t *mem)
  998. #define dev_proc_begin_transparency_mask(proc)\
  999. dev_t_proc_begin_transparency_mask(proc, gx_device)
  1000. /*
  1001. Store a pointer to the rendered transparency mask into *pptm, popping the
  1002. stack like end_group. Normally, the client will follow this by using
  1003. rc_assign to store the rendered mask into pis->{opacity,shape}.mask. If
  1004. end_mask fails, the stack is *not* popped.
  1005. */
  1006. #define dev_t_proc_end_transparency_mask(proc, dev_t)\
  1007. int proc(gx_device *dev,\
  1008. gs_transparency_mask_t **pptm)
  1009. #define dev_proc_end_transparency_mask(proc)\
  1010. dev_t_proc_end_transparency_mask(proc, gx_device)
  1011. /*
  1012. Pop the transparency stack, discarding the top element, which may be
  1013. either a group or a mask. Set *ppts to 0 iff the stack is now empty.
  1014. */
  1015. #define dev_t_proc_discard_transparency_layer(proc, dev_t)\
  1016. int proc(gx_device *dev,\
  1017. gs_transparency_state_t **ppts)
  1018. #define dev_proc_discard_transparency_layer(proc)\
  1019. dev_t_proc_discard_transparency_layer(proc, gx_device)
  1020. /* (end of transparency driver interface extensions) */
  1021. /* (start of DeviceN color support) */
  1022. /*
  1023. * The following macros are defined in gxcmap.h
  1024. *
  1025. * dev_t_proc_get_color_mapping_procs
  1026. * dev_proc_get_color_mapping_procs
  1027. * dev_t_proc_get_color_comp_index
  1028. * dev_proc_get_color_comp_index
  1029. * dev_t_proc_encode_color
  1030. * dev_proc_encode_color
  1031. * dev_t_proc_decode_color
  1032. * dev_proc_decode_color
  1033. */
  1034. /* (end of DeviceN color support) */
  1035. /*
  1036. Pattern management for high level devices.
  1037. Now we need it for PatternType 1 only.
  1038. Return codes :
  1039. 1 - the device handles high level patterns.
  1040. 0 - the device needs low level pattern tiles.
  1041. <0 - error.
  1042. */
  1043. /* High level device support. */
  1044. typedef enum {
  1045. pattern_manage__can_accum,
  1046. pattern_manage__start_accum,
  1047. pattern_manage__finish_accum,
  1048. pattern_manage__load,
  1049. pattern_manage__shading_area
  1050. } pattern_manage_t;
  1051. #define dev_t_proc_pattern_manage(proc, dev_t)\
  1052. int proc(gx_device *pdev, gx_bitmap_id id,\
  1053. gs_pattern1_instance_t *pinst, pattern_manage_t function)
  1054. #define dev_proc_pattern_manage(proc)\
  1055. dev_t_proc_pattern_manage(proc, gx_device)
  1056. /*
  1057. Fill rectangle with a high level color.
  1058. Return rangecheck, if the device can't handle the high level color.
  1059. The graphics library calls this function with degenerate (widths=0)
  1060. rectangles, to know whether the device can handle a rectangle with
  1061. the high level color. The device should skip such rectangles returning
  1062. a proper code.
  1063. Currently this function is used with gs_rectfill and gs_fillpage only.
  1064. In future it should be called while decomposing other objects.
  1065. */
  1066. #define dev_t_proc_fill_rectangle_hl_color(proc, dev_t)\
  1067. int proc(dev_t *dev, const gs_fixed_rect *rect, \
  1068. const gs_imager_state *pis, const gx_drawing_color *pdcolor, \
  1069. const gx_clip_path *pcpath)
  1070. #define dev_proc_fill_rectangle_hl_color(proc)\
  1071. dev_t_proc_fill_rectangle_hl_color(proc, gx_device)
  1072. /*
  1073. Include a color space into the output.
  1074. This function is used to include DefaultGray, DefaultRGB,
  1075. DefaultCMYK into PDF, PS, EPS output.
  1076. Low level devices should ignore this call.
  1077. */
  1078. #define dev_t_proc_include_color_space(proc, dev_t)\
  1079. int proc(dev_t *dev, gs_color_space *cspace, const byte *res_name, int name_length)
  1080. #define dev_proc_include_color_space(proc)\
  1081. dev_t_proc_include_color_space(proc, gx_device)
  1082. /* Shading support. */
  1083. typedef struct gs_fill_attributes_s {
  1084. const gs_fixed_rect *clip;
  1085. bool swap_axes;
  1086. const gx_device_halftone *ht; /* Reserved for possible use in future. */
  1087. gs_logical_operation_t lop; /* Reserved for possible use in future. */
  1088. fixed ystart, yend; /* Only for X-independent gradients. Base coordinates of the gradient. */
  1089. } gs_fill_attributes;
  1090. /* Fill a linear color scanline. */
  1091. #define dev_t_proc_fill_linear_color_scanline(proc, dev_t)\
  1092. int proc(dev_t *dev, const gs_fill_attributes *fa,\
  1093. int i, int j, int w, /* scanline coordinates and width */\
  1094. const frac31 *c0, /* initial color for the pixel (i,j), the integer part */\
  1095. const int32_t *c0_f, /* initial color for the pixel (i,j), the fraction part numerator */\
  1096. const int32_t *cg_num, /* color gradient numerator */\
  1097. int32_t cg_den /* color gradient denominator */)
  1098. #define dev_proc_fill_linear_color_scanline(proc)\
  1099. dev_t_proc_fill_linear_color_scanline(proc, gx_device)
  1100. /* Fill a linear color trapezoid. */
  1101. /* The server assumes a strongly linear color,
  1102. i.e. it can ignore any of c0, c1, c2, c3. */
  1103. /* [p0 : p1] - left edge, from bottom to top.
  1104. [p2 : p3] - right edge, from bottom to top.
  1105. The filled area is within Y-spans of both edges. */
  1106. /* If either (c0 and c1) or (c2 and c3) may be NULL.
  1107. In this case the color doesn't depend on X (on Y if fa->swap_axes).
  1108. In this case the base coordinates for the color gradient
  1109. may be unequal to p0, p1, p2, p3, and must be provided/taken
  1110. in/from fa->ystart, fa->yend.
  1111. The rerurn value 0 is not allowed in this case. */
  1112. /* Return values :
  1113. 1 - success;
  1114. 0 - Too big. The area isn't filled. The client must decompose the area.
  1115. <0 - error.
  1116. */
  1117. #define dev_t_proc_fill_linear_color_trapezoid(proc, dev_t)\
  1118. int proc(dev_t *dev, const gs_fill_attributes *fa,\
  1119. const gs_fixed_point *p0, const gs_fixed_point *p1,\
  1120. const gs_fixed_point *p2, const gs_fixed_point *p3,\
  1121. const frac31 *c0, const frac31 *c1,\
  1122. const frac31 *c2, const frac31 *c3)
  1123. #define dev_proc_fill_linear_color_trapezoid(proc)\
  1124. dev_t_proc_fill_linear_color_trapezoid(proc, gx_device)
  1125. /* Fill a linear color triangle. */
  1126. /* Return values :
  1127. 1 - success;
  1128. 0 - Too big. The area isn't filled. The client must decompose the area.
  1129. <0 - error.
  1130. */
  1131. #define dev_t_proc_fill_linear_color_triangle(proc, dev_t)\
  1132. int proc(dev_t *dev, const gs_fill_attributes *fa,\
  1133. const gs_fixed_point *p0, const gs_fixed_point *p1,\
  1134. const gs_fixed_point *p2,\
  1135. const frac31 *c0, const frac31 *c1, const frac31 *c2)
  1136. #define dev_proc_fill_linear_color_triangle(proc)\
  1137. dev_t_proc_fill_linear_color_triangle(proc, gx_device)
  1138. /*
  1139. * Update the equivalent colors for spot colors in a color space. The default
  1140. * procedure does nothing. However this routine provides a method for devices
  1141. * to determine an equivalent color for a spot color. See comments at the
  1142. * start of src/gsequivc.c.
  1143. */
  1144. #define dev_t_proc_update_spot_equivalent_colors(proc, dev_t)\
  1145. int proc(dev_t *dev, const gs_state * pgs)
  1146. #define dev_proc_update_spot_equivalent_colors(proc)\
  1147. dev_t_proc_update_spot_equivalent_colors(proc, gx_device)
  1148. /* Define the device procedure vector template proper. */
  1149. #define gx_device_proc_struct(dev_t)\
  1150. { dev_t_proc_open_device((*open_device), dev_t);\
  1151. dev_t_proc_get_initial_matrix((*get_initial_matrix), dev_t);\
  1152. dev_t_proc_sync_output((*sync_output), dev_t);\
  1153. dev_t_proc_output_page((*output_page), dev_t);\
  1154. dev_t_proc_close_device((*close_device), dev_t);\
  1155. dev_t_proc_map_rgb_color((*map_rgb_color), dev_t);\
  1156. dev_t_proc_map_color_rgb((*map_color_rgb), dev_t);\
  1157. dev_t_proc_fill_rectangle((*fill_rectangle), dev_t);\
  1158. dev_t_proc_tile_rectangle((*tile_rectangle), dev_t);\
  1159. dev_t_proc_copy_mono((*copy_mono), dev_t);\
  1160. dev_t_proc_copy_color((*copy_color), dev_t);\
  1161. dev_t_proc_draw_line((*obsolete_draw_line), dev_t);\
  1162. dev_t_proc_get_bits((*get_bits), dev_t);\
  1163. dev_t_proc_get_params((*get_params), dev_t);\
  1164. dev_t_proc_put_params((*put_params), dev_t);\
  1165. dev_t_proc_map_cmyk_color((*map_cmyk_color), dev_t);\
  1166. dev_t_proc_get_xfont_procs((*get_xfont_procs), dev_t);\
  1167. dev_t_proc_get_xfont_device((*get_xfont_device), dev_t);\
  1168. dev_t_proc_map_rgb_alpha_color((*map_rgb_alpha_color), dev_t);\
  1169. dev_t_proc_get_page_device((*get_page_device), dev_t);\
  1170. dev_t_proc_get_alpha_bits((*get_alpha_bits), dev_t);\
  1171. dev_t_proc_copy_alpha((*copy_alpha), dev_t);\
  1172. dev_t_proc_get_band((*get_band), dev_t);\
  1173. dev_t_proc_copy_rop((*copy_rop), dev_t);\
  1174. dev_t_proc_fill_path((*fill_path), dev_t);\
  1175. dev_t_proc_stroke_path((*stroke_path), dev_t);\
  1176. dev_t_proc_fill_mask((*fill_mask), dev_t);\
  1177. dev_t_proc_fill_trapezoid((*fill_trapezoid), dev_t);\
  1178. dev_t_proc_fill_parallelogram((*fill_parallelogram), dev_t);\
  1179. dev_t_proc_fill_triangle((*fill_triangle), dev_t);\
  1180. dev_t_proc_draw_thin_line((*draw_thin_line), dev_t);\
  1181. dev_t_proc_begin_image((*begin_image), dev_t);\
  1182. dev_t_proc_image_data((*image_data), dev_t);\
  1183. dev_t_proc_end_image((*end_image), dev_t);\
  1184. dev_t_proc_strip_tile_rectangle((*strip_tile_rectangle), dev_t);\
  1185. dev_t_proc_strip_copy_rop((*strip_copy_rop), dev_t);\
  1186. dev_t_proc_get_clipping_box((*get_clipping_box), dev_t);\
  1187. dev_t_proc_begin_typed_image((*begin_typed_image), dev_t);\
  1188. dev_t_proc_get_bits_rectangle((*get_bits_rectangle), dev_t);\
  1189. dev_t_proc_map_color_rgb_alpha((*map_color_rgb_alpha), dev_t);\
  1190. dev_t_proc_create_compositor((*create_compositor), dev_t);\
  1191. dev_t_proc_get_hardware_params((*get_hardware_params), dev_t);\
  1192. dev_t_proc_text_begin((*text_begin), dev_t);\
  1193. dev_t_proc_finish_copydevice((*finish_copydevice), dev_t);\
  1194. dev_t_proc_begin_transparency_group((*begin_transparency_group), dev_t);\
  1195. dev_t_proc_end_transparency_group((*end_transparency_group), dev_t);\
  1196. dev_t_proc_begin_transparency_mask((*begin_transparency_mask), dev_t);\
  1197. dev_t_proc_end_transparency_mask((*end_transparency_mask), dev_t);\
  1198. dev_t_proc_discard_transparency_layer((*discard_transparency_layer), dev_t);\
  1199. dev_t_proc_get_color_mapping_procs((*get_color_mapping_procs), dev_t); \
  1200. dev_t_proc_get_color_comp_index((*get_color_comp_index), dev_t); \
  1201. dev_t_proc_encode_color((*encode_color), dev_t); \
  1202. dev_t_proc_decode_color((*decode_color), dev_t); \
  1203. dev_t_proc_pattern_manage((*pattern_manage), dev_t); \
  1204. dev_t_proc_fill_rectangle_hl_color((*fill_rectangle_hl_color), dev_t); \
  1205. dev_t_proc_include_color_space((*include_color_space), dev_t); \
  1206. dev_t_proc_fill_linear_color_scanline((*fill_linear_color_scanline), dev_t); \
  1207. dev_t_proc_fill_linear_color_trapezoid((*fill_linear_color_trapezoid), dev_t); \
  1208. dev_t_proc_fill_linear_color_triangle((*fill_linear_color_triangle), dev_t); \
  1209. dev_t_proc_update_spot_equivalent_colors((*update_spot_equivalent_colors), dev_t); \
  1210. }
  1211. /*
  1212. * Provide procedures for passing image data. image_data and end_image
  1213. * are the equivalents of the obsolete driver procedures. image_plane_data
  1214. * was originally planned as a driver procedure, but is now associated with
  1215. * the image enumerator, like the other two.
  1216. */
  1217. typedef struct gx_image_plane_s {
  1218. const byte *data;
  1219. int data_x;
  1220. uint raster;
  1221. } gx_image_plane_t;
  1222. #define gx_device_begin_image(dev, pis, pim, format, prect, pdcolor, pcpath, memory, pinfo)\
  1223. ((*dev_proc(dev, begin_image))\
  1224. (dev, pis, pim, format, prect, pdcolor, pcpath, memory, pinfo))
  1225. #define gx_device_begin_typed_image(dev, pis, pmat, pim, prect, pdcolor, pcpath, memory, pinfo)\
  1226. ((*dev_proc(dev, begin_typed_image))\
  1227. (dev, pis, pmat, pim, prect, pdcolor, pcpath, memory, pinfo))
  1228. /*
  1229. * The driver-like procedures gx_device_{image_data, image_plane_data,
  1230. * end_image} are now DEPRECATED and will eventually be removed.
  1231. * Their replacements no longer take an ignored dev argument.
  1232. */
  1233. int gx_image_data(gx_image_enum_common_t *info, const byte **planes,
  1234. int data_x, uint raster, int height);
  1235. /*
  1236. * Solely for backward compatibility, gx_image_plane_data doesn't return
  1237. * rows_used.
  1238. */
  1239. int gx_image_plane_data(gx_image_enum_common_t *info,
  1240. const gx_image_plane_t *planes, int height);
  1241. int gx_image_plane_data_rows(gx_image_enum_common_t *info,
  1242. const gx_image_plane_t *planes, int height,
  1243. int *rows_used);
  1244. int gx_image_flush(gx_image_enum_common_t *info);
  1245. bool gx_image_planes_wanted(const gx_image_enum_common_t *info, byte *wanted);
  1246. int gx_image_end(gx_image_enum_common_t *info, bool draw_last);
  1247. #define gx_device_image_data(dev, info, planes, data_x, raster, height)\
  1248. gx_image_data(info, planes, data_x, raster, height)
  1249. #define gx_device_image_plane_data(dev, info, planes, height)\
  1250. gx_image_plane_data(info, planes, height)
  1251. #define gx_device_end_image(dev, info, draw_last)\
  1252. gx_image_end(info, draw_last)
  1253. /*
  1254. * Get the anti-aliasing parameters for a device. This replaces the
  1255. * obsolete get_alpha_bits device procedure.
  1256. */
  1257. #define gx_device_get_alpha_bits(dev, type)\
  1258. gx_default_get_alpha_bits(dev, type)
  1259. /* A generic device procedure record. */
  1260. struct gx_device_procs_s gx_device_proc_struct(gx_device);
  1261. /*
  1262. * Define unaligned analogues of the copy_xxx procedures.
  1263. * These are slower than the standard procedures, which require
  1264. * aligned bitmaps, and also are not portable to non-byte-addressed machines.
  1265. *
  1266. * We allow both unaligned data and unaligned scan line widths;
  1267. * however, we do require that both of these be aligned modulo the largest
  1268. * power of 2 bytes that divides the data depth, i.e.:
  1269. * depth alignment
  1270. * <= 8 1
  1271. * 16 2
  1272. * 24 1
  1273. * 32 4
  1274. */
  1275. dev_proc_copy_mono(gx_copy_mono_unaligned);
  1276. dev_proc_copy_color(gx_copy_color_unaligned);
  1277. dev_proc_copy_alpha(gx_copy_alpha_unaligned);
  1278. /* A generic device */
  1279. struct gx_device_s {
  1280. gx_device_common;
  1281. };
  1282. extern_st(st_device);
  1283. struct_proc_finalize(gx_device_finalize); /* public for subclasses */
  1284. /* We use vacuous enum/reloc procedures, rather than 0, so that */
  1285. /* gx_device can have subclasses. */
  1286. #define public_st_device() /* in gsdevice.c */\
  1287. gs_public_st_complex_only(st_device, gx_device, "gx_device",\
  1288. 0, gs_no_struct_enum_ptrs, gs_no_struct_reloc_ptrs, gx_device_finalize)
  1289. #define st_device_max_ptrs 0
  1290. /* Enumerate or relocate a pointer to a device. */
  1291. /* These take the containing space into account properly. */
  1292. gx_device *gx_device_enum_ptr(gx_device *);
  1293. gx_device *gx_device_reloc_ptr(gx_device *, gc_state_t *);
  1294. /* Define typedefs for some of the device procedures, because */
  1295. /* ansi2knr can't handle dev_proc_xxx((*xxx)) in a formal argument list. */
  1296. typedef dev_proc_map_rgb_color((*dev_proc_map_rgb_color_t));
  1297. typedef dev_proc_map_color_rgb((*dev_proc_map_color_rgb_t));
  1298. /*
  1299. * A forwarding device forwards all non-display operations, and possibly
  1300. * some imaging operations (possibly transformed in some way), to another
  1301. * device called the "target". This is used for many different purposes
  1302. * internally, including clipping, banding, image and pattern accumulation,
  1303. * compositing, halftoning, and the null device.
  1304. */
  1305. #define gx_device_forward_common\
  1306. gx_device_common;\
  1307. gx_device *target
  1308. /* A generic forwarding device. */
  1309. typedef struct gx_device_forward_s {
  1310. gx_device_forward_common;
  1311. } gx_device_forward;
  1312. extern_st(st_device_forward);
  1313. #define public_st_device_forward() /* in gsdevice.c */\
  1314. gs_public_st_complex_only(st_device_forward, gx_device_forward,\
  1315. "gx_device_forward", 0, device_forward_enum_ptrs,\
  1316. device_forward_reloc_ptrs, gx_device_finalize)
  1317. #define st_device_forward_max_ptrs (st_device_max_ptrs + 1)
  1318. /* A null device. This is used to temporarily disable output. */
  1319. #ifndef gx_device_null_DEFINED
  1320. # define gx_device_null_DEFINED
  1321. typedef struct gx_device_null_s gx_device_null;
  1322. #endif
  1323. struct gx_device_null_s {
  1324. gx_device_forward_common;
  1325. };
  1326. extern const gx_device_null gs_null_device;
  1327. #define gx_device_is_null(dev)\
  1328. ((dev)->dname == gs_null_device.dname)
  1329. extern_st(st_device_null);
  1330. #define public_st_device_null() /* in gsdevice.c */\
  1331. gs_public_st_complex_only(st_device_null, gx_device_null,\
  1332. "gx_device_null", 0, device_forward_enum_ptrs,\
  1333. device_forward_reloc_ptrs, gx_device_finalize)
  1334. #define st_device_null_max_ptrs st_device_forward_max_ptrs
  1335. /*
  1336. * Initialize a just-allocated device from a prototype. If internal =
  1337. * false, the device is marked retained; if internal = true, the device is
  1338. * not marked retained. See the beginning of this file for more information
  1339. * about what this means. Normally, devices created for temporary use have
  1340. * internal = true (retained = false).
  1341. */
  1342. void gx_device_init(gx_device * dev, const gx_device * proto,
  1343. gs_memory_t * mem, bool internal);
  1344. /* Make a null device. */
  1345. /* The gs_memory_t argument is 0 if the device is temporary and local, */
  1346. /* or the allocator that was used to allocate it if it is a real object. */
  1347. void gs_make_null_device(gx_device_null *dev_null, gx_device *target,
  1348. gs_memory_t *mem);
  1349. /* Is a null device ? */
  1350. bool gs_is_null_device(gx_device *dev);
  1351. /* Set the target of a (forwarding) device. */
  1352. void gx_device_set_target(gx_device_forward *fdev, gx_device *target);
  1353. /* Mark a device as retained or not retained. */
  1354. void gx_device_retain(gx_device *dev, bool retained);
  1355. /* Calculate the raster (number of bytes in a scan line), */
  1356. /* with byte or word padding. */
  1357. uint gx_device_raster(const gx_device * dev, bool pad_to_word);
  1358. /* Adjust the resolution for devices that only have a fixed set of */
  1359. /* geometries, so that the apparent size in inches remains constant. */
  1360. /* If fit=1, the resolution is adjusted so that the entire image fits; */
  1361. /* if fit=0, one dimension fits, but the other one is clipped. */
  1362. int gx_device_adjust_resolution(gx_device * dev, int actual_width, int actual_height, int fit);
  1363. /* Set the HWMargins to values defined in inches. */
  1364. /* If move_origin is true, also reset the Margins. */
  1365. void gx_device_set_margins(gx_device * dev, const float *margins /*[4] */ ,
  1366. bool move_origin);
  1367. /* Set the width and height (in pixels), updating MediaSize. */
  1368. void gx_device_set_width_height(gx_device * dev, int width, int height);
  1369. /* Set the resolution (in pixels per inch), updating width and height. */
  1370. void gx_device_set_resolution(gx_device * dev, floatp x_dpi, floatp y_dpi);
  1371. /* Set the MediaSize (in 1/72" units), updating width and height. */
  1372. void gx_device_set_media_size(gx_device * dev, floatp media_width, floatp media_height);
  1373. /****** BACKWARD COMPATIBILITY ******/
  1374. #define gx_device_set_page_size(dev, w, h)\
  1375. gx_device_set_media_size(dev, w, h)
  1376. /*
  1377. * Temporarily install a null device, or a special device such as
  1378. * a clipping or cache device.
  1379. */
  1380. void gx_set_device_only(gs_state *, gx_device *);
  1381. /* Close a device. */
  1382. int gs_closedevice(gx_device *);
  1383. /* "Free" a device locally allocated on the stack, by finalizing it. */
  1384. void gx_device_free_local(gx_device *);
  1385. /* ------ Device types (an unused concept right now) ------ */
  1386. #define dev_type_proc_initialize(proc)\
  1387. int proc(gx_device *)
  1388. typedef struct gx_device_type_s {
  1389. gs_memory_type_ptr_t stype;
  1390. dev_type_proc_initialize((*initialize));
  1391. } gx_device_type;
  1392. #define device_type(dtname, stype, initproc)\
  1393. private dev_type_proc_initialize(initproc);\
  1394. const gx_device_type dtname = { &stype, initproc }
  1395. /*dev_type_proc_initialize(gdev_initialize); */
  1396. #endif /* gxdevcli_INCLUDED */