Gosu
Bitmap.hpp
Go to the documentation of this file.
1 
4 #pragma once
5 
6 #include <Gosu/Fwd.hpp>
7 #include <Gosu/Color.hpp>
8 #include <Gosu/GraphicsBase.hpp>
9 #include <Gosu/Platform.hpp>
10 #include <string>
11 #include <vector>
12 
13 namespace Gosu
14 {
19  class Bitmap
20  {
21  unsigned w, h;
22  std::vector<Color> pixels;
23 
24  public:
26  : w(0), h(0)
27  {
28  }
29 
30  Bitmap(unsigned w, unsigned h, Color c = Color::NONE)
31  : w(w), h(h), pixels(w * h, c)
32  {
33  }
34 
35  unsigned width() const
36  {
37  return w;
38  }
39 
40  unsigned height() const
41  {
42  return h;
43  }
44 
45  void swap(Bitmap& other);
46 
47  void resize(unsigned width, unsigned height, Color c = Color::NONE);
48 
51  Color get_pixel(unsigned x, unsigned y) const
52  {
53  return pixels[y * w + x];
54  }
55 
58  void set_pixel(unsigned x, unsigned y, Color c)
59  {
60  pixels[y * w + x] = c;
61  }
62 
66  void insert(const Bitmap& source, int x, int y);
67 
71  void insert(const Bitmap& source, int x, int y, unsigned src_x, unsigned src_y,
72  unsigned src_width, unsigned src_height);
73 
76  const Color* data() const
77  {
78  return &pixels[0];
79  }
80 
82  {
83  return &pixels[0];
84  }
85  };
86 
88  void load_image_file(Bitmap& bitmap, const std::string& filename);
90  void load_image_file(Bitmap& bitmap, Reader input);
91 
93  void save_image_file(const Bitmap& bitmap, const std::string& filename);
95  void save_image_file(const Bitmap& bitmap, Writer writer,
96  const std::string& format_hint = "png");
97 
101  void apply_color_key(Bitmap& bitmap, Color key);
102 
105  void unapply_color_key(Bitmap& bitmap, Color background);
106 
107  void apply_border_flags(Bitmap& dest, const Bitmap& source, unsigned src_x, unsigned src_y,
108  unsigned src_width, unsigned src_height, unsigned border_flags);
109 }
void unapply_color_key(Bitmap &bitmap, Color background)
The reverse of apply_color_key.
void apply_border_flags(Bitmap &dest, const Bitmap &source, unsigned src_x, unsigned src_y, unsigned src_width, unsigned src_height, unsigned border_flags)
The library&#39;s main namespace.
Definition: Audio.hpp:12
const Color * data() const
Direct access to the array of color values.
Definition: Bitmap.hpp:76
Contains forward declarations of all of Gosu&#39;s available classes.
unsigned height() const
Definition: Bitmap.hpp:40
void resize(unsigned width, unsigned height, Color c=Color::NONE)
Represents an RGBA color value with 8 bits for each channel.
Definition: Color.hpp:16
void swap(Bitmap &other)
unsigned width() const
Definition: Bitmap.hpp:35
Color * data()
Definition: Bitmap.hpp:81
void load_image_file(Bitmap &bitmap, const std::string &filename)
Loads any supported image into a Bitmap.
Utility class that points to a specific position in a resource and offers an interface for sequential...
Definition: IO.hpp:26
void set_pixel(unsigned x, unsigned y, Color c)
Sets the pixel at the specified position to a color.
Definition: Bitmap.hpp:58
Rectangular area of pixels, each represented by a Color value.
Definition: Bitmap.hpp:19
Bitmap(unsigned w, unsigned h, Color c=Color::NONE)
Definition: Bitmap.hpp:30
void save_image_file(const Bitmap &bitmap, const std::string &filename)
Saves a Bitmap to a file.
void apply_color_key(Bitmap &bitmap, Color key)
Set the alpha value of all pixels which are equal to the color key to zero.
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.
Color get_pixel(unsigned x, unsigned y) const
Returns the color at the specified position.
Definition: Bitmap.hpp:51
Utility class that points to a specific position in a resource and offers an interface for sequential...
Definition: IO.hpp:84
Interface of the Color class.
static const Color NONE
Definition: Color.hpp:133
Contains general typedefs and enums related to graphics.