mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-24 18:51:11 +00:00
[MOVED FROM BAD 31/68] colorspace: Revive element
Now based on Orc.
This commit is contained in:
parent
0125cb55b9
commit
7bc588631a
6 changed files with 1716 additions and 1442 deletions
|
@ -1,15 +1,22 @@
|
||||||
plugin_LTLIBRARIES = libgstyuvtorgbcolorspace.la
|
plugin_LTLIBRARIES = libgstcolorspace.la
|
||||||
|
|
||||||
if HAVE_CPU_I386
|
ORC_SOURCE=gstcolorspaceorc
|
||||||
ARCHSRCS = yuv2rgb_mmx16.s
|
include $(top_srcdir)/common/orc.mak
|
||||||
else
|
|
||||||
ARCHSRCS =
|
libgstcolorspace_la_SOURCES = gstcolorspace.c
|
||||||
endif
|
nodist_libgstcolorspace_la_SOURCES = $(ORC_NODIST_SOURCES)
|
||||||
|
libgstcolorspace_la_CFLAGS = \
|
||||||
|
$(GST_PLUGINS_BASE_CFLAGS) \
|
||||||
|
$(GST_CFLAGS) \
|
||||||
|
$(ORC_CFLAGS)
|
||||||
|
libgstcolorspace_la_LIBADD = \
|
||||||
|
$(GST_PLUGINS_BASE_LIBS) -lgstvideo-$(GST_MAJORMINOR) \
|
||||||
|
$(GST_BASE_LIBS) \
|
||||||
|
$(GST_LIBS) \
|
||||||
|
$(ORC_LIBS)
|
||||||
|
libgstcolorspace_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
||||||
|
libgstcolorspace_la_LIBTOOLFLAGS = --tag=disable-static
|
||||||
|
|
||||||
|
noinst_HEADERS = gstcolorspace.h
|
||||||
|
|
||||||
libgstyuvtorgbcolorspace_la_SOURCES = gstcolorspace.c yuv2rgb.c
|
|
||||||
libgstyuvtorgbcolorspace_la_CFLAGS = $(GST_CFLAGS)
|
|
||||||
libgstyuvtorgbcolorspace_la_LIBADD =
|
|
||||||
libgstyuvtorgbcolorspace_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
|
|
||||||
libgstyuvtorgbcolorspace_la_LIBTOOLFLAGS = --tag=disable-static
|
|
||||||
|
|
||||||
noinst_HEADERS = yuv2rgb.h gstcolorspace.h
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
/* GStreamer
|
/* GStreamer
|
||||||
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
||||||
|
* This file:
|
||||||
|
* Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
||||||
|
* Copyright (C) 2010 David Schleef <ds@schleef.org>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
@ -17,610 +20,413 @@
|
||||||
* Boston, MA 02111-1307, USA.
|
* Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SECTION:element-colorspace
|
||||||
|
*
|
||||||
|
* Convert video frames between a great variety of colorspace formats.
|
||||||
|
*
|
||||||
|
* <refsect2>
|
||||||
|
* <title>Example launch line</title>
|
||||||
|
* |[
|
||||||
|
* gst-launch -v videotestsrc ! video/x-raw-yuv,format=\(fourcc\)YUY2 ! colorspace ! ximagesink
|
||||||
|
* ]|
|
||||||
|
* </refsect2>
|
||||||
|
*/
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
# include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "gstcolorspace.h"
|
#include "gstcolorspace.h"
|
||||||
#include <gst/gst.h>
|
|
||||||
#include <gst/video/video.h>
|
#include <gst/video/video.h>
|
||||||
|
|
||||||
#include "yuv2rgb.h"
|
GST_DEBUG_CATEGORY (colorspace_debug);
|
||||||
|
#define GST_CAT_DEFAULT colorspace_debug
|
||||||
|
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 } ;" \
|
||||||
|
GST_VIDEO_CAPS_RGB";" \
|
||||||
|
GST_VIDEO_CAPS_BGR";" \
|
||||||
|
GST_VIDEO_CAPS_RGBx";" \
|
||||||
|
GST_VIDEO_CAPS_xRGB";" \
|
||||||
|
GST_VIDEO_CAPS_BGRx";" \
|
||||||
|
GST_VIDEO_CAPS_xBGR";" \
|
||||||
|
GST_VIDEO_CAPS_RGBA";" \
|
||||||
|
GST_VIDEO_CAPS_ARGB";" \
|
||||||
|
GST_VIDEO_CAPS_BGRA";" \
|
||||||
|
GST_VIDEO_CAPS_ABGR";" \
|
||||||
|
GST_VIDEO_CAPS_RGB_16";" \
|
||||||
|
GST_VIDEO_CAPS_RGB_15";" \
|
||||||
|
"video/x-raw-rgb, bpp = (int)8, depth = (int)8, " \
|
||||||
|
"width = "GST_VIDEO_SIZE_RANGE" , " \
|
||||||
|
"height = " GST_VIDEO_SIZE_RANGE ", " \
|
||||||
|
"framerate = "GST_VIDEO_FPS_RANGE ";" \
|
||||||
|
GST_VIDEO_CAPS_GRAY8";" \
|
||||||
|
GST_VIDEO_CAPS_GRAY16("BIG_ENDIAN")";" \
|
||||||
|
GST_VIDEO_CAPS_GRAY16("LITTLE_ENDIAN")";"
|
||||||
|
|
||||||
static GstColorspaceFormat gst_colorspace_formats[] = {
|
static GstStaticPadTemplate gst_csp_src_template =
|
||||||
{GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420"))},
|
GST_STATIC_PAD_TEMPLATE ("src",
|
||||||
{GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("YV12"))},
|
GST_PAD_SRC,
|
||||||
{GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB)},
|
GST_PAD_ALWAYS,
|
||||||
{GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB)},
|
GST_STATIC_CAPS (CSP_VIDEO_CAPS)
|
||||||
{GST_STATIC_CAPS (GST_VIDEO_CAPS_RGB_16)},
|
);
|
||||||
};
|
|
||||||
|
|
||||||
static GstColorspaceConverter gst_colorspace_converters[] = {
|
static GstStaticPadTemplate gst_csp_sink_template =
|
||||||
{GST_COLORSPACE_I420, GST_COLORSPACE_RGB32, gst_colorspace_I420_to_rgb32},
|
|
||||||
{GST_COLORSPACE_YV12, GST_COLORSPACE_RGB32, gst_colorspace_YV12_to_rgb32},
|
|
||||||
{GST_COLORSPACE_I420, GST_COLORSPACE_RGB24, gst_colorspace_I420_to_rgb24},
|
|
||||||
{GST_COLORSPACE_YV12, GST_COLORSPACE_RGB24, gst_colorspace_YV12_to_rgb24},
|
|
||||||
{GST_COLORSPACE_I420, GST_COLORSPACE_RGB16, gst_colorspace_I420_to_rgb16},
|
|
||||||
{GST_COLORSPACE_YV12, GST_COLORSPACE_RGB16, gst_colorspace_YV12_to_rgb16},
|
|
||||||
};
|
|
||||||
|
|
||||||
static GstStaticPadTemplate gst_colorspace_sink_template =
|
|
||||||
GST_STATIC_PAD_TEMPLATE ("sink",
|
GST_STATIC_PAD_TEMPLATE ("sink",
|
||||||
GST_PAD_SINK,
|
GST_PAD_SINK,
|
||||||
GST_PAD_ALWAYS,
|
GST_PAD_ALWAYS,
|
||||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{ I420, YV12 }"))
|
GST_STATIC_CAPS (CSP_VIDEO_CAPS)
|
||||||
);
|
);
|
||||||
|
|
||||||
static GstStaticPadTemplate gst_colorspace_src_template =
|
GType gst_csp_get_type (void);
|
||||||
GST_STATIC_PAD_TEMPLATE ("src",
|
|
||||||
GST_PAD_SRC,
|
|
||||||
GST_PAD_ALWAYS,
|
|
||||||
GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB "; "
|
|
||||||
GST_VIDEO_CAPS_RGB "; " GST_VIDEO_CAPS_RGB_16)
|
|
||||||
);
|
|
||||||
|
|
||||||
/* Stereo signals and args */
|
static gboolean gst_csp_set_caps (GstBaseTransform * btrans,
|
||||||
enum
|
GstCaps * incaps, GstCaps * outcaps);
|
||||||
|
static gboolean gst_csp_get_unit_size (GstBaseTransform * btrans,
|
||||||
|
GstCaps * caps, guint * size);
|
||||||
|
static GstFlowReturn gst_csp_transform (GstBaseTransform * btrans,
|
||||||
|
GstBuffer * inbuf, GstBuffer * outbuf);
|
||||||
|
|
||||||
|
static GQuark _QRAWRGB; /* "video/x-raw-rgb" */
|
||||||
|
static GQuark _QRAWYUV; /* "video/x-raw-yuv" */
|
||||||
|
static GQuark _QALPHAMASK; /* "alpha_mask" */
|
||||||
|
|
||||||
|
/* copies the given caps */
|
||||||
|
static GstCaps *
|
||||||
|
gst_csp_caps_remove_format_info (GstCaps * caps)
|
||||||
{
|
{
|
||||||
/* FILL ME */
|
GstStructure *yuvst, *rgbst, *grayst;
|
||||||
LAST_SIGNAL
|
|
||||||
};
|
|
||||||
|
|
||||||
enum
|
/* We know there's only one structure since we're given simple caps */
|
||||||
{
|
caps = gst_caps_copy (caps);
|
||||||
ARG_0,
|
|
||||||
ARG_SOURCE,
|
|
||||||
ARG_DEST
|
|
||||||
};
|
|
||||||
|
|
||||||
static void gst_colorspace_base_init (gpointer g_class);
|
yuvst = gst_caps_get_structure (caps, 0);
|
||||||
static void gst_colorspace_class_init (GstColorspaceClass * klass);
|
|
||||||
static void gst_colorspace_init (GstColorspace * space);
|
|
||||||
|
|
||||||
static void gst_colorspace_set_property (GObject * object, guint prop_id,
|
gst_structure_set_name (yuvst, "video/x-raw-yuv");
|
||||||
const GValue * value, GParamSpec * pspec);
|
gst_structure_remove_fields (yuvst, "format", "endianness", "depth",
|
||||||
static void gst_colorspace_get_property (GObject * object, guint prop_id,
|
"bpp", "red_mask", "green_mask", "blue_mask", "alpha_mask",
|
||||||
GValue * value, GParamSpec * pspec);
|
"palette_data", NULL);
|
||||||
|
|
||||||
static GstPadLinkReturn
|
rgbst = gst_structure_copy (yuvst);
|
||||||
gst_colorspace_link (GstPad * pad, const GstCaps * caps);
|
gst_structure_set_name (rgbst, "video/x-raw-rgb");
|
||||||
static void gst_colorspace_chain (GstPad * pad, GstData * _data);
|
gst_structure_remove_fields (rgbst, "color-matrix", "chroma-site", NULL);
|
||||||
static GstStateChangeReturn gst_colorspace_change_state (GstElement * element,
|
|
||||||
GstStateChange transition);
|
grayst = gst_structure_copy (rgbst);
|
||||||
|
gst_structure_set_name (grayst, "video/x-raw-gray");
|
||||||
|
|
||||||
|
gst_caps_append_structure (caps, rgbst);
|
||||||
|
gst_caps_append_structure (caps, grayst);
|
||||||
|
|
||||||
|
return caps;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static GstElementClass *parent_class = NULL;
|
|
||||||
|
|
||||||
/*static guint gst_colorspace_signals[LAST_SIGNAL] = { 0 }; */
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
static gboolean
|
static gboolean
|
||||||
colorspace_setup_converter (GstColorspace * space, GstCaps * from_caps,
|
gst_csp_structure_is_alpha (GstStructure * s)
|
||||||
GstCaps * to_caps)
|
|
||||||
{
|
{
|
||||||
guint32 from_space, to_space;
|
GQuark name;
|
||||||
GstStructure *from_struct;
|
|
||||||
GstStructure *to_struct;
|
|
||||||
|
|
||||||
g_return_val_if_fail (to_caps != NULL, FALSE);
|
name = gst_structure_get_name_id (s);
|
||||||
g_return_val_if_fail (from_caps != NULL, FALSE);
|
|
||||||
|
|
||||||
from_struct = gst_caps_get_structure (from_caps, 0);
|
if (name == _QRAWRGB) {
|
||||||
to_struct = gst_caps_get_structure (to_caps, 0);
|
return gst_structure_id_has_field (s, _QALPHAMASK);
|
||||||
|
} else if (name == _QRAWYUV) {
|
||||||
|
guint32 fourcc;
|
||||||
|
|
||||||
from_space = GST_MAKE_FOURCC ('R', 'G', 'B', ' ');
|
if (!gst_structure_get_fourcc (s, "format", &fourcc))
|
||||||
gst_structure_get_fourcc (from_struct, "format", &from_space);
|
return FALSE;
|
||||||
|
|
||||||
to_space = GST_MAKE_FOURCC ('R', 'G', 'B', ' ');
|
return (fourcc == GST_MAKE_FOURCC ('A', 'Y', 'U', 'V'));
|
||||||
gst_structure_get_fourcc (to_struct, "format", &to_space);
|
|
||||||
|
|
||||||
GST_INFO ("set up converter for " GST_FOURCC_FORMAT
|
|
||||||
" (%08x) to " GST_FOURCC_FORMAT " (%08x)",
|
|
||||||
GST_FOURCC_ARGS (from_space), from_space,
|
|
||||||
GST_FOURCC_ARGS (to_space), to_space);
|
|
||||||
|
|
||||||
switch (from_space) {
|
|
||||||
case GST_MAKE_FOURCC ('R', 'G', 'B', ' '):
|
|
||||||
{
|
|
||||||
gint from_bpp;
|
|
||||||
|
|
||||||
gst_structure_get_int (from_struct, "bpp", &from_bpp);
|
|
||||||
|
|
||||||
switch (to_space) {
|
|
||||||
case GST_MAKE_FOURCC ('R', 'G', 'B', ' '):
|
|
||||||
#ifdef HAVE_HERMES
|
|
||||||
{
|
|
||||||
gint to_bpp;
|
|
||||||
|
|
||||||
gst_structure_get_int (to_struct, "bpp", &to_bpp);
|
|
||||||
|
|
||||||
gst_structure_get_int (from_struct, "red_mask", &space->source.r);
|
|
||||||
gst_structure_get_int (from_struct, "green_mask", &space->source.g);
|
|
||||||
gst_structure_get_int (from_struct, "blue_mask", &space->source.b);
|
|
||||||
space->source.a = 0;
|
|
||||||
space->srcbpp = space->source.bits = from_bpp;
|
|
||||||
space->source.indexed = 0;
|
|
||||||
space->source.has_colorkey = 0;
|
|
||||||
|
|
||||||
GST_INFO ("source red mask %08x", space->source.r);
|
|
||||||
GST_INFO ("source green mask %08x", space->source.g);
|
|
||||||
GST_INFO ("source blue mask %08x", space->source.b);
|
|
||||||
GST_INFO ("source bpp %08x", space->srcbpp);
|
|
||||||
|
|
||||||
gst_structure_get_int (to_struct, "red_mask", &space->dest.r);
|
|
||||||
gst_structure_get_int (to_struct, "green_mask", &space->dest.g);
|
|
||||||
gst_structure_get_int (to_struct, "blue_mask", &space->dest.b);
|
|
||||||
space->dest.a = 0;
|
|
||||||
space->destbpp = space->dest.bits = to_bpp;
|
|
||||||
space->dest.indexed = 0;
|
|
||||||
space->dest.has_colorkey = 0;
|
|
||||||
|
|
||||||
GST_INFO ("dest red mask %08x", space->dest.r);
|
|
||||||
GST_INFO ("dest green mask %08x", space->dest.g);
|
|
||||||
GST_INFO ("dest blue mask %08x", space->dest.b);
|
|
||||||
GST_INFO ("dest bpp %08x", space->destbpp);
|
|
||||||
|
|
||||||
if (!Hermes_ConverterRequest (space->h_handle, &space->source,
|
|
||||||
&space->dest)) {
|
|
||||||
g_warning ("Hermes: could not get converter\n");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
GST_INFO ("converter set up");
|
|
||||||
space->type = GST_COLORSPACE_HERMES;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
g_warning ("colorspace: compiled without hermes!");
|
|
||||||
return FALSE;
|
|
||||||
#endif
|
|
||||||
case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
|
|
||||||
if (from_bpp == 32) {
|
|
||||||
space->type = GST_COLORSPACE_RGB32_YV12;
|
|
||||||
space->destbpp = 12;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
|
|
||||||
if (from_bpp == 32) {
|
|
||||||
space->type = GST_COLORSPACE_RGB32_I420;
|
|
||||||
space->destbpp = 12;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
|
|
||||||
GST_INFO ("colorspace: RGB to YUV with bpp %d not implemented!!",
|
|
||||||
from_bpp);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
|
|
||||||
switch (to_space) {
|
|
||||||
case GST_MAKE_FOURCC ('R', 'G', 'B', ' '):
|
|
||||||
GST_INFO ("colorspace: YUV to RGB");
|
|
||||||
|
|
||||||
gst_structure_get_int (to_struct, "bpp", &space->destbpp);
|
|
||||||
space->converter =
|
|
||||||
gst_colorspace_yuv2rgb_get_converter (from_caps, to_caps);
|
|
||||||
space->type = GST_COLORSPACE_YUV_RGB;
|
|
||||||
return TRUE;
|
|
||||||
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
|
|
||||||
space->type = GST_COLORSPACE_NONE;
|
|
||||||
space->destbpp = 12;
|
|
||||||
return TRUE;
|
|
||||||
case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
|
|
||||||
space->type = GST_COLORSPACE_420_SWAP;
|
|
||||||
space->destbpp = 12;
|
|
||||||
return TRUE;
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
|
|
||||||
switch (to_space) {
|
|
||||||
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
|
|
||||||
space->type = GST_COLORSPACE_YUY2_I420;
|
|
||||||
space->destbpp = 12;
|
|
||||||
return TRUE;
|
|
||||||
case GST_MAKE_FOURCC ('Y', 'U', 'Y', '2'):
|
|
||||||
space->type = GST_COLORSPACE_NONE;
|
|
||||||
space->destbpp = 16;
|
|
||||||
return TRUE;
|
|
||||||
case GST_MAKE_FOURCC ('R', 'G', 'B', ' '):
|
|
||||||
GST_INFO ("colorspace: YUY2 to RGB not implemented!!");
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
|
|
||||||
switch (to_space) {
|
|
||||||
case GST_MAKE_FOURCC ('R', 'G', 'B', ' '):
|
|
||||||
GST_INFO ("colorspace: YV12 to RGB");
|
|
||||||
|
|
||||||
gst_structure_get_int (to_struct, "bpp", &space->destbpp);
|
|
||||||
space->converter =
|
|
||||||
gst_colorspace_yuv2rgb_get_converter (from_caps, to_caps);
|
|
||||||
space->type = GST_COLORSPACE_YUV_RGB;
|
|
||||||
return TRUE;
|
|
||||||
case GST_MAKE_FOURCC ('I', '4', '2', '0'):
|
|
||||||
space->type = GST_COLORSPACE_420_SWAP;
|
|
||||||
space->destbpp = 12;
|
|
||||||
return TRUE;
|
|
||||||
case GST_MAKE_FOURCC ('Y', 'V', '1', '2'):
|
|
||||||
space->type = GST_COLORSPACE_NONE;
|
|
||||||
space->destbpp = 12;
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
/* The caps can be transformed into any other caps with format info removed.
|
||||||
|
* However, we should prefer passthrough, so if passthrough is possible,
|
||||||
|
* put it first in the list. */
|
||||||
static GstCaps *
|
static GstCaps *
|
||||||
gst_colorspace_caps_remove_format_info (GstCaps * caps, const char *media_type)
|
gst_csp_transform_caps (GstBaseTransform * btrans,
|
||||||
|
GstPadDirection direction, GstCaps * caps)
|
||||||
{
|
{
|
||||||
int i;
|
GstCaps *template;
|
||||||
GstStructure *structure;
|
GstCaps *tmp, *tmp2;
|
||||||
|
GstCaps *result;
|
||||||
|
GstStructure *s;
|
||||||
|
GstCaps *alpha, *non_alpha;
|
||||||
|
|
||||||
for (i = 0; i < gst_caps_get_size (caps); i++) {
|
template = gst_static_pad_template_get_caps (&gst_csp_src_template);
|
||||||
structure = gst_caps_get_structure (caps, i);
|
result = gst_caps_copy (caps);
|
||||||
|
|
||||||
gst_structure_set_name (structure, media_type);
|
/* Get all possible caps that we can transform to */
|
||||||
gst_structure_remove_field (structure, "format");
|
tmp = gst_csp_caps_remove_format_info (caps);
|
||||||
gst_structure_remove_field (structure, "endianness");
|
tmp2 = gst_caps_intersect (tmp, template);
|
||||||
gst_structure_remove_field (structure, "depth");
|
gst_caps_unref (tmp);
|
||||||
gst_structure_remove_field (structure, "bpp");
|
tmp = tmp2;
|
||||||
gst_structure_remove_field (structure, "red_mask");
|
|
||||||
gst_structure_remove_field (structure, "green_mask");
|
/* Now move alpha formats to the beginning if caps is an alpha format
|
||||||
gst_structure_remove_field (structure, "blue_mask");
|
* or at the end if caps is no alpha format */
|
||||||
|
alpha = gst_caps_new_empty ();
|
||||||
|
non_alpha = gst_caps_new_empty ();
|
||||||
|
|
||||||
|
while ((s = gst_caps_steal_structure (tmp, 0))) {
|
||||||
|
if (gst_csp_structure_is_alpha (s))
|
||||||
|
gst_caps_append_structure (alpha, s);
|
||||||
|
else
|
||||||
|
gst_caps_append_structure (non_alpha, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_caps_do_simplify (caps);
|
s = gst_caps_get_structure (caps, 0);
|
||||||
return caps;
|
gst_caps_unref (tmp);
|
||||||
}
|
|
||||||
|
|
||||||
static GstCaps *
|
if (gst_csp_structure_is_alpha (s)) {
|
||||||
gst_colorspace_getcaps (GstPad * pad)
|
gst_caps_append (alpha, non_alpha);
|
||||||
{
|
tmp = alpha;
|
||||||
GstColorspace *space;
|
|
||||||
GstPad *otherpad;
|
|
||||||
GstCaps *othercaps;
|
|
||||||
GstCaps *caps;
|
|
||||||
|
|
||||||
space = GST_COLORSPACE (gst_pad_get_parent (pad));
|
|
||||||
|
|
||||||
otherpad = (pad == space->srcpad) ? space->sinkpad : space->srcpad;
|
|
||||||
|
|
||||||
othercaps = gst_pad_get_allowed_caps (otherpad);
|
|
||||||
|
|
||||||
othercaps = gst_colorspace_caps_remove_format_info (othercaps,
|
|
||||||
(pad == space->srcpad) ? "video/x-raw-rgb" : "video/x-raw-yuv");
|
|
||||||
|
|
||||||
caps = gst_caps_intersect (othercaps, gst_pad_get_pad_template_caps (pad));
|
|
||||||
gst_caps_free (othercaps);
|
|
||||||
|
|
||||||
return caps;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstColorSpaceFormatType
|
|
||||||
gst_colorspace_get_format (const GstCaps * caps)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (gst_colorspace_formats); i++) {
|
|
||||||
GstCaps *icaps;
|
|
||||||
GstCaps *fcaps;
|
|
||||||
|
|
||||||
fcaps =
|
|
||||||
gst_caps_copy (gst_static_caps_get (&gst_colorspace_formats[i].caps));
|
|
||||||
|
|
||||||
icaps = gst_caps_intersect (caps, fcaps);
|
|
||||||
if (!gst_caps_is_empty (icaps)) {
|
|
||||||
gst_caps_free (icaps);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
gst_caps_free (icaps);
|
|
||||||
}
|
|
||||||
|
|
||||||
g_assert_not_reached ();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define ROUND_UP_2(x) (((x)+1)&~1)
|
|
||||||
#define ROUND_UP_4(x) (((x)+3)&~3)
|
|
||||||
#define ROUND_UP_8(x) (((x)+7)&~7)
|
|
||||||
|
|
||||||
static int
|
|
||||||
gst_colorspace_format_get_size (GstColorSpaceFormatType index, int width,
|
|
||||||
int height)
|
|
||||||
{
|
|
||||||
int size;
|
|
||||||
|
|
||||||
switch (index) {
|
|
||||||
case GST_COLORSPACE_I420:
|
|
||||||
case GST_COLORSPACE_YV12:
|
|
||||||
size = ROUND_UP_4 (width) * ROUND_UP_2 (height);
|
|
||||||
size += ROUND_UP_8 (width) / 2 * ROUND_UP_2 (height) / 2;
|
|
||||||
size += ROUND_UP_8 (width) / 2 * ROUND_UP_2 (height) / 2;
|
|
||||||
return size;
|
|
||||||
break;
|
|
||||||
case GST_COLORSPACE_RGB32:
|
|
||||||
return width * height * 4;
|
|
||||||
break;
|
|
||||||
case GST_COLORSPACE_RGB24:
|
|
||||||
return ROUND_UP_4 (width * 3) * height;
|
|
||||||
break;
|
|
||||||
case GST_COLORSPACE_RGB16:
|
|
||||||
return ROUND_UP_4 (width * 2) * height;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
g_assert_not_reached ();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
gst_colorspace_get_converter (GstColorSpaceFormatType from,
|
|
||||||
GstColorSpaceFormatType to)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < G_N_ELEMENTS (gst_colorspace_converters); i++) {
|
|
||||||
GstColorspaceConverter *converter = gst_colorspace_converters + i;
|
|
||||||
|
|
||||||
if (from == converter->from && to == converter->to) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
g_assert_not_reached ();
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstPadLinkReturn
|
|
||||||
gst_colorspace_link (GstPad * pad, const GstCaps * caps)
|
|
||||||
{
|
|
||||||
GstColorspace *space;
|
|
||||||
GstPad *otherpad;
|
|
||||||
GstStructure *structure;
|
|
||||||
GstPadLinkReturn link_ret;
|
|
||||||
int width, height;
|
|
||||||
double fps;
|
|
||||||
int format_index;
|
|
||||||
|
|
||||||
space = GST_COLORSPACE (gst_pad_get_parent (pad));
|
|
||||||
otherpad = (pad == space->sinkpad) ? space->srcpad : space->sinkpad;
|
|
||||||
|
|
||||||
link_ret = gst_pad_try_set_caps (otherpad, caps);
|
|
||||||
if (link_ret == GST_PAD_LINK_OK) {
|
|
||||||
return link_ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
structure = gst_caps_get_structure (caps, 0);
|
|
||||||
|
|
||||||
format_index = gst_colorspace_get_format (caps);
|
|
||||||
g_print ("format index is %d\n", format_index);
|
|
||||||
|
|
||||||
gst_structure_get_int (structure, "width", &width);
|
|
||||||
gst_structure_get_int (structure, "height", &height);
|
|
||||||
gst_structure_get_double (structure, "framerate", &fps);
|
|
||||||
|
|
||||||
GST_INFO ("size: %dx%d", space->width, space->height);
|
|
||||||
|
|
||||||
if (gst_pad_is_negotiated (otherpad)) {
|
|
||||||
GstCaps *othercaps;
|
|
||||||
|
|
||||||
othercaps = gst_caps_copy (gst_pad_get_negotiated_caps (otherpad));
|
|
||||||
|
|
||||||
gst_caps_set_simple (othercaps,
|
|
||||||
"width", G_TYPE_INT, width,
|
|
||||||
"height", G_TYPE_INT, height, "framerate", G_TYPE_DOUBLE, fps, NULL);
|
|
||||||
|
|
||||||
link_ret = gst_pad_try_set_caps (otherpad, othercaps);
|
|
||||||
if (link_ret != GST_PAD_LINK_OK) {
|
|
||||||
return link_ret;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pad == space->srcpad) {
|
|
||||||
space->src_format_index = format_index;
|
|
||||||
} else {
|
} else {
|
||||||
space->sink_format_index = format_index;
|
gst_caps_append (non_alpha, alpha);
|
||||||
|
tmp = non_alpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gst_pad_is_negotiated (otherpad)) {
|
gst_caps_append (result, tmp);
|
||||||
space->converter_index =
|
|
||||||
gst_colorspace_get_converter (space->sink_format_index,
|
|
||||||
space->src_format_index);
|
|
||||||
|
|
||||||
g_print ("using index %d\n", space->converter_index);
|
GST_DEBUG_OBJECT (btrans, "transformed %" GST_PTR_FORMAT " into %"
|
||||||
|
GST_PTR_FORMAT, caps, result);
|
||||||
|
|
||||||
space->sink_size = gst_colorspace_format_get_size (space->sink_format_index,
|
return result;
|
||||||
width, height);
|
}
|
||||||
space->src_size = gst_colorspace_format_get_size (space->src_format_index,
|
|
||||||
width, height);
|
static gboolean
|
||||||
space->width = width;
|
gst_csp_set_caps (GstBaseTransform * btrans, GstCaps * incaps,
|
||||||
space->height = height;
|
GstCaps * outcaps)
|
||||||
space->fps = fps;
|
{
|
||||||
|
GstCsp *space;
|
||||||
|
GstVideoFormat in_format;
|
||||||
|
GstVideoFormat out_format;
|
||||||
|
gint in_height, in_width;
|
||||||
|
gint out_height, out_width;
|
||||||
|
gint in_fps_n, in_fps_d, in_par_n, in_par_d;
|
||||||
|
gint out_fps_n, out_fps_d, out_par_n, out_par_d;
|
||||||
|
gboolean have_in_par, have_out_par;
|
||||||
|
gboolean have_in_interlaced, have_out_interlaced;
|
||||||
|
gboolean in_interlaced, out_interlaced;
|
||||||
|
gboolean ret;
|
||||||
|
|
||||||
|
space = GST_CSP (btrans);
|
||||||
|
|
||||||
|
/* input caps */
|
||||||
|
|
||||||
|
ret = gst_video_format_parse_caps (incaps, &in_format, &in_width, &in_height);
|
||||||
|
if (!ret)
|
||||||
|
goto no_width_height;
|
||||||
|
|
||||||
|
ret = gst_video_parse_caps_framerate (incaps, &in_fps_n, &in_fps_d);
|
||||||
|
if (!ret)
|
||||||
|
goto no_framerate;
|
||||||
|
|
||||||
|
have_in_par = gst_video_parse_caps_pixel_aspect_ratio (incaps,
|
||||||
|
&in_par_n, &in_par_d);
|
||||||
|
have_in_interlaced = gst_video_format_parse_caps_interlaced (incaps,
|
||||||
|
&in_interlaced);
|
||||||
|
|
||||||
|
|
||||||
|
/* output caps */
|
||||||
|
|
||||||
|
ret =
|
||||||
|
gst_video_format_parse_caps (outcaps, &out_format, &out_width,
|
||||||
|
&out_height);
|
||||||
|
if (!ret)
|
||||||
|
goto no_width_height;
|
||||||
|
|
||||||
|
ret = gst_video_parse_caps_framerate (outcaps, &out_fps_n, &out_fps_d);
|
||||||
|
if (!ret)
|
||||||
|
goto no_framerate;
|
||||||
|
|
||||||
|
have_out_par = gst_video_parse_caps_pixel_aspect_ratio (outcaps,
|
||||||
|
&out_par_n, &out_par_d);
|
||||||
|
have_out_interlaced = gst_video_format_parse_caps_interlaced (incaps,
|
||||||
|
&out_interlaced);
|
||||||
|
|
||||||
|
|
||||||
|
/* these must match */
|
||||||
|
if (in_width != out_width || in_height != out_height ||
|
||||||
|
in_fps_n != out_fps_n || in_fps_d != out_fps_d)
|
||||||
|
goto format_mismatch;
|
||||||
|
|
||||||
|
/* if present, these must match too */
|
||||||
|
if (have_in_par && have_out_par &&
|
||||||
|
(in_par_n != out_par_n || in_par_d != out_par_d))
|
||||||
|
goto format_mismatch;
|
||||||
|
|
||||||
|
/* if present, these must match too */
|
||||||
|
if (have_in_interlaced && have_out_interlaced &&
|
||||||
|
in_interlaced != out_interlaced)
|
||||||
|
goto format_mismatch;
|
||||||
|
|
||||||
|
space->width = in_width;
|
||||||
|
space->height = in_height;
|
||||||
|
space->interlaced = in_interlaced;
|
||||||
|
|
||||||
|
|
||||||
|
/* palette, only for from data */
|
||||||
|
/* FIXME add palette handling */
|
||||||
|
|
||||||
|
GST_DEBUG ("reconfigured %d %d", space->from_format, space->to_format);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
no_width_height:
|
||||||
|
{
|
||||||
|
GST_DEBUG_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");
|
||||||
|
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");
|
||||||
|
space->from_format = GST_VIDEO_FORMAT_UNKNOWN;
|
||||||
|
space->to_format = GST_VIDEO_FORMAT_UNKNOWN;
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_BOILERPLATE (GstCsp, gst_csp, GstVideoFilter, GST_TYPE_VIDEO_FILTER);
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_csp_base_init (gpointer klass)
|
||||||
|
{
|
||||||
|
GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
|
||||||
|
|
||||||
|
gst_element_class_add_pad_template (element_class,
|
||||||
|
gst_static_pad_template_get (&gst_csp_src_template));
|
||||||
|
gst_element_class_add_pad_template (element_class,
|
||||||
|
gst_static_pad_template_get (&gst_csp_sink_template));
|
||||||
|
|
||||||
|
gst_element_class_set_details_simple (element_class,
|
||||||
|
" Colorspace converter", "Filter/Converter/Video",
|
||||||
|
"Converts video from one colorspace to another",
|
||||||
|
"GStreamer maintainers <gstreamer-devel@lists.sourceforge.net>");
|
||||||
|
|
||||||
|
_QRAWRGB = g_quark_from_string ("video/x-raw-rgb");
|
||||||
|
_QRAWYUV = g_quark_from_string ("video/x-raw-yuv");
|
||||||
|
_QALPHAMASK = g_quark_from_string ("alpha_mask");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_csp_finalize (GObject * obj)
|
||||||
|
{
|
||||||
|
GstCsp *space = GST_CSP (obj);
|
||||||
|
|
||||||
|
if (space->palette)
|
||||||
|
g_free (space->palette);
|
||||||
|
|
||||||
|
G_OBJECT_CLASS (parent_class)->finalize (obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_csp_class_init (GstCspClass * klass)
|
||||||
|
{
|
||||||
|
GObjectClass *gobject_class = (GObjectClass *) klass;
|
||||||
|
GstBaseTransformClass *gstbasetransform_class =
|
||||||
|
(GstBaseTransformClass *) klass;
|
||||||
|
|
||||||
|
gobject_class->finalize = gst_csp_finalize;
|
||||||
|
|
||||||
|
gstbasetransform_class->transform_caps =
|
||||||
|
GST_DEBUG_FUNCPTR (gst_csp_transform_caps);
|
||||||
|
gstbasetransform_class->set_caps = GST_DEBUG_FUNCPTR (gst_csp_set_caps);
|
||||||
|
gstbasetransform_class->get_unit_size =
|
||||||
|
GST_DEBUG_FUNCPTR (gst_csp_get_unit_size);
|
||||||
|
gstbasetransform_class->transform = GST_DEBUG_FUNCPTR (gst_csp_transform);
|
||||||
|
|
||||||
|
gstbasetransform_class->passthrough_on_same_caps = TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
gst_csp_init (GstCsp * space, GstCspClass * klass)
|
||||||
|
{
|
||||||
|
space->from_format = GST_VIDEO_FORMAT_UNKNOWN;
|
||||||
|
space->to_format = GST_VIDEO_FORMAT_UNKNOWN;
|
||||||
|
space->palette = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_csp_get_unit_size (GstBaseTransform * btrans, GstCaps * caps, guint * size)
|
||||||
|
{
|
||||||
|
gboolean ret = TRUE;
|
||||||
|
GstVideoFormat format;
|
||||||
|
gint width, height;
|
||||||
|
|
||||||
|
g_assert (size);
|
||||||
|
|
||||||
|
ret = gst_video_format_parse_caps (caps, &format, &width, &height);
|
||||||
|
if (ret) {
|
||||||
|
*size = gst_video_format_get_size (format, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
static GstFlowReturn
|
||||||
|
gst_csp_transform (GstBaseTransform * btrans, GstBuffer * inbuf,
|
||||||
|
GstBuffer * outbuf)
|
||||||
|
{
|
||||||
|
GstCsp *space;
|
||||||
|
|
||||||
|
space = GST_CSP (btrans);
|
||||||
|
|
||||||
|
GST_DEBUG ("from %d -> to %d", space->from_format, space->to_format);
|
||||||
|
|
||||||
|
if (G_UNLIKELY (space->from_format == GST_VIDEO_FORMAT_UNKNOWN ||
|
||||||
|
space->to_format == GST_VIDEO_FORMAT_UNKNOWN))
|
||||||
|
goto unknown_format;
|
||||||
|
|
||||||
|
|
||||||
|
/* baseclass copies timestamps */
|
||||||
|
GST_DEBUG ("from %d -> to %d done", space->from_format, space->to_format);
|
||||||
|
|
||||||
|
return GST_FLOW_OK;
|
||||||
|
|
||||||
|
/* ERRORS */
|
||||||
|
unknown_format:
|
||||||
|
{
|
||||||
|
GST_ELEMENT_ERROR (space, CORE, NOT_IMPLEMENTED, (NULL),
|
||||||
|
("attempting to convert colorspaces between unknown formats"));
|
||||||
|
return GST_FLOW_NOT_NEGOTIATED;
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
if (gst_pad_is_negotiated (otherpad)) {
|
not_supported:
|
||||||
g_warning ("could not get converter\n");
|
{
|
||||||
return GST_PAD_LINK_REFUSED;
|
GST_ELEMENT_ERROR (space, CORE, NOT_IMPLEMENTED, (NULL),
|
||||||
|
("cannot convert between formats"));
|
||||||
|
return GST_FLOW_NOT_SUPPORTED;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return GST_PAD_LINK_OK;
|
|
||||||
}
|
|
||||||
|
|
||||||
GType
|
|
||||||
gst_colorspace_get_type (void)
|
|
||||||
{
|
|
||||||
static GType colorspace_type = 0;
|
|
||||||
|
|
||||||
if (!colorspace_type) {
|
|
||||||
static const GTypeInfo colorspace_info = {
|
|
||||||
sizeof (GstColorspaceClass),
|
|
||||||
gst_colorspace_base_init,
|
|
||||||
NULL,
|
|
||||||
(GClassInitFunc) gst_colorspace_class_init,
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
sizeof (GstColorspace),
|
|
||||||
0,
|
|
||||||
(GInstanceInitFunc) gst_colorspace_init,
|
|
||||||
};
|
|
||||||
|
|
||||||
colorspace_type =
|
|
||||||
g_type_register_static (GST_TYPE_ELEMENT, "GstColorspace",
|
|
||||||
&colorspace_info, 0);
|
|
||||||
}
|
|
||||||
return colorspace_type;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_colorspace_base_init (gpointer g_class)
|
|
||||||
{
|
|
||||||
GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
|
|
||||||
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
|
||||||
gst_static_pad_template_get (&gst_colorspace_src_template));
|
|
||||||
gst_element_class_add_pad_template (element_class,
|
|
||||||
gst_static_pad_template_get (&gst_colorspace_sink_template));
|
|
||||||
|
|
||||||
gst_element_class_set_details_simple (element_class, "Colorspace converter",
|
|
||||||
"Filter/Converter/Video",
|
|
||||||
"Converts video from YUV to RGB", "Wim Taymans <wim.taymans@chello.be>");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_colorspace_class_init (GstColorspaceClass * klass)
|
|
||||||
{
|
|
||||||
GObjectClass *gobject_class;
|
|
||||||
GstElementClass *gstelement_class;
|
|
||||||
|
|
||||||
gobject_class = (GObjectClass *) klass;
|
|
||||||
gstelement_class = (GstElementClass *) klass;
|
|
||||||
|
|
||||||
parent_class = g_type_class_peek_parent (klass);
|
|
||||||
|
|
||||||
gobject_class->set_property = gst_colorspace_set_property;
|
|
||||||
gobject_class->get_property = gst_colorspace_get_property;
|
|
||||||
|
|
||||||
gstelement_class->change_state = gst_colorspace_change_state;
|
|
||||||
|
|
||||||
gst_colorspace_table_init (NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_colorspace_init (GstColorspace * space)
|
|
||||||
{
|
|
||||||
space->sinkpad =
|
|
||||||
gst_pad_new_from_static_template (&gst_colorspace_sink_template, "sink");
|
|
||||||
gst_pad_set_link_function (space->sinkpad, gst_colorspace_link);
|
|
||||||
gst_pad_set_getcaps_function (space->sinkpad, gst_colorspace_getcaps);
|
|
||||||
gst_pad_set_chain_function (space->sinkpad, gst_colorspace_chain);
|
|
||||||
gst_element_add_pad (GST_ELEMENT (space), space->sinkpad);
|
|
||||||
|
|
||||||
space->srcpad =
|
|
||||||
gst_pad_new_from_static_template (&gst_colorspace_src_template, "src");
|
|
||||||
gst_element_add_pad (GST_ELEMENT (space), space->srcpad);
|
|
||||||
gst_pad_set_link_function (space->srcpad, gst_colorspace_link);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_colorspace_chain (GstPad * pad, GstData * _data)
|
|
||||||
{
|
|
||||||
GstBuffer *buf = GST_BUFFER (_data);
|
|
||||||
GstColorspace *space;
|
|
||||||
GstBuffer *outbuf = NULL;
|
|
||||||
GstColorspaceConverter *converter;
|
|
||||||
|
|
||||||
g_return_if_fail (pad != NULL);
|
|
||||||
g_return_if_fail (GST_IS_PAD (pad));
|
|
||||||
g_return_if_fail (buf != NULL);
|
|
||||||
|
|
||||||
space = GST_COLORSPACE (gst_pad_get_parent (pad));
|
|
||||||
|
|
||||||
g_return_if_fail (space != NULL);
|
|
||||||
g_return_if_fail (GST_IS_COLORSPACE (space));
|
|
||||||
|
|
||||||
if (GST_BUFFER_SIZE (buf) < space->sink_size) {
|
|
||||||
g_critical ("input size is smaller than expected");
|
|
||||||
}
|
|
||||||
|
|
||||||
outbuf =
|
|
||||||
gst_pad_alloc_buffer_and_set_caps (space->srcpad, GST_BUFFER_OFFSET_NONE,
|
|
||||||
space->src_size);
|
|
||||||
|
|
||||||
converter = gst_colorspace_converters + space->converter_index;
|
|
||||||
converter->convert (space, GST_BUFFER_DATA (outbuf), GST_BUFFER_DATA (buf));
|
|
||||||
|
|
||||||
GST_BUFFER_TIMESTAMP (outbuf) = GST_BUFFER_TIMESTAMP (buf);
|
|
||||||
GST_BUFFER_DURATION (outbuf) = GST_BUFFER_DURATION (buf);
|
|
||||||
|
|
||||||
gst_buffer_unref (buf);
|
|
||||||
gst_pad_push (space->srcpad, GST_DATA (outbuf));
|
|
||||||
}
|
|
||||||
|
|
||||||
static GstStateChangeReturn
|
|
||||||
gst_colorspace_change_state (GstElement * element, GstStateChange transition)
|
|
||||||
{
|
|
||||||
GstColorspace *space;
|
|
||||||
|
|
||||||
space = GST_COLORSPACE (element);
|
|
||||||
|
|
||||||
switch (transition) {
|
|
||||||
case GST_STATE_CHANGE_PAUSED_TO_PLAYING:
|
|
||||||
break;
|
|
||||||
case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
|
|
||||||
break;
|
|
||||||
case GST_STATE_CHANGE_PAUSED_TO_READY:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent_class->change_state (element, transition);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_colorspace_set_property (GObject * object, guint prop_id,
|
|
||||||
const GValue * value, GParamSpec * pspec)
|
|
||||||
{
|
|
||||||
GstColorspace *space;
|
|
||||||
|
|
||||||
g_return_if_fail (GST_IS_COLORSPACE (object));
|
|
||||||
space = GST_COLORSPACE (object);
|
|
||||||
|
|
||||||
switch (prop_id) {
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_colorspace_get_property (GObject * object, guint prop_id, GValue * value,
|
|
||||||
GParamSpec * pspec)
|
|
||||||
{
|
|
||||||
GstColorspace *space;
|
|
||||||
|
|
||||||
g_return_if_fail (GST_IS_COLORSPACE (object));
|
|
||||||
space = GST_COLORSPACE (object);
|
|
||||||
|
|
||||||
switch (prop_id) {
|
|
||||||
default:
|
|
||||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
plugin_init (GstPlugin * plugin)
|
plugin_init (GstPlugin * plugin)
|
||||||
{
|
{
|
||||||
if (!gst_element_register (plugin, "colorspace", GST_RANK_PRIMARY - 1,
|
GST_DEBUG_CATEGORY_INIT (colorspace_debug, "colorspace", 0,
|
||||||
GST_TYPE_COLORSPACE))
|
"Colorspace Converter");
|
||||||
return FALSE;
|
GST_DEBUG_CATEGORY_GET (colorspace_performance, "GST_PERFORMANCE");
|
||||||
|
|
||||||
return TRUE;
|
return gst_element_register (plugin, "colorspace",
|
||||||
|
GST_RANK_NONE, GST_TYPE_CSP);
|
||||||
}
|
}
|
||||||
|
|
||||||
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
|
||||||
GST_VERSION_MINOR,
|
GST_VERSION_MINOR,
|
||||||
"yuvtorgbcolorspace",
|
"colorspace", "Colorspace conversion", plugin_init, VERSION, "LGPL", "", "")
|
||||||
"YUV to RGB colorspace converter",
|
|
||||||
plugin_init, VERSION, "LGPL", GST_PACKAGE_NAME, GST_PACKAGE_ORIGIN)
|
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
/* GStreamer
|
/* GStreamer
|
||||||
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
|
||||||
|
* This file:
|
||||||
|
* Copyright (C) 2003 Ronald Bultje <rbultje@ronald.bitfreak.net>
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
* modify it under the terms of the GNU Library General Public
|
* modify it under the terms of the GNU Library General Public
|
||||||
|
@ -17,85 +19,46 @@
|
||||||
* Boston, MA 02111-1307, USA.
|
* Boston, MA 02111-1307, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _GST_COLORSPACE_H_
|
#ifndef __GST_COLORSPACE_H__
|
||||||
#define _GST_COLORSPACE_H_
|
#define __GST_COLORSPACE_H__
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
|
#include <gst/video/video.h>
|
||||||
|
#include <gst/video/gstvideofilter.h>
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
#define GST_TYPE_COLORSPACE \
|
#define GST_TYPE_CSP (gst_csp_get_type())
|
||||||
(gst_colorspace_get_type())
|
#define GST_CSP(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_CSP,GstCsp))
|
||||||
#define GST_COLORSPACE(obj) \
|
#define GST_CSP_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_CSP,GstCspClass))
|
||||||
(G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_COLORSPACE,GstColorspace))
|
#define GST_IS_CSP(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_CSP))
|
||||||
#define GST_COLORSPACE_CLASS(klass) \
|
#define GST_IS_CSP_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_CSP))
|
||||||
(G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_COLORSPACE,GstColorspaceClass))
|
|
||||||
#define GST_COLORSPACE_GET_CLASS(obj) \
|
|
||||||
(G_TYPE_INSTANCE_GET_CLASS((obj),GST_TYPE_COLORSPACE,GstColorspaceClass))
|
|
||||||
#define GST_IS_COLORSPACE(obj) \
|
|
||||||
(G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_COLORSPACE))
|
|
||||||
#define GST_IS_COLORSPACE_CLASS(klass) \
|
|
||||||
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_COLORSPACE))
|
|
||||||
|
|
||||||
typedef struct _GstColorspace GstColorspace;
|
typedef struct _GstCsp GstCsp;
|
||||||
typedef struct _GstColorspaceClass GstColorspaceClass;
|
typedef struct _GstCspClass GstCspClass;
|
||||||
|
|
||||||
typedef enum {
|
/**
|
||||||
GST_COLORSPACE_NONE,
|
* GstCsp:
|
||||||
GST_COLORSPACE_HERMES,
|
*
|
||||||
GST_COLORSPACE_YUV_RGB,
|
* Opaque object data structure.
|
||||||
GST_COLORSPACE_YUY2_I420,
|
*/
|
||||||
GST_COLORSPACE_RGB32_I420,
|
struct _GstCsp {
|
||||||
GST_COLORSPACE_RGB32_YV12,
|
GstVideoFilter element;
|
||||||
GST_COLORSPACE_420_SWAP,
|
|
||||||
} GstColorSpaceConverterType;
|
|
||||||
|
|
||||||
struct _GstColorspace {
|
|
||||||
GstElement element;
|
|
||||||
|
|
||||||
GstPad *sinkpad,*srcpad;
|
|
||||||
|
|
||||||
int converter_index;
|
|
||||||
|
|
||||||
int src_format_index;
|
|
||||||
int sink_format_index;
|
|
||||||
|
|
||||||
int src_size;
|
|
||||||
int sink_size;
|
|
||||||
|
|
||||||
int src_stride;
|
|
||||||
int sink_stride;
|
|
||||||
|
|
||||||
gint width, height;
|
gint width, height;
|
||||||
gdouble fps;
|
gboolean interlaced;
|
||||||
|
gfloat fps;
|
||||||
|
|
||||||
|
GstVideoFormat from_format;
|
||||||
|
GstVideoFormat to_format;
|
||||||
|
guint32 *palette;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstColorspaceClass {
|
struct _GstCspClass
|
||||||
GstElementClass parent_class;
|
{
|
||||||
|
GstVideoFilterClass parent_class;
|
||||||
};
|
};
|
||||||
|
|
||||||
GType gst_colorspace_get_type(void);
|
|
||||||
|
|
||||||
typedef struct _GstColorspaceFormat {
|
|
||||||
GstStaticCaps caps;
|
|
||||||
|
|
||||||
} GstColorspaceFormat;
|
|
||||||
|
|
||||||
typedef enum {
|
|
||||||
GST_COLORSPACE_I420,
|
|
||||||
GST_COLORSPACE_YV12,
|
|
||||||
GST_COLORSPACE_RGB32,
|
|
||||||
GST_COLORSPACE_RGB24,
|
|
||||||
GST_COLORSPACE_RGB16,
|
|
||||||
} GstColorSpaceFormatType;
|
|
||||||
|
|
||||||
typedef struct _GstColorspaceConverter {
|
|
||||||
GstColorSpaceFormatType from;
|
|
||||||
GstColorSpaceFormatType to;
|
|
||||||
void (*convert) (GstColorspace *colorspace, unsigned char *dest, unsigned char *src);
|
|
||||||
} GstColorspaceConverter;
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif /* __GST_COLORSPACE_H__ */
|
||||||
|
|
||||||
|
|
1311
gst/colorspace/gstcolorspaceorc.orc
Normal file
1311
gst/colorspace/gstcolorspaceorc.orc
Normal file
File diff suppressed because it is too large
Load diff
|
@ -1,716 +0,0 @@
|
||||||
/* 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
|
||||||
#include "config.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <math.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
#include "yuv2rgb.h"
|
|
||||||
|
|
||||||
#undef HAVE_LIBMMX
|
|
||||||
|
|
||||||
#ifdef HAVE_LIBMMX
|
|
||||||
#include <mmx.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static int V_r_tab[256];
|
|
||||||
static int V_g_tab[256];
|
|
||||||
static int U_g_tab[256];
|
|
||||||
static int U_b_tab[256];
|
|
||||||
|
|
||||||
#define CB_BASE 1
|
|
||||||
#define CR_BASE (CB_BASE*CB_RANGE)
|
|
||||||
#define LUM_BASE (CR_BASE*CR_RANGE)
|
|
||||||
|
|
||||||
#define Min(x,y) (((x) < (y)) ? (x) : (y))
|
|
||||||
#define Max(x,y) (((x) > (y)) ? (x) : (y))
|
|
||||||
|
|
||||||
#define GAMMA_CORRECTION(x) ((int)(pow((x) / 255.0, 1.0 / gammaCorrect) * 255.0))
|
|
||||||
#define CHROMA_CORRECTION256(x) ((x) >= 128 \
|
|
||||||
? 128 + Min(127, (int)(((x) - 128.0) * chromaCorrect)) \
|
|
||||||
: 128 - Min(128, (int)((128.0 - (x)) * chromaCorrect)))
|
|
||||||
#define CHROMA_CORRECTION128(x) ((x) >= 0 \
|
|
||||||
? Min(127, (int)(((x) * chromaCorrect))) \
|
|
||||||
: Max(-128, (int)(((x) * chromaCorrect))))
|
|
||||||
#define CHROMA_CORRECTION256D(x) ((x) >= 128 \
|
|
||||||
? 128.0 + Min(127.0, (((x) - 128.0) * chromaCorrect)) \
|
|
||||||
: 128.0 - Min(128.0, (((128.0 - (x)) * chromaCorrect))))
|
|
||||||
#define CHROMA_CORRECTION128D(x) ((x) >= 0 \
|
|
||||||
? Min(127.0, ((x) * chromaCorrect)) \
|
|
||||||
: Max(-128.0, ((x) * chromaCorrect)))
|
|
||||||
|
|
||||||
|
|
||||||
void gst_colorspace_I420_to_rgb16 (GstColorspace * space, unsigned char *src,
|
|
||||||
unsigned char *dest);
|
|
||||||
void gst_colorspace_I420_to_rgb24 (GstColorspace * space, unsigned char *src,
|
|
||||||
unsigned char *dest);
|
|
||||||
void gst_colorspace_I420_to_rgb32 (GstColorspace * space, unsigned char *src,
|
|
||||||
unsigned char *dest);
|
|
||||||
#ifdef HAVE_LIBMMX
|
|
||||||
void gst_colorspace_I420_to_bgr16_mmx (GstColorspace * space,
|
|
||||||
unsigned char *src, unsigned char *dest);
|
|
||||||
void gst_colorspace_I420_to_bgr32_mmx (GstColorspace * space,
|
|
||||||
unsigned char *src, unsigned char *dest);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void gst_colorspace_YV12_to_rgb16 (GstColorspace * space, unsigned char *src,
|
|
||||||
unsigned char *dest);
|
|
||||||
void gst_colorspace_YV12_to_rgb24 (GstColorspace * space, unsigned char *src,
|
|
||||||
unsigned char *dest);
|
|
||||||
void gst_colorspace_YV12_to_rgb32 (GstColorspace * space, unsigned char *src,
|
|
||||||
unsigned char *dest);
|
|
||||||
#ifdef HAVE_LIBMMX
|
|
||||||
void gst_colorspace_YV12_to_bgr16_mmx (GstColorspace * space,
|
|
||||||
unsigned char *src, unsigned char *dest);
|
|
||||||
void gst_colorspace_YV12_to_bgr32_mmx (GstColorspace * space,
|
|
||||||
unsigned char *src, unsigned char *dest);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_colorspace_yuv_to_rgb16 (GstColorspace * space,
|
|
||||||
unsigned char *out,
|
|
||||||
unsigned char *lum,
|
|
||||||
unsigned char *cr, unsigned char *cb, int cols, int rows);
|
|
||||||
static void
|
|
||||||
gst_colorspace_yuv_to_rgb24 (GstColorspace * space,
|
|
||||||
unsigned char *out,
|
|
||||||
unsigned char *lum,
|
|
||||||
unsigned char *cr, unsigned char *cb, int cols, int rows);
|
|
||||||
static void
|
|
||||||
gst_colorspace_yuv_to_rgb32 (GstColorspace * space,
|
|
||||||
unsigned char *out,
|
|
||||||
unsigned char *lum,
|
|
||||||
unsigned char *cr, unsigned char *cb, int cols, int rows);
|
|
||||||
#if 0
|
|
||||||
static void gst_colorspace_yuv_to_rgb16 (GstColorspaceYUVTables * tables,
|
|
||||||
unsigned char *lum,
|
|
||||||
unsigned char *cr,
|
|
||||||
unsigned char *cb, unsigned char *out, int cols, int rows);
|
|
||||||
static void gst_colorspace_yuv_to_rgb24 (GstColorspaceYUVTables * tables,
|
|
||||||
unsigned char *lum,
|
|
||||||
unsigned char *cr,
|
|
||||||
unsigned char *cb, unsigned char *out, int cols, int rows);
|
|
||||||
static void gst_colorspace_yuv_to_rgb32 (GstColorspaceYUVTables * tables,
|
|
||||||
unsigned char *lum,
|
|
||||||
unsigned char *cr,
|
|
||||||
unsigned char *cb, unsigned char *out, int cols, int rows);
|
|
||||||
#ifdef HAVE_LIBMMX
|
|
||||||
void gst_colorspace_yuv_to_bgr32_mmx (GstColorspaceYUVTables * tables,
|
|
||||||
unsigned char *lum,
|
|
||||||
unsigned char *cr,
|
|
||||||
unsigned char *cb, unsigned char *out, int cols, int rows);
|
|
||||||
extern void gst_colorspace_yuv_to_bgr16_mmx (GstColorspaceYUVTables * tables,
|
|
||||||
unsigned char *lum,
|
|
||||||
unsigned char *cr,
|
|
||||||
unsigned char *cb, unsigned char *out, int cols, int rows);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define ROUND_UP_2(x) (((x)+1)&~1)
|
|
||||||
#define ROUND_UP_4(x) (((x)+3)&~3)
|
|
||||||
#define ROUND_UP_8(x) (((x)+7)&~7)
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_colorspace_I420_to_rgb32 (GstColorspace * space, unsigned char *dest,
|
|
||||||
unsigned char *src)
|
|
||||||
{
|
|
||||||
unsigned char *src_U;
|
|
||||||
unsigned char *src_V;
|
|
||||||
|
|
||||||
src_U = src + ROUND_UP_4 (space->width) * ROUND_UP_2 (space->height);
|
|
||||||
src_V =
|
|
||||||
src_U + ROUND_UP_8 (space->width) / 2 * ROUND_UP_2 (space->height) / 2;
|
|
||||||
|
|
||||||
gst_colorspace_yuv_to_rgb32 (space,
|
|
||||||
dest, src, src_U, src_V, space->width, space->height);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_colorspace_I420_to_rgb24 (GstColorspace * space, unsigned char *dest,
|
|
||||||
unsigned char *src)
|
|
||||||
{
|
|
||||||
unsigned char *src_U;
|
|
||||||
unsigned char *src_V;
|
|
||||||
|
|
||||||
src_U = src + ROUND_UP_4 (space->width) * ROUND_UP_2 (space->height);
|
|
||||||
src_V =
|
|
||||||
src_U + ROUND_UP_8 (space->width) / 2 * ROUND_UP_2 (space->height) / 2;
|
|
||||||
|
|
||||||
gst_colorspace_yuv_to_rgb24 (space,
|
|
||||||
dest, src, src_U, src_V, space->width, space->height);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_colorspace_I420_to_rgb16 (GstColorspace * space, unsigned char *dest,
|
|
||||||
unsigned char *src)
|
|
||||||
{
|
|
||||||
unsigned char *src_U;
|
|
||||||
unsigned char *src_V;
|
|
||||||
|
|
||||||
src_U = src + ROUND_UP_4 (space->width) * ROUND_UP_2 (space->height);
|
|
||||||
src_V =
|
|
||||||
src_U + ROUND_UP_8 (space->width) / 2 * ROUND_UP_2 (space->height) / 2;
|
|
||||||
|
|
||||||
gst_colorspace_yuv_to_rgb16 (space,
|
|
||||||
dest, src, src_U, src_V, space->width, space->height);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_colorspace_YV12_to_rgb32 (GstColorspace * space, unsigned char *dest,
|
|
||||||
unsigned char *src)
|
|
||||||
{
|
|
||||||
unsigned char *src_U;
|
|
||||||
unsigned char *src_V;
|
|
||||||
|
|
||||||
src_V = src + ROUND_UP_4 (space->width) * ROUND_UP_2 (space->height);
|
|
||||||
src_U =
|
|
||||||
src_V + ROUND_UP_8 (space->width) / 2 * ROUND_UP_2 (space->height) / 2;
|
|
||||||
|
|
||||||
gst_colorspace_yuv_to_rgb32 (space,
|
|
||||||
dest, src, src_U, src_V, space->width, space->height);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_colorspace_YV12_to_rgb24 (GstColorspace * space, unsigned char *dest,
|
|
||||||
unsigned char *src)
|
|
||||||
{
|
|
||||||
unsigned char *src_U;
|
|
||||||
unsigned char *src_V;
|
|
||||||
|
|
||||||
src_V = src + ROUND_UP_4 (space->width) * ROUND_UP_2 (space->height);
|
|
||||||
src_U =
|
|
||||||
src_V + ROUND_UP_8 (space->width) / 2 * ROUND_UP_2 (space->height) / 2;
|
|
||||||
|
|
||||||
gst_colorspace_yuv_to_rgb24 (space,
|
|
||||||
dest, src, src_U, src_V, space->width, space->height);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_colorspace_YV12_to_rgb16 (GstColorspace * space, unsigned char *dest,
|
|
||||||
unsigned char *src)
|
|
||||||
{
|
|
||||||
unsigned char *src_U;
|
|
||||||
unsigned char *src_V;
|
|
||||||
|
|
||||||
src_V = src + ROUND_UP_4 (space->width) * ROUND_UP_2 (space->height);
|
|
||||||
src_U =
|
|
||||||
src_V + ROUND_UP_8 (space->width) / 2 * ROUND_UP_2 (space->height) / 2;
|
|
||||||
|
|
||||||
gst_colorspace_yuv_to_rgb16 (space,
|
|
||||||
dest, src, src_U, src_V, space->width, space->height);
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_LIBMMX
|
|
||||||
void
|
|
||||||
gst_colorspace_I420_to_bgr32_mmx (GstColorspace * space, unsigned char *src,
|
|
||||||
unsigned char *dest)
|
|
||||||
{
|
|
||||||
int size;
|
|
||||||
|
|
||||||
GST_DEBUG ("gst_colorspace_I420_to_rgb32_mmx");
|
|
||||||
|
|
||||||
size = space->width * space->height;
|
|
||||||
|
|
||||||
gst_colorspace_yuv_to_bgr32_mmx (NULL, src, /* Y component */
|
|
||||||
src + size, /* cr component */
|
|
||||||
src + size + (size >> 2), /* cb component */
|
|
||||||
dest, space->height, space->width);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_colorspace_I420_to_bgr16_mmx (GstColorspace * space, unsigned char *src,
|
|
||||||
unsigned char *dest)
|
|
||||||
{
|
|
||||||
int size;
|
|
||||||
|
|
||||||
GST_DEBUG ("gst_colorspace_I420_to_bgr16_mmx ");
|
|
||||||
|
|
||||||
size = space->width * space->height;
|
|
||||||
|
|
||||||
gst_colorspace_yuv_to_bgr16_mmx (NULL, src, /* Y component */
|
|
||||||
src + size, /* cr component */
|
|
||||||
src + size + (size >> 2), /* cb component */
|
|
||||||
dest, space->height, space->width);
|
|
||||||
GST_DEBUG ("gst_colorspace_I420_to_bgr16_mmx done");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_colorspace_YV12_to_bgr32_mmx (GstColorspace * space, unsigned char *src,
|
|
||||||
unsigned char *dest)
|
|
||||||
{
|
|
||||||
int size;
|
|
||||||
|
|
||||||
GST_DEBUG ("gst_colorspace_YV12_to_rgb32_mmx");
|
|
||||||
|
|
||||||
size = space->width * space->height;
|
|
||||||
|
|
||||||
gst_colorspace_yuv_to_bgr32_mmx (NULL, src, /* Y component */
|
|
||||||
src + size + (size >> 2), /* cb component */
|
|
||||||
src + size, /* cr component */
|
|
||||||
dest, space->height, space->width);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_colorspace_YV12_to_bgr16_mmx (GstColorspace * space, unsigned char *src,
|
|
||||||
unsigned char *dest)
|
|
||||||
{
|
|
||||||
int size;
|
|
||||||
|
|
||||||
GST_DEBUG ("gst_colorspace_YV12_to_bgr16_mmx ");
|
|
||||||
|
|
||||||
size = space->width * space->height;
|
|
||||||
|
|
||||||
gst_colorspace_yuv_to_bgr16_mmx (NULL, src, /* Y component */
|
|
||||||
src + size + (size >> 2), /* cb component */
|
|
||||||
src + size, /* cr component */
|
|
||||||
dest, space->height, space->width);
|
|
||||||
GST_DEBUG ("gst_colorspace_YV12_to_bgr16_mmx done");
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
/*
|
|
||||||
* How many 1 bits are there in the longword.
|
|
||||||
* Low performance, do not call often.
|
|
||||||
*/
|
|
||||||
|
|
||||||
static int
|
|
||||||
number_of_bits_set (a)
|
|
||||||
unsigned long a;
|
|
||||||
{
|
|
||||||
if (!a)
|
|
||||||
return 0;
|
|
||||||
if (a & 1)
|
|
||||||
return 1 + number_of_bits_set (a >> 1);
|
|
||||||
return (number_of_bits_set (a >> 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* How many 0 bits are there at most significant end of longword.
|
|
||||||
* Low performance, do not call often.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
free_bits_at_top (a)
|
|
||||||
unsigned long a;
|
|
||||||
{
|
|
||||||
/* assume char is 8 bits */
|
|
||||||
if (!a)
|
|
||||||
return sizeof (unsigned long) * 8;
|
|
||||||
/* assume twos complement */
|
|
||||||
if (((long) a) < 0l)
|
|
||||||
return 0;
|
|
||||||
return 1 + free_bits_at_top (a << 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* How many 0 bits are there at least significant end of longword.
|
|
||||||
* Low performance, do not call often.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
free_bits_at_bottom (a)
|
|
||||||
unsigned long a;
|
|
||||||
{
|
|
||||||
/* assume char is 8 bits */
|
|
||||||
if (!a)
|
|
||||||
return sizeof (unsigned long) * 8;
|
|
||||||
if (((long) a) & 1l)
|
|
||||||
return 0;
|
|
||||||
return 1 + free_bits_at_bottom (a >> 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
*--------------------------------------------------------------
|
|
||||||
*
|
|
||||||
* InitColor16Dither --
|
|
||||||
*
|
|
||||||
* To get rid of the multiply and other conversions in color
|
|
||||||
* dither, we use a lookup table.
|
|
||||||
*
|
|
||||||
* Results:
|
|
||||||
* None.
|
|
||||||
*
|
|
||||||
* Side effects:
|
|
||||||
* The lookup tables are initialized.
|
|
||||||
*
|
|
||||||
*--------------------------------------------------------------
|
|
||||||
*/
|
|
||||||
|
|
||||||
void
|
|
||||||
gst_colorspace_table_init (GstColorspace * space)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < 256; i++) {
|
|
||||||
V_r_tab[i] = (0.419 / 0.299) * (i - 128);
|
|
||||||
V_g_tab[i] = -(0.299 / 0.419) * (i - 128);
|
|
||||||
U_g_tab[i] = -(0.114 / 0.331) * (i - 128);
|
|
||||||
U_b_tab[i] = (0.587 / 0.331) * (i - 128);
|
|
||||||
}
|
|
||||||
#if 0
|
|
||||||
int CR, CB, i;
|
|
||||||
int *L_tab, *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab;
|
|
||||||
long *r_2_pix_alloc;
|
|
||||||
long *g_2_pix_alloc;
|
|
||||||
long *b_2_pix_alloc;
|
|
||||||
long depth = 32;
|
|
||||||
long red_mask = 0xff0000;
|
|
||||||
long green_mask = 0x00ff00;
|
|
||||||
long blue_mask = 0x0000ff;
|
|
||||||
|
|
||||||
L_tab = space->L_tab = (int *) malloc (256 * sizeof (int));
|
|
||||||
Cr_r_tab = space->Cr_r_tab = (int *) malloc (256 * sizeof (int));
|
|
||||||
Cr_g_tab = space->Cr_g_tab = (int *) malloc (256 * sizeof (int));
|
|
||||||
Cb_g_tab = space->Cb_g_tab = (int *) malloc (256 * sizeof (int));
|
|
||||||
Cb_b_tab = space->Cb_b_tab = (int *) malloc (256 * sizeof (int));
|
|
||||||
|
|
||||||
r_2_pix_alloc = (long *) malloc (768 * sizeof (long));
|
|
||||||
g_2_pix_alloc = (long *) malloc (768 * sizeof (long));
|
|
||||||
b_2_pix_alloc = (long *) malloc (768 * sizeof (long));
|
|
||||||
|
|
||||||
if (L_tab == NULL ||
|
|
||||||
Cr_r_tab == NULL ||
|
|
||||||
Cr_g_tab == NULL ||
|
|
||||||
Cb_g_tab == NULL ||
|
|
||||||
Cb_b_tab == NULL ||
|
|
||||||
r_2_pix_alloc == NULL || g_2_pix_alloc == NULL || b_2_pix_alloc == NULL) {
|
|
||||||
fprintf (stderr, "Could not get enough memory in InitColorDither\n");
|
|
||||||
exit (1);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < 256; i++) {
|
|
||||||
L_tab[i] = i;
|
|
||||||
/*
|
|
||||||
if (gammaCorrectFlag) {
|
|
||||||
L_tab[i] = GAMMA_CORRECTION(i);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
CB = CR = i;
|
|
||||||
/*
|
|
||||||
if (chromaCorrectFlag) {
|
|
||||||
CB -= 128;
|
|
||||||
CB = CHROMA_CORRECTION128(CB);
|
|
||||||
CR -= 128;
|
|
||||||
CR = CHROMA_CORRECTION128(CR);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
*/
|
|
||||||
{
|
|
||||||
CB -= 128;
|
|
||||||
CR -= 128;
|
|
||||||
}
|
|
||||||
Cr_r_tab[i] = (0.419 / 0.299) * CR;
|
|
||||||
Cr_g_tab[i] = -(0.299 / 0.419) * CR;
|
|
||||||
Cb_g_tab[i] = -(0.114 / 0.331) * CB;
|
|
||||||
Cb_b_tab[i] = (0.587 / 0.331) * CB;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Set up entries 0-255 in rgb-to-pixel value tables.
|
|
||||||
*/
|
|
||||||
for (i = 0; i < 256; i++) {
|
|
||||||
r_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set (red_mask));
|
|
||||||
r_2_pix_alloc[i + 256] <<= free_bits_at_bottom (red_mask);
|
|
||||||
g_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set (green_mask));
|
|
||||||
g_2_pix_alloc[i + 256] <<= free_bits_at_bottom (green_mask);
|
|
||||||
b_2_pix_alloc[i + 256] = i >> (8 - number_of_bits_set (blue_mask));
|
|
||||||
b_2_pix_alloc[i + 256] <<= free_bits_at_bottom (blue_mask);
|
|
||||||
/*
|
|
||||||
* If we have 16-bit output depth, then we double the value
|
|
||||||
* in the top word. This means that we can write out both
|
|
||||||
* pixels in the pixel doubling mode with one op. It is
|
|
||||||
* harmless in the normal case as storing a 32-bit value
|
|
||||||
* through a short pointer will lose the top bits anyway.
|
|
||||||
* A similar optimisation for Alpha for 64 bit has been
|
|
||||||
* prepared for, but is not yet implemented.
|
|
||||||
*/
|
|
||||||
if (!(depth == 32) && !(depth == 24)) {
|
|
||||||
|
|
||||||
r_2_pix_alloc[i + 256] |= (r_2_pix_alloc[i + 256]) << 16;
|
|
||||||
g_2_pix_alloc[i + 256] |= (g_2_pix_alloc[i + 256]) << 16;
|
|
||||||
b_2_pix_alloc[i + 256] |= (b_2_pix_alloc[i + 256]) << 16;
|
|
||||||
|
|
||||||
}
|
|
||||||
#ifdef SIXTYFOUR_BIT
|
|
||||||
if (depth == 32) {
|
|
||||||
|
|
||||||
r_2_pix_alloc[i + 256] |= (r_2_pix_alloc[i + 256]) << 32;
|
|
||||||
g_2_pix_alloc[i + 256] |= (g_2_pix_alloc[i + 256]) << 32;
|
|
||||||
b_2_pix_alloc[i + 256] |= (b_2_pix_alloc[i + 256]) << 32;
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Spread out the values we have to the rest of the array so that
|
|
||||||
* we do not need to check for overflow.
|
|
||||||
*/
|
|
||||||
for (i = 0; i < 256; i++) {
|
|
||||||
r_2_pix_alloc[i] = r_2_pix_alloc[256];
|
|
||||||
r_2_pix_alloc[i + 512] = r_2_pix_alloc[511];
|
|
||||||
g_2_pix_alloc[i] = g_2_pix_alloc[256];
|
|
||||||
g_2_pix_alloc[i + 512] = g_2_pix_alloc[511];
|
|
||||||
b_2_pix_alloc[i] = b_2_pix_alloc[256];
|
|
||||||
b_2_pix_alloc[i + 512] = b_2_pix_alloc[511];
|
|
||||||
}
|
|
||||||
|
|
||||||
space->r_2_pix = r_2_pix_alloc + 256;
|
|
||||||
space->g_2_pix = g_2_pix_alloc + 256;
|
|
||||||
space->b_2_pix = b_2_pix_alloc + 256;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_colorspace_yuv_to_rgb32 (GstColorspace * space,
|
|
||||||
unsigned char *dest,
|
|
||||||
unsigned char *Y, unsigned char *U, unsigned char *V, int width, int height)
|
|
||||||
{
|
|
||||||
int x, y;
|
|
||||||
int src_rowstride;
|
|
||||||
int dest_rowstride;
|
|
||||||
|
|
||||||
src_rowstride = ROUND_UP_4 (space->width);
|
|
||||||
dest_rowstride = width * 4;
|
|
||||||
for (y = 0; y < height; y++) {
|
|
||||||
for (x = 0; x < width; x++) {
|
|
||||||
dest[x * 4 + 0] = 0;
|
|
||||||
dest[x * 3 + 1] = CLAMP (Y[x] + V_r_tab[V[x / 2]], 0, 255);
|
|
||||||
dest[x * 3 + 2] =
|
|
||||||
CLAMP (Y[x] + U_g_tab[U[x / 2]] + V_g_tab[V[x / 2]], 0, 255);
|
|
||||||
dest[x * 3 + 3] = CLAMP (Y[x] + U_b_tab[U[x / 2]], 0, 255);
|
|
||||||
}
|
|
||||||
Y += src_rowstride;
|
|
||||||
dest += dest_rowstride;
|
|
||||||
if (y & 1) {
|
|
||||||
U += src_rowstride / 2;
|
|
||||||
V += src_rowstride / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_colorspace_yuv_to_rgb24 (GstColorspace * space,
|
|
||||||
unsigned char *dest,
|
|
||||||
unsigned char *Y, unsigned char *U, unsigned char *V, int width, int height)
|
|
||||||
{
|
|
||||||
int x, y;
|
|
||||||
int src_rowstride;
|
|
||||||
int dest_rowstride;
|
|
||||||
|
|
||||||
src_rowstride = ROUND_UP_4 (space->width);
|
|
||||||
dest_rowstride = ROUND_UP_4 (width * 3);
|
|
||||||
for (y = 0; y < height; y++) {
|
|
||||||
for (x = 0; x < width; x++) {
|
|
||||||
dest[x * 3 + 0] = CLAMP (Y[x] + V_r_tab[V[x / 2]], 0, 255);
|
|
||||||
dest[x * 3 + 1] =
|
|
||||||
CLAMP (Y[x] + U_g_tab[U[x / 2]] + V_g_tab[V[x / 2]], 0, 255);
|
|
||||||
dest[x * 3 + 2] = CLAMP (Y[x] + U_b_tab[U[x / 2]], 0, 255);
|
|
||||||
}
|
|
||||||
Y += src_rowstride;
|
|
||||||
dest += dest_rowstride;
|
|
||||||
if (y & 1) {
|
|
||||||
U += src_rowstride / 2;
|
|
||||||
V += src_rowstride / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_colorspace_yuv_to_rgb16 (GstColorspace * space,
|
|
||||||
unsigned char *dest,
|
|
||||||
unsigned char *Y, unsigned char *U, unsigned char *V, int width, int height)
|
|
||||||
{
|
|
||||||
int x, y;
|
|
||||||
int src_rowstride;
|
|
||||||
int dest_rowstride;
|
|
||||||
int r, g, b;
|
|
||||||
|
|
||||||
src_rowstride = ROUND_UP_4 (space->width);
|
|
||||||
dest_rowstride = ROUND_UP_4 (width * 2);
|
|
||||||
for (y = 0; y < height; y++) {
|
|
||||||
for (x = 0; x < width; x++) {
|
|
||||||
r = CLAMP (Y[x] + V_r_tab[V[x / 2]], 0, 255);
|
|
||||||
g = CLAMP (Y[x] + U_g_tab[U[x / 2]] + V_g_tab[V[x / 2]], 0, 255);
|
|
||||||
b = CLAMP (Y[x] + U_b_tab[U[x / 2]], 0, 255);
|
|
||||||
*(unsigned short *) (dest + x * 2) =
|
|
||||||
((r & 0xf8) << 8) | ((g & 0xfc) << 3) | (b >> 3);
|
|
||||||
}
|
|
||||||
Y += src_rowstride;
|
|
||||||
dest += dest_rowstride;
|
|
||||||
if (y & 1) {
|
|
||||||
U += src_rowstride / 2;
|
|
||||||
V += src_rowstride / 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef HAVE_LIBMMX
|
|
||||||
static mmx_t MMX_80w = (mmx_t) (long long) 0x0080008000800080LL; /*dd 00080 0080h, 000800080h */
|
|
||||||
|
|
||||||
static mmx_t MMX_00FFw = (mmx_t) (long long) 0x00ff00ff00ff00ffLL; /*dd 000FF 00FFh, 000FF00FFh */
|
|
||||||
static mmx_t MMX_FF00w = (mmx_t) (long long) 0xff00ff00ff00ff00LL; /*dd 000FF 00FFh, 000FF00FFh */
|
|
||||||
|
|
||||||
static mmx_t MMX32_Vredcoeff = (mmx_t) (long long) 0x0059005900590059LL;
|
|
||||||
static mmx_t MMX32_Ubluecoeff = (mmx_t) (long long) 0x0072007200720072LL;
|
|
||||||
static mmx_t MMX32_Ugrncoeff = (mmx_t) (long long) 0xffeaffeaffeaffeaLL;
|
|
||||||
static mmx_t MMX32_Vgrncoeff = (mmx_t) (long long) 0xffd2ffd2ffd2ffd2LL;
|
|
||||||
|
|
||||||
static void
|
|
||||||
gst_colorspace_yuv_to_bgr32_mmx (tables, lum, cr, cb, out, rows, cols)
|
|
||||||
GstColorspaceYUVTables *tables;
|
|
||||||
unsigned char *lum;
|
|
||||||
unsigned char *cr;
|
|
||||||
unsigned char *cb;
|
|
||||||
unsigned char *out;
|
|
||||||
int cols, rows;
|
|
||||||
|
|
||||||
{
|
|
||||||
guint32 *row1 = (guint32 *) out; /* 32 bit target */
|
|
||||||
int cols4 = cols >> 2;
|
|
||||||
|
|
||||||
int y, x;
|
|
||||||
|
|
||||||
for (y = rows >> 1; y; y--) {
|
|
||||||
for (x = cols4; x; x--) {
|
|
||||||
|
|
||||||
/* create Cr (result in mm1) */
|
|
||||||
movd_m2r (*(mmx_t *) cb, mm1); /* 0 0 0 0 v3 v2 v1 v0 */
|
|
||||||
pxor_r2r (mm7, mm7); /* 00 00 00 00 00 00 00 00 */
|
|
||||||
movd_m2r (*(mmx_t *) lum, mm2); /* 0 0 0 0 l3 l2 l1 l0 */
|
|
||||||
punpcklbw_r2r (mm7, mm1); /* 0 v3 0 v2 00 v1 00 v0 */
|
|
||||||
punpckldq_r2r (mm1, mm1); /* 00 v1 00 v0 00 v1 00 v0 */
|
|
||||||
psubw_m2r (MMX_80w, mm1); /* mm1-128:r1 r1 r0 r0 r1 r1 r0 r0 */
|
|
||||||
|
|
||||||
/* create Cr_g (result in mm0) */
|
|
||||||
movq_r2r (mm1, mm0); /* r1 r1 r0 r0 r1 r1 r0 r0 */
|
|
||||||
pmullw_m2r (MMX32_Vgrncoeff, mm0); /* red*-46dec=0.7136*64 */
|
|
||||||
pmullw_m2r (MMX32_Vredcoeff, mm1); /* red*89dec=1.4013*64 */
|
|
||||||
psraw_i2r (6, mm0); /* red=red/64 */
|
|
||||||
psraw_i2r (6, mm1); /* red=red/64 */
|
|
||||||
|
|
||||||
/* create L1 L2 (result in mm2,mm4) */
|
|
||||||
/* L2=lum+cols */
|
|
||||||
movq_m2r (*(mmx_t *) (lum + cols), mm3); /* 0 0 0 0 L3 L2 L1 L0 */
|
|
||||||
punpckldq_r2r (mm3, mm2); /* L3 L2 L1 L0 l3 l2 l1 l0 */
|
|
||||||
movq_r2r (mm2, mm4); /* L3 L2 L1 L0 l3 l2 l1 l0 */
|
|
||||||
pand_m2r (MMX_FF00w, mm2); /* L3 0 L1 0 l3 0 l1 0 */
|
|
||||||
pand_m2r (MMX_00FFw, mm4); /* 0 L2 0 L0 0 l2 0 l0 */
|
|
||||||
psrlw_i2r (8, mm2); /* 0 L3 0 L1 0 l3 0 l1 */
|
|
||||||
|
|
||||||
/* create R (result in mm6) */
|
|
||||||
movq_r2r (mm2, mm5); /* 0 L3 0 L1 0 l3 0 l1 */
|
|
||||||
movq_r2r (mm4, mm6); /* 0 L2 0 L0 0 l2 0 l0 */
|
|
||||||
paddsw_r2r (mm1, mm5); /* lum1+red:x R3 x R1 x r3 x r1 */
|
|
||||||
paddsw_r2r (mm1, mm6); /* lum1+red:x R2 x R0 x r2 x r0 */
|
|
||||||
packuswb_r2r (mm5, mm5); /* R3 R1 r3 r1 R3 R1 r3 r1 */
|
|
||||||
packuswb_r2r (mm6, mm6); /* R2 R0 r2 r0 R2 R0 r2 r0 */
|
|
||||||
pxor_r2r (mm7, mm7); /* 00 00 00 00 00 00 00 00 */
|
|
||||||
punpcklbw_r2r (mm5, mm6); /* R3 R2 R1 R0 r3 r2 r1 r0 */
|
|
||||||
|
|
||||||
/* create Cb (result in mm1) */
|
|
||||||
movd_m2r (*(mmx_t *) cr, mm1); /* 0 0 0 0 u3 u2 u1 u0 */
|
|
||||||
punpcklbw_r2r (mm7, mm1); /* 0 u3 0 u2 00 u1 00 u0 */
|
|
||||||
punpckldq_r2r (mm1, mm1); /* 00 u1 00 u0 00 u1 00 u0 */
|
|
||||||
psubw_m2r (MMX_80w, mm1); /* mm1-128:u1 u1 u0 u0 u1 u1 u0 u0 */
|
|
||||||
/* create Cb_g (result in mm5) */
|
|
||||||
movq_r2r (mm1, mm5); /* u1 u1 u0 u0 u1 u1 u0 u0 */
|
|
||||||
pmullw_m2r (MMX32_Ugrncoeff, mm5); /* blue*-109dec=1.7129*64 */
|
|
||||||
pmullw_m2r (MMX32_Ubluecoeff, mm1); /* blue*114dec=1.78125*64 */
|
|
||||||
psraw_i2r (6, mm5); /* blue=red/64 */
|
|
||||||
psraw_i2r (6, mm1); /* blue=blue/64 */
|
|
||||||
|
|
||||||
/* create G (result in mm7) */
|
|
||||||
movq_r2r (mm2, mm3); /* 0 L3 0 L1 0 l3 0 l1 */
|
|
||||||
movq_r2r (mm4, mm7); /* 0 L2 0 L0 0 l2 0 l1 */
|
|
||||||
paddsw_r2r (mm5, mm3); /* lum1+Cb_g:x G3t x G1t x g3t x g1t */
|
|
||||||
paddsw_r2r (mm5, mm7); /* lum1+Cb_g:x G2t x G0t x g2t x g0t */
|
|
||||||
paddsw_r2r (mm0, mm3); /* lum1+Cr_g:x G3 x G1 x g3 x g1 */
|
|
||||||
paddsw_r2r (mm0, mm7); /* lum1+blue:x G2 x G0 x g2 x g0 */
|
|
||||||
packuswb_r2r (mm3, mm3); /* G3 G1 g3 g1 G3 G1 g3 g1 */
|
|
||||||
packuswb_r2r (mm7, mm7); /* G2 G0 g2 g0 G2 G0 g2 g0 */
|
|
||||||
punpcklbw_r2r (mm3, mm7); /* G3 G2 G1 G0 g3 g2 g1 g0 */
|
|
||||||
|
|
||||||
/* create B (result in mm5) */
|
|
||||||
movq_r2r (mm2, mm3); /* 0 L3 0 L1 0 l3 0 l1 */
|
|
||||||
movq_r2r (mm4, mm5); /* 0 L2 0 L0 0 l2 0 l1 */
|
|
||||||
paddsw_r2r (mm1, mm3); /* lum1+blue:x B3 x B1 x b3 x b1 */
|
|
||||||
paddsw_r2r (mm1, mm5); /* lum1+blue:x B2 x B0 x b2 x b0 */
|
|
||||||
packuswb_r2r (mm3, mm3); /* B3 B1 b3 b1 B3 B1 b3 b1 */
|
|
||||||
packuswb_r2r (mm5, mm5); /* B2 B0 b2 b0 B2 B0 b2 b0 */
|
|
||||||
punpcklbw_r2r (mm3, mm5); /* B3 B2 B1 B0 b3 b2 b1 b0 */
|
|
||||||
|
|
||||||
/* fill destination row1 (needed are mm6=Rr,mm7=Gg,mm5=Bb) */
|
|
||||||
|
|
||||||
pxor_r2r (mm2, mm2); /* 0 0 0 0 0 0 0 0 */
|
|
||||||
pxor_r2r (mm4, mm4); /* 0 0 0 0 0 0 0 0 */
|
|
||||||
movq_r2r (mm6, mm1); /* R3 R2 R1 R0 r3 r2 r1 r0 */
|
|
||||||
movq_r2r (mm5, mm3); /* B3 B2 B1 B0 b3 b2 b1 b0 */
|
|
||||||
/* process lower lum */
|
|
||||||
punpcklbw_r2r (mm4, mm1); /* 0 r3 0 r2 0 r1 0 r0 */
|
|
||||||
punpcklbw_r2r (mm4, mm3); /* 0 b3 0 b2 0 b1 0 b0 */
|
|
||||||
movq_r2r (mm1, mm2); /* 0 r3 0 r2 0 r1 0 r0 */
|
|
||||||
movq_r2r (mm3, mm0); /* 0 b3 0 b2 0 b1 0 b0 */
|
|
||||||
punpcklwd_r2r (mm1, mm3); /* 0 r1 0 b1 0 r0 0 b0 */
|
|
||||||
punpckhwd_r2r (mm2, mm0); /* 0 r3 0 b3 0 r2 0 b2 */
|
|
||||||
|
|
||||||
pxor_r2r (mm2, mm2); /* 0 0 0 0 0 0 0 0 */
|
|
||||||
movq_r2r (mm7, mm1); /* G3 G2 G1 G0 g3 g2 g1 g0 */
|
|
||||||
punpcklbw_r2r (mm1, mm2); /* g3 0 g2 0 g1 0 g0 0 */
|
|
||||||
punpcklwd_r2r (mm4, mm2); /* 0 0 g1 0 0 0 g0 0 */
|
|
||||||
por_r2r (mm3, mm2); /* 0 r1 g1 b1 0 r0 g0 b0 */
|
|
||||||
movq_r2m (mm2, *(mmx_t *) row1); /* wrote out ! row1 */
|
|
||||||
|
|
||||||
pxor_r2r (mm2, mm2); /* 0 0 0 0 0 0 0 0 */
|
|
||||||
punpcklbw_r2r (mm1, mm4); /* g3 0 g2 0 g1 0 g0 0 */
|
|
||||||
punpckhwd_r2r (mm2, mm4); /* 0 0 g3 0 0 0 g2 0 */
|
|
||||||
por_r2r (mm0, mm4); /* 0 r3 g3 b3 0 r2 g2 b2 */
|
|
||||||
movq_r2m (mm4, *(mmx_t *) (row1 + 2)); /* wrote out ! row1 */
|
|
||||||
|
|
||||||
/* fill destination row2 (needed are mm6=Rr,mm7=Gg,mm5=Bb) */
|
|
||||||
/* this can be done "destructive" */
|
|
||||||
pxor_r2r (mm2, mm2); /* 0 0 0 0 0 0 0 0 */
|
|
||||||
punpckhbw_r2r (mm2, mm6); /* 0 R3 0 R2 0 R1 0 R0 */
|
|
||||||
punpckhbw_r2r (mm1, mm5); /* G3 B3 G2 B2 G1 B1 G0 B0 */
|
|
||||||
movq_r2r (mm5, mm1); /* G3 B3 G2 B2 G1 B1 G0 B0 */
|
|
||||||
punpcklwd_r2r (mm6, mm1); /* 0 R1 G1 B1 0 R0 G0 B0 */
|
|
||||||
movq_r2m (mm1, *(mmx_t *) (row1 + cols)); /* wrote out ! row2 */
|
|
||||||
punpckhwd_r2r (mm6, mm5); /* 0 R3 G3 B3 0 R2 G2 B2 */
|
|
||||||
movq_r2m (mm5, *(mmx_t *) (row1 + cols + 2)); /* wrote out ! row2 */
|
|
||||||
|
|
||||||
lum += 4;
|
|
||||||
cr += 2;
|
|
||||||
cb += 2;
|
|
||||||
row1 += 4;
|
|
||||||
}
|
|
||||||
lum += cols;
|
|
||||||
row1 += cols;
|
|
||||||
}
|
|
||||||
|
|
||||||
emms ();
|
|
||||||
|
|
||||||
}
|
|
||||||
#endif
|
|
|
@ -1,97 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 1995 The Regents of the University of California.
|
|
||||||
* All rights reserved.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software and its
|
|
||||||
* documentation for any purpose, without fee, and without written agreement is
|
|
||||||
* hereby granted, provided that the above copyright notice and the following
|
|
||||||
* two paragraphs appear in all copies of this software.
|
|
||||||
*
|
|
||||||
* IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
|
|
||||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
|
|
||||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
|
|
||||||
* CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
||||||
* ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO
|
|
||||||
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __YUV2RGB_H__
|
|
||||||
#define __YUV2RGB_H__
|
|
||||||
|
|
||||||
#include <gst/gst.h>
|
|
||||||
#include "gstcolorspace.h"
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
typedef struct _GstColorspaceYUVTables GstColorspaceYUVTables;
|
|
||||||
|
|
||||||
struct _GstColorspaceYUVTables {
|
|
||||||
int gammaCorrectFlag;
|
|
||||||
double gammaCorrect;
|
|
||||||
int chromaCorrectFlag;
|
|
||||||
double chromaCorrect;
|
|
||||||
|
|
||||||
int *L_tab, *Cr_r_tab, *Cr_g_tab, *Cb_g_tab, *Cb_b_tab;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* We define tables that convert a color value between -256 and 512
|
|
||||||
* into the R, G and B parts of the pixel. The normal range is 0-255.
|
|
||||||
**/
|
|
||||||
|
|
||||||
long *r_2_pix;
|
|
||||||
long *g_2_pix;
|
|
||||||
long *b_2_pix;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct _GstColorspaceConverter GstColorspaceConverter;
|
|
||||||
typedef void (*GstColorspaceConvertFunction) (GstColorspaceConverter *space, guchar *src, guchar *dest);
|
|
||||||
|
|
||||||
struct _GstColorspaceConverter {
|
|
||||||
guint width;
|
|
||||||
guint height;
|
|
||||||
guint insize;
|
|
||||||
guint outsize;
|
|
||||||
/* private */
|
|
||||||
GstColorspaceYUVTables *color_tables;
|
|
||||||
GstColorspaceConvertFunction convert;
|
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void gst_colorspace_table_init (GstColorspace *space);
|
|
||||||
|
|
||||||
void gst_colorspace_I420_to_rgb32(GstColorspace *space,
|
|
||||||
unsigned char *src, unsigned char *dest);
|
|
||||||
void gst_colorspace_I420_to_rgb24(GstColorspace *space,
|
|
||||||
unsigned char *src, unsigned char *dest);
|
|
||||||
void gst_colorspace_I420_to_rgb16(GstColorspace *space,
|
|
||||||
unsigned char *src, unsigned char *dest);
|
|
||||||
void gst_colorspace_YV12_to_rgb32(GstColorspace *space,
|
|
||||||
unsigned char *src, unsigned char *dest);
|
|
||||||
void gst_colorspace_YV12_to_rgb24(GstColorspace *space,
|
|
||||||
unsigned char *src, unsigned char *dest);
|
|
||||||
void gst_colorspace_YV12_to_rgb16(GstColorspace *space,
|
|
||||||
unsigned char *src, unsigned char *dest);
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
GstColorspaceYUVTables * gst_colorspace_init_yuv(long depth,
|
|
||||||
long red_mask, long green_mask, long blue_mask);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#if 0
|
|
||||||
GstColorspaceConverter* gst_colorspace_yuv2rgb_get_converter (const GstCaps *from, const GstCaps *to);
|
|
||||||
#define gst_colorspace_convert(converter, src, dest) \
|
|
||||||
(converter)->convert((converter), (src), (dest))
|
|
||||||
void gst_colorspace_converter_destroy (GstColorspaceConverter *space);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
G_END_DECLS
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
Loading…
Reference in a new issue