forked from preble/pypinproc
-
Notifications
You must be signed in to change notification settings - Fork 4
/
dmd.h
136 lines (107 loc) · 4.25 KB
/
dmd.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/**
* Copyright (c) 2009-2011 Adam Preble and Gerry Stellenberg
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
**
*
* DMD Library
*
* This library (dmd.h and dmd.c) provide functions for managing and manipulating
* bitmaps that represent DMD (dot matrix display) frame buffers. The functions
* here are based on the DMDBuffer class interface in pypinproc, and have been
* adapted here for use in other contexts with an emphasis on portability and
* zero dependencies.
*
* - Adam Preble, March 2011
*/
#ifndef _DMD_H_
#define _DMD_H_
#if defined(__cplusplus)
#define DMD_EXTERN_C_BEGIN extern "C" {
#define DMD_EXTERN_C_END }
#else
#define DMD_EXTERN_C_BEGIN
#define DMD_EXTERN_C_END
#endif
DMD_EXTERN_C_BEGIN
typedef unsigned char DMDColor;
/**
* Geometry Types
*
* DMDRect, DMDSize, DMDPoint data structures adapted from Apple's Core Graphics data structures.
*/
typedef unsigned DMDDimension;
typedef struct _DMDPoint {
DMDDimension x, y;
} DMDPoint;
typedef struct _DMDSize {
DMDDimension width, height;
} DMDSize;
typedef struct _DMDRect {
DMDPoint origin;
DMDSize size;
} DMDRect;
static inline DMDPoint DMDPointMake(DMDDimension x, DMDDimension y) { DMDPoint p = {x, y}; return p; }
static inline DMDSize DMDSizeMake(DMDDimension w, DMDDimension h) { DMDSize s = {w, h}; return s; }
static inline DMDRect DMDRectMake(DMDDimension x, DMDDimension y, DMDDimension w, DMDDimension h) { DMDRect r = {{x, y}, {w, h}}; return r; }
static inline DMDDimension DMDRectGetMinX(DMDRect r) { return r.origin.x; }
static inline DMDDimension DMDRectGetMinY(DMDRect r) { return r.origin.y; }
static inline DMDDimension DMDRectGetMaxX(DMDRect r) { return r.origin.x + r.size.width; }
static inline DMDDimension DMDRectGetMaxY(DMDRect r) { return r.origin.y + r.size.height; }
DMDRect DMDRectIntersection(DMDRect a, DMDRect b);
/**
* DMDFrame - Creation/Management
*/
typedef struct _DMDFrame {
DMDSize size;
DMDColor *buffer;
} DMDFrame;
DMDFrame *DMDFrameCreate(DMDSize size);
void DMDFrameDelete(DMDFrame *frame);
DMDFrame *DMDFrameCopy(DMDFrame *frame);
/**
* DMDFrame - Accessors
*/
DMDRect DMDFrameGetBounds(DMDFrame *frame);
DMDSize DMDFrameGetSize(DMDFrame *frame);
unsigned DMDFrameGetBufferSize(DMDFrame *frame);
static inline DMDColor *DMDFrameGetDotPointer(DMDFrame *frame, DMDPoint p) { return &frame->buffer[p.y * frame->size.width + p.x]; }
static inline DMDColor DMDFrameGetDot(DMDFrame *frame, DMDPoint p) { return frame->buffer[p.y * frame->size.width + p.x]; }
static inline void DMDFrameSetDot(DMDFrame *frame, DMDPoint p, DMDColor c) { frame->buffer[p.y * frame->size.width + p.x] = c; }
/**
* DMDFrame - Manipulation
*/
void DMDFrameFillRect(DMDFrame *frame, DMDRect rect, DMDColor color);
typedef enum {
DMDBlendModeCopy = 0,
DMDBlendModeAdd = 1,
DMDBlendModeSubtract = 2,
DMDBlendModeBlackSource = 3,
DMDBlendModeAlpha = 4,
DMDBlendModeAlphaBoth = 5,
} DMDBlendMode;
void DMDFrameCopyRect(DMDFrame *from, DMDRect fromRect, DMDFrame *to, DMDPoint toPoint, DMDBlendMode blendMode);
/**
* DMDFrame - P-ROC DMD Driver Support
*/
void DMDFrameCopyPROCSubframes(DMDFrame *frame, unsigned char *dots, DMDDimension width, DMDDimension height, unsigned subframes, unsigned char *colorMap);
DMD_EXTERN_C_END
#endif
/* _DMD_H_ */