Bitmap.hpp
Go to the documentation of this file.
1 
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
#define GOSU_DEPRECATED
Definition: Platform.hpp:85
GOSU_DEPRECATED Reader loadFromBMP(Bitmap &bmp, Reader reader)
unsigned height() const
Definition: Bitmap.hpp:30
Contains declarations of all of Gosu&#39;s available classes.
void setPixel(unsigned x, unsigned y, Color c)
Sets the pixel at the specified position to a color.
Definition: Bitmap.hpp:42
void resize(unsigned width, unsigned height, Color c=Color::NONE)
Represents an RGBA color value with 8 bits for each channel.
Definition: Color.hpp:18
void applyColorKey(Bitmap &bitmap, Color key)
Set the alpha value of all pixels which are equal to the color key to zero.
void swap(Bitmap &other)
Color * data()
Definition: Bitmap.hpp:58
GOSU_DEPRECATED void fill(Color c)
GOSU_DEPRECATED Reader loadFromPNG(Bitmap &bmp, Reader reader)
GOSU_DEPRECATED void replace(Color oldColor, Color newColor)
void loadImageFile(Bitmap &bitmap, const std::wstring &filename)
Loads any supported image into a Bitmap.
Rectangular area of pixels, each represented by a Color value.
Definition: Bitmap.hpp:20
GOSU_DEPRECATED Writer saveToBMP(const Bitmap &bmp, Writer writer)
const Color * data() const
Direct access to the array of color values.
Definition: Bitmap.hpp:57
Bitmap(unsigned w, unsigned h, Color c=Color::NONE)
Definition: Bitmap.hpp:27
unsigned width() const
Definition: Bitmap.hpp:29
void saveImageFile(const Bitmap &bitmap, const std::wstring &filename)
Saves a Bitmap to a file.
Macros and utility functions to facilitate programming on all of Gosu&#39;s supported platforms...
void insert(const Bitmap &source, int x, int y)
Inserts a bitmap at the given position.
Utility class that points to a specific position in a resource and offers an interface for sequential...
Definition: IO.hpp:86
Color getPixel(unsigned x, unsigned y) const
Returns the color at the specified position.
Definition: Bitmap.hpp:38
GOSU_DEPRECATED Writer saveToPNG(const Bitmap &bmp, Writer writer)
Interface of the Color class.
static const Color NONE
Definition: Color.hpp:147
void unapplyColorKey(Bitmap &bitmap, Color background)
The reverse of applyColorKey.
Contains general typedefs and enums related to graphics.
void applyBorderFlags(Bitmap &dest, const Bitmap &source, unsigned srcX, unsigned srcY, unsigned srcWidth, unsigned srcHeight, unsigned borderFlags)