-
Notifications
You must be signed in to change notification settings - Fork 0
/
aim.h
41 lines (31 loc) · 1.04 KB
/
aim.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#ifndef AIM__AIM_H
#define AIM__AIM_H
#include <stdbool.h>
struct image {
unsigned int cols, rows;
/* Black-white image, one _BIT_ per pixel. Rows-oriented,
* rows are rounded to whole bytes. */
unsigned char *bitmap;
};
static unsigned int image_rowbytes(struct image *img);
static bool image_getpixel(struct image *img, unsigned int x, unsigned int y);
static void image_putpixel(struct image *img, unsigned int x, unsigned int y, bool pixel);
void exercise(struct image * restrict in, struct image * restrict out);
/** Implementation: */
static inline unsigned int
image_rowbytes(struct image *img)
{
return (img->cols + 7) / 8;
}
static inline bool
image_getpixel(struct image *img, unsigned int x, unsigned int y)
{
return (img->bitmap[image_rowbytes(img) * y + x / 8] >> (7 - x % 8)) & 1;
}
static inline void
image_putpixel(struct image *img, unsigned int x, unsigned int y, bool pixel)
{
(img->bitmap[image_rowbytes(img) * y + x / 8] &= ~(1 << (7 - x % 8)));
(img->bitmap[image_rowbytes(img) * y + x / 8] |= pixel << (7 - x % 8));
}
#endif