Bitmapped Graphics Library
The Bitmapped Graphics Library (BMGLib)
BMGLib is a collection of projects that allow developers to read and write several graphics format files. Examples have been provided that show you how to display the bitmaps in applications built with MSVC++ or BCB. It provides functions that simplify using image files for OpenGL textures and saving OpenGL images to a file. It supports alpha blending with solid backgrounds and background images. It supports GeoTIFF images. BMGLib will display non-animated GIFs. A separate library, GIFLib, has been provided that will support animated GIFs.
BMGLib supports the following Image formats:
| File Format | READ | WRITE |
| Windows Bitmap (BMP) | YES | YES |
| Tagged Information File Format (TIFF) | YES | YES |
| Portable Network Graphics (PNG) | YES | YES |
| Joint Photographic Experts Group (JPEG) | YES | YES |
| Silicon Graphics International RGB & RGBA | YES | YES |
| Compuserve GIF | YES | NO |
| Animator (CEL,FLI,FLC) | YES | NO |
| Truevision Targa (TGA) | YES | YES |
| Adobe Photoshop (PSD) | YES | NO |
| IFF | YES | NO |
| PCX | YES | NO |
You can download the BMGLib source and project files below. The current version will compile with BCB 5+ or VC++ 6. Documentation and example applications have been provided as well.
Download BMGLib (2.53 MB)
You should read the following documents before building
and using BMGLib:
c:\Projects\BMGLib\readme.txt
(general information)
c:\Projects\BMGLib\BMGLib_DLL\BMGLibAPI.txt
(API documentation)
The current version (2.5) is probably the last version I intend to release at this time. I will provide bug fixes as I find them; however, I do not intend to add any new functionality unless I require it. If BMGLib does not satisfy your requirements then I suggest that you look at the plethora of free image format libraries that are available on the Internet. www.sourceforge.net is a good place to start.
Common Questions
When I try to compile BMGLib I get a linker error that tells me that it cannot find OGL.BPI. Where can I get OGL.BPI?
You can't. It is a custom component that I created. You do not need it to create BMGLib. You will need to remove the OGL.BPI file from the library list. You can use any ASCII text editor to edit the BPR file. Remove all references to OGL.BPI (and any other BPI file that the editor cannot find) from the BPR file.
A BMGLib function crashes after I use StretchBlt on a large image. Why?
This is a problem with your graphics card driver. I
have seen messages in the newsgroups that indicate that you should not use
StretchBlt on images that are larger than the dimensions of your screen.
If you attempt to do so, your graphics card driver will overwrite memory causing
the application to crash in random places or, in my case, cause Windows 2000 to
Blue Screen. If you must use StretchBlt on a huge image, then you will
need to break the image into smaller subimages and use StretchBlt on the
subimages. The dimensions of the subimages should be smaller than your
screen.
Credits
BMGLib uses several open source libraries that I obtained from the Internet. LibTIFF is a TIFF file format library that was originally developed by Silicon Graphics International (SGI). The library is currently being developed and distributed by www.libTIFF.org. LibJPEG is an open source JPEG file format library that is distributed by the Independent JPEG Group (IJG). LibPNG is an open source PNG file format library supported by people who wanted an alternative to GIF. Long live the rebellion! The zlib library is an open source library for file compression. It is distributed by other closely allied rebels. The GeoTIFF library (and its supporting projection library) can be obtained from the Remote Sensing web site. The LibUnGIF library is Eric Raymond's response to the Unisys LZW patent.
A Little History
24 January 2004
Released BMGLib 2.5
Added the PCX format as a read-only format.
The ReadTIFF function has been modified to read multiplanar images and and 16-bit per color images. 16-bit per color images are converted to 8-bit
per color images to conform to the Windows operating system. The 8 LSBs of each color are removed. This will result in a loss of resolution when
you try to display 16-bit per color images on Windows.
25 March 2003
Released BMGLib 2.4
Updated the TIFFlib library to 3.5.7
Updated the zlib library to 1.1.4
Updated the PNGLib library to 1.2.5
Many OpenGL cards support the EXT_BGRA option. This allows users to insert
and extract pixels in Windows' BGR & BGRA formats. A flag has been added
to the GetUnpackedArray and SaveUnpackedArray functions that allow users to
take advantage of the BGRA extension.
BORLAND USERS: The PNG.H file in PNGLib 1.2.5 declared all exported functions
to be 'external'. This forced me to create a static library for PNGLib and
and link that library with the BMGLib and BMGLibPNG DLLs. From now on, you
will need to build the libPNGStat project before building those 2 DLLs.
29 Sep 2002
The errCorruptFile error term was added to the BMGErr enumeration.
The ReadCEL function was modified to read FLI and FLC formats (which
appear to use the CEL file name extension).
Added PSD (Adobe Photoshop) and IFF formats to the list of read-only
formats. These "obscure" formats were used in several 3DS files
that I downloaded from the Internet.
Created a write function for TGA files (WriteTGA)
11 Nov 2001 - Bug fix for BMGLib 2.2
Line 244 in BMGDLL.c should be
if ( GetDataFromBitmap( hBitmap, &img, 1 ) == BMG_OK )
This modification must be made for version 2.1 and versions of 2.2 obtained prior to 11 Nov 2001.
Also, release versions of BMGLib created with the BCB compiler had memory access violations when the user tried to open a GIF file that was not present. The problem appears to be a bug in the BCB compiler. A "patch" was applied to correct the compiler error. The patch causes a warning to be issued when the GIF.c module is compiled.
22 Sep 2001 - BMGLib 2.2 Released
Three new utility functions were added. The ConvertPaletteToRGB function converts 1, 4, 8, and 16-BPP images to 24-BPP or 32-BPP images. It
simply copies 24-BPP and 32-BPP images. The GetDataFromFile function reads any one of the supported file formats and returns the data in a
BMGImageStruct. The CopyBMGImage function simply copies the contents of 1 BMGImageStruct to another.
The alpha blending implementation was incorrect in previous versions of BMGLib. This problem was corrected. The SetBMGBackgroundColor function must
be called to specify the background color when alpha blending with bland (single color)
backgrounds is requested.
Furthermore, BMGLib can now blend a background image with a foreground image.The SetBMGBackgroundBitmap and SetBMGBackgroundImage functions can be used to
specify the background images.
07/27/01 - BMGLib 2.1 Released
Fixed a bug in CompressBMGImage which mangled 16 BPP images.
Error codes were implemented in all BMG functions. The GetLastBMGError and GetLastBMGErrorMessage were added to
retrieve the error codes. Most BMGLib
functions return BMG_OK if no error occurs; otherwise, they will return an error code. Functions that return an HBITMAP will return a non-null handle
if no error occurs. If NULL is returned, then the GetLastBMGError can be used to determine what the error was.
Two functions were added to convert color images to grayscale and pseudo grayscale images.
In previous versions, the HBITMAP passed into the SaveBitmapToFile and GetDataFromBitmap functions had to be handles to device independent bitmaps
(DIB). Version 2.1 allows you to pass HANDLES to DIBs and device dependent bitmaps (DDB). Thanks to Rene Pilon for pointing out this deficiency.
16 BPP HBITMAPS can now be saved in TIFF, PNG, and JPEG formats.
All GeoTIFF functions were removed from BMGLib. A BMGGeoTIFF project was created and the
GeoTIFF functionality was implemented in it. I did this because I rarely needed to mix GeoTIFFs with
other image formats. It also reduced the size of the BMGLib.DLL. See the
"Projects\BMGlib\BMGGeoTIFF_DLL" folder for the project and examples.
Several people did not require all of the image formats that were included in BMGLib and would ask for a list of files required for specific formats. I
have created projects that build stand-alone DLLs for JPEG (BMGLibJPEG), TIFF (BMGLibTIFF), and PNG (BMGLibPNG). The project files that build these
stand-alone DLLs can be found in the "Projects\BMGlib\BMGlib_DLL" folder.
Version 2.0 of BMGLib used my GIFLib library. I replaced this library with Eric Raymond's libungif library. I did this to remove the C++ code and
keep the entire project in C. The C++ GIFLib class is still distributed with the project since it supports animated GIFs (BMGLib does not support animated
GIFs).
02/18/01 - BMGLib 2 is released. This is a major rewrite. Several additional file formats are now supported. OpenGL texture support was added. GeoTIFF support was added. A consistent interface between all image formats was created. Lot's of work - Lot's of changes.
09/03/00 - Upgraded libTIFF to version 3.5.5. This had 2 effects: 1) The VC++ "save" bug was fixed. 2) The LZW compression algorithm was removed to prevent violations of the UNISYS patent. It will still read LZW compressed files; however, it will not create them.
Removed the BC++/OWL projects. BC++ 5.02 w/ patch 1 consistently hangs when compiling on my dual processor, Win2K system. I have decided to discontinue supporting BC++/OWL since Borland will never fix this problem and it has abandoned OWL
08/11/00 - Fixed a minor indexing error in the TIFF file reading code. Added a VC++ project file that builds the BMGLib DLL. Added an MFC demo.
05/19/00 - BCB 5 added a declaration for INT32 that conflicted with the declaration in jmorecfg.h in the libJPEG code. jmorecfg.h was modified to accommodate BCB 5.
04/07/00 - libPNG was added to the BMGLib DLL. BMGLib DLL now reads and writes TIFF, JPEG, and PNG files.
03/05/00 - BMGLib combines libtiff and libjpeg into a single DLL that will save the contents of a TIFF or JPEG file into an HBITMAP or store the contents of an HBITMAP into a TIFF or JPEG file.
ZIP support has been added to TIFF images. The zlib library was used.