The FBuffer module essentially implements a device independent pixelmap. It contains a number of useful functions to read and write color information from/to all VglTools supported hardware platforms. It also has functions to read and write it's contents to a number of industry standard file formats such as JPEG, GIF, TIFF, TARGA, BMP, PNG etc.
Pixelmap is used to store the contents of a hardware frame buffer in a device dependent manner.
The functions associated with a ZBuffer object are the following.
*vgl_ZBufferBegin - create an instance of a ZBuffer object vgl_ZBufferEnd - destroy an instance of a ZBuffer object vgl_ZBufferError - return ZBuffer object error flag
vgl_ZBufferClear - set entire z-buffer to far value vgl_ZBufferDef - define maximum device coordinate extent Inq - inquire maximum device coordinate extent vgl_ZBufferSetDepth - set individual z-buffer pixel depth GetDepth - get individual z-buffer pixel depth
See Chapter 7, Drawing Functions for details.vgl_DrawFunZBufferRead (drawfun,left,right,bottom,top,zbuffer) vgl_DrawFunZBufferWrite (drawfun,left,right,bottom,top,zbuffer)
*vgl_ZBufferBegin - create an instance of an ZBuffer object
vgl_ZBuffer *vgl_ZBufferBegin ()
None
Destroy an instance of a ZBuffer object using
void vgl_ZBufferEnd (vgl_ZBuffer *zbuffer)
Return the current value of a ZBuffer object error flag using
Vint vgl_ZBufferError (vgl_ZBuffer *zbuffer)
vgl_ZBufferClear - clear entire z-buffer to far value
void vgl_ZBufferClear (vgl_ZBuffer *zbuffer)
zbuffer Pointer to ZBuffer object.
None
vgl_ZBufferDef - define maximum device coordinate dimensions
void vgl_ZBufferDef (vgl_ZBuffer *zbuffer, Vint xsize, Vint ysize)
zbuffer Pointer to ZBuffer object. xsize Width of zbuffer in pixels ysize Height of zbuffer in pixels
None
Inquire of defined xsize and ysize as output arguments using
void vgl_ZBufferInq (vgl_ZBuffer *zbuffer, Vint *xsize, Vint *ysize)
vgl_ZBufferSetDepth - set individual zbuffer depth value
void vgl_ZBufferSetDepth (vgl_ZBuffer *zbuffer, Vint ix, Vint iy, Vfloat z)
zbuffer Pointer to ZBuffer object. ix, iy Device coordinates of pixel to set. z Depth coordinate
None
The depth coordinate lies in the interval [0.,1.].
Get z as an output argument using
void vgl_ZBufferGetDepth (vgl_ZBuffer *zbuffer, Vint ix, Vint iy, Vfloat *z)
*vgl_FBufferBegin - create an instance of a FBuffer object vgl_FBufferEnd - destroy an instance of a FBuffer object vgl_FBufferError - return FBuffer object error flag vgl_FBufferCopy - make a copy of a FBuffer object
vgl_FBufferBorder - add a constant color border vgl_FBufferBrightContrast - adjust brightness and contrast vgl_FBufferClear - set frame buffer to current color vgl_FBufferColor - set current RGB components of color vgl_FBufferCut - cut out a frame buffer vgl_FBufferDef - define frame buffer dimensions Inq - inquire frame buffer dimensions vgl_FBufferGammaWarp - perform gamma correction vgl_FBufferGreyScale - convert to gray scale vgl_FBufferPaste - paste in a frame buffer vgl_FBufferReverseBW - reverse black and white pixels vgl_FBufferRotate - rotate counterclockwise by 90 degrees vgl_FBufferScale - scale a frame buffer by an integer factor vgl_FBufferSetColor - set individual frame buffer RGB value GetColor - get individual frame buffer RGB value vgl_FBufferSetColorAlpha - set individual frame buffer RGBA value GetColorAlpha - get individual frame buffer RGBA value vgl_FBufferSetParamf - set image file interface parameters vgl_FBufferSetParami - set image file interface parameters vgl_FBufferSetPixel - set individual frame buffer pixel value GetPixel - get individual frame buffer pixel value vgl_FBufferOpenFFMPEG - open FFMPEG supported video file vgl_FBufferWriteFFMPEG - write FFMPEG supported video file vgl_FBufferCloseFFMPEG - close FFMPEG supported video file vgl_FBufferReadBMP - read from BMP file vgl_FBufferWriteBMP - write to BMP file vgl_FBufferWriteEPS - write to Encapsulated PostScript file vgl_FBufferReadGIF - read from GIF file vgl_FBufferWriteGIF - write to GIF file vgl_FBufferAppendGIF - append to a GIF file vgl_FBufferReadJPEG - read from JPEG file vgl_FBufferWriteJPEG - write to JPEG file vgl_FBufferWritePict - write to Pict file vgl_FBufferReadPNG - read from PNG file vgl_FBufferWritePNG - write to PNG file vgl_FBufferReadSGI - read from SGI RGB file vgl_FBufferWriteSGI - write to SGI RGB file vgl_FBufferWriteSVG - write to Scaleable Vector Graphics file vgl_FBufferReadTarga - read from Targa file vgl_FBufferWriteTarga - write to Targa file vgl_FBufferReadTIFF - read from Tiff file vgl_FBufferWriteTIFF - write to Tiff file vgl_FBufferWriteWINAVI - write to Microsoft Windows AVI stream vgl_FBufferCloseWINAVI - close Microsoft Windows AVI stream vgl_FBufferReadWINDIB - read from Microsoft Windows memory DIB vgl_FBufferWriteWINDIB - write to Microsoft Windows memory DIB vgl_FBufferPixelmap - convert Pixelmap object vgl_FBufferZoom - change dimensions of a frame buffer
See Chapter 7, Drawing Functions for details.vgl_DrawFunFBufferRead (drawfun,left,right,bottom,top,fbuffer) vgl_DrawFunFBufferWrite (drawfun,left,right,bottom,top,fbuffer)
The FBuffer module contains a number of image processing functions. The brightness, contrast, and gamma warp may be adjusted using vgl_FBufferBrightContrast and vgl_FBufferGammaWarp . Black and white pixels may be reversed using vgl_FBufferReverseBW. A color image may be converted to grey scale using vgl_FBufferGreyScale. A useful function for adding a border to an image is vgl_FBufferBorder It is possible to cut and paste portions of frame buffer using vgl_FBufferCut and vgl_FBufferPaste. The vgl_FBufferZoom will resize an image. This function is useful for creating thumbnails of an image or other resizing purposes.
The support of the Microsoft Windows AVI image format depends upon external library support. The Windows AVI image file format is supported by vgl_FBufferWriteWINAVI and vgl_FBufferCloseWINAVI. The symbol VKI_WIND_WIN32 must be defined for the function calls to the underlying Windows AVI API to be compiled.
The PNG (Portable Network Graphics) image format is supported by vgl_FBufferReadPNG and vgl_FBufferWritePNG. The symbol VKI_LIBAPI_PNG or VKI_EXTAPI_PNG must be defined for the function calls to the underlying PNG library to be compiled. Use the symbol VKI_LIBAPI_PNG if using the public source or the symbol VKI_EXTAPI_PNG if using the delivered source. The PNG library in turn depends upon zlib. The source code for the underlying PNG libraries, libpng and zlib, is publicly available. See the following URL for libpng.
http://www.libpng.orgSee the following URL for zlib.
http://www.gzip.org/zlib
The TIFF file format is supported by vgl_FBufferReadTIFF. The symbol VKI_LIBAPI_TIFF or VKI_EXTAPI_TIFF must be defined for the function calls to the underlying TIFF library to be compiled. The writing of TIFF files is supported without using an external library. However if VKI_LIBAPI_TIFF is defined the writing of TIFF files will use the external library functions. Use the symbol VKI_LIBAPI_TIFF if using the public source or the symbol VKI_EXTAPI_TIFF if using the delivered source. The source code for the underlying TIFF libraries libtiff and zlib, is publicly available. See the following URL.
http://www.remotesensing.org/libtiff
The JPEG file format is supported by vgl_FBufferReadJPEG. The symbol VKI_LIBAPI_JPEG or VKI_EXTAPI_JPEG must be defined for the function calls to the underlying JPEG library to be compiled. The writing of JPEG files is supported without using an external library. However if VKI_LIBAPI_JPEG is defined the writing of JPEG files will use the external library functions. Use the symbol VKI_LIBAPI_JPEG if using the public source or the symbol VKI_EXTAPI_JPEG if using the delivered source.
http://www.ffmpeg.org
*vgl_FBufferBegin - create an instance of a FBuffer object
vgl_FBuffer *vgl_FBufferBegin ()
None
Destroy an instance of a FBuffer object using
void vgl_FBufferEnd (vgl_FBuffer *fbuffer)
Return the current value of a FBuffer object error flag using
Vint vgl_FBufferError (vgl_FBuffer *fbuffer)Make a copy of a FBuffer object. The private data from the fromfbuffer object is copied to the fbuffer object. Any previous private data in fbuffer is lost.
void vgl_FBufferCopy (vgl_FBuffer *fbuffer, vgl_FBuffer *fromfbuffer)
vgl_FBufferBorder - add a constant color border
void vgl_FBufferBorder (vgl_FBuffer *fbuffer, Vint borderwidth)
fbuffer Pointer to FBuffer object. borderwidth Width of border in pixels
None
vgl_FBufferBrightContrast - adjust brightness and contrast
void vgl_FBufferBrightContrast (vgl_FBuffer *fbuffer, Vfloat bright, Vfloat contrast)
fbuffer Pointer to FBuffer object. bright Brightness bias. contrast Contrast factor.
None
The equation applied to each component, c, of the color is:
c = (c + bright - .5) * contrast + .5
vgl_FBufferClear - clear rectangle of frame buffer to current color
void vgl_FBufferClear (vgl_FBuffer *fbuffer, Vint left, Vint right, Vint bottom, Vint top)
fbuffer Pointer to FBuffer object. left Left device coordinate limit of rectangle right Right device coordinate limit of rectangle bottom Bottom device coordinate limit of rectangle top Top device coordinate limit of rectangle
None
vgl_FBufferColor - set RGB components of current color
void vgl_FBufferColor (vgl_FBuffer *fbuffer, Vfloat c[3])
fbuffer Pointer to FBuffer object. c RGB components of current color.
None
vgl_FBufferCut - cut out a frame buffer
void vgl_FBufferCut (vgl_FBuffer *fbuffer, Vint xorig, Vint yorig, vgl_FBuffer *cutfbuffer)
fbuffer Pointer to FBuffer object. xorig,yorig X and y pixel location in fbuffer from which to cut image.
cutfbuffer Pointer to FBuffer object into which cut is written.
vgl_FBufferDef - define frame buffer dimensions
void vgl_FBufferDef (vgl_FBuffer *fbuffer, Vint xsize, Vint ysize)
fbuffer Pointer to FBuffer object. xsize Width of frame buffer in pixels ysize Height of frame buffer in pixels
None
Inquire of defined xsize and ysize as output arguments using
void vgl_FBufferInq (vgl_FBuffer *fbuffer, Vint *xsize, Vint *ysize)
vgl_FBufferGammaWarp - perform gamma correction
void vgl_FBufferGammaWarp (vgl_FBuffer *fbuffer, Vfloat gamma)
fbuffer Pointer to FBuffer object. gamma Gamma correction factor
None
The equation applied to each component, c, of the color is:
c = c ** 1./gamma
vgl_FBufferGreyScale - convert to gray scale
void vgl_FBufferGreyScale (vgl_FBuffer *fbuffer)
fbuffer Pointer to FBuffer object.
None
The equation for grayscale is:
grayscale = .3*red + .5*green + .2*blue;
vgl_FBufferPaste - paste in a frame buffer
void vgl_FBufferPaste (vgl_FBuffer *fbuffer, Vint xorig, Vint yorig, vgl_FBuffer *pastefbuffer)
fbuffer Pointer to FBuffer object. xorig,yorig X and y pixel location in fbuffer in which to paste image.
pastefbuffer Pointer to FBuffer object from which paste is read.
vgl_FBufferReverseBW - reverse black and white pixels in a frame buffer
void vgl_FBufferReverseBW (vgl_FBuffer *fbuffer)
fbuffer Pointer to FBuffer object.
None
vgl_FBufferScale - scale a frame buffer by an integer factor
void vgl_FBufferScale (vgl_FBuffer *fbuffer, Vint fac, vgl_FBuffer *scafbuffer)
fbuffer Pointer to FBuffer object. fac Integer scaling factor.
scafbuffer Pointer to FBuffer object into which scaled frame buffer is written.
vgl_FBufferRotate - rotate counterclockwise by 90 degrees
void vgl_FBufferRotate (vgl_FBuffer *fbuffer, vgl_FBuffer *rotfbuffer)
fbuffer Pointer to FBuffer object.
rotfbuffer Pointer to FBuffer object into which rotated frame buffer is written.
vgl_FBufferSetColor - set a frame buffer RGB color value
void vgl_FBufferSetColor (vgl_FBuffer *fbuffer, Vint ix, Vint iy, Vfloat c[3])
fbuffer Pointer to FBuffer object. ix, iy Device coordinates of pixel to set. c RGB components of color.
None
The RGB components lie in the interval [0.,1.]. Each color is represented by 8 bits. The bits for each color are packed in an unsigned integer with red occupying the least significant byte.
Get c as an output argument using
void vgl_FBufferGetColor (vgl_FBuffer *fbuffer, Vint ix, Vint iy, Vfloat c[3])
vgl_FBufferSetColorAlpha - set a frame buffer RGBA color value
void vgl_FBufferSetColorAlpha (vgl_FBuffer *fbuffer, Vint ix, Vint iy, Vfloat c[4])
fbuffer Pointer to FBuffer object. ix, iy Device coordinates of pixel to set. c RGBA components of color.
None
The RGBA components lie in the interval [0.,1.]. Internally each component is represented by 8 bits. The bits for each component are packed in an unsigned integer with red occupying the least significant byte.
Get c as an output argument using
void vgl_FBufferGetColorAlpha (vgl_FBuffer *fbuffer, Vint ix, Vint iy, Vfloat c[4])
vgl_FBufferSetParamf - set file interface parameters
void vgl_FBufferSetParamf (vgl_FBuffer *fbuffer, Vint type, Vint fparam)
fbuffer Pointer to FBuffer object. type Type of display parameter to set =FBUFFER_DELAYSECONDS Delay time in seconds fparam Specifies the float value that type will be set to.
None
vgl_FBufferSetParami - set file interface parameters
void vgl_FBufferSetParami (vgl_FBuffer *fbuffer, Vint type, Vint iparam)
fbuffer Pointer to FBuffer object. type Type of display parameter to set =FBUFFER_BITRATE Bit rate for H264 MP4 =FBUFFER_INTERLACE Interlace image file =FBUFFER_LOOPS Number of times to loop animation =FBUFFER_LOOPSFLAG Looping flag =FBUFFER_GRAYSCALE Gray scale flag =FBUFFER_COMPFACT Compression factor =FBUFFER_AVICOMPFACT AVI compression factor =FBUFFER_AVICOMPTYPE AVI compression type =FBUFFER_GIFCOMPTYPE GIF compression type =FBUFFER_GIFCMAPTYPE GIF base colormap type =FBUFFER_GIFCMAPMATCH GIF Attempt exact colormap =FBUFFER_TIFFCOMPTYPE TIFF compression type iparam Specifies the integer value that type will be set to. =VGL_ON Enable =VGL_OFF Disable =FBUFFER_AVICOMP_INTELINDEO INTEL Indeo =FBUFFER_AVICOMP_CINEPAK Cinepak =FBUFFER_AVICOMP_MSVIDEO Microsoft Video 1 =FBUFFER_GIFCOMP_RLE Run length encoding (not patented) =FBUFFER_GIFCOMP_LZW LZW compression (patented) =FBUFFER_GIFCMAP_DITHER Use a dithered colormap =FBUFFER_GIFCOMP_332RGB Use a 332 bit RGB colormap =FBUFFER_TIFFCOMP_NONE Use no compression =FBUFFER_TIFFCOMP_LZW LZW compression =FBUFFER_TIFFCOMP_DEFLATE Deflation compression =FBUFFER_TIFFCOMP_NATIVE Native compression
None
The parameter FBUFFER_BITRATE set the bit rate used in H264 encoded MP4 files. The higher the bit rate the higher the vides quality resulting in a larger file size By default FBUFFER_BITRATE is set to 200000.
Specify a the integer number of times the images in an animated GIF file are to be replayed. A value of zero results in an infinite number of loops. Note that the looping facility for GIF files is a Netscape Navigator extension. By default FBUFFER_LOOPS is set to 0. Use FBUFFER_LOOPSFLAG to enable looping. By default FBUFFER_LOOPSFLAG is set to VGL_OFF.
Specify a flag to turn gray scale image writing on or off. If gray scale is enabled the color contents of the frame buffer will be written to image format in gray scale. This parameter affects all image format writing functions such as vgl_FBufferWriteGIF. By default FBUFFER_GRAYSCALE is set to VGL_OFF.
The compression factor, FBUFFER_COMPFACT is an integer number of percent suggesting a target compression factor. This parameter affects the writing of JPEG and AVI image files. By default FBUFFER_COMPFACT is set to 85.
The parameters, FBUFFER_AVICOMPFACT and FBUFFER_AVICOMPTYPE affect the writing of AVI files using the function vgl_FBufferWriteWINAVI. The compression type, FBUFFER_AVICOMPTYPE selects video compression. The recommended compression type for scientific and engineering graphics is FBUFFER_AVICOMP_MSVIDEO. By default FBUFFER_AVICOMPTYPE is set to FBUFFER_AVICOMP_NONE.
The parameter FBUFFER_GIFCOMPTYPE affects the writing of GIF files using the function vgl_FBufferWriteGIF. The importance of this parameter is due to the existence of a Unisys patent on the LZW compression algorithm. The value FBUFFER_GIFCOMP_RLE indicates the use of a non-patented run length encoding compression algorithm. The value FBUFFER_GIFCOMP_ZLW indicates the use of the patented LZW compression algorithm. By default FBUFFER_GIFCOMPTYPE is set to FBUFFER_GIFCOMP_LZW.
The parameter FBUFFER_TIFFCOMPTYPE affects the writing of TIFF files using the function vgl_FBufferWriteTIFF. By default FBUFFER_TIFFCOMPTYPE is set to FBUFFER_TIFFCOMP_LZW. Note that some Microsoft Windows applications do not handle the default compression properly. Use FBUFFER_TIFFCOMP_NATIVE if consistent results with Windows applications is required.
The parameters FBUFFER_GIFCMAPTYPE and FBUFFER_GIFCMAPMATCH affect the type of color map to be generated for writing GIF files using the function vgl_FBufferWriteGIF. If FBUFFER_GIFCMAPMATCH is enabled, then an attempt is made to generate a color map in which each color in the image is exactly represented in the color map. This will succeed only if the number of unique colors in the image is less than or equal to 256. If an exact match is not possible or FBUFFER_GIFCMAPMATCH is disabled, then the color map generated is determined by FBUFFER_GIFCMAPTYPE. By default FBUFFER_GIFCMAPTYPE is set to FBUFFER_GIFCMAP_DITHER and FBUFFER_GIFCMAPMATCH is set to VGL_OFF.
vgl_FBufferSetPixel - set a frame buffer pixel value
void vgl_FBufferSetPixel (vgl_FBuffer *fbuffer, Vint ix, Vint iy, Vuint value)
fbuffer Pointer to FBuffer object. ix, iy Device coordinates of pixel to set. value Value
None
Each color is represented by 8 bits. The bits for each color are packed in an unsigned integer with red occupying the least significant byte.
Get value as an output argument using
void vgl_FBufferGetPixel (vgl_FBuffer *fbuffer, Vint ix, Vint iy, Vuint *value)
vgl_FBufferOpenFFMPEG - open FFMPEG supported video file
void vgl_FBufferOpenFFMPEG (vgl_FBuffer *fbuffer, Vint codectype, Vint filetype, Vchar *pathname)
fbuffer Pointer to FBuffer object. codectype Video coded type =FBUFFER_FFMPEG_CODEC_MPEG4 MPEG4 codec =FBUFFER_FFMPEG_CODEC_H264 H264 codec =FBUFFER_FFMPEG_CODEC_PNG PNG codec =FBUFFER_FFMPEG_CODEC_QTRLE QTRLE codec filetype Video coded type =FBUFFER_FFMPEG_MP4 MP4 file =FBUFFER_FFMPEG_MOV QuickTime MOV format pathname Name of video file to open
None
sizes must be even numbers. Write individual images using vgl_FBufferWriteFFMPEG. Close the video file using vgl_FBufferCloseFFMPEG.image horizontal and vertical
MP4 files can be encoded with either the MPEG4 or the H264 encoders, while MOV files can be encoded with any of the provided encoders.
vgl_FBufferWriteFFMPEG - write FFMPEG supported video file
void vgl_FBufferWriteFFMPEG (vgl_FBuffer *fbuffer)
fbuffer Pointer to FBuffer object.
None
vgl_FBufferCloseFFMPEG - close FFMPEG supported video file
void vgl_FBufferCloseFFMPEG (vgl_FBuffer *fbuffer)
fbuffer Pointer to FBuffer object.
None
vgl_FBufferReadBMP,vgl_FBufferWriteBMP - Read/Write BMP image file.
void vgl_FBufferReadBMP (vgl_FBuffer *fbuffer, Vchar *pathname) void vgl_FBufferWriteBMP (vgl_FBuffer *fbuffer, Vchar *pathname)
fbuffer Pointer to FBuffer object. pathname Name of file to which frame buffer contents are read/written
None
vgl_FBufferWriteEPS - Write frame buffer contents to Encapsulated Postscript
void vgl_FBufferWriteEPS (vgl_FBuffer *fbuffer, Vchar *pathname)
fbuffer Pointer to FBuffer object. pathname Name of file to which frame buffer contents are written
None
vgl_FBufferReadGIF,vgl_FBufferWriteGIF,vgl_FBufferAppendGIF - GIF file interface
void vgl_FBufferReadGIF (vgl_FBuffer *fbuffer, Vchar *pathname) void vgl_FBufferWriteGIF (vgl_FBuffer *fbuffer, Vchar *pathname) void vgl_FBufferAppendGIF (vgl_FBuffer *fbuffer, Vchar *pathname)
fbuffer Pointer to FBuffer object. pathname Name of file to which frame buffer contents are read/written
None
An image may be appended to an existing GIF file to produce an "animated" GIF file using vgl_FBufferAppendGIF. The appended GIF file will use the same grayflag that was used to create the first image on the file. Use vgl_FBufferSetParami and vgl_FBufferSetParamf to control delay time, number of loops, interlacing, etc. The image will be written in grayscale if FBUFFER_GRAYSCALE is enabled using vgl_FBufferSetParami.
vgl_FBufferReadJPEG,vgl_FBufferWriteJPEG - Read/Write JPEG image file
void vgl_FBufferReadJPEG (vgl_FBuffer *fbuffer, Vchar *pathname) void vgl_FBufferWriteJPEG (vgl_FBuffer *fbuffer, Vchar *pathname)
fbuffer Pointer to FBuffer object. pathname Name of file to which frame buffer contents are written
None
vgl_FBufferWritePict - Write frame buffer contents to Pict formatted file
void vgl_FBufferWritePict (vgl_FBuffer *fbuffer, Vchar *pathname)
fbuffer Pointer to FBuffer object. pathname Name of file to which frame buffer contents are written
None
vgl_FBufferReadPNG,vgl_FBufferWritePNG - PNG file interface
void vgl_FBufferReadPNG (vgl_FBuffer *fbuffer, Vchar *pathname) void vgl_FBufferWritePNG (vgl_FBuffer *fbuffer, Vchar *pathname)
fbuffer Pointer to FBuffer object. pathname Name of file to which frame buffer contents are read/written
None
vgl_FBufferReadSGI,vgl_FBufferWriteSGI - Read/Write SGI RGB image file
void vgl_FBufferReadSGI (vgl_FBuffer *fbuffer, Vchar *pathname) void vgl_FBufferWriteSGI (vgl_FBuffer *fbuffer, Vchar *pathname)
fbuffer Pointer to FBuffer object. pathname Name of file to which frame buffer contents are read/written
None
vgl_FBufferWriteSVG - write to Scaleable Vector Graphics file
void vgl_FBufferWriteSVG (vgl_FBuffer *fbuffer, Vchar *pathname)
fbuffer Pointer to FBuffer object. pathname Name of file to which frame buffer contents are written
None
vgl_FBufferReadTarga,vgl_FBufferWriteTarga - Read/Write Targa image file
void vgl_FBufferReadTarga (vgl_FBuffer *fbuffer, Vchar *pathname) void vgl_FBufferWriteTarga (vgl_FBuffer *fbuffer, Vchar *pathname)
fbuffer Pointer to FBuffer object. pathname Name of file to which frame buffer contents are read/written
None
vgl_FBufferReadTIFF,vgl_FBufferWriteTIFF - Read/Write Tiff image file
void vgl_FBufferReadTIFF (vgl_FBuffer *fbuffer, Vchar *pathname) void vgl_FBufferWriteTIFF (vgl_FBuffer *fbuffer, Vchar *pathname)
fbuffer Pointer to FBuffer object. pathname Name of file to which frame buffer contents are written
None
vgl_FBufferWriteWINAVI - write to Microsoft Windows AVI stream
void vgl_FBufferWriteWINAVI (vgl_FBuffer *fbuffer, PAVIFILE *avifile) void vgl_FBufferCloseWINAVI (vgl_FBuffer *fbuffer)
fbuffer Pointer to FBuffer object. avifile PAVIFILE pointer to AVI file
None
The AVI file may be compressed if desired. Set the compression type and factor using vgl_FBufferSetParami. By default the AVI is not compressed.
Before these functions may be called the Microsoft Windows AVI file interface must be initialized. Once initialized, an AVI file is opened as follows:
#include <VfW.h> PAVIFILE avifile; /* initialize AVI interface only once in application */ AVIFileInit (); /* open any number of AVI files */ AVIFileOpen (&avifile,"myfile.avi",OF_CREATE|OF_WRITE,NULL);
Note that the initialization is performed only once during an application. At this point several samples may be written to a video stream by calling vgl_FBufferWriteWINAVI for each sample and calling vgl_FBufferCloseWINAVI to close the video stream. After all samples are written to the AVI file, the file must be released. Once all AVI file processing is complete, the AVI file interface must be exited as follows:
/* release each AVI file when finished writing samples */ AVIFileRelease (avifile); /* exit AVI interface only once in application */ AVIFileExit ();
The Microsoft Windows library vfw32.lib must be used at link time to satisfy the external references to the AVI system.
vgl_FBufferReadWINDIB - read from Microsoft Windows memory DIB
void vgl_FBufferReadWINDIB (vgl_FBuffer *fbuffer, BITMAPINFO *binfo, LPVOID bdata)
fbuffer Pointer to FBuffer object. binfo BITMAPINFO structure with members set. bdata Pointer to allocated memory which holds image data
None
vgl_FBufferWriteWINDIB - write to Microsoft Windows memory DIB
void vgl_FBufferWriteWINDIB (vgl_FBuffer *fbuffer, BITMAPINFO *binfo, LPVOID bdata)
fbuffer Pointer to FBuffer object. binfo BITMAPINFO structure with members set.
bdata Pointer to allocated memory to hold image data
DWORD biSize = sizeof(BITMAPINFOHEADER) LONG biWidth = xsize, width of frame buffer in pixels LONG biHeight = ysize, height of frame buffer in pixels WORD biPlanes = 1 WORD biBitCount = 16 or 24 DWORD biCompression = BI_RGB DWORD biSizeImage = (((biWidth * biBitCount) + 31) & ~31) >> 3
Get the current width and height of the frame buffer using vgl_FBufferInq. The use of a biBitCount of 16 is recommended for compatibility with most printers. The pointer to the image data, bdata, must have been allocated to be at least biSizeImage bytes.
When using Microsoft Foundation Classes (MFC). Printing can be implemented using this function. In the view class header add the following:
vgl_FBuffer *m_fbuffer; BITMAPINFO m_binfo; LPVOID m_bdata;
In the view class OnPreparePrinting grab the frame buffer and write it to a DIB data structure as follows:
Vint width; Vint height; long rowsize; Vint ierr; /* Instance FBuffer object and grab frame buffer contents */ m_fbuffer = vgl_FBufferBegin (); vgl_DrawFunSetWindow (m_dfdv); vgl_DrawFunFBufferRead (m_dfdv,0,0,0,0,m_fbuffer); vgl_FBufferInq (m_fbuffer,&width,&height); /* Fill in binfo data structure */ memset(&m_binfo,0,sizeof(BITMAPINFO)); m_binfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER); m_binfo.bmiHeader.biHeight = height; m_binfo.bmiHeader.biWidth = width; m_binfo.bmiHeader.biPlanes = 1; m_binfo.bmiHeader.biBitCount = 16; m_binfo.bmiHeader.biCompression = BI_RGB; rowsize = ((((width * m_binfo.bmiHeader.biBitCount) + 31) & ~31) >> 3); m_binfo.bmiHeader.biSizeImage = rowsize * height; m_bdata = (LPVOID)malloc(m_binfo.bmiHeader.biSizeImage); /* Write frame buffer to DIB data structure */ vgl_FBufferWriteWINDIB (m_fbuffer,&m_binfo,m_bdata,0);
In the view class OnPrint apply any scale factors to the DIB and send to printer.
float fact; Vint width; Vint height; vgl_FBufferInq (m_fbuffer,&width,&height); fact = (float)GetDeviceCaps(pDC->GetSafeHdc(),HORZRES)/(float)width; /* Shrink it by 75 percent as an example */ fact *= .75; /* Send to printer */ StretchDIBits (pDC->GetSafeHdc(), 0,0,(int)fact*width,(int)fact*height, 0,0,width,height, m_bdata,&m_binfo, DIB_RGB_COLORS, SRCCOPY);
In the view class OnEndPrinting free objects and memory as follows:
vgl_FBufferEnd (m_fbuffer); free(m_bdata);
vgl_FBufferPixelmap - convert Pixelmap object
void vgl_FBufferPixelmap (vgl_FBuffer *fbuffer, vgl_Pixelmap *pixelmap)
fbuffer Pointer to FBuffer object. pixelmap Pointer to Pixelmap object.
None
vgl_FBufferZoom - change the dimensions of a frame buffer
void vgl_FBufferZoom (vgl_FBuffer *fbuffer, vgl_FBuffer *zoomfbuffer)
fbuffer Pointer to FBuffer object.
zoomfbuffer Pointer to FBuffer object into which frame buffer of changed dimensions is written.
*vgl_PixelmapBegin - create an instance of a Pixelmap object vgl_PixelmapEnd - destroy an instance of a Pixelmap object vgl_PixelmapError - return Pixelmap object error flag
vgl_PixelmapSetBuffer - set pixelmap buffer type GetBuffer - get pixelmap buffer type vgl_PixelmapSetOrigin - set origin of pixelmap GetOrigin - get origin of pixelmap vgl_PixelmapSetSize - set size of pixelmap GetSize - get size of pixelmap
Transfer of frame buffer or zbuffer contents is performed by:vgl_DrawFunPixelmapCreate (drawfun,pixelmap) vgl_DrawFunPixelmapDestroy (drawfun,pixelmap)
The default buffer type is the frame buffer. Use vgl_PixelmapSetBuffer to set the buffer type. By default the entire buffer is read and written by the device interface functions above. Use vgl_PixelmapSetSize to specify the size of the pixelmap in pixel coordinates to be read and written. The origin of the pixelmap in the device interface window may be specified using vgl_PixelmapSetOrigin.vgl_DrawFunPixelmapRead (drawfun,pixelmap) vgl_DrawFunPixelmapWrite (drawfun,pixelmap)
See Chapter 7, Drawing Functions for details.
*vgl_PixelmapBegin - create an instance of a Pixelmap object
vgl_Pixelmap *vgl_PixelmapBegin ()
None
Destroy an instance of a Pixelmap object using
void vgl_PixelmapEnd (vgl_Pixelmap *pixelmap)
Return the current value of a Pixelmap object error flag using
Vint vgl_PixelmapError (vgl_Pixelmap *pixelmap)
vgl_PixelmapSetBuffer - set pixelmap buffer type
void vgl_PixelmapSetBuffer (vgl_Pixelmap *pixelmap, Vint buffer)
pixelmap Pointer to Pixelmap object. buffer Buffer type =PIXELMAP_FBUFFER Frame (color) buffer =PIXELMAP_ZBUFFER Z (depth) buffer
None
Get buffer as an output argument using
void vgl_PixelmapGetBuffer (vgl_Pixelmap *pixelmap, Vint *buffer)
vgl_PixelmapSetOrigin - set origin of pixelmap
void vgl_PixelmapSetOrigin (vgl_Pixelmap *pixelmap, Vint xorig, Vint yorig)
pixelmap Pointer to Pixelmap object. xorig,yorig Lower left hand corner of pixelmap in device coordinates.
None
Get xorig and yorig as output arguments using
void vgl_PixelmapGetOrigin (vgl_Pixelmap *pixelmap, Vint *xorig, Vint *yorig)
vgl_PixelmapSetSize - set size of pixelmap
void vgl_PixelmapSetSize (vgl_Pixelmap *pixelmap, Vint xsize, Vint ysize)
pixelmap Pointer to Pixelmap object. xsize,ysize Horizontal and vertical size of pixelmap in device coordinates
None
Get xsize and ysize as output arguments using
void vgl_PixelmapGetSize (vgl_Pixelmap *pixelmap, Vint *xsize, Vint *ysize)