2003-06-13 05:37:19 +00:00
|
|
|
/* GStreamer
|
|
|
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define DEBUG_ENABLED
|
2003-11-06 22:17:19 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
2003-11-07 12:47:01 +00:00
|
|
|
|
2003-06-13 05:37:19 +00:00
|
|
|
#include <gst/gst.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <videoflip.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "gstvideoflip.h"
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_videoflip_planar411 (GstVideoflip * scale, unsigned char *dest,
|
|
|
|
unsigned char *src);
|
2003-06-13 05:37:19 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
static void gst_videoflip_flip (GstVideoflip * videoflip, unsigned char *dest,
|
2003-06-13 05:37:19 +00:00
|
|
|
unsigned char *src, int sw, int sh, int dw, int dh);
|
|
|
|
|
|
|
|
struct videoflip_format_struct videoflip_formats[] = {
|
2004-03-14 22:34:33 +00:00
|
|
|
/* planar */
|
|
|
|
{"YV12", 12, gst_videoflip_planar411,},
|
|
|
|
{"I420", 12, gst_videoflip_planar411,},
|
2003-06-13 05:37:19 +00:00
|
|
|
};
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
int videoflip_n_formats =
|
|
|
|
sizeof (videoflip_formats) / sizeof (videoflip_formats[0]);
|
2003-06-13 05:37:19 +00:00
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *
|
2004-03-14 22:34:33 +00:00
|
|
|
videoflip_get_cap (struct videoflip_format_struct *format)
|
2003-06-13 05:37:19 +00:00
|
|
|
{
|
|
|
|
unsigned int fourcc;
|
2003-12-22 01:47:09 +00:00
|
|
|
GstStructure *structure;
|
2003-06-13 05:37:19 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (format->scale == NULL)
|
2003-06-13 05:37:19 +00:00
|
|
|
return NULL;
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
fourcc =
|
|
|
|
GST_MAKE_FOURCC (format->fourcc[0], format->fourcc[1], format->fourcc[2],
|
|
|
|
format->fourcc[3]);
|
2003-06-13 05:37:19 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (format->bpp) {
|
|
|
|
structure = gst_structure_new ("video/x-raw-rgb",
|
2004-03-15 19:32:27 +00:00
|
|
|
"depth", G_TYPE_INT, format->bpp,
|
|
|
|
"bpp", G_TYPE_INT, format->depth,
|
|
|
|
"endianness", G_TYPE_INT, format->endianness,
|
|
|
|
"red_mask", G_TYPE_INT, format->red_mask,
|
|
|
|
"green_mask", G_TYPE_INT, format->green_mask,
|
|
|
|
"blue_mask", G_TYPE_INT, format->blue_mask, NULL);
|
2004-03-14 22:34:33 +00:00
|
|
|
} else {
|
|
|
|
structure = gst_structure_new ("video/x-raw-yuv",
|
2004-03-15 19:32:27 +00:00
|
|
|
"format", GST_TYPE_FOURCC, fourcc, NULL);
|
2003-06-13 05:37:19 +00:00
|
|
|
}
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
return structure;
|
2003-06-13 05:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct videoflip_format_struct *
|
2004-03-14 22:34:33 +00:00
|
|
|
videoflip_find_by_caps (const GstCaps * caps)
|
2003-06-13 05:37:19 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
GST_DEBUG ("finding %p", caps);
|
2003-06-13 05:37:19 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
g_return_val_if_fail (caps != NULL, NULL);
|
2003-06-13 05:37:19 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
for (i = 0; i < videoflip_n_formats; i++) {
|
2003-06-13 05:37:19 +00:00
|
|
|
GstCaps *c;
|
|
|
|
|
2003-12-22 01:47:09 +00:00
|
|
|
c = gst_caps_new_full (videoflip_get_cap (videoflip_formats + i), NULL);
|
2004-03-14 22:34:33 +00:00
|
|
|
if (c) {
|
|
|
|
if (gst_caps_is_always_compatible (caps, c)) {
|
2004-03-15 19:32:27 +00:00
|
|
|
gst_caps_free (c);
|
|
|
|
return videoflip_formats + i;
|
2003-06-13 05:37:19 +00:00
|
|
|
}
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_caps_free (c);
|
2003-06-13 05:37:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_videoflip_setup (GstVideoflip * videoflip)
|
2003-06-13 05:37:19 +00:00
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
if (videoflip->from_width == 0 || videoflip->from_height == 0) {
|
2003-06-13 05:37:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
switch (videoflip->method) {
|
2003-06-13 05:37:19 +00:00
|
|
|
case GST_VIDEOFLIP_METHOD_90R:
|
|
|
|
case GST_VIDEOFLIP_METHOD_90L:
|
|
|
|
case GST_VIDEOFLIP_METHOD_TRANS:
|
|
|
|
case GST_VIDEOFLIP_METHOD_OTHER:
|
|
|
|
videoflip->to_height = videoflip->from_width;
|
|
|
|
videoflip->to_width = videoflip->from_height;
|
|
|
|
break;
|
|
|
|
case GST_VIDEOFLIP_METHOD_IDENTITY:
|
|
|
|
case GST_VIDEOFLIP_METHOD_180:
|
|
|
|
case GST_VIDEOFLIP_METHOD_HORIZ:
|
|
|
|
case GST_VIDEOFLIP_METHOD_VERT:
|
|
|
|
videoflip->to_height = videoflip->from_height;
|
|
|
|
videoflip->to_width = videoflip->from_width;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* FIXME */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("format=%p \"%s\" from %dx%d to %dx%d",
|
2004-03-14 22:34:33 +00:00
|
|
|
videoflip->format, videoflip->format->fourcc,
|
|
|
|
videoflip->from_width, videoflip->from_height,
|
|
|
|
videoflip->to_width, videoflip->to_height);
|
2003-06-13 05:37:19 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
if (videoflip->method == GST_VIDEOFLIP_METHOD_IDENTITY) {
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("videoflip: using passthru");
|
2003-06-13 05:37:19 +00:00
|
|
|
videoflip->passthru = TRUE;
|
|
|
|
videoflip->inited = TRUE;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
videoflip->from_buf_size = (videoflip->from_width * videoflip->from_height
|
2004-03-14 22:34:33 +00:00
|
|
|
* videoflip->format->depth) / 8;
|
2003-06-13 05:37:19 +00:00
|
|
|
videoflip->to_buf_size = (videoflip->to_width * videoflip->to_height
|
2004-03-14 22:34:33 +00:00
|
|
|
* videoflip->format->depth) / 8;
|
2003-06-13 05:37:19 +00:00
|
|
|
|
|
|
|
videoflip->inited = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_videoflip_planar411 (GstVideoflip * scale, unsigned char *dest,
|
|
|
|
unsigned char *src)
|
2003-06-13 05:37:19 +00:00
|
|
|
{
|
|
|
|
int sw = scale->from_width;
|
|
|
|
int sh = scale->from_height;
|
|
|
|
int dw = scale->to_width;
|
|
|
|
int dh = scale->to_height;
|
|
|
|
|
2003-06-29 19:46:12 +00:00
|
|
|
GST_DEBUG ("videoflip: scaling planar 4:1:1 %dx%d to %dx%d", sw, sh, dw, dh);
|
2003-06-13 05:37:19 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_videoflip_flip (scale, dest, src, sw, sh, dw, dh);
|
2003-06-13 05:37:19 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
src += sw * sh;
|
|
|
|
dest += dw * dh;
|
2003-06-13 05:37:19 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
dh = dh >> 1;
|
|
|
|
dw = dw >> 1;
|
|
|
|
sh = sh >> 1;
|
|
|
|
sw = sw >> 1;
|
2003-06-13 05:37:19 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_videoflip_flip (scale, dest, src, sw, sh, dw, dh);
|
2003-06-13 05:37:19 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
src += sw * sh;
|
|
|
|
dest += dw * dh;
|
2003-06-13 05:37:19 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_videoflip_flip (scale, dest, src, sw, sh, dw, dh);
|
2003-06-13 05:37:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2004-03-14 22:34:33 +00:00
|
|
|
gst_videoflip_flip (GstVideoflip * videoflip, unsigned char *dest,
|
2003-06-13 05:37:19 +00:00
|
|
|
unsigned char *src, int sw, int sh, int dw, int dh)
|
|
|
|
{
|
2004-03-14 22:34:33 +00:00
|
|
|
int x, y;
|
2003-06-13 05:37:19 +00:00
|
|
|
|
2004-03-14 22:34:33 +00:00
|
|
|
switch (videoflip->method) {
|
2003-06-13 05:37:19 +00:00
|
|
|
case GST_VIDEOFLIP_METHOD_90R:
|
2004-03-14 22:34:33 +00:00
|
|
|
for (y = 0; y < dh; y++) {
|
2004-03-15 19:32:27 +00:00
|
|
|
for (x = 0; x < dw; x++) {
|
|
|
|
dest[y * dw + x] = src[(sh - 1 - x) * sw + y];
|
|
|
|
}
|
2003-06-13 05:37:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEOFLIP_METHOD_90L:
|
2004-03-14 22:34:33 +00:00
|
|
|
for (y = 0; y < dh; y++) {
|
2004-03-15 19:32:27 +00:00
|
|
|
for (x = 0; x < dw; x++) {
|
|
|
|
dest[y * dw + x] = src[x * sw + (sw - 1 - y)];
|
|
|
|
}
|
2003-06-13 05:37:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEOFLIP_METHOD_180:
|
2004-03-14 22:34:33 +00:00
|
|
|
for (y = 0; y < dh; y++) {
|
2004-03-15 19:32:27 +00:00
|
|
|
for (x = 0; x < dw; x++) {
|
|
|
|
dest[y * dw + x] = src[(sh - 1 - y) * sw + (sw - 1 - x)];
|
|
|
|
}
|
2003-06-13 05:37:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEOFLIP_METHOD_HORIZ:
|
2004-03-14 22:34:33 +00:00
|
|
|
for (y = 0; y < dh; y++) {
|
2004-03-15 19:32:27 +00:00
|
|
|
for (x = 0; x < dw; x++) {
|
|
|
|
dest[y * dw + x] = src[y * sw + (sw - 1 - x)];
|
|
|
|
}
|
2003-06-13 05:37:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEOFLIP_METHOD_VERT:
|
2004-03-14 22:34:33 +00:00
|
|
|
for (y = 0; y < dh; y++) {
|
2004-03-15 19:32:27 +00:00
|
|
|
for (x = 0; x < dw; x++) {
|
|
|
|
dest[y * dw + x] = src[(sh - 1 - y) * sw + x];
|
|
|
|
}
|
2003-06-13 05:37:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEOFLIP_METHOD_TRANS:
|
2004-03-14 22:34:33 +00:00
|
|
|
for (y = 0; y < dh; y++) {
|
2004-03-15 19:32:27 +00:00
|
|
|
for (x = 0; x < dw; x++) {
|
|
|
|
dest[y * dw + x] = src[x * sw + y];
|
|
|
|
}
|
2003-06-13 05:37:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case GST_VIDEOFLIP_METHOD_OTHER:
|
2004-03-14 22:34:33 +00:00
|
|
|
for (y = 0; y < dh; y++) {
|
2004-03-15 19:32:27 +00:00
|
|
|
for (x = 0; x < dw; x++) {
|
|
|
|
dest[y * dw + x] = src[(sh - 1 - x) * sw + (sw - 1 - y)];
|
|
|
|
}
|
2003-06-13 05:37:19 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* FIXME */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|