1 /* Copyright (C) 2001, Ghostgum Software Pty Ltd.  All rights reserved.
2 
3    This software is provided AS-IS with no warranty, either express or
4    implied.
5 
6    This software is distributed under license and may not be copied,
7    modified or distributed except as expressly authorized under the terms
8    of the license contained in the file LICENSE in this distribution.
9 
10    For more information about licensing, please refer to
11    http://www.ghostscript.com/licensing/. For information on
12    commercial licensing, go to http://www.artifex.com/licensing/ or
13    contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14    San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15  */
16 
17 /* $Id: gdevdsp.h,v 1.2 2002/05/29 11:39:43 ghostgum Exp $ */
18 
19 /* gdevdisp.h - callback structure for DLL based display device */
20 
21 #ifndef gdevdisp_INCLUDED
22 #  define gdevdisp_INCLUDED
23 
24 /*
25  * The callback structure must be provided by calling the
26  * Ghostscript APIs in the following order:
27  *  gsapi_new_instance(&minst);
28  *  gsapi_set_display_callback(minst, callback);
29  *  gsapi_init_with_arg(minst, argc, argv);
30  *
31  * Supported parameters and default values are:
32  * -dDisplayHandle=0                      long
33  *    Caller supplied handle.
34  *    Included as first parameter of all callback functions.
35  *
36  * -dDisplayFormat=0                      long
37  *    Color format specified using bitfields below.
38  *    Included as argument of display_size() and display_presize()
39  * These can only be changed when the device is closed.
40  *
41  * The second parameter of all callback functions "void *device"
42  * is the address of the Ghostscript display device instance.
43  * The arguments "void *handle" and "void *device" together
44  * uniquely identify an instance of the display device.
45  *
46  * A typical sequence of callbacks would be
47  *  open, presize, memalloc, size, sync, page
48  *  presize, memfree, memalloc, size, sync, page
49  *  preclose, memfree, close
50  * The caller should not access the image buffer:
51  *  - before the first sync
52  *  - between presize and size
53  *  - after preclose
54  * If opening the device fails, you might see the following:
55  *  open, presize, memalloc, memfree, close
56  *
57  */
58 
59 #define DISPLAY_VERSION_MAJOR 1
60 #define DISPLAY_VERSION_MINOR 0
61 
62 /* The display format is set by a combination of the following bitfields */
63 
64 /* Define the color space alternatives */
65 typedef enum DISPLAY_FORMAT_COLOR_e {
66     DISPLAY_COLORS_NATIVE = (1<<0),
67     DISPLAY_COLORS_GRAY   = (1<<1),
68     DISPLAY_COLORS_RGB    = (1<<2),
69     DISPLAY_COLORS_CMYK   = (1<<3)
70 } DISPLAY_FORMAT_COLOR;
71 #define DISPLAY_COLORS_MASK 0x000fL
72 
73 /* Define whether alpha information, or an extra unused bytes is included */
74 /* DISPLAY_ALPHA_FIRST and DISPLAY_ALPHA_LAST are not implemented */
75 typedef enum DISPLAY_FORMAT_ALPHA_e {
76     DISPLAY_ALPHA_NONE   = (0<<4),
77     DISPLAY_ALPHA_FIRST  = (1<<4),
78     DISPLAY_ALPHA_LAST   = (1<<5),
79     DISPLAY_UNUSED_FIRST = (1<<6),	/* e.g. Mac xRGB */
80     DISPLAY_UNUSED_LAST  = (1<<7)	/* e.g. Windows BGRx */
81 } DISPLAY_FORMAT_ALPHA;
82 #define DISPLAY_ALPHA_MASK 0x0070L
83 
84 /* Define the depth per component for DISPLAY_COLORS_GRAY,
85  * DISPLAY_COLORS_RGB and DISPLAY_COLORS_CMYK,
86  * or the depth per pixel for DISPLAY_COLORS_NATIVE
87  * DISPLAY_DEPTH_2 and DISPLAY_DEPTH_12 have not been tested.
88  */
89 typedef enum DISPLAY_FORMAT_DEPTH_e {
90     DISPLAY_DEPTH_1   = (1<<8),
91     DISPLAY_DEPTH_2   = (1<<9),
92     DISPLAY_DEPTH_4   = (1<<10),
93     DISPLAY_DEPTH_8   = (1<<11),
94     DISPLAY_DEPTH_12  = (1<<12),
95     DISPLAY_DEPTH_16  = (1<<13)
96     /* unused (1<<14) */
97     /* unused (1<<15) */
98 } DISPLAY_FORMAT_DEPTH;
99 #define DISPLAY_DEPTH_MASK 0xff00L
100 
101 
102 /* Define whether Red/Cyan should come first,
103  * or whether Blue/Black should come first
104  */
105 typedef enum DISPLAY_FORMAT_ENDIAN_e {
106     DISPLAY_BIGENDIAN    = (0<<16),	/* Red/Cyan first */
107     DISPLAY_LITTLEENDIAN = (1<<16)	/* Blue/Black first */
108 } DISPLAY_FORMAT_ENDIAN;
109 #define DISPLAY_ENDIAN_MASK 0x00010000L
110 
111 /* Define whether the raster starts at the top or bottom of the bitmap */
112 typedef enum DISPLAY_FORMAT_FIRSTROW_e {
113     DISPLAY_TOPFIRST    = (0<<17),	/* Unix, Mac */
114     DISPLAY_BOTTOMFIRST = (1<<17)	/* Windows */
115 } DISPLAY_FORMAT_FIRSTROW;
116 #define DISPLAY_FIRSTROW_MASK 0x00020000L
117 
118 
119 /* Define whether packing RGB in 16-bits should use 555
120  * or 565 (extra bit for green)
121  */
122 typedef enum DISPLAY_FORMAT_555_e {
123     DISPLAY_NATIVE_555 = (0<<18),
124     DISPLAY_NATIVE_565 = (1<<18)
125 } DISPLAY_FORMAT_555;
126 #define DISPLAY_555_MASK 0x00040000L
127 
128 #ifndef display_callback_DEFINED
129 #define display_callback_DEFINED
130 typedef struct display_callback_s display_callback;
131 #endif
132 
133 struct display_callback_s {
134     /* Size of this structure */
135     /* Used for checking if we have been handed a valid structure */
136     int size;
137 
138     /* Major version of this structure  */
139     /* The major version number will change if this structure changes. */
140     int version_major;
141 
142     /* Minor version of this structure */
143     /* The minor version number will change if new features are added
144      * without changes to this structure.  For example, a new color
145      * format.
146      */
147     int version_minor;
148 
149     /* New device has been opened */
150     /* This is the first event from this device. */
151     int (*display_open)(void *handle, void *device);
152 
153     /* Device is about to be closed. */
154     /* Device will not be closed until this function returns. */
155     int (*display_preclose)(void *handle, void *device);
156 
157     /* Device has been closed. */
158     /* This is the last event from this device. */
159     int (*display_close)(void *handle, void *device);
160 
161     /* Device is about to be resized. */
162     /* Resize will only occur if this function returns 0. */
163     /* raster is byte count of a row. */
164     int (*display_presize)(void *handle, void *device,
165 	int width, int height, int raster, unsigned int format);
166 
167     /* Device has been resized. */
168     /* New pointer to raster returned in pimage */
169     int (*display_size)(void *handle, void *device, int width, int height,
170 	int raster, unsigned int format, unsigned char *pimage);
171 
172     /* flushpage */
173     int (*display_sync)(void *handle, void *device);
174 
175     /* showpage */
176     /* If you want to pause on showpage, then don't return immediately */
177     int (*display_page)(void *handle, void *device, int copies, int flush);
178 
179     /* Notify the caller whenever a portion of the raster is updated. */
180     /* This can be used for cooperative multitasking or for
181      * progressive update of the display.
182      * This function pointer may be set to NULL if not required.
183      */
184     int (*display_update)(void *handle, void *device, int x, int y,
185 	int w, int h);
186 
187     /* Allocate memory for bitmap */
188     /* This is provided in case you need to create memory in a special
189      * way, e.g. shared.  If this is NULL, the Ghostscript memory device
190      * allocates the bitmap. This will only called to allocate the
191      * image buffer. The first row will be placed at the address
192      * returned by display_memalloc.
193      */
194     void *(*display_memalloc)(void *handle, void *device, unsigned long size);
195 
196     /* Free memory for bitmap */
197     /* If this is NULL, the Ghostscript memory device will free the bitmap */
198     int (*display_memfree)(void *handle, void *device, void *mem);
199 
200 };
201 
202 
203 #endif /* gdevdisp_INCLUDED */
204