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 <boost/scoped_ptr.hpp>
00011 #include <string>
00012 #include <vector>
00013
00014 namespace Gosu
00015 {
00020 class Bitmap
00021 {
00022 unsigned w, h;
00023 std::vector<Color> pixels;
00024
00025 public:
00026 Bitmap();
00027
00028 unsigned width() const { return w; }
00029 unsigned height() const { return h; }
00030
00031 void swap(Bitmap& other);
00032
00033 void resize(unsigned width, unsigned height, Color c = Colors::none);
00034
00035 void fill(Color c);
00036 void replace(Color oldColor, Color newColor);
00037
00040 Color getPixel(unsigned x, unsigned y) const { return pixels[y * w + x]; }
00041
00044 void setPixel(unsigned x, unsigned y, Color c) { pixels[y * w + x] = c; }
00045
00049 void insert(const Bitmap& source, int x, int y);
00050
00054 void insert(const Bitmap& source, int x, int y, unsigned srcX,
00055 unsigned srcY, unsigned srcWidth, unsigned srcHeight);
00056
00057 #ifndef __BIG_ENDIAN__
00059 const unsigned* glCompatibleData() const { return reinterpret_cast<const unsigned*>(&pixels[0]); }
00060 #endif
00061 };
00062
00064 Reader loadFromBMP(Bitmap& bmp, Reader reader);
00066 Writer saveToBMP(const Bitmap& bmp, Writer writer);
00068 Reader loadFromPNG(Bitmap& bmp, Reader reader);
00070 Writer saveToPNG(const Bitmap& bmp, Writer writer);
00071
00075 void applyColorKey(Bitmap& bitmap, Color key);
00076
00077 void applyBorderFlags(Bitmap& dest, const Bitmap& source,
00078 unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
00079 unsigned borderFlags);
00080
00081
00082 Bitmap quickLoadBitmap(const std::wstring& filename);
00083 }
00084
00085 #endif