25 struct { uint8_t r, g, b, a; };
26 struct { uint8_t red, green, blue, alpha; };
34 uint32_t height, width;
53image_t *load_image(
const char *filename);
63void save_image(
image_t *img,
const char *filename);
81image_t *new_image(uint32_t width, uint32_t height);
117 Image(uint32_t width, uint32_t height) : data(new_image(width, height)) {}
122 Image(
const char *filename) : data(load_image(filename)) { }
124 Image() : data(nullptr) {}
126 ~Image() {
if(!data) free_image(data);}
129 pixel_t* operator[](uint32_t y) {
return &(data->rgba[data->width * y]); }
132 void save(
const char *filename)
const {
133 save_image(data, filename);
137 uint32_t width()
const {
return data->width; }
140 uint32_t height()
const {
return data->height; }
142 bool empty()
const {
return data ==
nullptr;}
152#define pixel_xy(img,x,y) (img)->rgba[(x) + (y)*(img)->width]