-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgraphics_common.h
159 lines (138 loc) · 4.46 KB
/
graphics_common.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* -*- C++ -*-
*
* graphics_mmx.h - graphics macros common to graphics_* & AnimationInfo
*
* Copyright (c) 2009 Mion. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifdef BPP16
#define BPP 16
#define RMASK 0xf800
#define GMASK 0x07e0
#define BMASK 0x001f
#define AMASK 0
#else
#define BPP 32
// the mask is the same as the one used in TTF_RenderGlyph_Blended
#define RMASK 0x00ff0000
#define GMASK 0x0000ff00
#define BMASK 0x000000ff
#define AMASK 0xff000000
#endif
#define RGBMASK 0x00ffffff
#ifdef BPP16
#define SET_PIXEL(rgb, alpha) {\
*dst_buffer = (((rgb)&0xf80000) >> 8) | (((rgb)&0xfc00) >> 5) | (((rgb)&0xf8) >> 3);\
*alphap++ = (alpha);\
}
#define BLEND_PIXEL(){\
Uint32 mask2 = (*alphap++ * alpha) >> 11;\
Uint32 s1 = (*src_buffer | *src_buffer << 16) & 0x07e0f81f;\
Uint32 d1 = (*dst_buffer | *dst_buffer << 16) & 0x07e0f81f;\
Uint32 mask1 = (d1 + ((s1-d1) * mask2 >> 5)) & 0x07e0f81f;\
*dst_buffer = mask1 | mask1 >> 16;\
}
#else
#define SET_PIXEL(rgb, alpha) {\
*dst_buffer = (rgb);\
*alphap = (alpha);\
alphap += 4;\
}
#define BLEND_PIXEL(){\
Uint32 mask2 = (*alphap * alpha) >> 8;\
Uint32 mask1 = mask2 ^ 0xff;\
Uint32 mask_rb = (((*dst_buffer & 0xff00ff) * mask1 +\
(*src_buffer & 0xff00ff) * mask2) >> 8) & 0xff00ff;\
Uint32 mask_g = (((*dst_buffer & 0x00ff00) * mask1 +\
(*src_buffer & 0x00ff00) * mask2) >> 8) & 0x00ff00;\
*dst_buffer = mask_rb | mask_g;\
alphap += 4;\
}
#define ADDBLEND_PIXEL(){\
Uint32 mask2 = (*alphap * alpha) >> 8;\
Uint32 mask_rb = (*dst_buffer & 0xff00ff) +\
((((*src_buffer & 0xff00ff) * mask2) >> 8) & 0xff00ff);\
mask_rb |= ((mask_rb & 0xff000000) ? 0xff0000 : 0) |\
((mask_rb & 0x0000ff00) ? 0x0000ff : 0);\
Uint32 mask_g = (*dst_buffer & 0x00ff00) +\
((((*src_buffer & 0x00ff00) * mask2) >> 8) & 0x00ff00);\
mask_g |= ((mask_g & 0xff0000) ? 0xff00 : 0);\
*dst_buffer = (mask_rb & 0xff00ff) | (mask_g & 0x00ff00);\
alphap += 4;\
}
#define SUBBLEND_PIXEL(){\
Uint32 mask2 = (*alphap * alpha) >> 8;\
Uint32 mask_r = (*dst_buffer & 0xff0000) -\
((((*src_buffer & 0xff0000) * mask2) >> 8) & 0xff0000);\
mask_r &= ((mask_r & 0xff000000) ? 0 : 0xff0000);\
Uint32 mask_g = (*dst_buffer & 0x00ff00) -\
((((*src_buffer & 0x00ff00) * mask2) >> 8) & 0x00ff00);\
mask_g &= ((mask_g & 0xffff0000) ? 0 : 0x00ff00);\
Uint32 mask_b = (*dst_buffer & 0x0000ff) -\
((((*src_buffer & 0x0000ff) * mask2) >> 8) & 0x0000ff);\
mask_b &= ((mask_b & 0xffffff00) ? 0 : 0x0000ff);\
*dst_buffer = (mask_r & 0xff0000) | (mask_g & 0x00ff00) | (mask_b & 0x0000ff);\
alphap += 4;\
}
#endif
#define BASIC_BLEND(){\
while(--n > 0) { \
BLEND_PIXEL(); \
++dst_buffer, ++src_buffer; \
} \
}
#define BASIC_ADDBLEND(){\
while(--n > 0) { \
ADDBLEND_PIXEL(); \
++dst_buffer, ++src_buffer; \
} \
}
#define BASIC_SUBBLEND(){\
while(--n > 0) { \
SUBBLEND_PIXEL(); \
++dst_buffer, ++src_buffer; \
} \
}
#define MEAN_PIXEL(){\
int result = ((int)(*src1) + (int)(*src2)) / 2; \
(*dst) = result; \
}
#define BASIC_MEAN(){\
while (--n > 0) { \
MEAN_PIXEL(); \
++dst; ++src1; ++src2; \
} \
}
#define ADDTO_PIXEL(){\
int result = (*dst) + (*src); \
(*dst) = (result < 255) ? result : 255; \
}
#define BASIC_ADDTO(){\
while (--n > 0) { \
ADDTO_PIXEL(); \
++dst, ++src; \
} \
}
#define SUBFROM_PIXEL(){\
int result = (*dst) - (*src); \
(*dst) = (result > 0) ? result : 0; \
}
#define BASIC_SUBFROM(){\
while(--n > 0) { \
SUBFROM_PIXEL(); \
++dst, ++src; \
} \
}