-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpixop.h
62 lines (54 loc) · 1.16 KB
/
pixop.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* (C) 2010 Andy
*
* routines to use the eink screen
*/
#ifndef _PIXOP_H_
#define _PIXOP_H_
#include <string.h>
typedef struct pixmap_str {
int width;
int height;
int bpp; /* bits per pixel */
unsigned char *surface; // 1 byte = 2 pixels
} pixmap_t;
static inline void c_truncate(int *ofs, int *len, int bound)
{
if (*ofs < 0) { /* decrease size by offset */
*len += *ofs;
*ofs = 0;
}
if (*ofs > bound) {
*len = 0;
*ofs = bound;
}
if (*len <= 0)
*len = 0;
if (*ofs + *len > bound)
*len = bound - *ofs;
}
static inline unsigned char *PIXMAP_POS(pixmap_t *pix,int x,int y) {
if(pix->bpp==8)
return pix->surface+y*pix->width+x;
else if (pix->bpp==4)
return pix->surface+((y*pix->width+x)>>1);
else
return pix->surface+((y*pix->width+x)*pix->bpp/8);
}
static inline pixmap_t * pix_alloc(int w, int h, int bpp)
{
int size = ((bpp*w+7)/8*h) + sizeof(pixmap_t) ;
pixmap_t * p = (pixmap_t *)calloc(1, size);
if (p) {
p->width = w ;
p->height = h ;
p->bpp=bpp;
p->surface = (unsigned char *)(p + 1);
}
return p ;
}
static inline void pix_free(pixmap_t* p)
{
free(p);
}
#endif