 |
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);
157 void Load(
const std::string& fileName) {
164 void LoadRaw(
const std::string& fileName,
int width,
int height,
int format,
int headerSize) {
165 set(::
LoadImageRaw(fileName.c_str(), width, height, format, headerSize));
171 void LoadAnim(
const std::string& fileName,
int* frames) {
179 const std::string& fileType,
180 const unsigned char *fileData,
190 ::UnloadImage(*
this);
198 inline bool Export(
const std::string& fileName) {
200 return ::ExportImage(*
this, fileName.c_str());
207 return ::ExportImageAsCode(*
this, fileName.c_str());
210 GETTERSETTER(
void*, Data, data)
211 GETTERSETTER(
int, Width, width)
212 GETTERSETTER(
int, Height, height)
220 return {
static_cast<float>(width),
static_cast<float>(height)};
227 return ::ImageCopy(*
this);
234 return ::ImageFromImage(*
this, rec);
241 ::ImageToPOT(
this, fillColor);
249 ::ImageFormat(
this, newFormat);
257 ::ImageAlphaMask(
this, alphaMask);
265 ::ImageAlphaCrop(
this, threshold);
273 ::ImageAlphaPremultiply(
this);
281 ::ImageCrop(
this, crop);
289 return Crop(0, 0,
static_cast<int>(size.x),
static_cast<int>(size.y));
295 inline Image&
Crop(
int offsetX,
int offsetY,
int newWidth,
int newHeight) {
297 static_cast<float>(offsetX),
298 static_cast<float>(offsetY),
299 static_cast<float>(newWidth),
300 static_cast<float>(newHeight)
302 ::ImageCrop(
this, rect);
310 ::ImageResize(
this, newWidth, newHeight);
318 ::ImageResizeNN(
this, newWidth, newHeight);
326 ::
Color color = {255, 255, 255, 255}) {
327 ::ImageResizeCanvas(
this, newWidth, newHeight, offsetX, offsetY, color);
335 ::ImageMipmaps(
this);
343 ::ImageDither(
this, rBpp, gBpp, bBpp, aBpp);
351 ::ImageFlipVertical(
this);
359 ::ImageFlipHorizontal(
this);
367 ::ImageRotateCW(
this);
375 ::ImageRotateCCW(
this);
383 ::ImageColorTint(
this, color);
391 ::ImageColorInvert(
this);
399 ::ImageColorGrayscale(
this);
409 ::ImageColorContrast(
this, contrast);
419 ::ImageColorBrightness(
this, brightness);
427 ::ImageColorReplace(
this, color, replace);
437 return ::GetImageAlphaBorder(*
this, threshold);
444 ::ImageClearBackground(
this, color);
452 ::ImageDrawPixel(
this, posX, posY, color);
457 ::ImageDrawPixelV(
this, position, color);
461 inline Image&
DrawLine(
int startPosX,
int startPosY,
int endPosX,
int endPosY,
462 ::
Color color = {255, 255, 255, 255}) {
463 ::ImageDrawLine(
this, startPosX, startPosY, endPosX, endPosY, color);
468 ::ImageDrawLineV(
this, start, end, color);
473 ::
Color color = {255, 255, 255, 255}) {
474 ::ImageDrawCircle(
this, centerX, centerY, radius, color);
479 ::
Color color = {255, 255, 255, 255}) {
480 ::ImageDrawCircleV(
this, center, radius, color);
485 ::
Color color = {255, 255, 255, 255}) {
486 ::ImageDrawRectangle(
this, posX, posY, width, height, color);
491 ::
Color color = {255, 255, 255, 255}) {
492 ::ImageDrawRectangleV(
this, position, size, color);
497 ::ImageDrawRectangleRec(
this, rec, color);
502 ::
Color color = {255, 255, 255, 255}) {
503 ::ImageDrawRectangleLines(
this, rec, thick, color);
508 ::
Color tint = {255, 255, 255, 255}) {
509 ::ImageDraw(
this, src, srcRec, dstRec, tint);
514 ::
Color color = {255, 255, 255, 255}) {
515 ::ImageDrawText(
this,
517 static_cast<int>(position.x),
518 static_cast<int>(position.y),
525 ::
Color color = {255, 255, 255, 255}) {
526 ::ImageDrawText(
this, text.c_str(), x, y, fontSize, color);
531 float fontSize,
float spacing, ::
Color tint = {255, 255, 255, 255}) {
532 ::ImageDrawTextEx(
this, font, text.c_str(), position, fontSize, spacing, tint);
540 return ::LoadImageColors(*
this);
546 inline ::Color*
LoadPalette(
int maxPaletteSize,
int *colorsCount) {
547 return ::LoadImagePalette(*
this, maxPaletteSize, colorsCount);
554 return ::LoadTextureFromImage(*
this);
560 inline operator ::Texture2D() {
565 inline void set(const ::Image& image) {
568 height = image.height;
569 mipmaps = image.mipmaps;
570 format = image.format;
575 #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.
static inline ::Image LoadImage(const std::string &fileName)
static inline ::Image LoadImageRaw(const std::string &fileName, int width, int height, int format, int headerSize)
::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)
static inline ::Image LoadImageFromMemory(const std::string &fileType, const unsigned char *fileData, int dataSize)
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 a new given width and height based on 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)
static inline ::Image LoadImageAnim(const std::string &fileName, int *frames)
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)
Load image from RAW file data.
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)
Load image from memory buffer, fileType refers to extension: i.e.
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)
Load image sequence from file (frames appended to image.data).
void Load(const std::string &fileName)
Load image from file into CPU memory (RAM)
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)
void Unload()
Unload image from CPU memory (RAM)
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 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.