raylib-cpp
C++ object-oriented wrapper library for raylib.
Image.hpp
1 #ifndef RAYLIB_CPP_IMAGE_HPP_
2 #define RAYLIB_CPP_IMAGE_HPP_
3 
4 #include <string>
5 #ifdef __cplusplus
6 extern "C"{
7 #endif
8 #include "raylib.h"
9 #ifdef __cplusplus
10 }
11 #endif
12 
13 #include "./raylib-cpp-utils.hpp"
14 
15 namespace raylib {
16  class Image : public ::Image {
17  public:
18  Image() {};
19  Image(::Image image) {
20  set(image);
21  }
22  Image(const std::string& fileName) {
23  Load(fileName);
24  }
25  Image(const std::string& fileName, int width, int height, int format, int headerSize) {
26  LoadRaw(fileName, width, height, format, headerSize);
27  }
28  Image(const std::string& fileName, int* frames) {
29  LoadAnim(fileName, frames);
30  }
31  Image(::Texture2D texture) {
32  set(::GetTextureData(texture));
33  }
34  Image(int width, int height, Color color = WHITE) {
35  set(::GenImageColor(width, height, color));
36  }
37 
38  static Image Text(std::string text, int fontSize, Color color) {
39  return ::ImageText(text.c_str(), fontSize, color);
40  }
41 
42  static Image Text(Font font, std::string text, float fontSize, float spacing, Color tint) {
43  return ::ImageTextEx(font, text.c_str(), fontSize, spacing, tint);
44  }
45 
46  static Image GetScreenData() {
47  return Image(::GetScreenData());
48  }
49 
50  static Image GenColor(int width, int height, Color color) {
51  return ::GenImageColor(width, height, color);
52  }
53 
54  static Image GenGradientV(int width, int height, Color top, Color bottom) {
55  return ::GenImageGradientV(width, height, top, bottom);
56  }
57 
58  static Image GenGradientH(int width, int height, Color left, Color right) {
59  return ::GenImageGradientH(width, height, left, right);
60  }
61 
62  static Image GenGradientRadial(int width, int height, float density, Color inner, Color outer) {
63  return ::GenImageGradientRadial(width, height, density, inner, outer);
64  }
65 
66  static Image GenChecked(int width, int height, int checksX, int checksY, Color col1, Color col2) {
67  return ::GenImageChecked(width, height, checksX, checksY, col1, col2);
68  }
69 
70  static Image GenWhiteNoise(int width, int height, float factor) {
71  return ::GenImageWhiteNoise(width, height, factor);
72  }
73 
74  static Image GenPerlinNoise(int width, int height, int offsetX, int offsetY, float scale) {
75  return ::GenImagePerlinNoise(width, height, offsetX, offsetY, scale);
76  }
77 
78  static Image GenCellular(int width, int height, int tileSize) {
79  return ::GenImageCellular(width, height, tileSize);
80  }
81 
82  ~Image() {
83  Unload();
84  };
85 
86  Image& operator=(const ::Image& image) {
87  set(image);
88  return *this;
89  }
90 
91  Image& operator=(const Image& image) {
92  set(image);
93  return *this;
94  }
95 
96  void Load(const std::string& fileName) {
97  set(::LoadImage(fileName.c_str()));
98  }
99 
100  void LoadRaw(const std::string& fileName, int width, int height, int format, int headerSize) {
101  set(::LoadImageRaw(fileName.c_str(), width, height, format, headerSize));
102  }
103 
104  void LoadAnim(const std::string& fileName, int* frames) {
105  set(::LoadImageAnim(fileName.c_str(), frames));
106  }
107 
108  inline void Unload() {
109  ::UnloadImage(*this);
110  };
111 
112  inline Image& Export(const std::string& fileName) {
113  ::ExportImage(*this, fileName.c_str());
114  return *this;
115  }
116  inline Image& ExportAsCode(const std::string& fileName) {
117  ::ExportImageAsCode(*this, fileName.c_str());
118  return *this;
119  }
120 
121  GETTERSETTER(void*,Data,data)
122  GETTERSETTER(int,Width,width)
123  GETTERSETTER(int,Height,height)
124  GETTERSETTER(int,Mipmaps,mipmaps)
125  GETTERSETTER(int,Format,format)
126 
127  inline Image Copy() {
128  return ::ImageCopy(*this);
129  }
130  inline Image FromImage(::Rectangle rec) {
131  return ::ImageFromImage(*this, rec);
132  }
133 
134  inline Image& ToPOT(Color fillColor) {
135  ::ImageToPOT(this, fillColor);
136  return *this;
137  }
138 
139  inline Image& Format(int newFormat) {
140  ::ImageFormat(this, newFormat);
141  return *this;
142  }
143 
144  inline Image& AlphaMask(Image alphaMask) {
145  ::ImageAlphaMask(this, alphaMask);
146  return *this;
147  }
148 
149  inline Image& AlphaCrop(float threshold) {
150  ::ImageAlphaCrop(this, threshold);
151  return *this;
152  }
153 
155  ::ImageAlphaPremultiply(this);
156  return *this;
157  }
158 
159  inline Image& Crop(::Rectangle crop) {
160  ::ImageCrop(this, crop);
161  return *this;
162  }
163  inline Image& Crop(int offsetX, int offsetY, int newWidth, int newHeight) {
164  ::ImageCrop(this, (Rectangle){ (float)offsetX, (float)offsetY, (float)newWidth, (float)newHeight });
165  return *this;
166  }
167 
168  inline Image& Resize(int newWidth, int newHeight) {
169  ::ImageResize(this, newWidth, newHeight);
170  return *this;
171  }
172  inline Image& ResizeNN(int newWidth, int newHeight) {
173  ::ImageResizeNN(this, newWidth, newHeight);
174  return *this;
175  }
176 
177  inline Image& ResizeCanvas(int newWidth, int newHeight, int offsetX, int offsetY, Color color) {
178  ::ImageResizeCanvas(this, newWidth, newHeight, offsetX, offsetY, color);
179  return *this;
180  }
181 
182  inline Image& Mipmaps() {
183  ::ImageMipmaps(this);
184  return *this;
185  }
186 
187  inline Image& Dither(int rBpp, int gBpp, int bBpp, int aBpp) {
188  ::ImageDither(this, rBpp, gBpp, bBpp, aBpp);
189  return *this;
190  }
191 
192  inline Image& FlipVertical() {
193  ::ImageFlipVertical(this);
194  return *this;
195  }
196  inline Image& FlipHorizontal() {
197  ::ImageFlipHorizontal(this);
198  return *this;
199  }
200 
201  inline Image& RotateCW() {
202  ::ImageRotateCW(this);
203  return *this;
204  }
205 
206  inline Image& RotateCCW() {
207  ::ImageRotateCCW(this);
208  return *this;
209  }
210 
211  inline Image& ColorTint(::Color color = WHITE) {
212  ::ImageColorTint(this, color);
213  return *this;
214  }
215 
216  inline Image& ColorInvert() {
217  ::ImageColorInvert(this);
218  return *this;
219  }
220 
221  inline Image& ColorGrayscale() {
222  ::ImageColorGrayscale(this);
223  return *this;
224  }
225  inline Image& ColorContrast(float contrast) {
226  ::ImageColorContrast(this, contrast);
227  return *this;
228  }
229  inline Image& ColorBrightness(int brightness) {
230  ::ImageColorBrightness(this, brightness);
231  return *this;
232  }
233  inline Image& ColorReplace(::Color color, ::Color replace) {
234  ::ImageColorReplace(this, color, replace);
235  return *this;
236  }
237 
238  inline ::Color* GetPalette(int maxPaletteSize, int *extractCount) {
239  return ::GetImagePalette(*this, maxPaletteSize, extractCount);
240  }
241 
242  inline Rectangle GetAlphaBorder(float threshold) const {
243  return ::GetImageAlphaBorder(*this, threshold);
244  }
245 
246  inline Image& ClearBackground(::Color color = WHITE) {
247  ::ImageClearBackground(this, color);
248  return *this;
249  }
250 
251  inline Image& DrawPixel(int posX, int posY, ::Color color) {
252  ::ImageDrawPixel(this, posX, posY, color);
253  return *this;
254  }
255 
256  inline Image& DrawPixel(::Vector2 position, ::Color color) {
257  ::ImageDrawPixelV(this, position, color);
258  return *this;
259  }
260 
261  inline Image& DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, ::Color color) {
262  ::ImageDrawLine(this, startPosX, startPosY, endPosX, endPosY, color);
263  return *this;
264  }
265 
266  inline Image& DrawLine(::Vector2 start, ::Vector2 end, ::Color color) {
267  ::ImageDrawLineV(this, start, end, color);
268  return *this;
269  }
270 
271  inline Image& DrawCircle(int centerX, int centerY, int radius, ::Color color) {
272  ::ImageDrawCircle(this, centerX, centerY, radius, color);
273  return *this;
274  }
275 
276  inline Image& DrawCircle(::Vector2 center, int radius, ::Color color) {
277  ::ImageDrawCircleV(this, center, radius, color);
278  return *this;
279  }
280  inline Image& DrawRectangle(int posX, int posY, int width, int height, ::Color color = WHITE) {
281  ::ImageDrawRectangle(this, posX, posY, width, height, color);
282  return *this;
283  }
284  inline Image& DrawRectangle(Vector2 position, Vector2 size, ::Color color = WHITE) {
285  ::ImageDrawRectangleV(this, position, size, color);
286  return *this;
287  }
288  inline Image& DrawRectangle(::Rectangle rec, ::Color color = WHITE) {
289  ::ImageDrawRectangleRec(this, rec, color);
290  return *this;
291  }
292  inline Image& DrawRectangleLines(::Rectangle rec, int thick, ::Color color) {
293  ::ImageDrawRectangleLines(this, rec, thick, color);
294  return *this;
295  }
296  inline Image& Draw(::Image& src, ::Rectangle srcRec, ::Rectangle dstRec, ::Color tint = WHITE) {
297  ::ImageDraw(this, src, srcRec, dstRec, tint);
298  return *this;
299  }
300 
301  inline Image& DrawText(const std::string& text, ::Vector2 position, int fontSize, ::Color color = WHITE){
302  ::ImageDrawText(this, text.c_str(), (int)position.x, (int)position.y, fontSize, color);
303  return *this;
304  }
305  inline Image& DrawText(const std::string& text, int x, int y, int fontSize, ::Color color = WHITE){
306  ::ImageDrawText(this, text.c_str(), x, y, fontSize, color);
307  return *this;
308  }
309  inline Image& DrawText(::Font font, const std::string& text, ::Vector2 position, float fontSize, float spacing, ::Color tint = WHITE){
310  ::ImageDrawTextEx(this, font, text.c_str(), position, fontSize, spacing, tint);
311  return *this;
312  }
313 
314  inline ::Color* GetImageData() {
315  return ::GetImageData(*this);
316  }
317 
318  inline ::Vector4* GetImageDataNormalized() {
319  return ::GetImageDataNormalized(*this);
320  }
321  inline operator Texture2D() {
322  return ::LoadTextureFromImage(*this);
323  }
324 
325  protected:
326  inline void set(::Image image) {
327  data = image.data;
328  width = image.width;
329  height = image.height;
330  mipmaps = image.mipmaps;
331  format = image.format;
332  }
333  };
334 }
335 
336 #endif
raylib::Image::Dither
Image & Dither(int rBpp, int gBpp, int bBpp, int aBpp)
Definition: Image.hpp:187
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:14
raylib::Image::DrawRectangle
Image & DrawRectangle(Vector2 position, Vector2 size, ::Color color=WHITE)
Definition: Image.hpp:284
raylib::Image::ColorBrightness
Image & ColorBrightness(int brightness)
Definition: Image.hpp:229
raylib::Image::set
void set(::Image image)
Definition: Image.hpp:326
raylib::Image::Image
Image(::Texture2D texture)
Definition: Image.hpp:31
raylib::Image::~Image
~Image()
Definition: Image.hpp:82
raylib::Image::GetImageData
inline ::Color * GetImageData()
Definition: Image.hpp:314
raylib::Image::Format
Image & Format(int newFormat)
Definition: Image.hpp:139
raylib::Image::GenGradientV
static Image GenGradientV(int width, int height, Color top, Color bottom)
Definition: Image.hpp:54
raylib::Image::GetPalette
inline ::Color * GetPalette(int maxPaletteSize, int *extractCount)
Definition: Image.hpp:238
raylib::Image::DrawText
Image & DrawText(const std::string &text, ::Vector2 position, int fontSize, ::Color color=WHITE)
Definition: Image.hpp:301
raylib::Image::ColorInvert
Image & ColorInvert()
Definition: Image.hpp:216
raylib::Image::ToPOT
Image & ToPOT(Color fillColor)
Definition: Image.hpp:134
raylib::Image::ColorGrayscale
Image & ColorGrayscale()
Definition: Image.hpp:221
raylib::Image
Definition: Image.hpp:16
raylib::Image::Crop
Image & Crop(::Rectangle crop)
Definition: Image.hpp:159
raylib::Image::ExportAsCode
Image & ExportAsCode(const std::string &fileName)
Definition: Image.hpp:116
raylib::Image::Image
Image(const std::string &fileName)
Definition: Image.hpp:22
raylib::Image::GetImageDataNormalized
inline ::Vector4 * GetImageDataNormalized()
Definition: Image.hpp:318
raylib::Image::Image
Image(::Image image)
Definition: Image.hpp:19
raylib::Image::GenGradientH
static Image GenGradientH(int width, int height, Color left, Color right)
Definition: Image.hpp:58
raylib::Image::GenWhiteNoise
static Image GenWhiteNoise(int width, int height, float factor)
Definition: Image.hpp:70
raylib::Image::RotateCCW
Image & RotateCCW()
Definition: Image.hpp:206
raylib::Image::DrawLine
Image & DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, ::Color color)
Definition: Image.hpp:261
raylib::Image::DrawPixel
Image & DrawPixel(int posX, int posY, ::Color color)
Definition: Image.hpp:251
raylib::Image::DrawRectangle
Image & DrawRectangle(int posX, int posY, int width, int height, ::Color color=WHITE)
Definition: Image.hpp:280
raylib::Image::FlipVertical
Image & FlipVertical()
Definition: Image.hpp:192
raylib::Image::ColorContrast
Image & ColorContrast(float contrast)
Definition: Image.hpp:225
raylib::Image::DrawRectangleLines
Image & DrawRectangleLines(::Rectangle rec, int thick, ::Color color)
Definition: Image.hpp:292
raylib::Image::ClearBackground
Image & ClearBackground(::Color color=WHITE)
Definition: Image.hpp:246
raylib::Image::DrawCircle
Image & DrawCircle(::Vector2 center, int radius, ::Color color)
Definition: Image.hpp:276
raylib::Image::LoadRaw
void LoadRaw(const std::string &fileName, int width, int height, int format, int headerSize)
Definition: Image.hpp:100
raylib::Image::operator=
Image & operator=(const ::Image &image)
Definition: Image.hpp:86
raylib::Image::AlphaPremultiply
Image & AlphaPremultiply()
Definition: Image.hpp:154
raylib::Image::Crop
Image & Crop(int offsetX, int offsetY, int newWidth, int newHeight)
Definition: Image.hpp:163
raylib::Image::GetScreenData
static Image GetScreenData()
Definition: Image.hpp:46
raylib::Image::DrawText
Image & DrawText(::Font font, const std::string &text, ::Vector2 position, float fontSize, float spacing, ::Color tint=WHITE)
Definition: Image.hpp:309
raylib::Image::Mipmaps
Image & Mipmaps()
Definition: Image.hpp:182
raylib::Image::Image
Image(const std::string &fileName, int width, int height, int format, int headerSize)
Definition: Image.hpp:25
raylib::Image::DrawPixel
Image & DrawPixel(::Vector2 position, ::Color color)
Definition: Image.hpp:256
raylib::Rectangle
Definition: Rectangle.hpp:16
raylib::Font
Definition: Font.hpp:17
raylib::Vector2
Definition: Vector2.hpp:22
raylib::Image::Text
static Image Text(std::string text, int fontSize, Color color)
Definition: Image.hpp:38
raylib::Image::GetAlphaBorder
Rectangle GetAlphaBorder(float threshold) const
Definition: Image.hpp:242
raylib::Color
Definition: Color.hpp:18
raylib::Image::GenGradientRadial
static Image GenGradientRadial(int width, int height, float density, Color inner, Color outer)
Definition: Image.hpp:62
raylib::Image::GenPerlinNoise
static Image GenPerlinNoise(int width, int height, int offsetX, int offsetY, float scale)
Definition: Image.hpp:74
raylib::Image::LoadAnim
void LoadAnim(const std::string &fileName, int *frames)
Definition: Image.hpp:104
raylib::Image::AlphaMask
Image & AlphaMask(Image alphaMask)
Definition: Image.hpp:144
raylib::Image::Load
void Load(const std::string &fileName)
Definition: Image.hpp:96
raylib::Image::Image
Image(const std::string &fileName, int *frames)
Definition: Image.hpp:28
raylib::Image::DrawText
Image & DrawText(const std::string &text, int x, int y, int fontSize, ::Color color=WHITE)
Definition: Image.hpp:305
raylib::Texture2D
Texture Texture2D
Definition: Texture.hpp:162
raylib::Image::ColorTint
Image & ColorTint(::Color color=WHITE)
Definition: Image.hpp:211
raylib::Image::AlphaCrop
Image & AlphaCrop(float threshold)
Definition: Image.hpp:149
raylib::Image::Resize
Image & Resize(int newWidth, int newHeight)
Definition: Image.hpp:168
raylib::Image::GenCellular
static Image GenCellular(int width, int height, int tileSize)
Definition: Image.hpp:78
raylib::Image::Copy
Image Copy()
Definition: Image.hpp:127
raylib::Image::ResizeCanvas
Image & ResizeCanvas(int newWidth, int newHeight, int offsetX, int offsetY, Color color)
Definition: Image.hpp:177
raylib::Image::Unload
void Unload()
Definition: Image.hpp:108
raylib::Texture
Definition: Texture.hpp:19
raylib::Image::FlipHorizontal
Image & FlipHorizontal()
Definition: Image.hpp:196
raylib::Image::DrawCircle
Image & DrawCircle(int centerX, int centerY, int radius, ::Color color)
Definition: Image.hpp:271
raylib::Image::ResizeNN
Image & ResizeNN(int newWidth, int newHeight)
Definition: Image.hpp:172
raylib::Image::Image
Image(int width, int height, Color color=WHITE)
Definition: Image.hpp:34
raylib::Image::operator=
Image & operator=(const Image &image)
Definition: Image.hpp:91
raylib::Image::Export
Image & Export(const std::string &fileName)
Definition: Image.hpp:112
raylib::Image::GenChecked
static Image GenChecked(int width, int height, int checksX, int checksY, Color col1, Color col2)
Definition: Image.hpp:66
raylib::Image::RotateCW
Image & RotateCW()
Definition: Image.hpp:201
raylib::Image::Image
Image()
Definition: Image.hpp:18
raylib::Image::Text
static Image Text(Font font, std::string text, float fontSize, float spacing, Color tint)
Definition: Image.hpp:42
raylib::Image::Draw
Image & Draw(::Image &src, ::Rectangle srcRec, ::Rectangle dstRec, ::Color tint=WHITE)
Definition: Image.hpp:296
raylib::Image::DrawLine
Image & DrawLine(::Vector2 start, ::Vector2 end, ::Color color)
Definition: Image.hpp:266
raylib::Image::ColorReplace
Image & ColorReplace(::Color color, ::Color replace)
Definition: Image.hpp:233
raylib::Image::DrawRectangle
Image & DrawRectangle(::Rectangle rec, ::Color color=WHITE)
Definition: Image.hpp:288
raylib::Image::FromImage
Image FromImage(::Rectangle rec)
Definition: Image.hpp:130
raylib::Image::GenColor
static Image GenColor(int width, int height, Color color)
Definition: Image.hpp:50