 |
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) {
43 Image(
const std::string& fileName,
int width,
int height,
int format,
int headerSize) {
44 LoadRaw(fileName, width, height, format, headerSize);
46 Image(
const std::string& fileName,
int* frames) {
49 Image(
const std::string& fileType,
const unsigned char* fileData,
int dataSize) {
53 set(::GetTextureData(texture));
56 set(::GenImageColor(width, height, color));
58 Image(::
Font font,
const std::string& text,
float fontSize,
float spacing, ::
Color tint) {
59 set(::ImageTextEx(font, text.c_str(), fontSize, spacing, tint));
63 return ::ImageText(text.c_str(), fontSize, color);
67 return ::ImageTextEx(font, text.c_str(), fontSize, spacing, tint);
81 return ::GenImageColor(width, height, color);
88 return ::GenImageGradientV(width, height, top, bottom);
95 return ::GenImageGradientH(width, height, left, right);
103 return ::GenImageGradientRadial(width, height, density, inner, outer);
111 return ::GenImageChecked(width, height, checksX, checksY, col1, col2);
118 return ::GenImageWhiteNoise(width, height, factor);
125 return ::GenImagePerlinNoise(width, height, offsetX, offsetY, scale);
132 return ::GenImageCellular(width, height, tileSize);
149 void Load(
const std::string& fileName) {
150 set(::LoadImage(fileName.c_str()));
153 void LoadRaw(
const std::string& fileName,
int width,
int height,
int format,
int headerSize) {
154 set(::LoadImageRaw(fileName.c_str(), width, height, format, headerSize));
157 void LoadAnim(
const std::string& fileName,
int* frames) {
158 set(::LoadImageAnim(fileName.c_str(), frames));
161 void LoadFromMemory(
const std::string& fileType,
const unsigned char *fileData,
int dataSize) {
162 set(::LoadImageFromMemory(fileType.c_str(), fileData, dataSize));
166 ::UnloadImage(*
this);
172 inline bool Export(
const std::string& fileName) {
174 return ::ExportImage(*
this, fileName.c_str());
181 return ::ExportImageAsCode(*
this, fileName.c_str());
184 GETTERSETTER(
void*, Data, data)
185 GETTERSETTER(
int, Width, width)
186 GETTERSETTER(
int, Height, height)
194 return ::ImageCopy(*
this);
201 return ::ImageFromImage(*
this, rec);
208 ::ImageToPOT(
this, fillColor);
216 ::ImageFormat(
this, newFormat);
224 ::ImageAlphaMask(
this, alphaMask);
232 ::ImageAlphaCrop(
this, threshold);
240 ::ImageAlphaPremultiply(
this);
248 ::ImageCrop(
this, crop);
255 inline Image&
Crop(
int offsetX,
int offsetY,
int newWidth,
int newHeight) {
257 static_cast<float>(offsetX),
258 static_cast<float>(offsetY),
259 static_cast<float>(newWidth),
260 static_cast<float>(newHeight)
262 ::ImageCrop(
this, rect);
270 ::ImageResize(
this, newWidth, newHeight);
278 ::ImageResizeNN(
this, newWidth, newHeight);
286 ::ImageResizeCanvas(
this, newWidth, newHeight, offsetX, offsetY, color);
294 ::ImageMipmaps(
this);
302 ::ImageDither(
this, rBpp, gBpp, bBpp, aBpp);
310 ::ImageFlipVertical(
this);
318 ::ImageFlipHorizontal(
this);
326 ::ImageRotateCW(
this);
334 ::ImageRotateCCW(
this);
342 ::ImageColorTint(
this, color);
350 ::ImageColorInvert(
this);
358 ::ImageColorGrayscale(
this);
368 ::ImageColorContrast(
this, contrast);
378 ::ImageColorBrightness(
this, brightness);
386 ::ImageColorReplace(
this, color, replace);
396 return ::GetImageAlphaBorder(*
this, threshold);
403 ::ImageClearBackground(
this, color);
411 ::ImageDrawPixel(
this, posX, posY, color);
416 ::ImageDrawPixelV(
this, position, color);
421 ::ImageDrawLine(
this, startPosX, startPosY, endPosX, endPosY, color);
426 ::ImageDrawLineV(
this, start, end, color);
431 ::ImageDrawCircle(
this, centerX, centerY, radius, color);
436 ::ImageDrawCircleV(
this, center, radius, color);
441 ::ImageDrawRectangle(
this, posX, posY, width, height, color);
446 ::ImageDrawRectangleV(
this, position, size, color);
451 ::ImageDrawRectangleRec(
this, rec, color);
456 ::ImageDrawRectangleLines(
this, rec, thick, color);
461 ::
Color tint = WHITE) {
462 ::ImageDraw(
this, src, srcRec, dstRec, tint);
467 ::
Color color = WHITE) {
468 ::ImageDrawText(
this,
470 static_cast<int>(position.x),
471 static_cast<int>(position.y),
478 ::
Color color = WHITE) {
479 ::ImageDrawText(
this, text.c_str(), x, y, fontSize, color);
484 float fontSize,
float spacing, ::
Color tint = WHITE) {
485 ::ImageDrawTextEx(
this, font, text.c_str(), position, fontSize, spacing, tint);
493 return ::LoadImageColors(*
this);
499 inline ::Color*
LoadPalette(
int maxPaletteSize,
int *colorsCount) {
500 return ::LoadImagePalette(*
this, maxPaletteSize, colorsCount);
507 return ::LoadTextureFromImage(*
this);
513 inline operator ::Texture2D() {
521 height = image.height;
522 mipmaps = image.mipmaps;
523 format = image.format;
528 #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 & DrawRectangle(Vector2 position, Vector2 size, ::Color color=WHITE)
Image & ColorBrightness(int brightness)
Modify image color: brightness.
Image(::Texture2D texture)
Image(const std::string &fileType, const unsigned char *fileData, int dataSize)
Image & Format(int newFormat)
Convert image data to desired format.
static Image GenGradientV(int width, int height, Color top, Color bottom)
Generate image: vertical gradient.
Image & DrawText(const std::string &text, ::Vector2 position, int fontSize, ::Color color=WHITE)
Image & ColorInvert()
Modify image color: invert.
Image & ToPOT(Color fillColor)
Convert image to POT (power-of-two)
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 Image GenGradientH(int width, int height, Color left, Color right)
Generate image: horizontal gradient.
static Image GenWhiteNoise(int width, int height, float factor)
Generate image: white noise.
Image & RotateCCW()
Rotate image counter-clockwise 90deg.
Image & DrawLine(int startPosX, int startPosY, int endPosX, int endPosY, ::Color color)
bool ExportAsCode(const std::string &fileName)
Export image as code file defining an array of bytes, returns true on success.
Image & DrawPixel(int posX, int posY, ::Color color)
Draw pixel within an image.
Image & DrawRectangle(int posX, int posY, int width, int height, ::Color color=WHITE)
Image & FlipVertical()
Flip image vertically.
Image & ColorContrast(float contrast)
Modify image color: contrast.
Image & DrawRectangleLines(::Rectangle rec, int thick, ::Color color)
Image & ClearBackground(::Color color=WHITE)
Clear image background with given color.
Image & DrawCircle(::Vector2 center, int radius, ::Color color)
inline ::Color * LoadColors()
Load color data from image as a Color array (RGBA - 32bit)
void LoadRaw(const std::string &fileName, int width, int height, int format, int headerSize)
Image & operator=(const ::Image &image)
Image(::Font font, const std::string &text, float fontSize, float spacing, ::Color tint)
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)
static Image GetScreenData()
Get pixel data from screen buffer and return an Image (screenshot)
Image & DrawText(::Font font, const std::string &text, ::Vector2 position, float fontSize, float spacing, ::Color tint=WHITE)
Image & Mipmaps()
Generate all mipmap levels for a provided image.
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 & DrawPixel(::Vector2 position, ::Color color)
static Image Text(std::string text, int fontSize, Color color)
Rectangle GetAlphaBorder(float threshold) const
Get image alpha border rectangle.
static Image GenGradientRadial(int width, int height, float density, Color inner, Color outer)
Generate image: radial gradient.
static Image GenPerlinNoise(int width, int height, int offsetX, int offsetY, float scale)
Generate image: perlin noise.
void LoadAnim(const std::string &fileName, int *frames)
Image & AlphaMask(Image alphaMask)
Apply alpha mask to image.
void Load(const std::string &fileName)
Image(const std::string &fileName, int *frames)
Image & DrawText(const std::string &text, int x, int y, int fontSize, ::Color color=WHITE)
Image & ColorTint(::Color color=WHITE)
Modify image color: tint.
Image & AlphaCrop(float threshold)
Crop image depending on alpha value.
Image & Resize(int newWidth, int newHeight)
Resize and image to new size.
static Image GenCellular(int width, int height, int tileSize)
Generate image: cellular algorithm.
Image Copy()
Create an image duplicate (useful for transformations)
static Image Text(::Font font, std::string text, float fontSize, float spacing, ::Color tint)
Image & Draw(const ::Image &src, ::Rectangle srcRec, ::Rectangle dstRec, ::Color tint=WHITE)
Image & ResizeCanvas(int newWidth, int newHeight, int offsetX, int offsetY, Color color)
Resize canvas and fill with color.
Image & FlipHorizontal()
Flip image horizontally.
Image & DrawCircle(int centerX, int centerY, int radius, ::Color color)
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(int width, int height, Color color=WHITE)
Image & operator=(const Image &image)
static Image GenChecked(int width, int height, int checksX, int checksY, Color col1, Color col2)
Generate image: checked.
Image & RotateCW()
Rotate image clockwise 90deg.
Image & DrawLine(::Vector2 start, ::Vector2 end, ::Color color)
Image & ColorReplace(::Color color, ::Color replace)
Modify image color: replace color.
Image & DrawRectangle(::Rectangle rec, ::Color color=WHITE)
Image FromImage(::Rectangle rec)
Create an image from another image piece.
static Image GenColor(int width, int height, Color color)
Generate image: plain color.