 |
raylib-cpp
C++ object-oriented wrapper library for raylib.
|
25 #ifndef RAYLIB_CPP_INCLUDE_IMAGE_HPP_
26 #define RAYLIB_CPP_INCLUDE_IMAGE_HPP_
30 #include "./raylib.hpp"
31 #include "./raylib-cpp-utils.hpp"
40 Image(
const std::string& fileName) {
44 Image(
const std::string& fileName,
int width,
int height,
int format,
int headerSize) {
45 LoadRaw(fileName, width, height, format, headerSize);
48 Image(
const std::string& fileName,
int* frames) {
52 Image(
const std::string& fileType,
const unsigned char* fileData,
int dataSize) {
56 Image(const ::Texture2D& texture) {
57 set(::GetTextureData(texture));
60 Image(
int width,
int height, ::
Color color = {255, 255, 255, 255}) {
61 set(::GenImageColor(width, height, color));
64 Image(const ::Font& font,
const std::string& text,
float fontSize,
float spacing,
65 ::
Color tint = {255, 255, 255, 255}) {
66 set(::ImageTextEx(font, text.c_str(), fontSize, spacing, tint));
69 static ::Image
Text(
const std::string& text,
int fontSize,
70 ::
Color color = {255, 255, 255, 255}) {
71 return ::ImageText(text.c_str(), fontSize, color);
74 static ::Image
Text(const ::Font& font,
const std::string& text,
float fontSize,
float spacing,
75 ::
Color tint = {255, 255, 255, 255}) {
76 return ::ImageTextEx(font, text.c_str(), fontSize, spacing, tint);
83 return ::GetScreenData();
89 static ::Image
Color(
int width,
int height, ::
Color color = {255, 255, 255, 255}) {
90 return ::GenImageColor(width, height, color);
97 return ::GenImageGradientV(width, height, top, bottom);
104 return ::GenImageGradientH(width, height, left, right);
112 return ::GenImageGradientRadial(width, height, density, inner, outer);
118 static ::Image
Checked(
int width,
int height,
int checksX,
int checksY,
120 return ::GenImageChecked(width, height, checksX, checksY, col1, col2);
126 static ::Image
WhiteNoise(
int width,
int height,
float factor) {
127 return ::GenImageWhiteNoise(width, height, factor);
133 static ::Image
PerlinNoise(
int width,
int height,
int offsetX,
int offsetY,
134 float scale = 1.0f) {
135 return ::GenImagePerlinNoise(width, height, offsetX, offsetY, scale);
141 static ::Image
Cellular(
int width,
int height,
int tileSize) {
142 return ::GenImageCellular(width, height, tileSize);
159 void Load(
const std::string& fileName) {
160 set(::LoadImage(fileName.c_str()));
163 void LoadRaw(
const std::string& fileName,
int width,
int height,
int format,
int headerSize) {
164 set(::LoadImageRaw(fileName.c_str(), width, height, format, headerSize));
167 void LoadAnim(
const std::string& fileName,
int* frames) {
168 set(::LoadImageAnim(fileName.c_str(), frames));
172 const std::string& fileType,
173 const unsigned char *fileData,
175 set(::LoadImageFromMemory(fileType.c_str(), fileData, dataSize));
180 ::UnloadImage(*
this);
188 inline bool Export(
const std::string& fileName) {
190 return ::ExportImage(*
this, fileName.c_str());
197 return ::ExportImageAsCode(*
this, fileName.c_str());
200 GETTERSETTER(
void*, Data, data)
201 GETTERSETTER(
int, Width, width)
202 GETTERSETTER(
int, Height, height)
210 return {
static_cast<float>(width),
static_cast<float>(height)};
217 return ::ImageCopy(*
this);
224 return ::ImageFromImage(*
this, rec);
231 ::ImageToPOT(
this, fillColor);
239 ::ImageFormat(
this, newFormat);
247 ::ImageAlphaMask(
this, alphaMask);
255 ::ImageAlphaCrop(
this, threshold);
263 ::ImageAlphaPremultiply(
this);
271 ::ImageCrop(
this, crop);
279 return Crop(0, 0,
static_cast<int>(size.x),
static_cast<int>(size.y));
285 inline Image&
Crop(
int offsetX,
int offsetY,
int newWidth,
int newHeight) {
287 static_cast<float>(offsetX),
288 static_cast<float>(offsetY),
289 static_cast<float>(newWidth),
290 static_cast<float>(newHeight)
292 ::ImageCrop(
this, rect);
300 ::ImageResize(
this, newWidth, newHeight);
308 ::ImageResizeNN(
this, newWidth, newHeight);
316 ::
Color color = {255, 255, 255, 255}) {
317 ::ImageResizeCanvas(
this, newWidth, newHeight, offsetX, offsetY, color);
325 ::ImageMipmaps(
this);
333 ::ImageDither(
this, rBpp, gBpp, bBpp, aBpp);
341 ::ImageFlipVertical(
this);
349 ::ImageFlipHorizontal(
this);
357 ::ImageRotateCW(
this);
365 ::ImageRotateCCW(
this);
373 ::ImageColorTint(
this, color);
381 ::ImageColorInvert(
this);
389 ::ImageColorGrayscale(
this);
399 ::ImageColorContrast(
this, contrast);
409 ::ImageColorBrightness(
this, brightness);
417 ::ImageColorReplace(
this, color, replace);
427 return ::GetImageAlphaBorder(*
this, threshold);
434 ::ImageClearBackground(
this, color);
442 ::ImageDrawPixel(
this, posX, posY, color);
447 ::ImageDrawPixelV(
this, position, color);
451 inline Image&
DrawLine(
int startPosX,
int startPosY,
int endPosX,
int endPosY,
452 ::
Color color = {255, 255, 255, 255}) {
453 ::ImageDrawLine(
this, startPosX, startPosY, endPosX, endPosY, color);
458 ::ImageDrawLineV(
this, start, end, color);
463 ::
Color color = {255, 255, 255, 255}) {
464 ::ImageDrawCircle(
this, centerX, centerY, radius, color);
469 ::
Color color = {255, 255, 255, 255}) {
470 ::ImageDrawCircleV(
this, center, radius, color);
475 ::
Color color = {255, 255, 255, 255}) {
476 ::ImageDrawRectangle(
this, posX, posY, width, height, color);
481 ::
Color color = {255, 255, 255, 255}) {
482 ::ImageDrawRectangleV(
this, position, size, color);
487 ::ImageDrawRectangleRec(
this, rec, color);
492 ::
Color color = {255, 255, 255, 255}) {
493 ::ImageDrawRectangleLines(
this, rec, thick, color);
498 ::
Color tint = {255, 255, 255, 255}) {
499 ::ImageDraw(
this, src, srcRec, dstRec, tint);
504 ::
Color color = {255, 255, 255, 255}) {
505 ::ImageDrawText(
this,
507 static_cast<int>(position.x),
508 static_cast<int>(position.y),
515 ::
Color color = {255, 255, 255, 255}) {
516 ::ImageDrawText(
this, text.c_str(), x, y, fontSize, color);
521 float fontSize,
float spacing, ::
Color tint = {255, 255, 255, 255}) {
522 ::ImageDrawTextEx(
this, font, text.c_str(), position, fontSize, spacing, tint);
530 return ::LoadImageColors(*
this);
536 inline ::Color*
LoadPalette(
int maxPaletteSize,
int *colorsCount) {
537 return ::LoadImagePalette(*
this, maxPaletteSize, colorsCount);
544 return ::LoadTextureFromImage(*
this);
550 inline operator ::Texture2D() {
555 inline void set(const ::Image& image) {
558 height = image.height;
559 mipmaps = image.mipmaps;
560 format = image.format;
565 #endif // RAYLIB_CPP_INCLUDE_IMAGE_HPP_
Image & Dither(int rBpp, int gBpp, int bBpp, int aBpp)
Dither image data to 16bpp or lower (Floyd-Steinberg dithering)
Provides all the classes associated with raylib-cpp.
inline ::Color * LoadPalette(int maxPaletteSize, int *colorsCount)
Load colors palette from image as a Color array (RGBA - 32bit)
Image & ColorBrightness(int brightness)
Modify image color: brightness.
::Image WhiteNoise(int width, int height, float factor)
Generate image: white noise.
::Image GradientRadial(int width, int height, float density, ::Color inner, ::Color outer)
Generate image: radial gradient.
Image(const std::string &fileType, const unsigned char *fileData, int dataSize)
Image(int width, int height, ::Color color={255, 255, 255, 255})
Image & ToPOT(::Color fillColor)
Convert image to POT (power-of-two)
Image & DrawCircle(::Vector2 center, int radius, ::Color color={255, 255, 255, 255})
Image & Format(int newFormat)
Convert image data to desired format.
Image & Draw(const ::Image &src, ::Rectangle srcRec, ::Rectangle dstRec, ::Color tint={255, 255, 255, 255})
inline ::Image Copy()
Create an image duplicate (useful for transformations)
Image & Crop(::Vector2 size)
Crop an image to area defined by a vector.
Image & ColorInvert()
Modify image color: invert.
Image & ColorGrayscale()
Modify image color: grayscale.
Image & Crop(::Rectangle crop)
Crop an image to area defined by a rectangle.
Image(const std::string &fileName)
Image & DrawText(const std::string &text, int x, int y, int fontSize, ::Color color={255, 255, 255, 255})
inline ::Vector2 GetSize()
Retrieve the width and height of the image.
Image & DrawPixel(::Vector2 position, ::Color color={255, 255, 255, 255})
::Image Text(const ::Font &font, const std::string &text, float fontSize, float spacing, ::Color tint={255, 255, 255, 255})
Image & DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, ::Color color={255, 255, 255, 255})
Image & RotateCCW()
Rotate image counter-clockwise 90deg.
Image & DrawCircle(int centerX, int centerY, int radius, ::Color color={255, 255, 255, 255})
Image(const ::Font &font, const std::string &text, float fontSize, float spacing, ::Color tint={255, 255, 255, 255})
bool ExportAsCode(const std::string &fileName)
Export image as code file defining an array of bytes, returns true on success.
Image & DrawRectangle(Vector2 position, Vector2 size, ::Color color={255, 255, 255, 255})
Image & FlipVertical()
Flip image vertically.
Image & ColorContrast(float contrast)
Modify image color: contrast.
Image & DrawText(const std::string &text, ::Vector2 position, int fontSize, ::Color color={255, 255, 255, 255})
inline ::Color * LoadColors()
Load color data from image as a Color array (RGBA - 32bit)
::Image GetScreenData()
Get pixel data from screen buffer and return an Image (screenshot)
::Image PerlinNoise(int width, int height, int offsetX, int offsetY, float scale=1.0f)
Generate image: perlin noise.
void LoadRaw(const std::string &fileName, int width, int height, int format, int headerSize)
Image & operator=(const ::Image &image)
Image & DrawRectangle(::Rectangle rec, ::Color color={255, 255, 255, 255})
Image & DrawLine(::Vector2 start, ::Vector2 end, ::Color color={255, 255, 255, 255})
Image & AlphaPremultiply()
Premultiply alpha channel.
Image & Crop(int offsetX, int offsetY, int newWidth, int newHeight)
Crop an image to area defined by a rectangle.
void LoadFromMemory(const std::string &fileType, const unsigned char *fileData, int dataSize)
Image & ResizeCanvas(int newWidth, int newHeight, int offsetX, int offsetY, ::Color color={255, 255, 255, 255})
Resize canvas and fill with color.
Image & DrawPixel(int posX, int posY, ::Color color={255, 255, 255, 255})
Draw pixel within an image.
Image & Mipmaps()
Generate all mipmap levels for a provided image.
::Image Text(const std::string &text, int fontSize, ::Color color={255, 255, 255, 255})
Image(const std::string &fileName, int width, int height, int format, int headerSize)
bool Export(const std::string &fileName)
Export image data to file, returns true on success.
::Image GradientV(int width, int height, ::Color top, ::Color bottom)
Generate image: vertical gradient.
Image & DrawRectangleLines(::Rectangle rec, int thick, ::Color color={255, 255, 255, 255})
Image & ColorTint(::Color color={255, 255, 255, 255})
Modify image color: tint.
Rectangle GetAlphaBorder(float threshold) const
Get image alpha border rectangle.
::Image GradientH(int width, int height, ::Color left, ::Color right)
Generate image: horizontal gradient.
void set(const ::Image &image)
::Image Checked(int width, int height, int checksX, int checksY, ::Color col1, ::Color col2)
Generate image: checked.
void LoadAnim(const std::string &fileName, int *frames)
void Load(const std::string &fileName)
Image(const std::string &fileName, int *frames)
::Image Color(int width, int height, ::Color color={255, 255, 255, 255})
Generate image: plain color.
Image & AlphaCrop(float threshold)
Crop image depending on alpha value.
Image & Resize(int newWidth, int newHeight)
Resize and image to new size.
Image(const ::Texture2D &texture)
Image & FlipHorizontal()
Flip image horizontally.
inline ::Image FromImage(::Rectangle rec)
Create an image from another image piece.
inline ::Texture2D LoadTexture()
Load texture from image data.
Image & ResizeNN(int newWidth, int newHeight)
Resize and image to new size using Nearest-Neighbor scaling algorithm.
Image & operator=(const Image &image)
::Image Cellular(int width, int height, int tileSize)
Generate image: cellular algorithm.
Image(const ::Image &image)
Image & DrawText(const ::Font &font, const std::string &text, ::Vector2 position, float fontSize, float spacing, ::Color tint={255, 255, 255, 255})
Image & DrawRectangle(int posX, int posY, int width, int height, ::Color color={255, 255, 255, 255})
Image & ClearBackground(::Color color={0, 0, 0, 255})
Clear image background with given color.
Image & RotateCW()
Rotate image clockwise 90deg.
Image & AlphaMask(const ::Image &alphaMask)
Apply alpha mask to image.
Image & ColorReplace(::Color color, ::Color replace)
Modify image color: replace color.