2 * Copyright (C) 2009 Alex Ugarte <augarte@vicomtech.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
22 #define BLEND_NORMAL(B1,G1,R1,B2,G2,R2,B,G,R,alpha) \
23 B = ((B1*(255-alpha))+(B2*alpha))>>8; \
24 G = ((G1*(255-alpha))+(G2*alpha))>>8; \
25 R = ((R1*(255-alpha))+(R2*alpha))>>8;
27 #define BLEND_MODE BLEND_NORMAL
30 gst_videomixer_blend_bgra_bgra (guint8 * src, gint xpos, gint ypos,
31 gint src_width, gint src_height, gdouble src_alpha,
32 guint8 * dest, gint dest_width, gint dest_height)
36 gint src_stride, dest_stride;
37 gint src_add, dest_add;
40 src_stride = src_width * 4;
41 dest_stride = dest_width * 4;
43 b_alpha = (gint) (src_alpha * 255);
45 /* adjust src pointers for negative sizes */
52 src += -ypos * src_stride;
56 /* adjust width/height if the src is bigger than dest */
57 if (xpos + src_width > dest_width) {
58 src_width = dest_width - xpos;
60 if (ypos + src_height > dest_height) {
61 src_height = dest_height - ypos;
64 src_add = src_stride - (4 * src_width);
65 dest_add = dest_stride - (4 * src_width);
67 dest = dest + 4 * xpos + (ypos * dest_stride);
69 /* we convert a square of 2x2 samples to generate 4 Luma and 2 chroma samples */
70 for (i = 0; i < src_height; i++) {
71 for (j = 0; j < src_width; j++) {
72 alpha = (src[3] * b_alpha) >> 8;
73 BLEND_MODE (dest[1], dest[2], dest[3], src[1], src[2], src[3],
90 /* fill a buffer with a checkerboard pattern */
92 gst_videomixer_fill_bgra_checker (guint8 * dest, gint width, gint height)
95 static int tab[] = { 80, 160, 80, 160 };
97 for (i = 0; i < height; i++) {
98 for (j = 0; j < width; j++) {
99 *dest++ = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; //blue
100 *dest++ = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; //green
101 *dest++ = tab[((i & 0x8) >> 3) + ((j & 0x8) >> 3)]; //red
102 *dest++ = 0xFF; //alpha
108 gst_videomixer_fill_bgra_color (guint8 * dest, gint width, gint height,
109 gint colY, gint colU, gint colV)
111 gint red, green, blue;
114 //check this conversion
115 red = 1.164 * (colY - 16) + 1.596 * (colV - 128);
116 green = 1.164 * (colY - 16) - 0.813 * (colV - 128) - 0.391 * (colU - 128);
117 blue = 1.164 * (colY - 16) + 2.018 * (colU - 128);
120 for (i = 0; i < height; i++) {
121 for (j = 0; j < width; j++) {