Image
micro::image is a CPU-side pixel surface backed by an SDL_Surface. Use it
to load, create, or manipulate pixel data before uploading it to the GPU as a
texture.
Ownership is shared: copying an image shares the underlying surface, and the surface is freed only when the last owner is destroyed.
Loading from file
auto img = micro::image::load_png("assets/hero.png");
auto img = micro::image::load_bmp("assets/tile.bmp");
Loading from memory
Useful with embedded assets (see tools/res2code.py):
extern const std::uint8_t hero_png[];
extern const std::size_t hero_png_size;
auto img = micro::image::load_png({hero_png, hero_png_size});
Creating a blank image
micro::image img{256, 256}; // uninitialised pixels
img.clear(micro::color::black); // fill before use
Dimensions
int w = img.width();
int h = img.height();
Pixel access
micro::color c = img.read_pixel(x, y);
img.write_pixel(x, y, micro::color::red);
!!! warning
read_pixel and write_pixel are not suitable for per-frame or inner-loop
use. They prioritise correctness over performance.
Compositing
img.blit(src_img, x, y); // composite src_img onto img at (x, y)
img.set_color_key(micro::color::magenta); // treat magenta as transparent during blits
Saving
img.save_png("screenshot.png");
img.save_bmp("screenshot.bmp");
Duplicating
auto copy = img.duplicate(); // deep copy with its own pixel data