Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

provider_bmp.h

Go to the documentation of this file.
00001 /*
00002         $Id: provider_bmp.h,v 1.1 2001/03/06 15:09:12 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 
00014         File purpose:
00015                 BMP surface provider.
00016 */
00017 
00018 //This code currently supports Win32 DIBs in uncompressed 8 and 24 bpp.
00019 
00020 
00022 
00023 #ifndef header_bmpprovider
00024 #define header_bmpprovider
00025 
00026 #define BITMAP_ID     0x4D42      // universal id for a bitmap
00027 
00028 /* Compression encodings for BMP files */
00029 
00030 #ifndef WIN32
00031 #define BI_RGB          0
00032 #define BI_RLE8         1
00033 #define BI_RLE4         2
00034 #define BI_BITFIELDS    3
00035 #endif
00036 
00037 
00038 #include "generic_surfaceprovider.h"
00039 #include "../Display/pixelformat.h"
00040 #include <fstream>
00041 
00042 class CL_BMPProvider : public CL_SurfaceProvider_Generic
00043 //: Surface provider that can load BMP files.
00044 {
00045 public:
00046         
00047         static CL_Surface *create(
00048                 std::string handle,
00049                 CL_InputSourceProvider *provider,
00050                 bool transparent=false,
00051                 short trans_col=-1);
00052         //: Loads the bmp file 'handle' from the inputsource provider 'provider. 
00053         //: Creates a CL_Surface using the bmp image and returns it.
00054 
00055 
00056         CL_BMPProvider(
00057                 std::string name,
00058                 CL_InputSourceProvider *provider,
00059                 bool transparent=false,
00060                 short trans_col=-1);
00061         //: Constructs a surface provider that can read bmp files.
00066 
00067         virtual ~CL_BMPProvider();
00068 
00069         virtual unsigned int get_pitch() const;
00070         //: Returns the pitch of the image (bytes per line).
00071 /*
00072         virtual int get_translate_x() const { return biWidth; }
00073         //: Returns how many pixels to translate the image (X axis).
00074 
00075         virtual int get_translate_y() const { return biHeight; }
00076         //: Returns how many pixels to translate the image (Y axis).
00077 */
00078         virtual unsigned int get_width() const { return biWidth; }
00079         //: Returns the width of the image.
00080 
00081         virtual unsigned int get_height() const { return biHeight; }
00082         //: Returns the height of the image.
00083 
00084         virtual unsigned int get_num_frames() const { return 1; }
00085         //: Returns the number of subsprites in the image.
00086 /*
00087         virtual EPixelFormat get_pixel_format() const;
00088         //: Returns the pixelformat used by the image.
00089 */
00090         virtual unsigned int get_red_mask() const;
00091         virtual unsigned int get_green_mask() const;
00092         virtual unsigned int get_blue_mask() const;
00093         virtual unsigned int get_alpha_mask() const;
00094         virtual unsigned int get_depth() const;
00095 
00096         virtual CL_Palette *get_palette() const { return palette; }
00097         //: Returns the palette used by the image. NULL if system palette.
00098 
00099         virtual bool is_indexed() const { return biBitCount == 8;}
00100         
00101         virtual bool uses_src_colorkey() const { return trans_col != -1; }
00102 
00103         virtual unsigned int get_src_colorkey() const { return trans_col; }
00104         //: Returns the transparency color used, -1 if none.
00105 
00106         virtual void *get_data() const { return image; }
00107         //: Returns the image data. Provider must be locked before pointer is valid.
00108 
00109         virtual void perform_lock();
00110         //: Locks the surface provider.
00111 
00112         virtual void perform_unlock();
00113         //: Unlocks the surface provider.
00114 
00115 private:
00116         CL_InputSourceProvider *provider;
00117         //int pitch, height, width;
00118         //int bounding_left, bounding_top, bounding_right, bounding_bottom;
00119         bool transparent;
00120         int trans_col;
00121         std::string name;
00122 //      EPixelFormat pixelformat;
00123 /*
00124         unsigned int Rmask;
00125         unsigned int Gmask;
00126         unsigned int Bmask;
00127 */
00128         /* The Win32 BMP file header (14 bytes) */
00129         char   magic[2];
00130         unsigned int bfSize;
00131         unsigned short bfReserved1;
00132         unsigned short bfReserved2;
00133         unsigned int bfOffBits;
00134 
00135         /* The Win32 BITMAPINFOHEADER struct (40 bytes) */
00136         unsigned int biSize;
00137         int biWidth;
00138         int biHeight;
00139         unsigned short biPlanes;
00140         unsigned short biBitCount;
00141         unsigned int biCompression;
00142         unsigned int biSizeImage;
00143         int biXPelsPerMeter;
00144         int biYPelsPerMeter;
00145         unsigned int biClrUsed;
00146         unsigned int biClrImportant;
00147 
00148 
00149         CL_Palette *palette;
00150         unsigned char *image;
00151 };
00152 
00153 #endif

Generated at Wed Apr 4 19:54:02 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001