4 // header file for the BMGImage functions
6 // Copyright 2000, 2001 M. Scott Heiman
8 // You may use the software for any purpose you see fit. You may modify
9 // it, incorporate it in a commercial application, use it for school,
10 // even turn it in as homework. You must keep the Copyright in the
11 // header and source files. This software is not in the "Public Domain".
12 // You may use this software at your own risk. I have made a reasonable
13 // effort to verify that this software works in the manner I expect it to;
16 // THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" AND
17 // WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, INCLUDING
18 // WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A
19 // PARTICULAR PURPOSE. IN NO EVENT SHALL MICHAEL S. HEIMAN BE LIABLE TO
20 // YOU OR ANYONE ELSE FOR ANY DIRECT, SPECIAL, INCIDENTAL, INDIRECT OR
21 // CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING
22 // WITHOUT LIMITATION, LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE,
23 // OR THE CLAIMS OF THIRD PARTIES, WHETHER OR NOT MICHAEL S. HEIMAN HAS
24 // BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
25 // ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
26 // POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
29 #include "../osal_preproc.h"
32 typedef struct tagRGBQUAD
34 unsigned char rgbBlue;
35 unsigned char rgbGreen;
37 unsigned char rgbReserved;
45 errInvalidPixelFormat = 2,
46 errMemoryAllocation = 3,
48 errInvalidBitmapHandle = 5,
51 errUnsupportedFileFormat = 8,
52 errInvalidBMGImage = 9,
53 errInvalidFileExtension = 10,
56 errInvalidGeoTIFFPointer = 13,
57 errUndefinedBGImage = 14,
58 errBGImageTooSmall = 15,
62 typedef enum BMG_Error BMGError;
69 unsigned char bits_per_pixel;
71 unsigned short palette_size;
72 unsigned char bytes_per_palette_entry;
73 unsigned char *palette;
74 unsigned int scan_width;
75 int opt_for_bmp; /*= 1 if memory has been sized for HBITMAP, 0 otherwise*/
76 short transparency_index;
80 #if defined(__cplusplus)
84 /* initializes a BMGImage to default values */
86 void InitBMGImage(struct BMGImageStruct *img );
88 /* frees memory allocated to a BMGImage */
90 void FreeBMGImage( struct BMGImageStruct *img );
92 /* allocates memory (bits & palette) for a BMGImage.
93 returns 1 if successfull, 0 otherwise.
94 width, height, bits_per_pixel, palette_size, & opt_for_bmp must have valid
95 values before this function is called.
96 Assumes that all images with bits_per_pixel <= 8 requires a palette.
97 will set bits_per_palette_entry, scan_width, bits, & palette */
99 BMGError AllocateBMGImage( struct BMGImageStruct *img );
101 /* compresses 8 BPP paletted images to 1 BPP or 4 BPP paletted images if
104 BMGError CompressBMGImage( struct BMGImageStruct *img );
107 /* a utility function for freeing memory created in BMGLib */
109 void FreeBMGMemory( unsigned char *mem );
111 /* converts a color image to a gray scale image */
113 BMGError ConvertToGrayScale( struct BMGImageStruct *img );
115 /* converts a color image to a pseudo-gray scale image */
117 BMGError ConvertToPseudoGrayScale( struct BMGImageStruct *img );
119 /* stores the contents of a bitmap into a BMGImageStruct */
121 BMGError GetDataFromBitmap( HBITMAP hBitmap,
122 struct BMGImageStruct *img,
125 /* creates an HBITMAP from a BMGImageStruct */
127 HBITMAP CreateBitmapFromData( struct BMGImageStruct img,
130 /* sets the background color for alpha blending
131 color points to an array of 4 unsigned chars
132 color[0] = blue, color[1] = green, color[2] = red, color[3] = unused */
134 void SetBMGBackgroundColor( unsigned char *color );
136 /* defines the background bitmap that is used for alpha blending & transparent
139 BMGError SetBMGBackgroundBitmap( HBITMAP hBitmap );
141 /* defines the background image that is used for alpha blending & transparent
144 BMGError SetBMGBackgroundImage( struct BMGImageStruct img );
146 /* Converts paletted images and 16-BPP images to 24-BPP images */
148 BMGError ConvertPaletteToRGB( struct BMGImageStruct img_in,
149 struct BMGImageStruct *img_out );
151 /* copies the contents of the input image into the output image */
153 BMGError CopyBMGImage( struct BMGImageStruct img_in,
154 struct BMGImageStruct *img_out );
156 /* returns the last error state */
158 BMGError GetLastBMGError();
160 /* gets the error message */
162 void GetLastBMGErrorMessage( const char **msg );
164 #if defined(__cplusplus)