1 #ifndef RAYLIB_CPP_INCLUDE_IMAGE_HPP_
2 #define RAYLIB_CPP_INCLUDE_IMAGE_HPP_
6 #include "./raylib.hpp"
7 #include "./raylib-cpp-utils.hpp"
17 Image(const ::Image& image) {
21 Image(
const std::string& fileName) {
25 Image(
const std::string& fileName,
int width,
int height,
int format,
int headerSize) {
26 LoadRaw(fileName, width, height, format, headerSize);
29 Image(
const std::string& fileName,
int* frames) {
33 Image(
const std::string& fileType,
const unsigned char* fileData,
int dataSize) {
37 Image(const ::Texture2D& texture) {
38 set(::GetTextureData(texture));
41 Image(
int width,
int height, ::
Color color = {255, 255, 255, 255}) {
42 set(::GenImageColor(width, height, color));
45 Image(const ::Font& font,
const std::string& text,
float fontSize,
float spacing,
46 ::
Color tint = {255, 255, 255, 255}) {
47 set(::ImageTextEx(font, text.c_str(), fontSize, spacing, tint));
50 static ::Image Text(
const std::string& text,
int fontSize,
51 ::
Color color = {255, 255, 255, 255}) {
52 return ::ImageText(text.c_str(), fontSize, color);
55 static ::Image Text(const ::Font& font,
const std::string& text,
float fontSize,
float spacing,
56 ::
Color tint = {255, 255, 255, 255}) {
57 return ::ImageTextEx(font, text.c_str(), fontSize, spacing, tint);
64 return ::GetScreenData();
70 static ::Image
Color(
int width,
int height, ::
Color color = {255, 255, 255, 255}) {
71 return ::GenImageColor(width, height, color);
78 return ::GenImageGradientV(width, height, top, bottom);
85 return ::GenImageGradientH(width, height, left, right);
93 return ::GenImageGradientRadial(width, height, density, inner, outer);
99 static ::Image
Checked(
int width,
int height,
int checksX,
int checksY,
100 ::
Color col1 = {255, 255, 255, 255},
::Color col2 = {0, 0, 0, 255}) {
101 return ::GenImageChecked(width, height, checksX, checksY, col1, col2);
107 static ::Image
WhiteNoise(
int width,
int height,
float factor) {
108 return ::GenImageWhiteNoise(width, height, factor);
114 static ::Image
PerlinNoise(
int width,
int height,
int offsetX,
int offsetY,
115 float scale = 1.0f) {
116 return ::GenImagePerlinNoise(width, height, offsetX, offsetY, scale);
122 static ::Image
Cellular(
int width,
int height,
int tileSize) {
123 return ::GenImageCellular(width, height, tileSize);
130 Image& operator=(const ::Image& image) {
138 void Load(
const std::string& fileName) {
145 void LoadRaw(
const std::string& fileName,
int width,
int height,
int format,
int headerSize) {
146 set(::
LoadImageRaw(fileName.c_str(), width, height, format, headerSize));
152 void LoadAnim(
const std::string& fileName,
int* frames) {
160 const std::string& fileType,
161 const unsigned char *fileData,
171 ::UnloadImage(*
this);
179 inline bool Export(
const std::string& fileName) {
181 return ::ExportImage(*
this, fileName.c_str());
188 return ::ExportImageAsCode(*
this, fileName.c_str());
191 GETTERSETTER(
void*, Data, data)
192 GETTERSETTER(
int, Width, width)
193 GETTERSETTER(
int, Height, height)
201 return {
static_cast<float>(width),
static_cast<float>(height)};
208 return ::ImageCopy(*
this);
215 return ::ImageFromImage(*
this, rec);
222 ::ImageToPOT(
this, fillColor);
230 ::ImageFormat(
this, newFormat);
238 ::ImageAlphaMask(
this, alphaMask);
246 ::ImageAlphaCrop(
this, threshold);
254 ::ImageAlphaPremultiply(
this);
262 ::ImageCrop(
this, crop);
270 return Crop(0, 0,
static_cast<int>(size.x),
static_cast<int>(size.y));
276 inline Image&
Crop(
int offsetX,
int offsetY,
int newWidth,
int newHeight) {
278 static_cast<float>(offsetX),
279 static_cast<float>(offsetY),
280 static_cast<float>(newWidth),
281 static_cast<float>(newHeight)
283 ::ImageCrop(
this, rect);
291 ::ImageResize(
this, newWidth, newHeight);
299 ::ImageResizeNN(
this, newWidth, newHeight);
307 ::
Color color = {255, 255, 255, 255}) {
308 ::ImageResizeCanvas(
this, newWidth, newHeight, offsetX, offsetY, color);
316 ::ImageMipmaps(
this);
324 ::ImageDither(
this, rBpp, gBpp, bBpp, aBpp);
332 ::ImageFlipVertical(
this);
340 ::ImageFlipHorizontal(
this);
348 ::ImageRotateCW(
this);
356 ::ImageRotateCCW(
this);
364 ::ImageColorTint(
this, color);
372 ::ImageColorInvert(
this);
380 ::ImageColorGrayscale(
this);
390 ::ImageColorContrast(
this, contrast);
400 ::ImageColorBrightness(
this, brightness);
408 ::ImageColorReplace(
this, color, replace);
418 return ::GetImageAlphaBorder(*
this, threshold);
425 ::ImageClearBackground(
this, color);
433 ::ImageDrawPixel(
this, posX, posY, color);
437 inline Image&
DrawPixel(::Vector2 position, ::
Color color = {255, 255, 255, 255}) {
438 ::ImageDrawPixelV(
this, position, color);
442 inline Image& DrawLine(
int startPosX,
int startPosY,
int endPosX,
int endPosY,
443 ::
Color color = {255, 255, 255, 255}) {
444 ::ImageDrawLine(
this, startPosX, startPosY, endPosX, endPosY, color);
448 inline Image& DrawLine(::Vector2 start, ::Vector2 end, ::
Color color = {255, 255, 255, 255}) {
449 ::ImageDrawLineV(
this, start, end, color);
453 inline Image& DrawCircle(
int centerX,
int centerY,
int radius,
454 ::
Color color = {255, 255, 255, 255}) {
455 ::ImageDrawCircle(
this, centerX, centerY, radius, color);
459 inline Image& DrawCircle(::Vector2 center,
int radius,
460 ::
Color color = {255, 255, 255, 255}) {
461 ::ImageDrawCircleV(
this, center, radius, color);
465 inline Image& DrawRectangle(
int posX,
int posY,
int width,
int height,
466 ::
Color color = {255, 255, 255, 255}) {
467 ::ImageDrawRectangle(
this, posX, posY, width, height, color);
471 inline Image& DrawRectangle(Vector2 position, Vector2 size,
472 ::
Color color = {255, 255, 255, 255}) {
473 ::ImageDrawRectangleV(
this, position, size, color);
477 inline Image& DrawRectangle(::Rectangle rec, ::
Color color = {255, 255, 255, 255}) {
478 ::ImageDrawRectangleRec(
this, rec, color);
482 inline Image& DrawRectangleLines(::Rectangle rec,
int thick = 1,
483 ::
Color color = {255, 255, 255, 255}) {
484 ::ImageDrawRectangleLines(
this, rec, thick, color);
488 inline Image& Draw(const ::Image& src, ::Rectangle srcRec, ::Rectangle dstRec,
489 ::
Color tint = {255, 255, 255, 255}) {
490 ::ImageDraw(
this, src, srcRec, dstRec, tint);
494 inline Image& DrawText(
const std::string& text, ::Vector2 position,
int fontSize,
495 ::
Color color = {255, 255, 255, 255}) {
496 ::ImageDrawText(
this,
498 static_cast<int>(position.x),
499 static_cast<int>(position.y),
505 inline Image& DrawText(
const std::string& text,
int x,
int y,
int fontSize,
506 ::
Color color = {255, 255, 255, 255}) {
507 ::ImageDrawText(
this, text.c_str(), x, y, fontSize, color);
511 inline Image& DrawText(const ::Font& font,
const std::string& text, ::Vector2 position,
512 float fontSize,
float spacing, ::
Color tint = {255, 255, 255, 255}) {
513 ::ImageDrawTextEx(
this, font, text.c_str(), position, fontSize, spacing, tint);
521 return ::LoadImageColors(*
this);
527 inline ::Color*
LoadPalette(
int maxPaletteSize,
int *colorsCount) {
528 return ::LoadImagePalette(*
this, maxPaletteSize, colorsCount);
535 ::UnloadImageColors(colors);
542 ::UnloadImagePalette(colors);
549 return ::LoadTextureFromImage(*
this);
555 inline operator ::Texture2D() {
562 static int GetPixelDataSize(
int width,
int height,
int format = PIXELFORMAT_UNCOMPRESSED_R32G32B32A32) {
563 return ::GetPixelDataSize(width, height, format);
572 return ::GetPixelDataSize(width, height, format);
576 inline void set(const ::Image& image) {
579 height = image.height;
580 mipmaps = image.mipmaps;
581 format = image.format;
586 #endif // RAYLIB_CPP_INCLUDE_IMAGE_HPP_