Commit b045ad22 authored by David Schleef's avatar David Schleef Committed by Wim Taymans

[MOVED FROM BAD 32/68] colorspace: Add conversion code

Work in progress.  Colorspace handles most format conversion using
3-stage getline/matrix/putline process using an AYUV or ARGB
intermediate, with most functions handled by Orc.  There is also
a table of single-pass conversions, all handled by Orc.  The plan
is to add optional stages for various chroma upsampling/downsampling
algorithms, dithering, and float/int16 intermediates, and then have
Orc create multi-stage functions at runtime.
parent 7bc58863
......@@ -3,7 +3,7 @@ plugin_LTLIBRARIES = libgstcolorspace.la
ORC_SOURCE=gstcolorspaceorc
include $(top_srcdir)/common/orc.mak
libgstcolorspace_la_SOURCES = gstcolorspace.c
libgstcolorspace_la_SOURCES = gstcolorspace.c colorspace.c
nodist_libgstcolorspace_la_SOURCES = $(ORC_NODIST_SOURCES)
libgstcolorspace_la_CFLAGS = \
$(GST_PLUGINS_BASE_CFLAGS) \
......@@ -17,6 +17,6 @@ libgstcolorspace_la_LIBADD = \
libgstcolorspace_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
libgstcolorspace_la_LIBTOOLFLAGS = --tag=disable-static
noinst_HEADERS = gstcolorspace.h
noinst_HEADERS = gstcolorspace.h colorspace.h
This diff is collapsed.
/* Colorspace conversion functions
* Copyright (C) 2010 David Schleef <ds@schleef.org>
*
* 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.
*/
#ifndef __COLORSPACE_H__
#define __COLORSPACE_H__
#include <gst/video/video.h>
G_BEGIN_DECLS
typedef struct _ColorspaceConvert ColorspaceConvert;
typedef struct _ColorspaceFrame ColorspaceComponent;
struct _ColorspaceComponent {
int offset;
int stride;
};
struct _ColorspaceConvert {
gint width, height;
gboolean interlaced;
GstVideoFormat from_format;
GstVideoFormat to_format;
guint32 *palette;
guint8 *tmpline;
int dest_offset[4];
int dest_stride[4];
int src_offset[4];
int src_stride[4];
void (*convert) (ColorspaceConvert *convert, guint8 *dest, guint8 *src);
void (*getline) (ColorspaceConvert *convert, guint8 *dest, guint8 *src, int j);
void (*putline) (ColorspaceConvert *convert, guint8 *dest, guint8 *src, int j);
void (*matrix) (ColorspaceConvert *convert);
};
ColorspaceConvert * colorspace_convert_new (GstVideoFormat to_format,
GstVideoFormat from_format, int width, int height);
void colorspace_convert_set_interlaced (ColorspaceConvert *convert,
gboolean interlaced);
void colorspace_convert_set_palette (ColorspaceConvert *convert,
guint32 *palette);
void colorspace_convert_free (ColorspaceConvert * convert);
void colorspace_convert_convert (ColorspaceConvert * convert,
guint8 *dest, guint8 *src);
G_END_DECLS
#endif /* __GST_COLORSPACE_H__ */
......@@ -47,7 +47,7 @@ GST_DEBUG_CATEGORY (colorspace_performance);
#define CSP_VIDEO_CAPS \
"video/x-raw-yuv, width = "GST_VIDEO_SIZE_RANGE" , " \
"height="GST_VIDEO_SIZE_RANGE",framerate="GST_VIDEO_FPS_RANGE"," \
"format= (fourcc) { I420 , NV12 , NV21 , YV12 , YUY2 , Y42B , Y444 , YUV9 , YVU9 , Y41B , Y800 , Y8 , GREY , Y16 , UYVY , YVYU , IYU1 , v308 , AYUV } ;" \
"format= (fourcc) { I420 , NV12 , NV21 , YV12 , YUY2 , Y42B , Y444 , YUV9 , YVU9 , Y41B , Y800 , Y8 , GREY , Y16 , UYVY , YVYU , IYU1 , v308 , AYUV, v210 } ;" \
GST_VIDEO_CAPS_RGB";" \
GST_VIDEO_CAPS_BGR";" \
GST_VIDEO_CAPS_RGBx";" \
......@@ -266,13 +266,23 @@ gst_csp_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
in_interlaced != out_interlaced)
goto format_mismatch;
space->from_format = in_format;
space->to_format = out_format;
space->width = in_width;
space->height = in_height;
space->interlaced = in_interlaced;
space->convert = colorspace_convert_new (out_format, in_format,
in_width, in_height);
if (space->convert) {
colorspace_convert_set_interlaced (space->convert, in_interlaced);
}
/* palette, only for from data */
/* FIXME add palette handling */
#if 0
colorspace_convert_set_palette (convert, palette);
#endif
GST_DEBUG ("reconfigured %d %d", space->from_format, space->to_format);
......@@ -281,21 +291,21 @@ gst_csp_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
/* ERRORS */
no_width_height:
{
GST_DEBUG_OBJECT (space, "did not specify width or height");
GST_ERROR_OBJECT (space, "did not specify width or height");
space->from_format = GST_VIDEO_FORMAT_UNKNOWN;
space->to_format = GST_VIDEO_FORMAT_UNKNOWN;
return FALSE;
}
no_framerate:
{
GST_DEBUG_OBJECT (space, "did not specify framerate");
GST_ERROR_OBJECT (space, "did not specify framerate");
space->from_format = GST_VIDEO_FORMAT_UNKNOWN;
space->to_format = GST_VIDEO_FORMAT_UNKNOWN;
return FALSE;
}
format_mismatch:
{
GST_DEBUG_OBJECT (space, "input and output formats do not match");
GST_ERROR_OBJECT (space, "input and output formats do not match");
space->from_format = GST_VIDEO_FORMAT_UNKNOWN;
space->to_format = GST_VIDEO_FORMAT_UNKNOWN;
return FALSE;
......@@ -393,6 +403,8 @@ gst_csp_transform (GstBaseTransform * btrans, GstBuffer * inbuf,
space->to_format == GST_VIDEO_FORMAT_UNKNOWN))
goto unknown_format;
colorspace_convert_convert (space->convert, GST_BUFFER_DATA (outbuf),
GST_BUFFER_DATA (inbuf));
/* baseclass copies timestamps */
GST_DEBUG ("from %d -> to %d done", space->from_format, space->to_format);
......
......@@ -25,6 +25,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/video/gstvideofilter.h>
#include "colorspace.h"
G_BEGIN_DECLS
......@@ -52,6 +53,8 @@ struct _GstCsp {
GstVideoFormat from_format;
GstVideoFormat to_format;
guint32 *palette;
ColorspaceConvert *convert;
};
struct _GstCspClass
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment