My Project
Loading...
Searching...
No Matches
image.h
Go to the documentation of this file.
1#ifndef IMAGE_H
2#define IMAGE_H
3
4#include "result.h"
5
6#include <stdint.h>
7#include <stdlib.h>
8
17#define pixel_at(img, x, y) ((img).pixels + (x) + (y) * (img).width)
18
22#define foreach_pixel(img, expression) \
23 for (uint32_t i = 0; i < (img).width; ++i) { \
24 for (uint32_t j = 0; j < (img).height; ++j) { \
25 expression; \
26 } \
27 }
28
32typedef struct __attribute__((packed)) {
33 uint8_t r, g, b;
34} Pixel;
35
39typedef struct {
40 uint32_t width, height;
41 Pixel *pixels;
42} Image;
43
45
49size_t calc_image_size(uint32_t width, uint32_t height);
50
55MaybeImage create_image(uint32_t width, uint32_t height);
56
63
64#endif /* IMAGE_H */
size_t calc_image_size(uint32_t width, uint32_t height)
Return required size for image pixels data.
MaybeImage create_image(uint32_t width, uint32_t height)
Create image structure with pre-allocated data. If memory cannot be allocated, image pixels are NULL.
struct __attribute__((packed))
Pixel with 1-byte color depth.
Definition image.h:32
void destroy_image(Image img)
Free image data.
Result and Maybe types.
#define Maybe(value_t)
Maybe result.
Definition result.h:62
RGB image.
Definition image.h:39
Pixel * pixels
Definition image.h:41
uint32_t height
Definition image.h:40