fb.h

Go to the documentation of this file.
00001 /*                            F B . H
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 2004-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 /** \addtogroup libfb */
00022 /*@{*/
00023 /** @file fb.h
00024  * @brief
00025  *  BRL "Generic" Framebuffer Library Interface Defines.
00026  *
00027  * This is the file that application programs should include for framebuffer support
00028  *
00029  *  @par Source
00030  *      SECAD/VLD Computing Consortium, Bldg 394
00031  *@n    The U. S. Army Ballistic Research Laboratory
00032  *@n    Aberdeen Proving Ground, Maryland  21005-5066
00033  *
00034  *  $Header: /cvsroot/brlcad/brlcad/include/fb.h,v 14.19 2006/09/18 05:24:07 lbutler Exp $
00035  */
00036 
00037 #ifndef FB_H
00038 #define FB_H seen
00039 
00040 #include "fbio.h"
00041 
00042 /*
00043  * Needed for fd_set, avoid including sys/select.h outright since it
00044  * conflicts on some systems (e.g. freebsd4).
00045  *
00046  * XXX would be nice to decouple this interface from fd_set as it's
00047  * only used in one place right now.
00048  */
00049 #if defined(HAVE_SYS_TYPES_H)
00050 #  include <sys/types.h>
00051 #endif
00052 #if defined(HAVE_SYS_TIME_H)
00053 #  include <sys/time.h>
00054 #endif
00055 #if defined(HAVE_UNISTD_H)
00056 #  include <unistd.h>
00057 #else
00058 #  if defined(HAVE_SYS_UNISTD_H)
00059 #    include <sys/unistd.h>
00060 #  endif
00061 #endif
00062 
00063 
00064 /* Library entry points which are macros. */
00065 #define fb_gettype(_ifp)                (_ifp->if_type)
00066 #define fb_getwidth(_ifp)               (_ifp->if_width)
00067 #define fb_getheight(_ifp)              (_ifp->if_height)
00068 #define fb_poll(_ifp)                   (*_ifp->if_poll)(_ifp)
00069 #define fb_help(_ifp)                   (*_ifp->if_help)(_ifp)
00070 #define fb_free(_ifp)                   (*_ifp->if_free)(_ifp)
00071 #define fb_clear(_ifp,_pp)              (*_ifp->if_clear)(_ifp,_pp)
00072 #define fb_read(_ifp,_x,_y,_pp,_ct)     (*_ifp->if_read)(_ifp,_x,_y,_pp,_ct)
00073 #define fb_write(_ifp,_x,_y,_pp,_ct)    (*_ifp->if_write)(_ifp,_x,_y,_pp,_ct)
00074 #define fb_rmap(_ifp,_cmap)             (*_ifp->if_rmap)(_ifp,_cmap)
00075 #define fb_wmap(_ifp,_cmap)             (*_ifp->if_wmap)(_ifp,_cmap)
00076 #define fb_view(_ifp,_xc,_yc,_xz,_yz)   (*_ifp->if_view)(_ifp,_xc,_yc,_xz,_yz)
00077 #define fb_getview(_ifp,_xcp,_ycp,_xzp,_yzp) \
00078                 (*_ifp->if_getview)(_ifp,_xcp,_ycp,_xzp,_yzp)
00079 #define fb_setcursor(_ifp,_bits,_xb,_yb,_xo,_yo) \
00080                 (*_ifp->if_setcursor)(_ifp,_bits,_xb,_yb,_xo,_yo)
00081 #define fb_cursor(_ifp,_mode,_x,_y)     (*_ifp->if_cursor)(_ifp,_mode,_x,_y)
00082 #define fb_getcursor(_ifp,_modep,_xp,_yp) \
00083                 (*_ifp->if_getcursor)(_ifp,_modep,_xp,_yp)
00084 #define fb_readrect(_ifp,_xmin,_ymin,_width,_height,_pp) \
00085                 (*_ifp->if_readrect)(_ifp,_xmin,_ymin,_width,_height,_pp)
00086 #define fb_writerect(_ifp,_xmin,_ymin,_width,_height,_pp) \
00087                 (*_ifp->if_writerect)(_ifp,_xmin,_ymin,_width,_height,_pp)
00088 #define fb_bwreadrect(_ifp,_xmin,_ymin,_width,_height,_pp) \
00089                 (*_ifp->if_bwreadrect)(_ifp,_xmin,_ymin,_width,_height,_pp)
00090 #define fb_bwwriterect(_ifp,_xmin,_ymin,_width,_height,_pp) \
00091                 (*_ifp->if_bwwriterect)(_ifp,_xmin,_ymin,_width,_height,_pp)
00092 
00093 /* Library entry points which are true functions. */
00094 #ifdef USE_PROTOTYPES
00095 FB_EXPORT extern void   fb_configureWindow(FBIO *, int, int);
00096 FB_EXPORT extern FBIO   *fb_open(char *file, int width, int height);
00097 FB_EXPORT extern int    fb_close(FBIO *ifp);
00098 FB_EXPORT extern int    fb_genhelp(void);
00099 FB_EXPORT extern int    fb_ioinit(FBIO *ifp);
00100 FB_EXPORT extern int    fb_seek(FBIO *ifp, int x, int y);
00101 FB_EXPORT extern int    fb_tell(FBIO *ifp, int *xp, int *yp);
00102 FB_EXPORT extern int    fb_rpixel(FBIO *ifp, unsigned char *pp);
00103 FB_EXPORT extern int    fb_wpixel(FBIO *ifp, unsigned char *pp);
00104 FB_EXPORT extern int    fb_flush(FBIO *ifp);
00105 FB_EXPORT extern void   fb_log(char *fmt, ...);
00106 FB_EXPORT extern int    fb_null(FBIO *ifp);
00107 FB_EXPORT extern int    fb_null_setcursor(FBIO *ifp, const unsigned char *bits, int xbits, int ybits, int xorig, int yorig);
00108 
00109 /* utility functions */
00110 FB_EXPORT extern int    fb_common_file_size(unsigned long int *widthp, unsigned long int *heightp, const char *filename, int pixel_size);
00111 FB_EXPORT extern int    fb_common_image_size(unsigned long int *widthp, unsigned long int *heightp, unsigned long int npixels);
00112 FB_EXPORT extern int    fb_common_name_size(unsigned long int *widthp, unsigned long int *heightp, const char *name);
00113 
00114 /* color mapping */
00115 FB_EXPORT extern int    fb_is_linear_cmap(const ColorMap *cmap);
00116 FB_EXPORT extern void   fb_make_linear_cmap(ColorMap *cmap);
00117 
00118 /* backward compatibility hacks */
00119 FB_EXPORT extern int    fb_reset(FBIO *ifp);
00120 FB_EXPORT extern int    fb_viewport(FBIO *ifp, int left, int top, int right, int bottom);
00121 FB_EXPORT extern int    fb_window(FBIO *ifp, int xcenter, int ycenter);
00122 FB_EXPORT extern int    fb_zoom(FBIO *ifp, int xzoom, int yzoom);
00123 FB_EXPORT extern int    fb_scursor(FBIO *ifp, int mode, int x, int y);
00124 
00125 /*
00126  * Some functions and variables we couldn't hide.
00127  * Not for general consumption.
00128  */
00129 FB_EXPORT extern int    _fb_pgin();
00130 FB_EXPORT extern int    _fb_pgout();
00131 FB_EXPORT extern int    _fb_pgflush();
00132 FB_EXPORT extern int    _fb_disk_enable;
00133 FB_EXPORT extern int    fb_sim_readrect(FBIO *ifp, int xmin, int ymin, int width, int height, unsigned char *pp);
00134 FB_EXPORT extern int    fb_sim_writerect(FBIO *ifp, int xmin, int ymin, int width, int height, const unsigned char *pp);
00135 FB_EXPORT extern int    fb_sim_bwreadrect(FBIO *ifp, int xmin, int ymin, int width, int height, unsigned char *pp);
00136 FB_EXPORT extern int    fb_sim_bwwriterect(FBIO *ifp, int xmin, int ymin, int width, int height, const unsigned char *pp);
00137 FB_EXPORT extern int    fb_sim_view(FBIO *ifp, int xcenter, int ycenter, int xzoom, int yzoom);
00138 FB_EXPORT extern int    fb_sim_getview(FBIO *ifp, int *xcenter, int *ycenter, int *xzoom, int *yzoom);
00139 FB_EXPORT extern int    fb_sim_cursor(FBIO *ifp, int mode, int x, int y);
00140 FB_EXPORT extern int    fb_sim_getcursor(FBIO *ifp, int *mode, int *x, int *y);
00141 #else
00142 FB_EXPORT extern FBIO   *fb_open();
00143 FB_EXPORT extern int    fb_close();
00144 FB_EXPORT extern int    fb_genhelp();
00145 FB_EXPORT extern int    fb_ioinit();
00146 FB_EXPORT extern int    fb_seek();
00147 FB_EXPORT extern int    fb_tell();
00148 FB_EXPORT extern int    fb_rpixel();
00149 FB_EXPORT extern int    fb_wpixel();
00150 FB_EXPORT extern int    fb_flush();
00151 FB_EXPORT extern void   fb_log();
00152 FB_EXPORT extern int    fb_null();
00153 FB_EXPORT extern int    fb_null_setcursor();
00154 /* utility functions */
00155 FB_EXPORT extern int    fb_common_file_size();
00156 FB_EXPORT extern int    fb_common_image_size();
00157 FB_EXPORT extern int    fb_common_name_size();
00158 
00159 /* colormap functions */
00160 FB_EXPORT extern int    fb_is_linear_cmap();
00161 FB_EXPORT extern void   fb_make_linear_cmap();
00162 
00163 /* backward compatibility hacks */
00164 FB_EXPORT extern int    fb_reset();
00165 FB_EXPORT extern int    fb_viewport();
00166 FB_EXPORT extern int    fb_window();
00167 FB_EXPORT extern int    fb_zoom();
00168 FB_EXPORT extern int    fb_scursor();
00169 
00170 /*
00171  * Some functions and variables we couldn't hide.
00172  * Not for general consumption.
00173  */
00174 FB_EXPORT extern int    _fb_pgin();
00175 FB_EXPORT extern int    _fb_pgout();
00176 FB_EXPORT extern int    _fb_pgflush();
00177 FB_EXPORT extern int    _fb_disk_enable;
00178 FB_EXPORT extern int    fb_sim_readrect();
00179 FB_EXPORT extern int    fb_sim_writerect();
00180 FB_EXPORT extern int    fb_sim_bwreadrect();
00181 FB_EXPORT extern int    fb_sim_bwwriterect();
00182 FB_EXPORT extern int    fb_sim_view();
00183 FB_EXPORT extern int    fb_sim_getview();
00184 FB_EXPORT extern int    fb_sim_cursor();
00185 FB_EXPORT extern int    fb_sim_getcursor();
00186 #endif
00187 
00188 #ifdef IF_X
00189   FB_EXPORT extern int _X24_open_existing();
00190   FB_EXPORT extern int X24_close_existing();
00191 #endif
00192 
00193 #ifdef IF_OGL
00194   FB_EXPORT extern int _ogl_open_existing();
00195   FB_EXPORT extern int ogl_close_existing();
00196 #endif
00197 
00198 #ifdef IF_WGL
00199   FB_EXPORT extern int _wgl_open_existing();
00200   FB_EXPORT extern int wgl_close_existing();
00201 #endif
00202 
00203 /*
00204  * Copy one RGB pixel to another.
00205  */
00206 #define COPYRGB(to,from) { (to)[RED]=(from)[RED];\
00207                            (to)[GRN]=(from)[GRN];\
00208                            (to)[BLU]=(from)[BLU]; }
00209 
00210 /**
00211  * A fast inline version of fb_wpixel.  This one does NOT check for errors,
00212  *  nor "return" a value.  For reasons of C syntax it needs the basename
00213  *  of an RGBpixel rather than a pointer to one.
00214  */
00215 #define FB_WPIXEL(ifp,pp) {if((ifp)->if_pno==-1)_fb_pgin((ifp),(ifp)->if_pixcur/(ifp)->if_ppixels);\
00216         (*((ifp)->if_pcurp+0))=(pp)[0];(*((ifp)->if_pcurp+1))=(pp)[1];(*((ifp)->if_pcurp+2))=(pp)[2];\
00217         (ifp)->if_pcurp+=3;(ifp)->if_pixcur++;(ifp)->if_pdirty=1;\
00218         if((ifp)->if_pcurp>=(ifp)->if_pendp){_fb_pgout((ifp));(ifp)->if_pno= -1;}}
00219 
00220 /* Debug Bitvector Definition */
00221 #define FB_DEBUG_BIO    1       /* Buffered io calls (less r/wpixel) */
00222 #define FB_DEBUG_CMAP   2       /* Contents of colormaps */
00223 #define FB_DEBUG_RW     4       /* Contents of reads and writes */
00224 #define FB_DEBUG_BRW    8       /* Buffered IO rpixel and wpixel */
00225 
00226 #define FB_CKMAG(_ptr, _magic, _str)    \
00227         if( !(_ptr) )  { \
00228                 fb_log("ERROR: null %s ptr, file %s, line %d\n", \
00229                         _str, __FILE__, __LINE__ ); \
00230                 abort(); \
00231         } else if( *((long *)(_ptr)) != (_magic) )  { \
00232                 fb_log("ERROR: bad %s ptr x%x, s/b x%x, was x%x, file %s, line %d\n", \
00233                         _str, _ptr, _magic, \
00234                         *((long *)(_ptr)), __FILE__, __LINE__ ); \
00235                 abort(); \
00236         }
00237 
00238 /* tcl.c */
00239 /* The presence of Tcl_Interp as an arg prevents giving arg list */
00240 FB_EXPORT extern void fb_tcl_setup();
00241 #ifdef BRLCAD_DEBUG
00242 FB_EXPORT extern int Fb_d_Init();
00243 #else
00244 FB_EXPORT extern int Fb_Init();
00245 #endif
00246 FB_EXPORT extern int fb_refresh(FBIO *ifp, int x, int y, int w, int h);
00247 
00248 /* vers.c */
00249 FB_EXPORT extern char fb_version[];
00250 
00251 #endif /* FB_H */
00252 /*@}*/
00253 /*
00254  * Local Variables:
00255  * mode: C
00256  * tab-width: 8
00257  * c-basic-offset: 4
00258  * indent-tabs-mode: t
00259  * End:
00260  * ex: shiftwidth=4 tabstop=8
00261  */
00262 

Generated on Mon Sep 18 01:24:40 2006 for BRL-CAD by  doxygen 1.4.6