summaryrefslogtreecommitdiffstats
path: root/sub
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-12-24 17:32:05 +0100
committerwm4 <wm4@nowhere>2015-12-24 17:32:10 +0100
commitbbb65ed84b04a834f3c72df1e9f46afb81d6ec91 (patch)
tree1294b999d8121abc18efa53c838486266c354a4e /sub
parent30074f8440bf5c90fb0cffd0f196863c6488bae4 (diff)
downloadmpv-bbb65ed84b04a834f3c72df1e9f46afb81d6ec91.tar.bz2
mpv-bbb65ed84b04a834f3c72df1e9f46afb81d6ec91.tar.xz
sub: use macros to remove code duplication
Meh.
Diffstat (limited to 'sub')
-rw-r--r--sub/draw_bmp.c80
1 files changed, 31 insertions, 49 deletions
diff --git a/sub/draw_bmp.c b/sub/draw_bmp.c
index 7be99d77f6..ce62a549c9 100644
--- a/sub/draw_bmp.c
+++ b/sub/draw_bmp.c
@@ -64,7 +64,16 @@ static bool get_sub_area(struct mp_rect bb, struct mp_image *temp,
struct sub_bitmap *sb, struct mp_image *out_area,
int *out_src_x, int *out_src_y);
-#define CONDITIONAL
+#define CONDITIONAL 1
+
+#define BLEND_CONST_ALPHA(TYPE) \
+ TYPE *dst_r = dst_rp; \
+ for (int x = 0; x < w; x++) { \
+ uint32_t srcap = srca_r[x]; \
+ if (CONDITIONAL && !srcap) continue; \
+ srcap *= srcamul; /* now 0..65025 */ \
+ dst_r[x] = (srcp * srcap + dst_r[x] * (65025 - srcap) + 32512) / 65025; \
+ }
// dst = srcp * (srca * srcamul) + dst * (1 - (srca * srcamul))
static void blend_const_alpha(void *dst, int dst_stride, int srcp,
@@ -77,31 +86,21 @@ static void blend_const_alpha(void *dst, int dst_stride, int srcp,
void *dst_rp = (uint8_t *)dst + dst_stride * y;
uint8_t *srca_r = srca + srca_stride * y;
if (bytes == 2) {
- uint16_t *dst_r = dst_rp;
- for (int x = 0; x < w; x++) {
- uint32_t srcap = srca_r[x];
-#ifdef CONDITIONAL
- if (!srcap)
- continue;
-#endif
- srcap *= srcamul; // now 0..65025
- dst_r[x] = (srcp * srcap + dst_r[x] * (65025 - srcap) + 32512) / 65025;
- }
+ BLEND_CONST_ALPHA(uint16_t)
} else if (bytes == 1) {
- uint8_t *dst_r = dst_rp;
- for (int x = 0; x < w; x++) {
- uint32_t srcap = srca_r[x];
-#ifdef CONDITIONAL
- if (!srcap)
- continue;
-#endif
- srcap *= srcamul; // now 0..65025
- dst_r[x] = (srcp * srcap + dst_r[x] * (65025 - srcap) + 32512) / 65025;
- }
+ BLEND_CONST_ALPHA(uint8_t)
}
}
}
+#define BLEND_SRC_ALPHA(TYPE) \
+ TYPE *dst_r = dst_rp, *src_r = src_rp; \
+ for (int x = 0; x < w; x++) { \
+ uint32_t srcap = srca_r[x]; \
+ if (CONDITIONAL && !srcap) continue; \
+ dst_r[x] = (src_r[x] * srcap + dst_r[x] * (255 - srcap) + 127) / 255; \
+ }
+
// dst = src * srca + dst * (1 - srca)
static void blend_src_alpha(void *dst, int dst_stride, void *src,
int src_stride, uint8_t *srca, int srca_stride,
@@ -112,29 +111,20 @@ static void blend_src_alpha(void *dst, int dst_stride, void *src,
void *src_rp = (uint8_t *)src + src_stride * y;
uint8_t *srca_r = srca + srca_stride * y;
if (bytes == 2) {
- uint16_t *dst_r = dst_rp, *src_r = src_rp;
- for (int x = 0; x < w; x++) {
- uint32_t srcap = srca_r[x];
-#ifdef CONDITIONAL
- if (!srcap)
- continue;
-#endif
- dst_r[x] = (src_r[x] * srcap + dst_r[x] * (255 - srcap) + 127) / 255;
- }
+ BLEND_SRC_ALPHA(uint16_t)
} else if (bytes == 1) {
- uint8_t *dst_r = dst_rp, *src_r = src_rp;
- for (int x = 0; x < w; x++) {
- uint16_t srcap = srca_r[x];
-#ifdef CONDITIONAL
- if (!srcap)
- continue;
-#endif
- dst_r[x] = (src_r[x] * srcap + dst_r[x] * (255 - srcap) + 127) / 255;
- }
+ BLEND_SRC_ALPHA(uint8_t)
}
}
}
+#define BLEND_SRC_DST_MUL(TYPE, MAX) \
+ TYPE *dst_r = dst_rp; \
+ for (int x = 0; x < w; x++) { \
+ uint16_t srcp = src_r[x] * srcmul; /* now 0..65025 */ \
+ dst_r[x] = (srcp * (MAX) + dst_r[x] * (65025 - srcp) + 32512) / 65025; \
+ }
+
// dst = src * srcmul + dst * (1 - src * srcmul)
static void blend_src_dst_mul(void *dst, int dst_stride,
uint8_t *src, int src_stride, uint8_t srcmul,
@@ -144,17 +134,9 @@ static void blend_src_dst_mul(void *dst, int dst_stride,
void *dst_rp = (uint8_t *)dst + dst_stride * y;
uint8_t *src_r = (uint8_t *)src + src_stride * y;
if (dst_bytes == 2) {
- uint16_t *dst_r = dst_rp;
- for (int x = 0; x < w; x++) {
- uint16_t srcp = src_r[x] * srcmul; // now 0..65025
- dst_r[x] = (srcp * 65025 + dst_r[x] * (65025 - srcp) + 32512) / 65025;
- }
+ BLEND_SRC_DST_MUL(uint16_t, 65025)
} else if (dst_bytes == 1) {
- uint8_t *dst_r = dst_rp;
- for (int x = 0; x < w; x++) {
- uint16_t srcp = src_r[x] * srcmul; // now 0..65025
- dst_r[x] = (srcp * 255 + dst_r[x] * (65025 - srcp) + 32512) / 65025;
- }
+ BLEND_SRC_DST_MUL(uint8_t, 255)
}
}
}