00001 00002 00003 00004 #ifndef GOSU_BITMAP_HPP 00005 #define GOSU_BITMAP_HPP 00006 00007 #include <Gosu/Color.hpp> 00008 #include <Gosu/Fwd.hpp> 00009 #include <Gosu/GraphicsBase.hpp> 00010 #include <Gosu/Platform.hpp> 00011 #include <boost/scoped_ptr.hpp> 00012 #include <string> 00013 #include <vector> 00014 00015 namespace Gosu 00016 { 00021 class Bitmap 00022 { 00023 unsigned w, h; 00024 std::vector<Color> pixels; 00025 00026 public: 00027 Bitmap() : w(0), h(0) {} 00028 Bitmap(unsigned w, unsigned h, Color c = Color::NONE) : w(w), h(h), pixels(w * h, c) {} 00029 00030 unsigned width() const { return w; } 00031 unsigned height() const { return h; } 00032 00033 void swap(Bitmap& other); 00034 00035 void resize(unsigned width, unsigned height, Color c = Color::NONE); 00036 00039 Color getPixel(unsigned x, unsigned y) const { return pixels[y * w + x]; } 00040 00043 void setPixel(unsigned x, unsigned y, Color c) { pixels[y * w + x] = c; } 00044 00048 void insert(const Bitmap& source, int x, int y); 00049 00053 void insert(const Bitmap& source, int x, int y, unsigned srcX, 00054 unsigned srcY, unsigned srcWidth, unsigned srcHeight); 00055 00058 const Color* data() const { return &pixels[0]; } 00059 Color* data() { return &pixels[0]; } 00060 00061 // Work with data() instead if you need fast operations. 00062 GOSU_DEPRECATED void fill(Color c); 00063 GOSU_DEPRECATED void replace(Color oldColor, Color newColor); 00064 }; 00065 00067 Bitmap loadImageFile(const std::wstring& filename); 00069 Bitmap loadImageFile(Reader input); 00070 00072 void saveImageFile(const Bitmap& bitmap, const std::wstring& filename); 00074 void saveImageFile(const Bitmap& bitmap, Gosu::Writer writer, 00075 const std::wstring& formatHint = L"png"); 00076 00080 void applyColorKey(Bitmap& bitmap, Color key); 00081 00084 void unapplyColorKey(Bitmap& bitmap, Color background); 00085 00086 void applyBorderFlags(Bitmap& dest, const Bitmap& source, 00087 unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight, 00088 unsigned borderFlags); 00089 00090 // Use loadImageFile/saveImageFile instead. 00091 GOSU_DEPRECATED Reader loadFromBMP(Bitmap& bmp, Reader reader); 00092 GOSU_DEPRECATED Writer saveToBMP(const Bitmap& bmp, Writer writer); 00093 GOSU_DEPRECATED Reader loadFromPNG(Bitmap& bmp, Reader reader); 00094 GOSU_DEPRECATED Writer saveToPNG(const Bitmap& bmp, Writer writer); 00095 } 00096 00097 #endif
Documentation not clear enough? Please go to one of the places listed on http://www.libgosu.org/ and leave feedback. Thanks!