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) {
156 Image& operator=(Image&& other) {
157 if (
this == &other) {
164 other.data =
nullptr;
176 void Load(
const std::string& fileName) {
183 void LoadRaw(
const std::string& fileName,
int width,
int height,
int format,
int headerSize) {
184 set(::
LoadImageRaw(fileName.c_str(), width, height, format, headerSize));
190 void LoadAnim(
const std::string& fileName,
int* frames) {
198 const std::string& fileType,
199 const unsigned char *fileData,
208 if (data !=
nullptr) {
209 ::UnloadImage(*
this);
217 inline bool Export(
const std::string& fileName)
const {
219 return ::ExportImage(*
this, fileName.c_str());
226 return ::ExportImageAsCode(*
this, fileName.c_str());
229 GETTERSETTER(
void*, Data, data)
230 GETTERSETTER(
int, Width, width)
231 GETTERSETTER(
int, Height, height)
239 return {
static_cast<float>(width),
static_cast<float>(height)};
246 return ::ImageCopy(*
this);
253 return ::ImageFromImage(*
this, rec);
260 ::ImageToPOT(
this, fillColor);
268 ::ImageFormat(
this, newFormat);
276 ::ImageAlphaCrop(
this, threshold);
284 ::ImageAlphaClear(
this, color, threshold);
292 ::ImageAlphaMask(
this, alphaMask);
300 ::ImageAlphaPremultiply(
this);
308 ::ImageCrop(
this, crop);
316 return Crop(0, 0,
static_cast<int>(size.x),
static_cast<int>(size.y));
322 inline Image&
Crop(
int offsetX,
int offsetY,
int newWidth,
int newHeight) {
324 static_cast<float>(offsetX),
325 static_cast<float>(offsetY),
326 static_cast<float>(newWidth),
327 static_cast<float>(newHeight)
329 ::ImageCrop(
this, rect);
337 ::ImageResize(
this, newWidth, newHeight);
345 ::ImageResizeNN(
this, newWidth, newHeight);
353 ::
Color color = {255, 255, 255, 255}) {
354 ::ImageResizeCanvas(
this, newWidth, newHeight, offsetX, offsetY, color);
362 ::ImageMipmaps(
this);
370 ::ImageDither(
this, rBpp, gBpp, bBpp, aBpp);
378 ::ImageFlipVertical(
this);
386 ::ImageFlipHorizontal(
this);
394 ::ImageRotateCW(
this);
402 ::ImageRotateCCW(
this);
410 ::ImageColorTint(
this, color);
418 ::ImageColorInvert(
this);
426 ::ImageColorGrayscale(
this);
436 ::ImageColorContrast(
this, contrast);
446 ::ImageColorBrightness(
this, brightness);
454 ::ImageColorReplace(
this, color, replace);
464 return ::GetImageAlphaBorder(*
this, threshold);
471 ::ImageClearBackground(
this, color);
479 ::ImageDrawPixel(
this, posX, posY, color);
483 inline Image&
DrawPixel(::Vector2 position, ::
Color color = {255, 255, 255, 255}) {
484 ::ImageDrawPixelV(
this, position, color);
488 inline Image& DrawLine(
int startPosX,
int startPosY,
int endPosX,
int endPosY,
489 ::
Color color = {255, 255, 255, 255}) {
490 ::ImageDrawLine(
this, startPosX, startPosY, endPosX, endPosY, color);
494 inline Image& DrawLine(::Vector2 start, ::Vector2 end, ::
Color color = {255, 255, 255, 255}) {
495 ::ImageDrawLineV(
this, start, end, color);
499 inline Image& DrawCircle(
int centerX,
int centerY,
int radius,
500 ::
Color color = {255, 255, 255, 255}) {
501 ::ImageDrawCircle(
this, centerX, centerY, radius, color);
505 inline Image& DrawCircle(::Vector2 center,
int radius,
506 ::
Color color = {255, 255, 255, 255}) {
507 ::ImageDrawCircleV(
this, center, radius, color);
511 inline Image& DrawRectangle(
int posX,
int posY,
int width,
int height,
512 ::
Color color = {255, 255, 255, 255}) {
513 ::ImageDrawRectangle(
this, posX, posY, width, height, color);
517 inline Image& DrawRectangle(Vector2 position, Vector2 size,
518 ::
Color color = {255, 255, 255, 255}) {
519 ::ImageDrawRectangleV(
this, position, size, color);
523 inline Image& DrawRectangle(::Rectangle rec, ::
Color color = {255, 255, 255, 255}) {
524 ::ImageDrawRectangleRec(
this, rec, color);
528 inline Image& DrawRectangleLines(::Rectangle rec,
int thick = 1,
529 ::
Color color = {255, 255, 255, 255}) {
530 ::ImageDrawRectangleLines(
this, rec, thick, color);
534 inline Image& Draw(const ::Image& src, ::Rectangle srcRec, ::Rectangle dstRec,
535 ::
Color tint = {255, 255, 255, 255}) {
536 ::ImageDraw(
this, src, srcRec, dstRec, tint);
540 inline Image& DrawText(
const std::string& text, ::Vector2 position,
int fontSize,
541 ::
Color color = {255, 255, 255, 255}) {
542 ::ImageDrawText(
this,
544 static_cast<int>(position.x),
545 static_cast<int>(position.y),
551 inline Image& DrawText(
const std::string& text,
int x,
int y,
int fontSize,
552 ::
Color color = {255, 255, 255, 255}) {
553 ::ImageDrawText(
this, text.c_str(), x, y, fontSize, color);
557 inline Image& DrawText(const ::Font& font,
const std::string& text, ::Vector2 position,
558 float fontSize,
float spacing, ::
Color tint = {255, 255, 255, 255}) {
559 ::ImageDrawTextEx(
this, font, text.c_str(), position, fontSize, spacing, tint);
567 return ::LoadImageColors(*
this);
573 inline ::Color*
LoadPalette(
int maxPaletteSize,
int *colorsCount)
const {
574 return ::LoadImagePalette(*
this, maxPaletteSize, colorsCount);
581 ::UnloadImageColors(colors);
588 ::UnloadImagePalette(colors);
595 return ::LoadTextureFromImage(*
this);
601 inline operator ::Texture2D() {
608 static int GetPixelDataSize(
int width,
int height,
int format = PIXELFORMAT_UNCOMPRESSED_R32G32B32A32) {
609 return ::GetPixelDataSize(width, height, format);
618 return ::GetPixelDataSize(width, height, format);
627 return data !=
nullptr;
631 inline void set(const ::Image& image) {
634 height = image.height;
635 mipmaps = image.mipmaps;
636 format = image.format;
641 #endif // RAYLIB_CPP_INCLUDE_IMAGE_HPP_