From 346de288460a89e97b45118b73ee0e1cbcb2bdc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Sat, 29 Sep 2012 12:30:20 +0100 Subject: [PATCH] cog: remove some old elements so they don't get ported accidentally They are replaced by videoconvert and gdkpixbufoverlay --- ext/cog/Makefile.am | 3 - ext/cog/gstcogcolorspace.c | 1049 ------------------------------------ ext/cog/gstcolorconvert.c | 383 ------------- ext/cog/gstlogoinsert.c | 508 ----------------- 4 files changed, 1943 deletions(-) delete mode 100644 ext/cog/gstcogcolorspace.c delete mode 100644 ext/cog/gstcolorconvert.c delete mode 100644 ext/cog/gstlogoinsert.c diff --git a/ext/cog/Makefile.am b/ext/cog/Makefile.am index 6ea839a03d..8100fc2f9d 100644 --- a/ext/cog/Makefile.am +++ b/ext/cog/Makefile.am @@ -29,14 +29,11 @@ libgstcog_la_SOURCES = \ cogvirtframe.c \ cogvirtframe.h \ gstcog.c \ - gstcogcolorspace.c \ gstcogdownsample.c \ gstcogmse.c \ gstcogscale.c \ gstcogutils.c \ gstcogutils.h \ - gstcolorconvert.c \ - gstlogoinsert.c \ gstcms.h \ gstcms.c nodist_libgstcog_la_SOURCES = $(ORC_NODIST_SOURCES) diff --git a/ext/cog/gstcogcolorspace.c b/ext/cog/gstcogcolorspace.c deleted file mode 100644 index 6b9080451f..0000000000 --- a/ext/cog/gstcogcolorspace.c +++ /dev/null @@ -1,1049 +0,0 @@ -/* GStreamer - * Copyright (C) <1999> Erik Walthinsen - * Copyright (C) <2003> David Schleef - * - * 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. - */ - -/* - * This file was (probably) generated from - * gstvideotemplate.c,v 1.18 2005/11/14 02:13:34 thomasvs Exp - * and - * $Id: make_filter,v 1.8 2004/04/19 22:51:57 ds Exp $ - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "gstcogutils.h" -#include "gstcogorc.h" - -#define GST_TYPE_COGCOLORSPACE \ - (gst_cogcolorspace_get_type()) -#define GST_COGCOLORSPACE(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_COGCOLORSPACE,GstCogcolorspace)) -#define GST_COGCOLORSPACE_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_COGCOLORSPACE,GstCogcolorspaceClass)) -#define GST_IS_COGCOLORSPACE(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_COGCOLORSPACE)) -#define GST_IS_COGCOLORSPACE_CLASS(obj) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_COGCOLORSPACE)) - -typedef struct _GstCogcolorspace GstCogcolorspace; -typedef struct _GstCogcolorspaceClass GstCogcolorspaceClass; - -struct _GstCogcolorspace -{ - GstBaseTransform base_transform; - - int quality; -}; - -struct _GstCogcolorspaceClass -{ - GstBaseTransformClass parent_class; - -}; - -GType gst_cogcolorspace_get_type (void); - -/* GstCogcolorspace signals and args */ -enum -{ - /* FILL ME */ - LAST_SIGNAL -}; - -#define DEFAULT_QUALITY 5 - -enum -{ - PROP_0, - PROP_QUALITY -}; - -static void gst_cogcolorspace_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec); -static void gst_cogcolorspace_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec); - -static GstCaps *gst_cogcolorspace_transform_caps (GstBaseTransform * - base_transform, GstPadDirection direction, GstCaps * caps); -static GstFlowReturn gst_cogcolorspace_transform (GstBaseTransform * - base_transform, GstBuffer * inbuf, GstBuffer * outbuf); -static gboolean gst_cogcolorspace_get_unit_size (GstBaseTransform * - base_transform, GstCaps * caps, guint * size); - -static GstStaticPadTemplate gst_cogcolorspace_sink_template = - GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV - ("{ I420, YV12, YUY2, UYVY, AYUV, Y42B, Y444, v216, v210 }") - ";" GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_xRGB - ";" GST_VIDEO_CAPS_xBGR ";" GST_VIDEO_CAPS_RGBA ";" GST_VIDEO_CAPS_BGRA - ";" GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_ABGR) - ); - -static GstStaticPadTemplate gst_cogcolorspace_src_template = - GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV - ("{ I420, YV12, YUY2, UYVY, AYUV, Y42B, Y444, v216, v210 }") - ";" GST_VIDEO_CAPS_RGBx ";" GST_VIDEO_CAPS_BGRx ";" GST_VIDEO_CAPS_xRGB - ";" GST_VIDEO_CAPS_xBGR ";" GST_VIDEO_CAPS_RGBA ";" GST_VIDEO_CAPS_BGRA - ";" GST_VIDEO_CAPS_ARGB ";" GST_VIDEO_CAPS_ABGR) - ); - -GST_BOILERPLATE (GstCogcolorspace, gst_cogcolorspace, GstBaseTransform, - GST_TYPE_BASE_TRANSFORM); - -static void -gst_cogcolorspace_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_cogcolorspace_src_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_cogcolorspace_sink_template)); - - gst_element_class_set_metadata (element_class, - "YCbCr/RGB format conversion", "Filter/Converter/Video", - "YCbCr/RGB format conversion", "David Schleef "); -} - -static void -gst_cogcolorspace_class_init (GstCogcolorspaceClass * colorspace_class) -{ - GObjectClass *gobject_class; - GstBaseTransformClass *base_transform_class; - - gobject_class = G_OBJECT_CLASS (colorspace_class); - base_transform_class = GST_BASE_TRANSFORM_CLASS (colorspace_class); - - gobject_class->set_property = gst_cogcolorspace_set_property; - gobject_class->get_property = gst_cogcolorspace_get_property; - - g_object_class_install_property (gobject_class, PROP_QUALITY, - g_param_spec_int ("quality", "Quality", "Quality", - 0, 10, DEFAULT_QUALITY, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - base_transform_class->transform = gst_cogcolorspace_transform; - base_transform_class->transform_caps = gst_cogcolorspace_transform_caps; - base_transform_class->get_unit_size = gst_cogcolorspace_get_unit_size; - - base_transform_class->passthrough_on_same_caps = TRUE; -} - -static void -gst_cogcolorspace_init (GstCogcolorspace * colorspace, - GstCogcolorspaceClass * klass) -{ - GST_DEBUG ("gst_cogcolorspace_init"); - - colorspace->quality = DEFAULT_QUALITY; -} - -static void -gst_cogcolorspace_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec) -{ - GstCogcolorspace *colorspace; - - g_return_if_fail (GST_IS_COGCOLORSPACE (object)); - colorspace = GST_COGCOLORSPACE (object); - - GST_DEBUG ("gst_cogcolorspace_set_property"); - switch (prop_id) { - case PROP_QUALITY: - GST_OBJECT_LOCK (colorspace); - colorspace->quality = g_value_get_int (value); - GST_OBJECT_UNLOCK (colorspace); - break; - default: - break; - } -} - -static void -gst_cogcolorspace_get_property (GObject * object, guint prop_id, GValue * value, - GParamSpec * pspec) -{ - GstCogcolorspace *colorspace; - - g_return_if_fail (GST_IS_COGCOLORSPACE (object)); - colorspace = GST_COGCOLORSPACE (object); - - switch (prop_id) { - case PROP_QUALITY: - GST_OBJECT_LOCK (colorspace); - g_value_set_int (value, colorspace->quality); - GST_OBJECT_UNLOCK (colorspace); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -#if 0 -static void -transform_value (GValue * dest) -{ - GValue fourcc = { 0 }; - - g_value_init (dest, GST_TYPE_LIST); - g_value_init (&fourcc, GST_TYPE_FOURCC); - - gst_value_set_fourcc (&fourcc, GST_MAKE_FOURCC ('I', '4', '2', '0')); - gst_value_list_append_value (dest, &fourcc); - - gst_value_set_fourcc (&fourcc, GST_MAKE_FOURCC ('Y', 'V', '1', '2')); - gst_value_list_append_value (dest, &fourcc); - - gst_value_set_fourcc (&fourcc, GST_MAKE_FOURCC ('Y', 'U', 'Y', '2')); - gst_value_list_append_value (dest, &fourcc); - - gst_value_set_fourcc (&fourcc, GST_MAKE_FOURCC ('U', 'Y', 'V', 'Y')); - gst_value_list_append_value (dest, &fourcc); - - gst_value_set_fourcc (&fourcc, GST_MAKE_FOURCC ('A', 'Y', 'U', 'V')); - gst_value_list_append_value (dest, &fourcc); - - gst_value_set_fourcc (&fourcc, GST_MAKE_FOURCC ('Y', '4', '2', 'B')); - gst_value_list_append_value (dest, &fourcc); - - gst_value_set_fourcc (&fourcc, GST_MAKE_FOURCC ('Y', '4', '4', '4')); - gst_value_list_append_value (dest, &fourcc); - - gst_value_set_fourcc (&fourcc, GST_MAKE_FOURCC ('v', '2', '1', '0')); - gst_value_list_append_value (dest, &fourcc); - - gst_value_set_fourcc (&fourcc, GST_MAKE_FOURCC ('v', '2', '1', '6')); - gst_value_list_append_value (dest, &fourcc); - - g_value_unset (&fourcc); -} -#endif - -static GstCaps * -gst_cogcolorspace_caps_remove_format_info (GstCaps * caps) -{ - int i; - GstStructure *structure; - GstCaps *rgbcaps; - - caps = gst_caps_copy (caps); - - for (i = 0; i < gst_caps_get_size (caps); i++) { - structure = gst_caps_get_structure (caps, i); - - gst_structure_set_name (structure, "video/x-raw-yuv"); - gst_structure_remove_field (structure, "format"); - gst_structure_remove_field (structure, "endianness"); - gst_structure_remove_field (structure, "depth"); - gst_structure_remove_field (structure, "bpp"); - gst_structure_remove_field (structure, "red_mask"); - gst_structure_remove_field (structure, "green_mask"); - gst_structure_remove_field (structure, "blue_mask"); - gst_structure_remove_field (structure, "alpha_mask"); - gst_structure_remove_field (structure, "palette_data"); - gst_structure_remove_field (structure, "color-matrix"); - gst_structure_remove_field (structure, "chroma-site"); - } - - caps = gst_caps_do_simplify (caps); - rgbcaps = gst_caps_copy (caps); - - for (i = 0; i < gst_caps_get_size (rgbcaps); i++) { - structure = gst_caps_get_structure (rgbcaps, i); - - gst_structure_set_name (structure, "video/x-raw-rgb"); - } - - gst_caps_append (caps, rgbcaps); - - return caps; -} - -static GstCaps * -gst_cogcolorspace_transform_caps (GstBaseTransform * base_transform, - GstPadDirection direction, GstCaps * caps) -{ -#if 0 - int i; - GstStructure *structure; - GValue new_value = { 0 }; - const GValue *value; - - caps = gst_caps_copy (caps); - - for (i = 0; i < gst_caps_get_size (caps); i++) { - structure = gst_caps_get_structure (caps, i); - - value = gst_structure_get_value (structure, "format"); - transform_value (&new_value); - gst_structure_set_value (structure, "format", &new_value); - g_value_unset (&new_value); - } - - return caps; -#endif -#if 0 - GstCaps *template; - GstCaps *result; - - template = gst_ffmpegcsp_codectype_to_caps (CODEC_TYPE_VIDEO, NULL); - result = gst_caps_intersect (caps, template); - gst_caps_unref (template); - - gst_caps_append (result, gst_ffmpegcsp_caps_remove_format_info (caps)); - - return result; -#endif - return gst_cogcolorspace_caps_remove_format_info (caps); -} - -static gboolean -gst_cogcolorspace_get_unit_size (GstBaseTransform * base_transform, - GstCaps * caps, guint * size) -{ - int width, height; - GstVideoFormat format; - gboolean ret; - - ret = gst_video_format_parse_caps (caps, &format, &width, &height); - if (!ret) - return FALSE; - - *size = gst_video_format_get_size (format, width, height); - - return TRUE; -} - -static CogColorMatrix -gst_cogcolorspace_caps_get_color_matrix (GstCaps * caps) -{ - const char *s; - - s = gst_video_parse_caps_color_matrix (caps); - - if (s == NULL) - return COG_COLOR_MATRIX_SDTV; - - if (strcmp (s, "sdtv") == 0) { - return COG_COLOR_MATRIX_SDTV; - } else if (strcmp (s, "hdtv") == 0) { - return COG_COLOR_MATRIX_HDTV; - } - - return COG_COLOR_MATRIX_SDTV; -} - -static CogChromaSite -gst_cogcolorspace_caps_get_chroma_site (GstCaps * caps) -{ - const char *s; - - s = gst_video_parse_caps_chroma_site (caps); - - if (s == NULL) - return COG_CHROMA_SITE_MPEG2; - - if (strcmp (s, "jpeg") == 0) { - return COG_CHROMA_SITE_JPEG; - } else if (strcmp (s, "mpeg2") == 0) { - return COG_CHROMA_SITE_MPEG2; - } - - return COG_CHROMA_SITE_MPEG2; -} - -static void -convert_I420_YUY2 (CogFrame * dest, CogFrame * src) -{ - int i; - - for (i = 0; i < dest->height; i += 2) { - cogorc_convert_I420_YUY2 (COG_FRAME_DATA_GET_LINE (dest->components + 0, i), - COG_FRAME_DATA_GET_LINE (dest->components + 0, i + 1), - COG_FRAME_DATA_GET_LINE (src->components + 0, i), - COG_FRAME_DATA_GET_LINE (src->components + 0, i + 1), - COG_FRAME_DATA_GET_LINE (src->components + 1, i >> 1), - COG_FRAME_DATA_GET_LINE (src->components + 2, i >> 1), - (dest->width + 1) / 2); - } -} - -static void -convert_I420_UYVY (CogFrame * dest, CogFrame * src) -{ - int i; - - for (i = 0; i < dest->height; i += 2) { - cogorc_convert_I420_UYVY (COG_FRAME_DATA_GET_LINE (dest->components + 0, i), - COG_FRAME_DATA_GET_LINE (dest->components + 0, i + 1), - COG_FRAME_DATA_GET_LINE (src->components + 0, i), - COG_FRAME_DATA_GET_LINE (src->components + 0, i + 1), - COG_FRAME_DATA_GET_LINE (src->components + 1, i >> 1), - COG_FRAME_DATA_GET_LINE (src->components + 2, i >> 1), - (dest->width + 1) / 2); - } -} - -static void -convert_I420_AYUV (CogFrame * dest, CogFrame * src) -{ - int i; - - for (i = 0; i < dest->height; i += 2) { - cogorc_convert_I420_AYUV (COG_FRAME_DATA_GET_LINE (dest->components + 0, i), - COG_FRAME_DATA_GET_LINE (dest->components + 0, i + 1), - COG_FRAME_DATA_GET_LINE (src->components + 0, i), - COG_FRAME_DATA_GET_LINE (src->components + 0, i + 1), - COG_FRAME_DATA_GET_LINE (src->components + 1, i >> 1), - COG_FRAME_DATA_GET_LINE (src->components + 2, i >> 1), dest->width); - } -} - -static void -convert_I420_Y42B (CogFrame * dest, CogFrame * src) -{ - cogorc_memcpy_2d (dest->components[0].data, dest->components[0].stride, - src->components[0].data, src->components[0].stride, - dest->width, dest->height); - - cogorc_planar_chroma_420_422 (dest->components[1].data, - 2 * dest->components[1].stride, - COG_FRAME_DATA_GET_LINE (dest->components + 2, 1), - 2 * dest->components[1].stride, src->components[1].data, - src->components[1].stride, (dest->width + 1) / 2, dest->height / 2); - - cogorc_planar_chroma_420_422 (dest->components[2].data, - 2 * dest->components[2].stride, - COG_FRAME_DATA_GET_LINE (dest->components + 2, 1), - 2 * dest->components[2].stride, src->components[2].data, - src->components[2].stride, (dest->width + 1) / 2, dest->height / 2); -} - -static void -convert_I420_Y444 (CogFrame * dest, CogFrame * src) -{ - cogorc_memcpy_2d (dest->components[0].data, dest->components[0].stride, - src->components[0].data, src->components[0].stride, - dest->width, dest->height); - - cogorc_planar_chroma_420_444 (dest->components[1].data, - 2 * dest->components[1].stride, - COG_FRAME_DATA_GET_LINE (dest->components + 1, 1), - 2 * dest->components[1].stride, src->components[1].data, - src->components[1].stride, (dest->width + 1) / 2, (dest->height + 1) / 2); - - cogorc_planar_chroma_420_444 (dest->components[2].data, - 2 * dest->components[2].stride, - COG_FRAME_DATA_GET_LINE (dest->components + 2, 1), - 2 * dest->components[2].stride, src->components[2].data, - src->components[2].stride, (dest->width + 1) / 2, (dest->height + 1) / 2); -} - -static void -convert_YUY2_I420 (CogFrame * dest, CogFrame * src) -{ - int i; - - for (i = 0; i < dest->height; i += 2) { - cogorc_convert_YUY2_I420 (COG_FRAME_DATA_GET_LINE (dest->components + 0, i), - COG_FRAME_DATA_GET_LINE (dest->components + 0, i + 1), - COG_FRAME_DATA_GET_LINE (dest->components + 1, i >> 1), - COG_FRAME_DATA_GET_LINE (dest->components + 2, i >> 1), - COG_FRAME_DATA_GET_LINE (src->components + 0, i), - COG_FRAME_DATA_GET_LINE (src->components + 0, i + 1), - (dest->width + 1) / 2); - } -} - -static void -convert_YUY2_AYUV (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_YUY2_AYUV (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, (dest->width + 1) / 2, dest->height); -} - -static void -convert_YUY2_Y42B (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_YUY2_Y42B (dest->components[0].data, - dest->components[0].stride, dest->components[1].data, - dest->components[1].stride, dest->components[2].data, - dest->components[2].stride, src->components[0].data, - src->components[0].stride, (dest->width + 1) / 2, dest->height); -} - -static void -convert_YUY2_Y444 (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_YUY2_Y444 (dest->components[0].data, - dest->components[0].stride, dest->components[1].data, - dest->components[1].stride, dest->components[2].data, - dest->components[2].stride, src->components[0].data, - src->components[0].stride, (dest->width + 1) / 2, dest->height); -} - - -static void -convert_UYVY_I420 (CogFrame * dest, CogFrame * src) -{ - int i; - - for (i = 0; i < dest->height; i += 2) { - cogorc_convert_UYVY_I420 (COG_FRAME_DATA_GET_LINE (dest->components + 0, i), - COG_FRAME_DATA_GET_LINE (dest->components + 0, i + 1), - COG_FRAME_DATA_GET_LINE (dest->components + 1, i >> 1), - COG_FRAME_DATA_GET_LINE (dest->components + 2, i >> 1), - COG_FRAME_DATA_GET_LINE (src->components + 0, i), - COG_FRAME_DATA_GET_LINE (src->components + 0, i + 1), - (dest->width + 1) / 2); - } -} - -static void -convert_UYVY_AYUV (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_UYVY_AYUV (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, (dest->width + 1) / 2, dest->height); -} - -static void -convert_UYVY_YUY2 (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_UYVY_YUY2 (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, (dest->width + 1) / 2, dest->height); -} - -static void -convert_UYVY_Y42B (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_UYVY_Y42B (dest->components[0].data, - dest->components[0].stride, dest->components[1].data, - dest->components[1].stride, dest->components[2].data, - dest->components[2].stride, src->components[0].data, - src->components[0].stride, (dest->width + 1) / 2, dest->height); -} - -static void -convert_UYVY_Y444 (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_UYVY_Y444 (dest->components[0].data, - dest->components[0].stride, dest->components[1].data, - dest->components[1].stride, dest->components[2].data, - dest->components[2].stride, src->components[0].data, - src->components[0].stride, (dest->width + 1) / 2, dest->height); -} - -static void -convert_AYUV_I420 (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_AYUV_I420 (COG_FRAME_DATA_GET_LINE (dest->components + 0, 0), - 2 * dest->components[0].stride, - COG_FRAME_DATA_GET_LINE (dest->components + 0, 1), - 2 * dest->components[0].stride, - dest->components[1].data, dest->components[1].stride, - dest->components[2].data, dest->components[2].stride, - COG_FRAME_DATA_GET_LINE (src->components + 0, 0), - /* FIXME why not 2* ? */ - src->components[0].stride, - COG_FRAME_DATA_GET_LINE (src->components + 0, 1), - src->components[0].stride, dest->width / 2, dest->height / 2); -} - -static void -convert_AYUV_YUY2 (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_AYUV_YUY2 (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, dest->width / 2, dest->height); -} - -static void -convert_AYUV_UYVY (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_AYUV_UYVY (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, dest->width / 2, dest->height); -} - -static void -convert_AYUV_Y42B (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_AYUV_Y42B (dest->components[0].data, - dest->components[0].stride, dest->components[1].data, - dest->components[1].stride, dest->components[2].data, - dest->components[2].stride, src->components[0].data, - src->components[0].stride, (dest->width + 1) / 2, dest->height); -} - -static void -convert_AYUV_Y444 (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_AYUV_Y444 (dest->components[0].data, - dest->components[0].stride, dest->components[1].data, - dest->components[1].stride, dest->components[2].data, - dest->components[2].stride, src->components[0].data, - src->components[0].stride, dest->width, dest->height); -} - -static void -convert_Y42B_I420 (CogFrame * dest, CogFrame * src) -{ - cogorc_memcpy_2d (dest->components[0].data, dest->components[0].stride, - src->components[0].data, src->components[0].stride, - dest->width, dest->height); - - cogorc_planar_chroma_422_420 (dest->components[1].data, - dest->components[1].stride, src->components[1].data, - 2 * src->components[1].stride, - COG_FRAME_DATA_GET_LINE (src->components + 1, 1), - 2 * src->components[1].stride, (dest->width + 1) / 2, - (dest->height + 1) / 2); - - cogorc_planar_chroma_422_420 (dest->components[2].data, - dest->components[2].stride, src->components[2].data, - 2 * src->components[2].stride, - COG_FRAME_DATA_GET_LINE (src->components + 2, 1), - 2 * src->components[2].stride, (dest->width + 1) / 2, - (dest->height + 1) / 2); -} - -static void -convert_Y42B_Y444 (CogFrame * dest, CogFrame * src) -{ - cogorc_memcpy_2d (dest->components[0].data, dest->components[0].stride, - src->components[0].data, src->components[0].stride, - dest->width, dest->height); - - cogorc_planar_chroma_422_444 (dest->components[1].data, - dest->components[1].stride, src->components[1].data, - src->components[1].stride, (dest->width + 1) / 2, dest->height); - - cogorc_planar_chroma_422_444 (dest->components[2].data, - dest->components[2].stride, src->components[2].data, - src->components[2].stride, (dest->width + 1) / 2, dest->height); -} - -static void -convert_Y42B_YUY2 (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_Y42B_YUY2 (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, src->components[1].data, - src->components[1].stride, src->components[2].data, - src->components[2].stride, (dest->width + 1) / 2, dest->height); -} - -static void -convert_Y42B_UYVY (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_Y42B_UYVY (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, src->components[1].data, - src->components[1].stride, src->components[2].data, - src->components[2].stride, (dest->width + 1) / 2, dest->height); -} - -static void -convert_Y42B_AYUV (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_Y42B_AYUV (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, src->components[1].data, - src->components[1].stride, src->components[2].data, - src->components[2].stride, (dest->width) / 2, dest->height); -} - -static void -convert_Y444_I420 (CogFrame * dest, CogFrame * src) -{ - cogorc_memcpy_2d (dest->components[0].data, dest->components[0].stride, - src->components[0].data, src->components[0].stride, - dest->width, dest->height); - - cogorc_planar_chroma_444_420 (dest->components[1].data, - dest->components[1].stride, src->components[1].data, - 2 * src->components[1].stride, - COG_FRAME_DATA_GET_LINE (src->components + 1, 1), - 2 * src->components[1].stride, (dest->width + 1) / 2, - (dest->height + 1) / 2); - - cogorc_planar_chroma_444_420 (dest->components[2].data, - dest->components[2].stride, src->components[2].data, - 2 * src->components[2].stride, - COG_FRAME_DATA_GET_LINE (src->components + 2, 1), - 2 * src->components[2].stride, (dest->width + 1) / 2, - (dest->height + 1) / 2); -} - -static void -convert_Y444_Y42B (CogFrame * dest, CogFrame * src) -{ - cogorc_memcpy_2d (dest->components[0].data, dest->components[0].stride, - src->components[0].data, src->components[0].stride, - dest->width, dest->height); - - cogorc_planar_chroma_444_422 (dest->components[1].data, - dest->components[1].stride, src->components[1].data, - src->components[1].stride, (dest->width + 1) / 2, dest->height); - - cogorc_planar_chroma_444_422 (dest->components[2].data, - dest->components[2].stride, src->components[2].data, - src->components[2].stride, (dest->width + 1) / 2, dest->height); -} - -static void -convert_Y444_YUY2 (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_Y444_YUY2 (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, src->components[1].data, - src->components[1].stride, src->components[2].data, - src->components[2].stride, (dest->width + 1) / 2, dest->height); -} - -static void -convert_Y444_UYVY (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_Y444_UYVY (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, src->components[1].data, - src->components[1].stride, src->components[2].data, - src->components[2].stride, (dest->width + 1) / 2, dest->height); -} - -static void -convert_Y444_AYUV (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_Y444_AYUV (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, src->components[1].data, - src->components[1].stride, src->components[2].data, - src->components[2].stride, dest->width, dest->height); -} - -static void -convert_AYUV_ARGB (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_AYUV_ARGB (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, dest->width, dest->height); -} - -static void -convert_AYUV_BGRA (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_AYUV_BGRA (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, dest->width, dest->height); -} - -static void -convert_AYUV_ABGR (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_AYUV_ABGR (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, dest->width, dest->height); -} - -static void -convert_AYUV_RGBA (CogFrame * dest, CogFrame * src) -{ - cogorc_convert_AYUV_RGBA (dest->components[0].data, - dest->components[0].stride, src->components[0].data, - src->components[0].stride, dest->width, dest->height); -} - -static void -convert_I420_BGRA (CogFrame * dest, CogFrame * src) -{ - int i; - int quality = 0; - - if (quality > 3) { - for (i = 0; i < dest->height; i++) { - if (i & 1) { - cogorc_convert_I420_BGRA_avg (COG_FRAME_DATA_GET_LINE (dest->components - + 0, i), COG_FRAME_DATA_GET_LINE (src->components + 0, i), - COG_FRAME_DATA_GET_LINE (src->components + 1, i >> 1), - COG_FRAME_DATA_GET_LINE (src->components + 1, (i >> 1) + 1), - COG_FRAME_DATA_GET_LINE (src->components + 2, i >> 1), - COG_FRAME_DATA_GET_LINE (src->components + 2, (i >> 1) + 1), - dest->width); - } else { - cogorc_convert_I420_BGRA (COG_FRAME_DATA_GET_LINE (dest->components + 0, - i), COG_FRAME_DATA_GET_LINE (src->components + 0, i), - COG_FRAME_DATA_GET_LINE (src->components + 1, i >> 1), - COG_FRAME_DATA_GET_LINE (src->components + 2, i >> 1), dest->width); - } - } - } else { - for (i = 0; i < dest->height; i++) { - cogorc_convert_I420_BGRA (COG_FRAME_DATA_GET_LINE (dest->components + 0, - i), COG_FRAME_DATA_GET_LINE (src->components + 0, i), - COG_FRAME_DATA_GET_LINE (src->components + 1, i >> 1), - COG_FRAME_DATA_GET_LINE (src->components + 2, i >> 1), dest->width); - } - } -} - - - - - -typedef struct -{ - uint32_t in_format; - uint32_t out_format; - void (*convert) (CogFrame * dest, CogFrame * src); -} CogColorspaceTransform; -static CogColorspaceTransform transforms[] = { - {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_YUY2, convert_I420_YUY2}, - {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_UYVY, convert_I420_UYVY}, - {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_AYUV, convert_I420_AYUV}, - {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_Y42B, convert_I420_Y42B}, - {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_Y444, convert_I420_Y444}, - - {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_I420, convert_YUY2_I420}, - {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_UYVY, convert_UYVY_YUY2}, /* alias */ - {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_AYUV, convert_YUY2_AYUV}, - {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_Y42B, convert_YUY2_Y42B}, - {GST_VIDEO_FORMAT_YUY2, GST_VIDEO_FORMAT_Y444, convert_YUY2_Y444}, - - {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_I420, convert_UYVY_I420}, - {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_YUY2, convert_UYVY_YUY2}, - {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_AYUV, convert_UYVY_AYUV}, - {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_Y42B, convert_UYVY_Y42B}, - {GST_VIDEO_FORMAT_UYVY, GST_VIDEO_FORMAT_Y444, convert_UYVY_Y444}, - - {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_I420, convert_AYUV_I420}, - {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_YUY2, convert_AYUV_YUY2}, - {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_UYVY, convert_AYUV_UYVY}, - {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_Y42B, convert_AYUV_Y42B}, - {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_Y444, convert_AYUV_Y444}, - - {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_I420, convert_Y42B_I420}, - {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_YUY2, convert_Y42B_YUY2}, - {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_UYVY, convert_Y42B_UYVY}, - {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_AYUV, convert_Y42B_AYUV}, - {GST_VIDEO_FORMAT_Y42B, GST_VIDEO_FORMAT_Y444, convert_Y42B_Y444}, - - {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_I420, convert_Y444_I420}, - {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_YUY2, convert_Y444_YUY2}, - {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_UYVY, convert_Y444_UYVY}, - {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_AYUV, convert_Y444_AYUV}, - {GST_VIDEO_FORMAT_Y444, GST_VIDEO_FORMAT_Y42B, convert_Y444_Y42B}, - - {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_ARGB, convert_AYUV_ARGB}, - {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_BGRA, convert_AYUV_BGRA}, - {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_xRGB, convert_AYUV_ARGB}, /* alias */ - {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_BGRx, convert_AYUV_BGRA}, /* alias */ - {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_ABGR, convert_AYUV_ABGR}, - {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_RGBA, convert_AYUV_RGBA}, - {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_xBGR, convert_AYUV_ABGR}, /* alias */ - {GST_VIDEO_FORMAT_AYUV, GST_VIDEO_FORMAT_RGBx, convert_AYUV_RGBA}, /* alias */ - - {GST_VIDEO_FORMAT_I420, GST_VIDEO_FORMAT_BGRA, convert_I420_BGRA}, -}; - -static GstFlowReturn -gst_cogcolorspace_transform (GstBaseTransform * base_transform, - GstBuffer * inbuf, GstBuffer * outbuf) -{ - GstCogcolorspace *compress; - CogFrame *out_frame; - CogFrame *frame; - int width, height; - uint32_t in_format; - uint32_t out_format; - CogFrameFormat new_subsample; - gboolean ret; - CogColorMatrix in_color_matrix; - CogColorMatrix out_color_matrix; - CogChromaSite in_chroma_site; - CogChromaSite out_chroma_site; - - g_return_val_if_fail (GST_IS_COGCOLORSPACE (base_transform), GST_FLOW_ERROR); - compress = GST_COGCOLORSPACE (base_transform); - - ret = gst_video_format_parse_caps (inbuf->caps, &in_format, &width, &height); - ret &= - gst_video_format_parse_caps (outbuf->caps, &out_format, &width, &height); - if (!ret) { - return GST_FLOW_ERROR; - } - - in_color_matrix = gst_cogcolorspace_caps_get_color_matrix (inbuf->caps); - out_color_matrix = gst_cogcolorspace_caps_get_color_matrix (outbuf->caps); - - in_chroma_site = gst_cogcolorspace_caps_get_chroma_site (inbuf->caps); - out_chroma_site = gst_cogcolorspace_caps_get_chroma_site (outbuf->caps); - - frame = gst_cog_buffer_wrap (gst_buffer_ref (inbuf), - in_format, width, height); - out_frame = gst_cog_buffer_wrap (gst_buffer_ref (outbuf), - out_format, width, height); - - if (in_format == out_format) { - memcpy (GST_BUFFER_DATA (outbuf), GST_BUFFER_DATA (inbuf), - GST_BUFFER_SIZE (outbuf)); - } - - { - int i; - - for (i = 0; i < sizeof (transforms) / sizeof (transforms[0]); i++) { - if (transforms[i].in_format == in_format && - transforms[i].out_format == out_format) { - transforms[i].convert (out_frame, frame); - cog_frame_unref (frame); - cog_frame_unref (out_frame); - - return GST_FLOW_OK; - } - } - - GST_DEBUG ("no fastpath match %d %d", in_format, out_format); - } - - switch (out_format) { - case GST_VIDEO_FORMAT_YUY2: - case GST_VIDEO_FORMAT_UYVY: - case GST_VIDEO_FORMAT_YVYU: - case GST_VIDEO_FORMAT_Y42B: - case GST_VIDEO_FORMAT_v210: - case GST_VIDEO_FORMAT_v216: - new_subsample = COG_FRAME_FORMAT_U8_422; - break; - case GST_VIDEO_FORMAT_I420: - case GST_VIDEO_FORMAT_YV12: - new_subsample = COG_FRAME_FORMAT_U8_420; - break; - case GST_VIDEO_FORMAT_Y444: - case GST_VIDEO_FORMAT_RGBx: - case GST_VIDEO_FORMAT_xRGB: - case GST_VIDEO_FORMAT_BGRx: - case GST_VIDEO_FORMAT_xBGR: - case GST_VIDEO_FORMAT_RGBA: - case GST_VIDEO_FORMAT_ARGB: - case GST_VIDEO_FORMAT_BGRA: - case GST_VIDEO_FORMAT_ABGR: - default: - new_subsample = COG_FRAME_FORMAT_U8_444; - break; - } - - frame = cog_virt_frame_new_unpack (frame); - - if (gst_video_format_is_yuv (out_format) && - gst_video_format_is_rgb (in_format)) { - frame = cog_virt_frame_new_color_matrix_RGB_to_YCbCr (frame, - out_color_matrix, 8); - frame = cog_virt_frame_new_subsample (frame, new_subsample, - out_chroma_site, (compress->quality >= 3) ? 2 : 1); - } - - if (gst_video_format_is_yuv (out_format) && - gst_video_format_is_yuv (in_format)) { - if ((in_color_matrix != out_color_matrix || - in_chroma_site != out_chroma_site)) { - frame = cog_virt_frame_new_subsample (frame, COG_FRAME_FORMAT_U8_444, - in_chroma_site, (compress->quality >= 5) ? 8 : 6); - frame = cog_virt_frame_new_color_matrix_YCbCr_to_YCbCr (frame, - in_color_matrix, out_color_matrix, 8); - } - frame = cog_virt_frame_new_subsample (frame, new_subsample, - in_chroma_site, (compress->quality >= 5) ? 8 : 6); - } - - if (gst_video_format_is_rgb (out_format) && - gst_video_format_is_yuv (in_format)) { - frame = cog_virt_frame_new_subsample (frame, new_subsample, - in_chroma_site, (compress->quality >= 3) ? 2 : 1); - frame = cog_virt_frame_new_color_matrix_YCbCr_to_RGB (frame, - in_color_matrix, (compress->quality >= 5) ? 8 : 6); - } - - switch (out_format) { - case GST_VIDEO_FORMAT_YUY2: - frame = cog_virt_frame_new_pack_YUY2 (frame); - break; - case GST_VIDEO_FORMAT_UYVY: - frame = cog_virt_frame_new_pack_UYVY (frame); - break; - case GST_VIDEO_FORMAT_AYUV: - frame = cog_virt_frame_new_pack_AYUV (frame); - break; - case GST_VIDEO_FORMAT_v216: - frame = cog_virt_frame_new_pack_v216 (frame); - break; - case GST_VIDEO_FORMAT_v210: - frame = cog_virt_frame_new_pack_v210 (frame); - break; - case GST_VIDEO_FORMAT_RGBx: - frame = cog_virt_frame_new_pack_RGBx (frame); - break; - case GST_VIDEO_FORMAT_xRGB: - frame = cog_virt_frame_new_pack_xRGB (frame); - break; - case GST_VIDEO_FORMAT_BGRx: - frame = cog_virt_frame_new_pack_BGRx (frame); - break; - case GST_VIDEO_FORMAT_xBGR: - frame = cog_virt_frame_new_pack_xBGR (frame); - break; - case GST_VIDEO_FORMAT_RGBA: - frame = cog_virt_frame_new_pack_RGBA (frame); - break; - case GST_VIDEO_FORMAT_ARGB: - frame = cog_virt_frame_new_pack_ARGB (frame); - break; - case GST_VIDEO_FORMAT_BGRA: - frame = cog_virt_frame_new_pack_BGRA (frame); - break; - case GST_VIDEO_FORMAT_ABGR: - frame = cog_virt_frame_new_pack_ABGR (frame); - break; - default: - break; - } - - cog_virt_frame_render (frame, out_frame); - cog_frame_unref (frame); - cog_frame_unref (out_frame); - - return GST_FLOW_OK; -} diff --git a/ext/cog/gstcolorconvert.c b/ext/cog/gstcolorconvert.c deleted file mode 100644 index c13168ab13..0000000000 --- a/ext/cog/gstcolorconvert.c +++ /dev/null @@ -1,383 +0,0 @@ -/* GStreamer - * Copyright (C) 2008 David Schleef - * - * 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 -#include -#include -#include -#include -#include -#include - -#include "gstcogutils.h" - -#include "gstcms.h" - -#define GST_TYPE_COLORCONVERT \ - (gst_colorconvert_get_type()) -#define GST_COLORCONVERT(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_COLORCONVERT,GstColorconvert)) -#define GST_COLORCONVERT_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_COLORCONVERT,GstColorconvertClass)) -#define GST_IS_COLORCONVERT(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_COLORCONVERT)) -#define GST_IS_COLORCONVERT_CLASS(obj) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_COLORCONVERT)) - -typedef struct _GstColorconvert GstColorconvert; -typedef struct _GstColorconvertClass GstColorconvertClass; - -struct _GstColorconvert -{ - GstBaseTransform base_transform; - - gchar *location; - - GstVideoFormat format; - int width; - int height; - -}; - -struct _GstColorconvertClass -{ - GstBaseTransformClass parent_class; - -}; - -enum -{ - ARG_0, -}; - -GType gst_colorconvert_get_type (void); - -static void gst_colorconvert_base_init (gpointer g_class); -static void gst_colorconvert_class_init (gpointer g_class, gpointer class_data); -static void gst_colorconvert_init (GTypeInstance * instance, gpointer g_class); - -static void gst_colorconvert_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec); -static void gst_colorconvert_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec); - -static gboolean gst_colorconvert_set_caps (GstBaseTransform * base_transform, - GstCaps * incaps, GstCaps * outcaps); -static GstFlowReturn gst_colorconvert_transform_ip (GstBaseTransform * - base_transform, GstBuffer * buf); -static CogFrame *cog_virt_frame_new_color_transform (CogFrame * frame); - -static GstStaticPadTemplate gst_colorconvert_sink_template = -GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{I420,YUY2,UYVY,AYUV}")) - ); - -static GstStaticPadTemplate gst_colorconvert_src_template = -GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("{I420,YUY2,UYVY,AYUV}")) - ); - -GType -gst_colorconvert_get_type (void) -{ - static GType compress_type = 0; - - if (!compress_type) { - static const GTypeInfo compress_info = { - sizeof (GstColorconvertClass), - gst_colorconvert_base_init, - NULL, - gst_colorconvert_class_init, - NULL, - NULL, - sizeof (GstColorconvert), - 0, - gst_colorconvert_init, - }; - - compress_type = g_type_register_static (GST_TYPE_BASE_TRANSFORM, - "GstColorconvert", &compress_info, 0); - } - return compress_type; -} - - -static void -gst_colorconvert_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_colorconvert_src_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_colorconvert_sink_template)); - - gst_element_class_set_metadata (element_class, "Convert colorspace", - "Filter/Effect/Video", - "Convert between SDTV and HDTV colorspace", - "David Schleef "); -} - -static void -gst_colorconvert_class_init (gpointer g_class, gpointer class_data) -{ - GObjectClass *gobject_class; - GstBaseTransformClass *base_transform_class; - - gobject_class = G_OBJECT_CLASS (g_class); - base_transform_class = GST_BASE_TRANSFORM_CLASS (g_class); - - gobject_class->set_property = gst_colorconvert_set_property; - gobject_class->get_property = gst_colorconvert_get_property; - - base_transform_class->set_caps = gst_colorconvert_set_caps; - base_transform_class->transform_ip = gst_colorconvert_transform_ip; -} - -static void -gst_colorconvert_init (GTypeInstance * instance, gpointer g_class) -{ - - GST_DEBUG ("gst_colorconvert_init"); -} - -static void -gst_colorconvert_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec) -{ - g_return_if_fail (GST_IS_COLORCONVERT (object)); - - GST_DEBUG ("gst_colorconvert_set_property"); - switch (prop_id) { - default: - break; - } -} - -static void -gst_colorconvert_get_property (GObject * object, guint prop_id, GValue * value, - GParamSpec * pspec) -{ - g_return_if_fail (GST_IS_COLORCONVERT (object)); - - switch (prop_id) { - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -static gboolean -gst_colorconvert_set_caps (GstBaseTransform * base_transform, - GstCaps * incaps, GstCaps * outcaps) -{ - GstColorconvert *li; - - g_return_val_if_fail (GST_IS_COLORCONVERT (base_transform), GST_FLOW_ERROR); - li = GST_COLORCONVERT (base_transform); - - gst_video_format_parse_caps (incaps, &li->format, &li->width, &li->height); - - return TRUE; -} - -static GstFlowReturn -gst_colorconvert_transform_ip (GstBaseTransform * base_transform, - GstBuffer * buf) -{ - GstColorconvert *li; - CogFrame *frame; - CogFrame *vf; - - g_return_val_if_fail (GST_IS_COLORCONVERT (base_transform), GST_FLOW_ERROR); - li = GST_COLORCONVERT (base_transform); - - frame = gst_cog_buffer_wrap (gst_buffer_ref (buf), - li->format, li->width, li->height); - - vf = cog_virt_frame_new_unpack (cog_frame_ref (frame)); - vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_444, - COG_CHROMA_SITE_MPEG2, 2); - vf = cog_virt_frame_new_color_transform (vf); - if (frame->format == COG_FRAME_FORMAT_YUYV) { - vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_422, - COG_CHROMA_SITE_MPEG2, 2); - vf = cog_virt_frame_new_pack_YUY2 (vf); - } else if (frame->format == COG_FRAME_FORMAT_UYVY) { - vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_422, - COG_CHROMA_SITE_MPEG2, 2); - vf = cog_virt_frame_new_pack_UYVY (vf); - } else if (frame->format == COG_FRAME_FORMAT_AYUV) { - vf = cog_virt_frame_new_pack_AYUV (vf); - } else if (frame->format == COG_FRAME_FORMAT_U8_420) { - vf = cog_virt_frame_new_subsample (vf, COG_FRAME_FORMAT_U8_420, - COG_CHROMA_SITE_MPEG2, 2); - } else { - g_assert_not_reached (); - } - - cog_virt_frame_render (vf, frame); - - cog_frame_unref (frame); - cog_frame_unref (vf); - - return GST_FLOW_OK; -} - - - -static void -color_transform (CogFrame * frame, void *_dest, int component, int j) -{ - uint8_t *dest = _dest; - uint8_t *src_y; - uint8_t *src_u; - uint8_t *src_v; - uint8_t *table; - int i; - - table = COG_OFFSET (frame->virt_priv2, component * 0x1000000); - - src_y = cog_virt_frame_get_line (frame->virt_frame1, 0, j); - src_u = cog_virt_frame_get_line (frame->virt_frame1, 1, j); - src_v = cog_virt_frame_get_line (frame->virt_frame1, 2, j); - - for (i = 0; i < frame->width; i++) { - dest[i] = table[(src_y[i] << 16) | (src_u[i] << 8) | (src_v[i])]; - } -} - -static uint8_t *get_color_transform_table (void); - -static CogFrame * -cog_virt_frame_new_color_transform (CogFrame * frame) -{ - CogFrame *virt_frame; - - g_return_val_if_fail (frame->format == COG_FRAME_FORMAT_U8_444, NULL); - - virt_frame = cog_frame_new_virtual (NULL, COG_FRAME_FORMAT_U8_444, - frame->width, frame->height); - virt_frame->virt_frame1 = frame; - virt_frame->render_line = color_transform; - - virt_frame->virt_priv2 = get_color_transform_table (); - - return virt_frame; -} - - -static uint8_t * -get_color_transform_table (void) -{ - static uint8_t *color_transform_table = NULL; - -#if 1 - if (!color_transform_table) { - ColorMatrix bt601_to_rgb; - ColorMatrix bt601_to_yuv; - ColorMatrix bt601_rgb_to_XYZ; - ColorMatrix dell_XYZ_to_rgb; - uint8_t *table_y; - uint8_t *table_u; - uint8_t *table_v; - int y, u, v; - - color_matrix_build_yuv_to_rgb_601 (&bt601_to_rgb); - color_matrix_build_rgb_to_yuv_601 (&bt601_to_yuv); - color_matrix_build_rgb_to_XYZ_601 (&bt601_rgb_to_XYZ); - color_matrix_build_XYZ_to_rgb_dell (&dell_XYZ_to_rgb); - - color_transform_table = g_malloc (0x1000000 * 3); - - table_y = COG_OFFSET (color_transform_table, 0 * 0x1000000); - table_u = COG_OFFSET (color_transform_table, 1 * 0x1000000); - table_v = COG_OFFSET (color_transform_table, 2 * 0x1000000); - - for (y = 0; y < 256; y++) { - for (u = 0; u < 256; u++) { - for (v = 0; v < 256; v++) { - Color c; - - c.v[0] = y; - c.v[1] = u; - c.v[2] = v; - color_matrix_apply (&bt601_to_rgb, &c, &c); - color_gamut_clamp (&c, &c); - color_transfer_function_apply (&c, &c); - color_matrix_apply (&bt601_rgb_to_XYZ, &c, &c); - color_matrix_apply (&dell_XYZ_to_rgb, &c, &c); - color_transfer_function_unapply (&c, &c); - color_gamut_clamp (&c, &c); - color_matrix_apply (&bt601_to_yuv, &c, &c); - - table_y[(y << 16) | (u << 8) | (v)] = rint (c.v[0]); - table_u[(y << 16) | (u << 8) | (v)] = rint (c.v[1]); - table_v[(y << 16) | (u << 8) | (v)] = rint (c.v[2]); - } - } - } - } -#endif -#if 0 - if (!color_transform_table) { - ColorMatrix bt709_to_bt601; - uint8_t *table_y; - uint8_t *table_u; - uint8_t *table_v; - int y, u, v; - - color_matrix_build_bt709_to_bt601 (&bt709_to_bt601); - - color_transform_table = g_malloc (0x1000000 * 3); - - table_y = COG_OFFSET (color_transform_table, 0 * 0x1000000); - table_u = COG_OFFSET (color_transform_table, 1 * 0x1000000); - table_v = COG_OFFSET (color_transform_table, 2 * 0x1000000); - - for (y = 0; y < 256; y++) { - for (u = 0; u < 256; u++) { - for (v = 0; v < 256; v++) { - Color c; - - c.v[0] = y; - c.v[1] = u; - c.v[2] = v; - color_matrix_apply (&bt709_to_bt601, &c, &c); - - table_y[(y << 16) | (u << 8) | (v)] = rint (c.v[0]); - table_u[(y << 16) | (u << 8) | (v)] = rint (c.v[1]); - table_v[(y << 16) | (u << 8) | (v)] = rint (c.v[2]); - } - } - } - } -#endif - - return color_transform_table; -} diff --git a/ext/cog/gstlogoinsert.c b/ext/cog/gstlogoinsert.c deleted file mode 100644 index dfcc7952ad..0000000000 --- a/ext/cog/gstlogoinsert.c +++ /dev/null @@ -1,508 +0,0 @@ -/* GStreamer - * Copyright (C) 2008 David Schleef - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include "gstcogutils.h" - -#define GST_TYPE_LOGOINSERT \ - (gst_logoinsert_get_type()) -#define GST_LOGOINSERT(obj) \ - (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_LOGOINSERT,GstLogoinsert)) -#define GST_LOGOINSERT_CLASS(klass) \ - (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_LOGOINSERT,GstLogoinsertClass)) -#define GST_IS_LOGOINSERT(obj) \ - (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_LOGOINSERT)) -#define GST_IS_LOGOINSERT_CLASS(obj) \ - (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_LOGOINSERT)) - -typedef struct _GstLogoinsert GstLogoinsert; -typedef struct _GstLogoinsertClass GstLogoinsertClass; - -struct _GstLogoinsert -{ - GstBaseTransform base_transform; - - char *location; - GstBuffer *buffer; - - GstVideoFormat format; - int width; - int height; - - gchar *data; - gsize size; - CogFrame *overlay_frame; - CogFrame *argb_frame; - CogFrame *alpha_frame; - -}; - -struct _GstLogoinsertClass -{ - GstBaseTransformClass parent_class; - -}; - -enum -{ - ARG_0, - ARG_LOCATION, - ARG_DATA -}; - -GType gst_logoinsert_get_type (void); - -GST_DEBUG_CATEGORY_STATIC (gst_logoinsert_debug_category); -#define GST_CAT_DEFAULT gst_logoinsert_debug_category - -static void gst_logoinsert_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec); -static void gst_logoinsert_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec); -static void gst_logoinsert_dispose (GObject * object); -static void gst_logoinsert_finalize (GObject * object); - -static void -gst_logoinsert_set_location (GstLogoinsert * li, const char *location); -static void gst_logoinsert_set_data (GstLogoinsert * li, GstBuffer * buffer); - -static gboolean gst_logoinsert_set_caps (GstBaseTransform * base_transform, - GstCaps * incaps, GstCaps * outcaps); -static GstFlowReturn gst_logoinsert_transform_ip (GstBaseTransform * - base_transform, GstBuffer * buf); -static CogFrame *cog_frame_new_from_png (void *data, int size); -static CogFrame *cog_virt_frame_extract_alpha (CogFrame * frame); -static CogFrame *cog_frame_realize (CogFrame * frame); - -static GstStaticPadTemplate gst_logoinsert_sink_template = -GST_STATIC_PAD_TEMPLATE ("sink", - GST_PAD_SINK, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")) - ); - -static GstStaticPadTemplate gst_logoinsert_src_template = -GST_STATIC_PAD_TEMPLATE ("src", - GST_PAD_SRC, - GST_PAD_ALWAYS, - GST_STATIC_CAPS (GST_VIDEO_CAPS_YUV ("I420")) - ); - -/* class initialization */ - -#define DEBUG_INIT(bla) \ - GST_DEBUG_CATEGORY_INIT (gst_logoinsert_debug_category, "logoinsert", 0, \ - "debug category for logoinsert element"); - -GST_BOILERPLATE_FULL (GstLogoinsert, gst_logoinsert, GstBaseTransform, - GST_TYPE_BASE_TRANSFORM, DEBUG_INIT); - -static void -gst_logoinsert_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_logoinsert_src_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_logoinsert_sink_template)); - - gst_element_class_set_metadata (element_class, - "Overlay image onto video", "Filter/Effect/Video", - "Overlay image onto video", "David Schleef "); -} - -static void -gst_logoinsert_class_init (GstLogoinsertClass * klass) -{ - GObjectClass *gobject_class; - GstBaseTransformClass *base_transform_class; - - gobject_class = G_OBJECT_CLASS (klass); - base_transform_class = GST_BASE_TRANSFORM_CLASS (klass); - - gobject_class->set_property = gst_logoinsert_set_property; - gobject_class->get_property = gst_logoinsert_get_property; - gobject_class->dispose = gst_logoinsert_dispose; - gobject_class->finalize = gst_logoinsert_finalize; - - g_object_class_install_property (gobject_class, ARG_LOCATION, - g_param_spec_string ("location", "location", - "location of PNG file to overlay", "", - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - g_object_class_install_property (gobject_class, ARG_DATA, - gst_param_spec_mini_object ("data", "data", - "Buffer containing PNG file to overlay", GST_TYPE_BUFFER, - G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - base_transform_class->set_caps = gst_logoinsert_set_caps; - base_transform_class->transform_ip = gst_logoinsert_transform_ip; -} - -static void -gst_logoinsert_init (GstLogoinsert * logoinsert, - GstLogoinsertClass * logoinsert_class) -{ - - GST_DEBUG ("gst_logoinsert_init"); -} - -static void -gst_logoinsert_set_property (GObject * object, guint prop_id, - const GValue * value, GParamSpec * pspec) -{ - GstLogoinsert *src; - - g_return_if_fail (GST_IS_LOGOINSERT (object)); - src = GST_LOGOINSERT (object); - - GST_DEBUG ("gst_logoinsert_set_property"); - switch (prop_id) { - case ARG_LOCATION: - gst_logoinsert_set_location (src, g_value_get_string (value)); - break; - case ARG_DATA: - gst_logoinsert_set_data (src, - (GstBuffer *) gst_value_get_mini_object (value)); - break; - default: - break; - } -} - -static void -gst_logoinsert_get_property (GObject * object, guint prop_id, GValue * value, - GParamSpec * pspec) -{ - GstLogoinsert *src; - - g_return_if_fail (GST_IS_LOGOINSERT (object)); - src = GST_LOGOINSERT (object); - - switch (prop_id) { - case ARG_LOCATION: - g_value_set_string (value, src->location); - break; - case ARG_DATA: - gst_value_set_mini_object (value, (GstMiniObject *) src->buffer); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - break; - } -} - -void -gst_logoinsert_dispose (GObject * object) -{ - g_return_if_fail (GST_IS_LOGOINSERT (object)); - - /* clean up as possible. may be called multiple times */ - - G_OBJECT_CLASS (parent_class)->dispose (object); -} - -void -gst_logoinsert_finalize (GObject * object) -{ - GstLogoinsert *logoinsert; - - g_return_if_fail (GST_IS_LOGOINSERT (object)); - logoinsert = GST_LOGOINSERT (object); - - g_free (logoinsert->location); - if (logoinsert->buffer) { - gst_buffer_unref (logoinsert->buffer); - } - if (logoinsert->overlay_frame) { - cog_frame_unref (logoinsert->overlay_frame); - logoinsert->overlay_frame = NULL; - } - if (logoinsert->alpha_frame) { - cog_frame_unref (logoinsert->alpha_frame); - logoinsert->alpha_frame = NULL; - } - if (logoinsert->argb_frame) { - cog_frame_unref (logoinsert->argb_frame); - logoinsert->argb_frame = NULL; - } - - G_OBJECT_CLASS (parent_class)->finalize (object); -} - -static gboolean -gst_logoinsert_set_caps (GstBaseTransform * base_transform, - GstCaps * incaps, GstCaps * outcaps) -{ - GstLogoinsert *li; - - g_return_val_if_fail (GST_IS_LOGOINSERT (base_transform), GST_FLOW_ERROR); - li = GST_LOGOINSERT (base_transform); - - gst_video_format_parse_caps (incaps, &li->format, &li->width, &li->height); - - return TRUE; -} - -static GstFlowReturn -gst_logoinsert_transform_ip (GstBaseTransform * base_transform, GstBuffer * buf) -{ - GstLogoinsert *li; - CogFrame *frame; - - g_return_val_if_fail (GST_IS_LOGOINSERT (base_transform), GST_FLOW_ERROR); - li = GST_LOGOINSERT (base_transform); - - if (li->argb_frame == NULL) - return GST_FLOW_OK; - - frame = gst_cog_buffer_wrap (gst_buffer_ref (buf), - li->format, li->width, li->height); - - if (li->overlay_frame == NULL) { - CogFrame *f; - - f = cog_virt_frame_extract_alpha (cog_frame_ref (li->argb_frame)); - f = cog_virt_frame_new_subsample (f, frame->format, - COG_CHROMA_SITE_MPEG2, 2); - li->alpha_frame = cog_frame_realize (f); - - f = cog_virt_frame_new_unpack (cog_frame_ref (li->argb_frame)); - f = cog_virt_frame_new_color_matrix_RGB_to_YCbCr (f, COG_COLOR_MATRIX_SDTV, - 8); - f = cog_virt_frame_new_subsample (f, frame->format, - COG_CHROMA_SITE_MPEG2, 2); - li->overlay_frame = cog_frame_realize (f); - } - - if (1) { - int i, j; - int k; - guint8 *dest; - guint8 *src; - guint8 *alpha; - int offset_x, offset_y; - - for (k = 0; k < 3; k++) { - offset_x = frame->components[k].width - - li->alpha_frame->components[k].width; - offset_y = frame->components[k].height - - li->alpha_frame->components[k].height; - - for (j = 0; j < li->overlay_frame->components[k].height; j++) { - dest = COG_FRAME_DATA_GET_LINE (frame->components + k, j + offset_y); - src = COG_FRAME_DATA_GET_LINE (li->overlay_frame->components + k, j); - alpha = COG_FRAME_DATA_GET_LINE (li->alpha_frame->components + k, j); - -#define oil_divide_255(x) ((((x)+128) + (((x)+128)>>8))>>8) - - for (i = 0; i < li->overlay_frame->components[k].width; i++) { - dest[i + offset_x] = - oil_divide_255 (src[i] * alpha[i] + dest[i + offset_x] * (255 - - alpha[i])); - } - } - } - } - - cog_frame_unref (frame); - - return GST_FLOW_OK; -} - -static GstBuffer * -get_buffer_from_file (const char *filename) -{ - gboolean ret; - GstBuffer *buffer; - gsize size; - gchar *data; - - ret = g_file_get_contents (filename, &data, &size, NULL); - if (!ret) - return NULL; - - buffer = gst_buffer_new (); - GST_BUFFER_DATA (buffer) = (guchar *) data; - GST_BUFFER_MALLOCDATA (buffer) = (guchar *) data; - GST_BUFFER_SIZE (buffer) = size; - - return buffer; -} - -static void -gst_logoinsert_set_location (GstLogoinsert * li, const char *location) -{ - g_free (li->location); - li->location = g_strdup (location); - - gst_logoinsert_set_data (li, get_buffer_from_file (li->location)); -} - -static void -gst_logoinsert_set_data (GstLogoinsert * li, GstBuffer * buffer) -{ - if (li->buffer) - gst_buffer_unref (li->buffer); - - /* steals the reference */ - li->buffer = buffer; - - if (li->overlay_frame) { - cog_frame_unref (li->overlay_frame); - li->overlay_frame = NULL; - } - if (li->alpha_frame) { - cog_frame_unref (li->alpha_frame); - li->alpha_frame = NULL; - } - if (li->argb_frame) { - cog_frame_unref (li->argb_frame); - li->argb_frame = NULL; - } - - if (li->buffer) { - li->argb_frame = cog_frame_new_from_png (GST_BUFFER_DATA (li->buffer), - GST_BUFFER_SIZE (li->buffer)); - } -} - - -/* load PNG into CogFrame */ - -struct png_data_struct -{ - unsigned char *data; - int size; - int offset; -}; - -static void -read_data (png_structp png_ptr, png_bytep data, png_size_t length) -{ - struct png_data_struct *s = png_get_io_ptr (png_ptr); - - memcpy (data, s->data + s->offset, length); - s->offset += length; -} - -static CogFrame * -cog_frame_new_from_png (void *data, int size) -{ - struct png_data_struct s = { 0 }; - png_structp png_ptr; - png_infop info_ptr; - png_bytep *rows; - CogFrame *frame; - guchar *frame_data; - int j; - int width, height; - int color_type; - - png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); - info_ptr = png_create_info_struct (png_ptr); - - s.data = data; - s.size = size; - png_set_read_fn (png_ptr, (void *) &s, read_data); - - png_read_info (png_ptr, info_ptr); - - width = png_get_image_width (png_ptr, info_ptr); - height = png_get_image_height (png_ptr, info_ptr); - color_type = png_get_color_type (png_ptr, info_ptr); - GST_DEBUG ("PNG size %dx%d color_type %d", width, height, color_type); - - png_set_strip_16 (png_ptr); - png_set_packing (png_ptr); - if (color_type == PNG_COLOR_TYPE_RGB) { - png_set_filler (png_ptr, 0xff, PNG_FILLER_BEFORE); - } - if (color_type == PNG_COLOR_TYPE_RGB_ALPHA) { - png_set_swap_alpha (png_ptr); - } - - frame_data = g_malloc (width * height * 4); - frame = cog_frame_new_from_data_ARGB (frame_data, width, height); - frame->regions[0] = frame_data; - - rows = (png_bytep *) g_malloc (sizeof (png_bytep) * height); - - for (j = 0; j < height; j++) { - rows[j] = COG_FRAME_DATA_GET_LINE (frame->components + 0, j); - } - png_read_image (png_ptr, rows); - g_free (rows); - - png_destroy_read_struct (&png_ptr, &info_ptr, (png_infopp) NULL); - - return frame; -} - -static void -extract_alpha (CogFrame * frame, void *_dest, int component, int j) -{ - uint8_t *dest = _dest; - uint8_t *src; - int i; - - src = COG_FRAME_DATA_GET_LINE (frame->virt_frame1->components + 0, j); - for (i = 0; i < frame->width; i++) { - dest[i] = src[i * 4 + 0]; - } -} - -static CogFrame * -cog_virt_frame_extract_alpha (CogFrame * frame) -{ - CogFrame *virt_frame; - - /* FIXME check that frame is a real AYUV frame */ - - virt_frame = cog_frame_new_virtual (NULL, COG_FRAME_FORMAT_U8_444, - frame->width, frame->height); - virt_frame->virt_frame1 = frame; - virt_frame->render_line = extract_alpha; - - return virt_frame; -} - -static CogFrame * -cog_frame_realize (CogFrame * frame) -{ - CogFrame *dest; - - dest = cog_frame_clone (NULL, frame); - cog_virt_frame_render (frame, dest); - cog_frame_unref (frame); - - return dest; -}