diff options
author | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2009-07-08 18:17:48 +0200 |
---|---|---|
committer | Sebastian Dröge <sebastian.droege@collabora.co.uk> | 2009-07-08 18:17:48 +0200 |
commit | 69f9b7c8d683326eb6dac0663e19bb9ef4938f0b (patch) | |
tree | 642fe103bf1da83026b84531749397cde67d35b9 /gst/videomixer/blend_bgra.c | |
parent | abd383a2a65ad9cdd2df0034a5b75dad9541d1e5 (diff) |
videomixer: Add support for ARGB
And clean up the caps parsing.
Diffstat (limited to 'gst/videomixer/blend_bgra.c')
-rw-r--r-- | gst/videomixer/blend_bgra.c | 202 |
1 files changed, 104 insertions, 98 deletions
diff --git a/gst/videomixer/blend_bgra.c b/gst/videomixer/blend_bgra.c index 1c9630ed..3cf08468 100644 --- a/gst/videomixer/blend_bgra.c +++ b/gst/videomixer/blend_bgra.c @@ -26,109 +26,115 @@ #define BLEND_MODE BLEND_NORMAL -void -gst_videomixer_blend_bgra_bgra (guint8 * src, gint xpos, gint ypos, - gint src_width, gint src_height, gdouble src_alpha, - guint8 * dest, gint dest_width, gint dest_height) -{ - gint alpha, b_alpha; - gint i, j; - gint src_stride, dest_stride; - gint src_add, dest_add; - gint B, G, R; - - src_stride = src_width * 4; - dest_stride = dest_width * 4; - - b_alpha = (gint) (src_alpha * 255); - - /* adjust src pointers for negative sizes */ - if (xpos < 0) { - src += -xpos * 4; - src_width -= -xpos; - xpos = 0; - } - if (ypos < 0) { - src += -ypos * src_stride; - src_height -= -ypos; - ypos = 0; - } - /* adjust width/height if the src is bigger than dest */ - if (xpos + src_width > dest_width) { - src_width = dest_width - xpos; - } - if (ypos + src_height > dest_height) { - src_height = dest_height - ypos; - } - - src_add = src_stride - (4 * src_width); - dest_add = dest_stride - (4 * src_width); - - dest = dest + 4 * xpos + (ypos * dest_stride); - - /* we convert a square of 2x2 samples to generate 4 Luma and 2 chroma samples */ - for (i = 0; i < src_height; i++) { - for (j = 0; j < src_width; j++) { - alpha = (src[3] * b_alpha) >> 8; - BLEND_MODE (dest[0], dest[1], dest[2], src[0], src[1], src[2], - B, G, R, alpha); - dest[0] = B; - dest[1] = G; - dest[2] = R; - dest[3] = 0xff; - - src += 4; - dest += 4; - } - src += src_add; - dest += dest_add; - } -} - -#undef BLEND_MODE - -/* fill a buffer with a checkerboard pattern */ -void -gst_videomixer_fill_bgra_checker (guint8 * dest, gint width, gint height) -{ - gint i, j; - static int tab[] = { 80, 160, 80, 160 }; - - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - *dest++ = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* blue */ - *dest++ = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* green */ - *dest++ = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* red */ - *dest++ = 0xFF; /* alpha */ - } - } +#define CREATE_FUNCTIONS(name, a, r, g, b) \ +void \ +gst_videomixer_blend_##name##_##name (guint8 * src, gint xpos, gint ypos, \ + gint src_width, gint src_height, gdouble src_alpha, \ + guint8 * dest, gint dest_width, gint dest_height) \ +{ \ + gint alpha, b_alpha; \ + gint i, j; \ + gint src_stride, dest_stride; \ + gint src_add, dest_add; \ + gint B, G, R; \ + \ + src_stride = src_width * 4; \ + dest_stride = dest_width * 4; \ + \ + b_alpha = (gint) (src_alpha * 255); \ + \ + /* adjust src pointers for negative sizes */ \ + if (xpos < 0) { \ + src += -xpos * 4; \ + src_width -= -xpos; \ + xpos = 0; \ + } \ + if (ypos < 0) { \ + src += -ypos * src_stride; \ + src_height -= -ypos; \ + ypos = 0; \ + } \ + /* adjust width/height if the src is bigger than dest */ \ + if (xpos + src_width > dest_width) { \ + src_width = dest_width - xpos; \ + } \ + if (ypos + src_height > dest_height) { \ + src_height = dest_height - ypos; \ + } \ + \ + src_add = src_stride - (4 * src_width); \ + dest_add = dest_stride - (4 * src_width); \ + \ + dest = dest + 4 * xpos + (ypos * dest_stride); \ + \ + /* we convert a square of 2x2 samples to generate 4 Luma and 2 chroma samples */ \ + for (i = 0; i < src_height; i++) { \ + for (j = 0; j < src_width; j++) { \ + alpha = (src[a] * b_alpha) >> 8; \ + BLEND_MODE (dest[b], dest[g], dest[r], src[b], src[g], src[r], \ + B, G, R, alpha); \ + dest[b] = B; \ + dest[g] = G; \ + dest[r] = R; \ + dest[a] = 0xff; \ + \ + src += 4; \ + dest += 4; \ + } \ + src += src_add; \ + dest += dest_add; \ + } \ +} \ +\ +/* fill a buffer with a checkerboard pattern */ \ +void \ +gst_videomixer_fill_##name##_checker (guint8 * dest, gint width, gint height) \ +{ \ + gint i, j; \ + static const int tab[] = { 80, 160, 80, 160 }; \ + \ + for (i = 0; i < height; i++) { \ + for (j = 0; j < width; j++) { \ + dest[b] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* blue */ \ + dest[g] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* green */ \ + dest[r] = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; /* red */ \ + dest[a] = 0xFF; /* alpha */ \ + dest += 4; \ + } \ + } \ +} \ +\ +void \ +gst_videomixer_fill_##name##_color (guint8 * dest, gint width, gint height, \ + gint colY, gint colU, gint colV) \ +{ \ + gint red, green, blue; \ + gint i, j; \ + \ + red = CLAMP (1.164 * (colY - 16) + 1.596 * (colV - 128), 0, 255); \ + green = \ + CLAMP (1.164 * (colY - 16) - 0.813 * (colV - 128) - 0.391 * (colU - 128), \ + 0, 255); \ + blue = CLAMP (1.164 * (colY - 16) + 2.018 * (colU - 128), 0, 255); \ + \ + for (i = 0; i < height; i++) { \ + for (j = 0; j < width; j++) { \ + dest[b] = blue; \ + dest[g] = green; \ + dest[r] = red; \ + dest[a] = 0xff; \ + dest += 4; \ + } \ + } \ } -void -gst_videomixer_fill_bgra_color (guint8 * dest, gint width, gint height, - gint colY, gint colU, gint colV) -{ - gint red, green, blue; - gint i, j; - - red = CLAMP (1.164 * (colY - 16) + 1.596 * (colV - 128), 0, 255); - green = - CLAMP (1.164 * (colY - 16) - 0.813 * (colV - 128) - 0.391 * (colU - 128), - 0, 255); - blue = CLAMP (1.164 * (colY - 16) + 2.018 * (colU - 128), 0, 255); - - for (i = 0; i < height; i++) { - for (j = 0; j < width; j++) { - *dest++ = blue; - *dest++ = green; - *dest++ = red; - *dest++ = 0xff; - } - } -} +CREATE_FUNCTIONS (argb, 0, 1, 2, 3); +CREATE_FUNCTIONS (bgra, 3, 2, 1, 0); size_t gst_videomixer_calculate_frame_size_bgra (gint width, gint height) { return GST_ROUND_UP_4 (width) * height * 4; } + +#undef BLEND_MODE |