Skip to content

Commit 01d35a1

Browse files
committed
Plugins (alphablend): Fix blending and associated crashes due to buffer overruns.
1 parent b40b4f7 commit 01d35a1

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

libvisual-plugins/plugins/morph/alphablend/morph_alphablend.c

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ static int lv_morph_alpha_init (VisPluginData *plugin);
3131
static void lv_morph_alpha_cleanup (VisPluginData *plugin);
3232
static void lv_morph_alpha_apply (VisPluginData *plugin, float progress, VisAudio *audio, VisVideo *dest, VisVideo *src1, VisVideo *src2);
3333

34-
static inline void alpha_blend_buffer (uint8_t *dest, uint8_t *src1, uint8_t *src2, int size, int depth, float alpha);
34+
typedef void (*BlendFunc) (uint8_t *, const uint8_t *, const uint8_t *, visual_size_t, uint8_t);
35+
36+
static BlendFunc get_blend_func (VisVideoDepth depth);
3537

3638
const VisPluginInfo *get_plugin_info (void)
3739
{
@@ -80,33 +82,38 @@ static void lv_morph_alpha_cleanup (VisPluginData *plugin)
8082

8183
static void lv_morph_alpha_apply (VisPluginData *plugin, float progress, VisAudio *audio, VisVideo *dest, VisVideo *src1, VisVideo *src2)
8284
{
83-
alpha_blend_buffer (visual_video_get_pixels (dest),
84-
visual_video_get_pixels (src1),
85-
visual_video_get_pixels (src2),
86-
visual_video_get_size (dest),
87-
visual_video_get_depth (dest),
88-
progress);
85+
int width = visual_video_get_width (dest);
86+
int height = visual_video_get_height (dest);
87+
int depth = visual_video_get_depth (dest);
88+
int pitch = visual_video_get_pitch (dest);
89+
90+
uint8_t *src1_row_ptr = visual_video_get_pixels (src1);
91+
uint8_t *src2_row_ptr = visual_video_get_pixels (src2);
92+
uint8_t *dest_row_ptr = visual_video_get_pixels (dest);
93+
94+
uint8_t alpha = progress * 255;
95+
BlendFunc blend_func = get_blend_func (depth);
96+
97+
for (int y = 0; y < height; y++) {
98+
blend_func (dest_row_ptr, src1_row_ptr, src2_row_ptr, width, alpha);
99+
src1_row_ptr += pitch;
100+
src2_row_ptr += pitch;
101+
dest_row_ptr += pitch;
102+
}
89103
}
90104

91-
static inline void alpha_blend_buffer (uint8_t *dest, uint8_t *src1, uint8_t *src2, int size, int depth, float progress)
105+
static BlendFunc get_blend_func (VisVideoDepth depth)
92106
{
93-
uint8_t a = progress * 255;
94-
95107
switch (depth) {
96108
case VISUAL_VIDEO_DEPTH_8BIT:
97-
visual_alpha_blend_8 (dest, src1, src2, size, a);
98-
break;
99-
109+
return visual_alpha_blend_8;
100110
case VISUAL_VIDEO_DEPTH_16BIT:
101-
visual_alpha_blend_16 (dest, src1, src2, size, a);
102-
break;
103-
111+
return visual_alpha_blend_16;
104112
case VISUAL_VIDEO_DEPTH_24BIT:
105-
visual_alpha_blend_24 (dest, src1, src2, size, a);
106-
break;
107-
113+
return visual_alpha_blend_24;
108114
case VISUAL_VIDEO_DEPTH_32BIT:
109-
visual_alpha_blend_32 (dest, src1, src2, size, a);
110-
break;
115+
return visual_alpha_blend_32;
116+
default:
117+
return NULL;
111118
}
112119
}

0 commit comments

Comments
 (0)