#include "KSurface.hpp" ➔ class KSurface


A class that holds a pixel surface (RGBA image).

#include "KColor.hpp"
#include "KRect.hpp"

class KSurface : KRect {};


KSurface(int width, int height);
KSurface(int width, int height, KColor color);
KSurface(std::string fileName);

Create a surface of pixel with specified dimension and color.
Or loads an image from a file.


int x, y;
int w, h;

Inherited from KRect.


void fill(KColor color);
void fill(KRect rect, KColor color);
void print(KSurface src, int x, int y);

Draw on the surface.

void set_pixel(int x, int y, KColor color);
KColor get_pixel(int x, int y);

Manipulate pixel.

void save(std::string fileName);
void clear();

Save the surface to a file as a BMP image.
Delete the surface.

void darker(unsigned char factor);
void blur(int radius);
void blur_quick(int factor);

Filters. Note that blur_quick() is way more efficient than blur().

bool unlock_write(bool force = false);

If the KSurface has been printed to a KWindow, an optimized copy exists in VRAM, thereby, any modification will cause a deletion of the optimized copy. To prevent bad uses of KSurface in this case (which could cause performance issues), the KSurface is "locked" (no modification can take place) when a VRAM copie is created until unlock_write(true) is called (it is important to set the force argument to true, otherwise the function is just testing is writing operations are allowed).


KSurface image("image.png");
KRect<> rect(0, 0, image.w, 10);

image.fill(rect, KColor::Green);

KWindow window("example", 400, 400);
window.print(image, 10, 10);