Bitmap.hpp
Go to the documentation of this file.
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 <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() : w(0), h(0) {}
00027         Bitmap(unsigned w, unsigned h, Color c = Color::NONE) : w(w), h(h), pixels(w * h, c) {}
00028 
00029         unsigned width()  const { return w; }
00030         unsigned height() const { return h; }
00031 
00032         void swap(Bitmap& other);
00033 
00034         void resize(unsigned width, unsigned height, Color c = Color::NONE);
00035         
00038         Color getPixel(unsigned x, unsigned y) const { return pixels[y * w + x]; }
00039 
00042         void setPixel(unsigned x, unsigned y, Color c) { pixels[y * w + x] = c; }
00043 
00047         void insert(const Bitmap& source, int x, int y);
00048 
00052         void insert(const Bitmap& source, int x, int y, unsigned srcX,
00053             unsigned srcY, unsigned srcWidth, unsigned srcHeight);
00054         
00057         const Color* data() const { return &pixels[0]; }
00058         Color* data()             { return &pixels[0]; }
00059 
00060         // Work with data() instead if you need fast operations.
00061         GOSU_DEPRECATED void fill(Color c);
00062         GOSU_DEPRECATED void replace(Color oldColor, Color newColor);
00063     };
00064     
00066     void loadImageFile(Bitmap& bitmap, const std::wstring& filename);
00068     void loadImageFile(Bitmap& bitmap, Reader input);
00069     
00071     void saveImageFile(const Bitmap& bitmap, const std::wstring& filename);
00073     void saveImageFile(const Bitmap& bitmap, Gosu::Writer writer,
00074         const std::wstring& formatHint = L"png");
00075 
00079     void applyColorKey(Bitmap& bitmap, Color key);
00080     
00083     void unapplyColorKey(Bitmap& bitmap, Color background);
00084     
00085     void applyBorderFlags(Bitmap& dest, const Bitmap& source,
00086         unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
00087         unsigned borderFlags);  
00088 
00089     // Use loadImageFile/saveImageFile instead.
00090     GOSU_DEPRECATED Reader loadFromBMP(Bitmap& bmp, Reader reader);
00091     GOSU_DEPRECATED Writer saveToBMP(const Bitmap& bmp, Writer writer);
00092     GOSU_DEPRECATED Reader loadFromPNG(Bitmap& bmp, Reader reader);
00093     GOSU_DEPRECATED Writer saveToPNG(const Bitmap& bmp, Writer writer);
00094 }
00095 
00096 #endif