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(::LoadImageFromTexture(texture));
41 Image(
int width,
int height, ::
Color color = {255, 255, 255, 255}) {
42 set(::GenImageColor(width, height, color));
45 Image(
const std::string& text,
int fontSize, ::
Color color = {255, 255, 255, 255}) {
46 set(::ImageText(text.c_str(), fontSize, color));
49 Image(const ::Font& font,
const std::string& text,
float fontSize,
float spacing,
50 ::
Color tint = {255, 255, 255, 255}) {
51 set(::ImageTextEx(font, text.c_str(), fontSize, spacing, tint));
68 static ::Image Text(
const std::string& text,
int fontSize,
69 ::
Color color = {255, 255, 255, 255}) {
70 return ::ImageText(text.c_str(), fontSize, color);
73 static ::Image Text(const ::Font& font,
const std::string& text,
float fontSize,
float spacing,
74 ::
Color tint = {255, 255, 255, 255}) {
75 return ::ImageTextEx(font, text.c_str(), fontSize, spacing, tint);
82 return ::LoadImageFromScreen();
88 static ::Image
Color(
int width,
int height, ::
Color color = {255, 255, 255, 255}) {
89 return ::GenImageColor(width, height, color);
96 return ::GenImageGradientV(width, height, top, bottom);
103 return ::GenImageGradientH(width, height, left, right);
111 return ::GenImageGradientRadial(width, height, density, inner, outer);
117 static ::Image
Checked(
int width,
int height,
int checksX,
int checksY,
118 ::
Color col1 = {255, 255, 255, 255},
::Color col2 = {0, 0, 0, 255}) {
119 return ::GenImageChecked(width, height, checksX, checksY, col1, col2);
125 static ::Image
WhiteNoise(
int width,
int height,
float factor) {
126 return ::GenImageWhiteNoise(width, height, factor);
132 static ::Image
Cellular(
int width,
int height,
int tileSize) {
133 return ::GenImageCellular(width, height, tileSize);
140 Image& operator=(const ::Image& image) {
145 Image& operator=(
const Image& other) {
146 if (
this == &other) {
154 Image& operator=(Image&& other) {
155 if (
this == &other) {
162 other.data =
nullptr;
174 void Load(
const std::string& fileName) {
181 void LoadRaw(
const std::string& fileName,
int width,
int height,
int format,
int headerSize) {
182 set(::
LoadImageRaw(fileName.c_str(), width, height, format, headerSize));
188 void LoadAnim(
const std::string& fileName,
int* frames) {
196 const std::string& fileType,
197 const unsigned char *fileData,
206 if (data !=
nullptr) {
207 ::UnloadImage(*
this);
215 inline bool Export(
const std::string& fileName)
const {
217 return ::ExportImage(*
this, fileName.c_str());
224 return ::ExportImageAsCode(*
this, fileName.c_str());
227 GETTERSETTER(
void*, Data, data)
228 GETTERSETTER(
int, Width, width)
229 GETTERSETTER(
int, Height, height)
237 return {
static_cast<float>(width),
static_cast<float>(height)};
244 return ::ImageCopy(*
this);
251 return ::ImageFromImage(*
this, rec);
258 ::ImageToPOT(
this, fillColor);
266 ::ImageFormat(
this, newFormat);
274 ::ImageAlphaCrop(
this, threshold);
282 ::ImageAlphaClear(
this, color, threshold);
290 ::ImageAlphaMask(
this, alphaMask);
298 ::ImageAlphaPremultiply(
this);
306 ::ImageCrop(
this, crop);
314 return Crop(0, 0,
static_cast<int>(size.x),
static_cast<int>(size.y));
320 inline Image&
Crop(
int offsetX,
int offsetY,
int newWidth,
int newHeight) {
322 static_cast<float>(offsetX),
323 static_cast<float>(offsetY),
324 static_cast<float>(newWidth),
325 static_cast<float>(newHeight)
327 ::ImageCrop(
this, rect);
335 ::ImageResize(
this, newWidth, newHeight);
343 ::ImageResizeNN(
this, newWidth, newHeight);
351 ::
Color color = {255, 255, 255, 255}) {
352 ::ImageResizeCanvas(
this, newWidth, newHeight, offsetX, offsetY, color);
360 ::ImageMipmaps(
this);
368 ::ImageDither(
this, rBpp, gBpp, bBpp, aBpp);
376 ::ImageFlipVertical(
this);
384 ::ImageFlipHorizontal(
this);
392 ::ImageRotateCW(
this);
400 ::ImageRotateCCW(
this);
408 ::ImageColorTint(
this, color);
416 ::ImageColorInvert(
this);
424 ::ImageColorGrayscale(
this);
434 ::ImageColorContrast(
this, contrast);
444 ::ImageColorBrightness(
this, brightness);
452 ::ImageColorReplace(
this, color, replace);
462 return ::GetImageAlphaBorder(*
this, threshold);
469 ::ImageClearBackground(
this, color);
477 ::ImageDrawPixel(
this, posX, posY, color);
481 inline Image&
DrawPixel(::Vector2 position, ::
Color color = {255, 255, 255, 255}) {
482 ::ImageDrawPixelV(
this, position, color);
486 inline Image& DrawLine(
int startPosX,
int startPosY,
int endPosX,
int endPosY,
487 ::
Color color = {255, 255, 255, 255}) {
488 ::ImageDrawLine(
this, startPosX, startPosY, endPosX, endPosY, color);
492 inline Image& DrawLine(::Vector2 start, ::Vector2 end, ::
Color color = {255, 255, 255, 255}) {
493 ::ImageDrawLineV(
this, start, end, color);
497 inline Image& DrawCircle(
int centerX,
int centerY,
int radius,
498 ::
Color color = {255, 255, 255, 255}) {
499 ::ImageDrawCircle(
this, centerX, centerY, radius, color);
503 inline Image& DrawCircle(::Vector2 center,
int radius,
504 ::
Color color = {255, 255, 255, 255}) {
505 ::ImageDrawCircleV(
this, center, radius, color);
509 inline Image& DrawRectangle(
int posX,
int posY,
int width,
int height,
510 ::
Color color = {255, 255, 255, 255}) {
511 ::ImageDrawRectangle(
this, posX, posY, width, height, color);
515 inline Image& DrawRectangle(Vector2 position, Vector2 size,
516 ::
Color color = {255, 255, 255, 255}) {
517 ::ImageDrawRectangleV(
this, position, size, color);
521 inline Image& DrawRectangle(::Rectangle rec, ::
Color color = {255, 255, 255, 255}) {
522 ::ImageDrawRectangleRec(
this, rec, color);
526 inline Image& DrawRectangleLines(::Rectangle rec,
int thick = 1,
527 ::
Color color = {255, 255, 255, 255}) {
528 ::ImageDrawRectangleLines(
this, rec, thick, color);
532 inline Image& Draw(const ::Image& src, ::Rectangle srcRec, ::Rectangle dstRec,
533 ::
Color tint = {255, 255, 255, 255}) {
534 ::ImageDraw(
this, src, srcRec, dstRec, tint);
538 inline Image& DrawText(
const std::string& text, ::Vector2 position,
int fontSize,
539 ::
Color color = {255, 255, 255, 255}) {
540 ::ImageDrawText(
this,
542 static_cast<int>(position.x),
543 static_cast<int>(position.y),
549 inline Image& DrawText(
const std::string& text,
int x,
int y,
int fontSize,
550 ::
Color color = {255, 255, 255, 255}) {
551 ::ImageDrawText(
this, text.c_str(), x, y, fontSize, color);
555 inline Image& DrawText(const ::Font& font,
const std::string& text, ::Vector2 position,
556 float fontSize,
float spacing, ::
Color tint = {255, 255, 255, 255}) {
557 ::ImageDrawTextEx(
this, font, text.c_str(), position, fontSize, spacing, tint);
565 return ::LoadImageColors(*
this);
571 inline ::Color*
LoadPalette(
int maxPaletteSize,
int *colorsCount)
const {
572 return ::LoadImagePalette(*
this, maxPaletteSize, colorsCount);
579 ::UnloadImageColors(colors);
586 ::UnloadImagePalette(colors);
593 return ::LoadTextureFromImage(*
this);
599 inline operator ::Texture2D() {
606 static int GetPixelDataSize(
int width,
int height,
int format = PIXELFORMAT_UNCOMPRESSED_R32G32B32A32) {
607 return ::GetPixelDataSize(width, height, format);
616 return ::GetPixelDataSize(width, height, format);
620 inline void set(const ::Image& image) {
623 height = image.height;
624 mipmaps = image.mipmaps;
625 format = image.format;
630 #endif // RAYLIB_CPP_INCLUDE_IMAGE_HPP_