Bitmap.hpp
Go to the documentation of this file.
1 
2 
3 
4 #ifndef GOSU_BITMAP_HPP
5 #define GOSU_BITMAP_HPP
6 
7 #include <Gosu/Color.hpp>
8 #include <Gosu/Fwd.hpp>
9 #include <Gosu/GraphicsBase.hpp>
10 #include <Gosu/Platform.hpp>
11 #include <string>
12 #include <vector>
13 
14 namespace Gosu
15 {
20  class Bitmap
21  {
22  unsigned w, h;
23  std::vector<Color> pixels;
24 
25  public:
26  Bitmap() : w(0), h(0) {}
27  Bitmap(unsigned w, unsigned h, Color c = Color::NONE) : w(w), h(h), pixels(w * h, c) {}
28 
29  unsigned width() const { return w; }
30  unsigned height() const { return h; }
31 
32  void swap(Bitmap& other);
33 
34  void resize(unsigned width, unsigned height, Color c = Color::NONE);
35 
38  Color getPixel(unsigned x, unsigned y) const { return pixels[y * w + x]; }
39 
42  void setPixel(unsigned x, unsigned y, Color c) { pixels[y * w + x] = c; }
43 
47  void insert(const Bitmap& source, int x, int y);
48 
52  void insert(const Bitmap& source, int x, int y, unsigned srcX,
53  unsigned srcY, unsigned srcWidth, unsigned srcHeight);
54 
57  const Color* data() const { return &pixels[0]; }
58  Color* data() { return &pixels[0]; }
59 
60  // Work with data() instead if you need fast operations.
61  GOSU_DEPRECATED void fill(Color c);
62  GOSU_DEPRECATED void replace(Color oldColor, Color newColor);
63  };
64 
66  void loadImageFile(Bitmap& bitmap, const std::wstring& filename);
68  void loadImageFile(Bitmap& bitmap, Reader input);
69 
71  void saveImageFile(const Bitmap& bitmap, const std::wstring& filename);
73  void saveImageFile(const Bitmap& bitmap, Gosu::Writer writer,
74  const std::wstring& formatHint = L"png");
75 
79  void applyColorKey(Bitmap& bitmap, Color key);
80 
83  void unapplyColorKey(Bitmap& bitmap, Color background);
84 
85  void applyBorderFlags(Bitmap& dest, const Bitmap& source,
86  unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight,
87  unsigned borderFlags);
88 
89  // Use loadImageFile/saveImageFile instead.
90  GOSU_DEPRECATED Reader loadFromBMP(Bitmap& bmp, Reader reader);
91  GOSU_DEPRECATED Writer saveToBMP(const Bitmap& bmp, Writer writer);
92  GOSU_DEPRECATED Reader loadFromPNG(Bitmap& bmp, Reader reader);
93  GOSU_DEPRECATED Writer saveToPNG(const Bitmap& bmp, Writer writer);
94 }
95 
96 #endif