bitmap.h

Go to the documentation of this file.
00001 #ifndef BITMAP_CLASS
00002 #define BITMAP_CLASS
00003 
00004 /*****************************************************************************\
00005 *                                                                             *
00006 *  Name   : bitmap                                                            *
00007 *  Author : Chris Koeritz                                                     *
00008 *                                                                             *
00009 *  Purpose:                                                                   *
00010 *                                                                             *
00011 *    Provides access to the windowing system's bitmap objects and allows      *
00012 *  them to be manipulated.                                                    *
00013 *                                                                             *
00014 *******************************************************************************
00015 * Copyright (c) 1997-$now By Author.  This program is free software; you can  *
00016 * redistribute it and/or modify it under the terms of the GNU General Public  *
00017 * License as published by the Free Software Foundation; either version 2 of   *
00018 * the License or (at your option) any later version.  This is online at:      *
00019 *     http://www.fsf.org/copyleft/gpl.html                                    *
00020 * Please send any updates to: fred@gruntose.com                               *
00021 \*****************************************************************************/
00022 
00023 #include "winexdll.h"
00024 
00025 #include <basis/portable.h>
00026 
00027 // forward.
00028 class palette;
00029 
00030 class WINDOWS_EXTENSIONS_CLASS_STYLE bitmap
00031 {
00032 public:
00033   bitmap();
00034     // constructs an empty, invalid bitmap.
00035   bitmap(const istring &filename);
00036     // constructs a bitmap from a file.
00037   bitmap(application_instance instance, const char *resource);
00038     // loads a bitmap from a "resource" id within the "instance".  the
00039     // "resource" can either be a textual name or a resource id created with
00040     // MAKEINTRESOURCE.
00041   bitmap(HGLOBAL global);
00042     // loads a bitmap from a "global" object.  this object must remain valid
00043     // for the life of the bitmap object.
00044   ~bitmap();
00045 
00046   bool valid() const { return _valid; }
00047     // reports whether construction succeeded or not.
00048 
00049   int image_size() const;
00050     // returns the size of the image in bytes.
00051   int width() const;
00052     // returns the pixel width of the image?
00053   int height() const;
00054     // returns the pixel height of the image?
00055   int colors() const;
00056     // returns the number of colors in the color table.  this is zero if
00057     // the image has better than eight bit color, since those types of bitmaps
00058     // have no color table.
00059 
00060   byte *get_bits() const;
00061     // returns the raw storage for the bitmap.  this could be stored in
00062     // top down or bottom up order.
00063 //how to tell?
00064 
00065   BITMAPINFOHEADER *get_header() const;
00066   BITMAPINFO *get_info() const;
00067   RGBQUAD *get_color_table() const;
00068     // returns a pointer to the color table structure for the bitmap, if it
00069     // has one.  NIL is returned if the bitmap has no table (because it has
00070     // more than 8 bits of color).
00071 
00072   void reset();
00073     // gets rid of any data held and resets the object to an unconstructed
00074     // state.
00075 
00076   bool paint(HDC context, const RECT &update_rectangle,
00077           const RECT &bitmap_portion) const;
00078     // the bitmap is painted to the screen using the device "context".  the
00079     // area to paint within the context is stored in "update_rectangle".
00080     // the segment that should be painted from the bitmap is defined by the
00081     // "bitmap_portion" rectangle.
00082 
00083   palette &get_palette() const { return *_palette; }
00084     // gets the palettized color table for this bitmap.
00085 
00086   bool load_from_file(const istring &fileName);
00087     // returns true if the "filename" can be loaded into the bitmap object.
00088   bool load_from_global(HGLOBAL glob);
00089     // returns true if a bitmap could be extracted from "glob".
00090   bool load_from_resource(application_instance instance, const char *resource);
00091     // returns true if the bitmap could be pulled out of the "instance"
00092     // using the "resource" id.
00093 
00094 private:
00095   bool _valid;  // true if this object has constructed properly.
00096   BITMAPFILEHEADER _file_header;  // a copy of the file header from disk.
00097   BITMAPINFO *_info;  // super-structure containing header and color table.
00098   BITMAPINFOHEADER *_header;  // header describing bitmap.
00099   RGBQUAD *_color_table;  // colors used in the bitmap.
00100   byte *_the_bits;  // storage of image bits.
00101   int _colors;  // number of colors used in the color table.
00102   HGLOBAL _optional_global;
00103     // tracks a global memory object if used to create a bitmap.
00104   palette *_palette;  // created once we know the colors for the bitmap.
00105 
00106   // forbidden.
00107   bitmap(const bitmap &to_copy);
00108   bitmap &operator =(const bitmap &to_copy);
00109 
00110   bool retrieve_palette(palette &to_fill) const;
00111     // stores the color table of this bitmap into a palette "to_fill".
00112 
00113   void make_pointers_valid(bool read_only);
00114     // given a valid pointer value in "_info", the other class members will
00115     // be created from the information there.  if "read_only" is true, no
00116     // fixups will be attempted on the header data.
00117 };
00118 
00119 #endif
00120 

Generated on Fri Nov 21 04:29:18 2008 for HOOPLE Libraries by  doxygen 1.5.1