-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxbuf.h
More file actions
69 lines (50 loc) · 1.74 KB
/
xbuf.h
File metadata and controls
69 lines (50 loc) · 1.74 KB
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
63
64
65
66
67
68
69
#ifndef XBUFF_HEADER
#define XBUFF_HEADER
#include "common.h"
typedef struct {
MemoryRect_t m;
BYTE* payload;
} Buffer_t;
#ifdef __cplusplus
extern "C" {
#endif
Buffer_t * CreateBuffer(int width, int height, int sample_sz);
Buffer_t * CreateBuffer2(int width, int height, int sample_sz, int pitch);
Buffer_t * CreateBuffer3(int width, int height, int sample_sz, int pitch, void* data);
void FreeBuffer(Buffer_t * buff);
int bufRectCpy(Buffer_t* buffDst, Point_t dstPoint, Buffer_t* buffSrc, Rect_t srcRect);
int bufFillByte(Buffer_t* buf, BYTE v);
// ----------------------------------------------------
// - MACROS AND INLINE METHODS -
// ----------------------------------------------------
INLINE_METHOD int buf4BytesAlign(int v) {
int wpad = v%4;
if (0!=wpad) v += 4-wpad;
return v;
}
INLINE_METHOD void bufWritePixel(Buffer_t* buf, int x, int y, Color32_t* c) {
void* d = &buf->payload[x*buf->m.sample_sz + y*buf->m.pitch];
memcpy(d,c,buf->m.sample_sz);
}
INLINE_METHOD void bufReadPixel(Buffer_t* buf, int x, int y, Color32_t* c) {
void* s = &buf->payload[x*buf->m.sample_sz + y*buf->m.pitch];
memcpy(c,s,buf->m.sample_sz);
}
INLINE_METHOD void bufWritePixelColor(Buffer_t* buf, int x, int y, int r, int g, int b, int a) {
Color32_t c = {{0}};
c.RGBA.r = r;
c.RGBA.g = g;
c.RGBA.b = b;
c.RGBA.a = a;
bufWritePixel(buf, x, y, &c);
}
INLINE_METHOD void bufWriteBlackPixel(Buffer_t* buf, int x, int y) {
memset(&buf->payload[x*buf->m.sample_sz + y*buf->m.pitch], 0, buf->m.sample_sz);
}
INLINE_METHOD void bufWriteBlackRows(Buffer_t* buf, int y) {
memset(&buf->payload[y*buf->m.pitch], 0, buf->m.width * buf->m.sample_sz);
}
#ifdef __cplusplus
}
#endif
#endif