BRL-CAD
fb.h
Go to the documentation of this file.
1 /* F B . H
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup libfb */
21 /** @{ */
22 /** @file fb.h
23  *
24  * "Generic" Framebuffer Library Interface Defines.
25  *
26  */
27 
28 #ifndef FB_H
29 #define FB_H
30 
31 #ifndef FB_EXPORT
32 # if defined(FB_DLL_EXPORTS) && defined(FB_DLL_IMPORTS)
33 # error "Only FB_DLL_EXPORTS or FB_DLL_IMPORTS can be defined, not both."
34 # elif defined(FB_DLL_EXPORTS)
35 # define FB_EXPORT __declspec(dllexport)
36 # elif defined(FB_DLL_IMPORTS)
37 # define FB_EXPORT __declspec(dllimport)
38 # else
39 # define FB_EXPORT
40 # endif
41 #endif
42 
43 /*
44  * Needed for fd_set, avoid including sys/select.h outright since it
45  * conflicts on some systems (e.g. freebsd4).
46  *
47  * FIXME: would be nice to decouple this interface from fd_set as it's
48  * only used in one place right now.
49  */
50 #include "common.h"
51 #if defined(HAVE_SYS_TYPES_H)
52 # include <sys/types.h>
53 #endif
54 #if defined(HAVE_SYS_TIME_H)
55 # include <sys/time.h>
56 #endif
57 
58 #include "bsocket.h"
59 #include "bio.h"
60 
61 #include "bu/bu_tcl.h"
62 #include "bu/magic.h"
63 #include "bu/vls.h"
64 
65 /**
66  * Format of disk pixels is .pix raw image files. Formerly used as
67  * arguments to many of the library routines, but has fallen into
68  * disuse due to the difficulties with ANSI function prototypes, and
69  * the fact that arrays are not real types in C. The most notable
70  * problem is that of passing a pointer to an array of RGBpixel. It
71  * looks doubly dimensioned, but isn't.
72  */
73 typedef unsigned char RGBpixel[3];
74 
75 
76 /**
77  * These generic color maps have up to 16 bits of significance,
78  * left-justified in a short. Think of this as fixed-point values
79  * from 0 to 1.
80  */
81 /* FIXME: ColorMap is same as RLEColorMap defined in 'orle.h' */
82 typedef struct {
83  unsigned short cm_red[256];
84  unsigned short cm_green[256];
85  unsigned short cm_blue[256];
86 } ColorMap;
87 
88 
89 #define PIXEL_NULL (unsigned char *) 0
90 #define RGBPIXEL_NULL (unsigned char *) 0
91 #define COLORMAP_NULL (ColorMap *) 0
92 
93 /* Use a typedef to hide the details of the framebuffer structure */
94 typedef struct fb_internal fb;
95 #define FB_NULL (fb *) 0
96 
97 /**
98  * assert the integrity of a framebuffer struct.
99  */
100 #define FB_CK_FB(_p) BU_CKMAG(_p, FB_MAGIC, "FB")
101 
103 
104 /* Library entry points */
105 
106 FB_EXPORT fb *fb_get();
107 FB_EXPORT void fb_put(fb *ifp);
108 FB_EXPORT extern char *fb_gettype(fb *ifp);
109 FB_EXPORT extern int fb_get_max_width(fb *ifp);
110 FB_EXPORT extern int fb_get_max_height(fb *ifp);
111 FB_EXPORT extern int fb_getwidth(fb *ifp);
112 FB_EXPORT extern int fb_getheight(fb *ifp);
113 FB_EXPORT extern int fb_poll(fb *ifp);
114 /* Returns in microseconds the maximum recommended amount of time to linger
115  * before polling for updates for a specific framebuffer instance (can be
116  * implementation dependent.) Zero means the fb_poll process does nothing
117  * (for example, the NULL fb). */
118 FB_EXPORT extern long fb_poll_rate(fb *ifp);
119 FB_EXPORT extern int fb_help(fb *ifp);
120 FB_EXPORT extern int fb_free(fb *ifp);
121 FB_EXPORT extern int fb_clear(fb *ifp, unsigned char *pp);
122 FB_EXPORT extern ssize_t fb_read(fb *ifp, int x, int y, unsigned char *pp, size_t count);
123 FB_EXPORT extern ssize_t fb_write(fb *ifp, int x, int y, const unsigned char *pp, size_t count);
124 FB_EXPORT extern int fb_rmap(fb *ifp, ColorMap *cmap);
125 FB_EXPORT extern int fb_wmap(fb *ifp, const ColorMap *cmap);
126 FB_EXPORT extern int fb_view(fb *ifp, int xcenter, int ycenter, int xzoom, int yzoom);
127 FB_EXPORT extern int fb_getview(fb *ifp, int *xcenter, int *ycenter, int *xzoom, int *yzoom);
128 FB_EXPORT extern int fb_setcursor(fb *ifp, const unsigned char *bits, int xb, int yb, int xo, int yo);
129 FB_EXPORT extern int fb_cursor(fb *ifp, int mode, int x, int y);
130 FB_EXPORT extern int fb_getcursor(fb *ifp, int *mode, int *x, int *y);
131 FB_EXPORT extern int fb_readrect(fb *ifp, int xmin, int ymin, int width, int height, unsigned char *pp);
132 FB_EXPORT extern int fb_writerect(fb *ifp, int xmin, int ymin, int width, int height, const unsigned char *pp);
133 FB_EXPORT extern int fb_bwreadrect(fb *ifp, int xmin, int ymin, int width, int height, unsigned char *pp);
134 FB_EXPORT extern int fb_bwwriterect(fb *ifp, int xmin, int ymin, int width, int height, const unsigned char *pp);
135 
136 FB_EXPORT extern fb *fb_open(const char *file, int _width, int _height);
137 FB_EXPORT extern int fb_close(fb *ifp);
138 FB_EXPORT extern int fb_close_existing(fb *ifp);
139 FB_EXPORT extern int fb_genhelp(void);
140 FB_EXPORT extern int fb_ioinit(fb *ifp);
141 FB_EXPORT extern int fb_seek(fb *ifp, int x, int y);
142 FB_EXPORT extern int fb_tell(fb *ifp, int *xp, int *yp);
143 FB_EXPORT extern int fb_rpixel(fb *ifp, unsigned char *pp);
144 FB_EXPORT extern int fb_wpixel(fb *ifp, unsigned char *pp);
145 FB_EXPORT extern int fb_flush(fb *ifp);
146 FB_EXPORT extern int fb_configure_window(fb *, int, int);
147 FB_EXPORT extern int fb_refresh(fb *ifp, int x, int y, int w, int h);
148 #if !defined(_WIN32) || defined(__CYGWIN__)
149 FB_EXPORT extern void fb_log(const char *fmt, ...) _BU_ATTR_PRINTF12;
150 #endif
151 FB_EXPORT extern int fb_null(fb *ifp);
152 FB_EXPORT extern int fb_null_setcursor(fb *ifp, const unsigned char *bits, int xbits, int ybits, int xorig, int yorig);
153 
154 /* utility functions */
155 FB_EXPORT extern int fb_common_file_size(size_t *widthp, size_t *heightp, const char *filename, int pixel_size);
156 FB_EXPORT extern int fb_common_image_size(size_t *widthp, size_t *heightp, size_t npixels);
157 FB_EXPORT extern int fb_common_name_size(size_t *widthp, size_t *heightp, const char *name);
158 FB_EXPORT extern int fb_write_fp(fb *ifp, FILE *fp, int req_width, int req_height, int crunch, int inverse, struct bu_vls *result);
159 FB_EXPORT extern int fb_read_fd(fb *ifp, int fd, int file_width, int file_height, int file_xoff, int file_yoff, int scr_width, int scr_height, int scr_xoff, int scr_yoff, int fileinput, char *file_name, int one_line_only, int multiple_lines, int autosize, int inverse, int clear, int zoom, struct bu_vls *result);
160 
161 FB_EXPORT extern void fb_set_interface(fb *ifp, const char *interface_type);
162 FB_EXPORT extern void fb_set_name(fb *ifp, const char *name);
163 FB_EXPORT extern char *fb_get_name(fb *ifp);
164 FB_EXPORT extern void fb_set_magic(fb *ifp, uint32_t magic);
165 FB_EXPORT extern long fb_get_pagebuffer_pixel_size(fb *ifp);
166 
167 FB_EXPORT extern int fb_is_set_fd(fb *ifp, fd_set *infds);
168 FB_EXPORT extern int fb_set_fd(fb *ifp, fd_set *select_list);
169 FB_EXPORT extern int fb_clear_fd(fb *ifp, fd_set *select_list);
170 
171 /* color mapping */
172 FB_EXPORT extern int fb_is_linear_cmap(const ColorMap *cmap);
173 FB_EXPORT extern void fb_make_linear_cmap(ColorMap *cmap);
174 
175 /* open_existing functionality. */
176 struct fb_platform_specific {uint32_t magic; void *data;};
177 FB_EXPORT extern struct fb_platform_specific *fb_get_platform_specific(uint32_t magic);
178 FB_EXPORT extern void fb_put_platform_specific(struct fb_platform_specific *fb_p);
179 FB_EXPORT extern fb *fb_open_existing(const char *file, int _width, int _height, struct fb_platform_specific *fb_p);
180 
181 /* backward compatibility hacks */
182 FB_EXPORT extern int fb_reset(fb *ifp);
183 FB_EXPORT extern int fb_viewport(fb *ifp, int left, int top, int right, int bottom);
184 FB_EXPORT extern int fb_window(fb *ifp, int xcenter, int ycenter);
185 FB_EXPORT extern int fb_zoom(fb *ifp, int xzoom, int yzoom);
186 FB_EXPORT extern int fb_scursor(fb *ifp, int mode, int x, int y);
187 
188 /*
189  * Copy one RGB pixel to another.
190  */
191 #define COPYRGB(to, from) { (to)[RED]=(from)[RED];\
192  (to)[GRN]=(from)[GRN];\
193  (to)[BLU]=(from)[BLU]; }
194 
195 /* Debug Bitvector Definition */
196 #define FB_DEBUG_BIO 1 /* Buffered io calls (less r/wpixel) */
197 #define FB_DEBUG_CMAP 2 /* Contents of colormaps */
198 #define FB_DEBUG_RW 4 /* Contents of reads and writes */
199 #define FB_DEBUG_BRW 8 /* Buffered IO rpixel and wpixel */
200 
201 /* tcl.c */
202 /* The presence of Tcl_Interp as an arg prevents giving arg list */
203 FB_EXPORT extern void fb_tcl_setup(void);
204 FB_EXPORT extern int Fb_Init(Tcl_Interp *interp);
205 
206 /**
207  * report version information about LIBFB
208  */
209 FB_EXPORT extern const char *fb_version(void);
210 
211 
212 /* To avoid breaking things too badly, temporarily expose
213  * what is now internal API */
214 #ifdef EXPOSE_FB_HEADER
215 # include "../src/libfb/fb_private.h"
216 #endif
217 
218 typedef struct fb_internal FBIO;
219 
220 
222 
223 #endif /* FB_H */
224 
225 /** @} */
226 /*
227  * Local Variables:
228  * mode: C
229  * tab-width: 8
230  * indent-tabs-mode: t
231  * c-file-style: "stroustrup"
232  * End:
233  * ex: shiftwidth=4 tabstop=8
234  */
char * fb_gettype(fb *ifp)
Definition: fb_generic.c:226
ptrdiff_t ssize_t
Definition: common.h:119
int fb_refresh(fb *ifp, int x, int y, int w, int h)
Definition: fb_generic.c:156
int fb_wpixel(fb *ifp, unsigned char *pp)
char filename[MAXLENGTH]
Definition: human.c:105
unsigned char RGBpixel[3]
Definition: fb.h:73
int fb_write_fp(fb *ifp, FILE *fp, int req_width, int req_height, int crunch, int inverse, struct bu_vls *result)
Definition: fb_generic.c:601
int fb_genhelp(void)
Definition: fb_generic.c:526
void fb_log(const char *fmt,...) _BU_ATTR_PRINTF12
Definition: fb_log.c:42
ustring interp
void * data
Definition: fb.h:176
int fb_help(fb *ifp)
Definition: fb_generic.c:260
Definition: clone.c:90
void fb_make_linear_cmap(ColorMap *cmap)
int fb_null(fb *ifp)
Definition: fb_generic.c:359
int fb_close_existing(fb *ifp)
Definition: fb_generic.c:498
fb * fb_open(const char *file, int _width, int _height)
Definition: fb_generic.c:384
int fb_tell(fb *ifp, int *xp, int *yp)
Header file for the BRL-CAD common definitions.
int fb_zoom(fb *ifp, int xzoom, int yzoom)
Definition: fb_util.c:151
int fb_getcursor(fb *ifp, int *mode, int *x, int *y)
Definition: fb_generic.c:304
int fb_is_linear_cmap(const ColorMap *cmap)
int fb_window(fb *ifp, int xcenter, int ycenter)
Definition: fb_util.c:133
int fb_read_fd(fb *ifp, int fd, int file_width, int file_height, int file_xoff, int file_yoff, int scr_width, int scr_height, int scr_xoff, int scr_yoff, int fileinput, char *file_name, int one_line_only, int multiple_lines, int autosize, int inverse, int clear, int zoom, struct bu_vls *result)
Definition: fb_generic.c:686
void fb_put(fb *ifp)
Definition: fb_generic.c:91
int fb_getheight(fb *ifp)
Definition: fb_generic.c:235
ustring width
int fb_cursor(fb *ifp, int mode, int x, int y)
Definition: fb_generic.c:300
struct fb_platform_specific * fb_get_platform_specific(uint32_t magic)
Definition: fb_generic.c:113
int fb_bwwriterect(fb *ifp, int xmin, int ymin, int width, int height, const unsigned char *pp)
Definition: fb_generic.c:320
void fb_set_magic(fb *ifp, uint32_t magic)
Definition: fb_generic.c:220
int fb_close(fb *ifp)
Definition: fb_generic.c:478
int fb_free(fb *ifp)
Definition: fb_generic.c:264
long fb_get_pagebuffer_pixel_size(fb *ifp)
Definition: fb_generic.c:185
int fb_scursor(fb *ifp, int mode, int x, int y)
Definition: fb_util.c:170
#define __BEGIN_DECLS
Definition: common.h:73
#define _BU_ATTR_PRINTF12
Definition: defines.h:149
int fb_view(fb *ifp, int xcenter, int ycenter, int xzoom, int yzoom)
Definition: fb_generic.c:288
static void top()
int fb_seek(fb *ifp, int x, int y)
int fb_getwidth(fb *ifp)
Definition: fb_generic.c:231
int fb_null_setcursor(fb *ifp, const unsigned char *bits, int xbits, int ybits, int xorig, int yorig)
Definition: fb_generic.c:372
int fb_common_name_size(size_t *widthp, size_t *heightp, const char *name)
Definition: asize.c:137
oldeumate l2 magic
Definition: nmg_mod.c:3843
void fb_tcl_setup(void)
int fb_viewport(fb *ifp, int left, int top, int right, int bottom)
Definition: fb_util.c:122
int fb_clear_fd(fb *ifp, fd_set *select_list)
Definition: fb_generic.c:210
int fb_configure_window(fb *, int, int)
Definition: fb_generic.c:162
int fb_readrect(fb *ifp, int xmin, int ymin, int width, int height, unsigned char *pp)
Definition: fb_generic.c:308
int fb_is_set_fd(fb *ifp, fd_set *infds)
Definition: fb_generic.c:191
Definition: fb.h:82
int fb_rpixel(fb *ifp, unsigned char *pp)
int fb_rmap(fb *ifp, ColorMap *cmap)
Definition: fb_generic.c:280
fb * fb_open_existing(const char *file, int _width, int _height, struct fb_platform_specific *fb_p)
Definition: fb_generic.c:146
int fb_getview(fb *ifp, int *xcenter, int *ycenter, int *xzoom, int *yzoom)
Definition: fb_generic.c:292
HIDDEN int zoom(struct ged *gedp, double sf)
Definition: zoom.c:26
fb * fb_get()
Definition: fb_generic.c:83
ssize_t fb_write(fb *ifp, int x, int y, const unsigned char *pp, size_t count)
Definition: fb_generic.c:276
int fb_common_file_size(size_t *widthp, size_t *heightp, const char *filename, int pixel_size)
Definition: asize.c:86
int fb_wmap(fb *ifp, const ColorMap *cmap)
Definition: fb_generic.c:284
uint32_t magic
Definition: fb.h:176
long fb_poll_rate(fb *ifp)
Definition: fb_generic.c:255
int fb_flush(fb *ifp)
const char * fb_version(void)
Definition: vers.c:31
int fb_set_fd(fb *ifp, fd_set *select_list)
Definition: fb_generic.c:200
int fb_ioinit(fb *ifp)
void fb_set_name(fb *ifp, const char *name)
Definition: fb_generic.c:171
int fb_common_image_size(size_t *widthp, size_t *heightp, size_t npixels)
Definition: asize.c:173
int fb_clear(fb *ifp, unsigned char *pp)
Definition: fb_generic.c:268
int fb_bwreadrect(fb *ifp, int xmin, int ymin, int width, int height, unsigned char *pp)
Definition: fb_generic.c:316
#define __END_DECLS
Definition: common.h:74
int fb_reset(fb *ifp)
Definition: fb_util.c:111
char * file_name
Definition: fb2pix.c:40
A frame-buffer IO structure.
Definition: fb_private.h:80
int fb_get_max_height(fb *ifp)
Definition: fb_generic.c:244
int fb_get_max_width(fb *ifp)
Definition: fb_generic.c:240
void fb_set_interface(fb *ifp, const char *interface_type)
Definition: fb_generic.c:97
Definition: vls.h:56
char * fb_get_name(fb *ifp)
Definition: fb_generic.c:179
int fb_setcursor(fb *ifp, const unsigned char *bits, int xb, int yb, int xo, int yo)
Definition: fb_generic.c:296
int fb_writerect(fb *ifp, int xmin, int ymin, int width, int height, const unsigned char *pp)
Definition: fb_generic.c:312
ssize_t fb_read(fb *ifp, int x, int y, unsigned char *pp, size_t count)
Definition: fb_generic.c:272
void fb_put_platform_specific(struct fb_platform_specific *fb_p)
Definition: fb_generic.c:129
int fb_poll(fb *ifp)
Definition: fb_generic.c:250
int Fb_Init(Tcl_Interp *interp)
Definition: tcl.c:113