Commit | Line | Data |
---|---|---|
6fb4bba9 WJ |
1 | /* Copyright (C) 1989, 1992 Aladdin Enterprises. All rights reserved. |
2 | Distributed by Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of Ghostscript. | |
5 | ||
6 | Ghostscript is distributed in the hope that it will be useful, but | |
7 | WITHOUT ANY WARRANTY. No author or distributor accepts responsibility | |
8 | to anyone for the consequences of using it or for whether it serves any | |
9 | particular purpose or works at all, unless he says so in writing. Refer | |
10 | to the Ghostscript General Public License for full details. | |
11 | ||
12 | Everyone is granted permission to copy, modify and redistribute | |
13 | Ghostscript, but only under the conditions described in the Ghostscript | |
14 | General Public License. A copy of this license is supposed to have been | |
15 | given to you along with Ghostscript so you can know your rights and | |
16 | responsibilities. It should be in a file named COPYING. Among other | |
17 | things, the copyright notice and this notice must be preserved on all | |
18 | copies. */ | |
19 | ||
20 | /* gxdevice.h */ | |
21 | /* Device description structure for Ghostscript library */ | |
22 | #include "gsmatrix.h" | |
23 | #include "gxbitmap.h" | |
24 | ||
25 | /* See drivers.doc for documentation of the driver interface. */ | |
26 | ||
27 | /* Define the type for device color indices. */ | |
28 | typedef unsigned long gx_color_index; | |
29 | /* Define the 'transparent' color index. */ | |
30 | #define gx_no_color_value (-1) /* no cast -> can be used in #if */ | |
31 | #define gx_no_color_index ((gx_color_index)gx_no_color_value) | |
32 | ||
33 | /* Define the type for gray or RGB values at the driver interface. */ | |
34 | typedef unsigned short gx_color_value; | |
35 | /* We might use less than the full range someday. */ | |
36 | /* ...bits must lie between 8 and 16. */ | |
37 | #define gx_color_value_bits (sizeof(gx_color_value) * 8) | |
38 | #define gx_max_color_value ((gx_color_value)((1L << gx_color_value_bits) - 1)) | |
39 | #define gx_color_value_to_byte(cv)\ | |
40 | ((cv) >> (gx_color_value_bits - 8)) | |
41 | #define gx_color_value_from_byte(cb)\ | |
42 | (((cb) << (gx_color_value_bits - 8)) + ((cb) >> (16 - gx_color_value_bits))) | |
43 | ||
44 | /* Define the structure for device color capabilities. */ | |
45 | typedef struct gx_device_color_info_s { | |
46 | int num_components; /* 1 = gray only, 3 = RGB, */ | |
47 | /* 4 = CMYK (not supported) */ | |
48 | int depth; /* # of bits per pixel */ | |
49 | gx_color_value max_gray; /* # of distinct gray levels -1 */ | |
50 | gx_color_value max_rgb; /* # of distinct color levels -1 */ | |
51 | /* (only relevant if num_comp. > 1) */ | |
52 | gx_color_value dither_gray; /* size of gray ramp for dithering */ | |
53 | gx_color_value dither_rgb; /* size of color cube ditto */ | |
54 | /* (only relevant if num_comp. > 1) */ | |
55 | } gx_device_color_info; | |
56 | #define dci_black_and_white { 1, 1, 1, 0, 2, 0 } | |
57 | #define dci_color(depth,maxv,dither) { 3, depth, maxv, maxv, dither, dither } | |
58 | #define gx_device_has_color(dev) ((dev)->color_info.num_components > 1) | |
59 | ||
60 | /* Structure for device procedures */ | |
61 | typedef struct gx_device_procs_s gx_device_procs; | |
62 | ||
63 | /* Structure for generic device description */ | |
64 | #define gx_device_common\ | |
65 | int params_size; /* size of this structure */\ | |
66 | gx_device_procs *procs;\ | |
67 | const char *dname; /* the device name */\ | |
68 | int width; /* width in pixels */\ | |
69 | int height; /* height in pixels */\ | |
70 | float x_pixels_per_inch; /* x density */\ | |
71 | float y_pixels_per_inch; /* y density */\ | |
72 | float l_margin, b_margin, r_margin, t_margin; /* margins around */\ | |
73 | /* imageable area, in inches */\ | |
74 | gx_device_color_info color_info; /* color information */\ | |
75 | int is_open /* true if device has been opened */ | |
76 | #define no_margins 0, 0, 0, 0 | |
77 | /* A generic device */ | |
78 | struct gx_device_s { | |
79 | gx_device_common; | |
80 | }; | |
81 | #ifndef gx_device_DEFINED | |
82 | # define gx_device_DEFINED | |
83 | typedef struct gx_device_s gx_device; | |
84 | #endif | |
85 | ||
86 | /* Define an opaque type for property lists. */ | |
87 | #ifndef gs_prop_item_DEFINED | |
88 | # define gs_prop_item_DEFINED | |
89 | typedef struct gs_prop_item_s gs_prop_item; | |
90 | #endif | |
91 | ||
92 | /* Definition of device procedures */ | |
93 | struct gx_device_procs_s { | |
94 | ||
95 | #define dev_proc_open_device(proc)\ | |
96 | int proc(P1(gx_device *dev)) | |
97 | dev_proc_open_device((*open_device)); | |
98 | ||
99 | #define dev_proc_get_initial_matrix(proc)\ | |
100 | void proc(P2(gx_device *dev, gs_matrix *pmat)) | |
101 | dev_proc_get_initial_matrix((*get_initial_matrix)); | |
102 | ||
103 | #define dev_proc_sync_output(proc)\ | |
104 | int proc(P1(gx_device *dev)) | |
105 | dev_proc_sync_output((*sync_output)); | |
106 | ||
107 | #define dev_proc_output_page(proc)\ | |
108 | int proc(P3(gx_device *dev, int num_copies, int flush)) | |
109 | dev_proc_output_page((*output_page)); | |
110 | ||
111 | #define dev_proc_close_device(proc)\ | |
112 | int proc(P1(gx_device *dev)) | |
113 | dev_proc_close_device((*close_device)); | |
114 | ||
115 | #define dev_proc_map_rgb_color(proc)\ | |
116 | gx_color_index proc(P4(gx_device *dev,\ | |
117 | gx_color_value red, gx_color_value green, gx_color_value blue)) | |
118 | dev_proc_map_rgb_color((*map_rgb_color)); | |
119 | ||
120 | #define dev_proc_map_color_rgb(proc)\ | |
121 | int proc(P3(gx_device *dev,\ | |
122 | gx_color_index color, gx_color_value rgb[3])) | |
123 | dev_proc_map_color_rgb((*map_color_rgb)); | |
124 | ||
125 | #define dev_proc_fill_rectangle(proc)\ | |
126 | int proc(P6(gx_device *dev,\ | |
127 | int x, int y, int width, int height, gx_color_index color)) | |
128 | dev_proc_fill_rectangle((*fill_rectangle)); | |
129 | ||
130 | #define dev_proc_tile_rectangle(proc)\ | |
131 | int proc(P10(gx_device *dev,\ | |
132 | gx_bitmap *tile, int x, int y, int width, int height,\ | |
133 | gx_color_index color0, gx_color_index color1,\ | |
134 | int phase_x, int phase_y)) | |
135 | dev_proc_tile_rectangle((*tile_rectangle)); | |
136 | ||
137 | #define dev_proc_copy_mono(proc)\ | |
138 | int proc(P11(gx_device *dev,\ | |
139 | unsigned char *data, int data_x, int raster, gx_bitmap_id id,\ | |
140 | int x, int y, int width, int height,\ | |
141 | gx_color_index color0, gx_color_index color1)) | |
142 | dev_proc_copy_mono((*copy_mono)); | |
143 | ||
144 | #define dev_proc_copy_color(proc)\ | |
145 | int proc(P9(gx_device *dev,\ | |
146 | unsigned char *data, int data_x, int raster, gx_bitmap_id id,\ | |
147 | int x, int y, int width, int height)) | |
148 | dev_proc_copy_color((*copy_color)); | |
149 | ||
150 | #define dev_proc_draw_line(proc)\ | |
151 | int proc(P6(gx_device *dev,\ | |
152 | int x0, int y0, int x1, int y1, gx_color_index color)) | |
153 | dev_proc_draw_line((*draw_line)); | |
154 | ||
155 | #define dev_proc_get_bits(proc)\ | |
156 | int proc(P5(gx_device *dev,\ | |
157 | int y, unsigned char *data, unsigned int size, int pad_to_word)) | |
158 | dev_proc_get_bits((*get_bits)); | |
159 | ||
160 | #define dev_proc_get_props(proc)\ | |
161 | int proc(P2(gx_device *dev, gs_prop_item *plist)) | |
162 | dev_proc_get_props((*get_props)); | |
163 | ||
164 | #define dev_proc_put_props(proc)\ | |
165 | int proc(P3(gx_device *dev, gs_prop_item *plist, int count)) | |
166 | dev_proc_put_props((*put_props)); | |
167 | ||
168 | }; | |
169 | ||
170 | /* Calculate the number of bytes in a scan line, */ | |
171 | /* with byte or word padding. */ | |
172 | extern unsigned int gx_device_bytes_per_scan_line(P2(gx_device *dev, int pad_to_word)); | |
173 | ||
174 | /* Default implementations of optional procedures */ | |
175 | dev_proc_open_device(gx_default_open_device); | |
176 | dev_proc_get_initial_matrix(gx_default_get_initial_matrix); | |
177 | dev_proc_sync_output(gx_default_sync_output); | |
178 | dev_proc_output_page(gx_default_output_page); | |
179 | dev_proc_close_device(gx_default_close_device); | |
180 | dev_proc_map_rgb_color(gx_default_map_rgb_color); | |
181 | dev_proc_map_color_rgb(gx_default_map_color_rgb); | |
182 | dev_proc_tile_rectangle(gx_default_tile_rectangle); | |
183 | dev_proc_copy_color(gx_default_copy_color); | |
184 | dev_proc_draw_line(gx_default_draw_line); | |
185 | dev_proc_get_bits(gx_default_get_bits); | |
186 | dev_proc_get_props(gx_default_get_props); | |
187 | dev_proc_put_props(gx_default_put_props); |