gstreamer/ext/opencv/gstopencvutils.c
Thiago Santos 824d69d5ad Adding gstopencvutils
Adds a file to keep utilitary functions together
2010-09-08 17:15:50 -03:00

82 lines
2.5 KiB
C

/* GStreamer
* Copyright (C) <2010> Thiago Santos <thiago.sousa.santos@collabora.co.uk>
*
* gstopencvutils.c: miscellaneous utility functions
*
* 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.
*/
#include "gstopencvutils.h"
gboolean
gst_opencv_get_ipl_depth_and_channels (GstStructure * structure,
gint * ipldepth, gint * channels, GError ** err)
{
gint depth, bpp;
if (gst_structure_has_name (structure, "video/x-raw-rgb")) {
*channels = 3;
if (!gst_structure_get_int (structure, "depth", &depth) ||
!gst_structure_get_int (structure, "bpp", &bpp)) {
g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
"No depth/bpp in caps");
return FALSE;
}
if (depth != bpp) {
g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
"Depth and bpp should be equal");
return FALSE;
}
if (depth == 24) {
/* TODO signdness? */
*ipldepth = IPL_DEPTH_8U;
} else {
g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
"Unsupported depth: %d", depth);
return FALSE;
}
return TRUE;
} else {
g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
"Unsupported caps %s", gst_structure_get_name (structure));
return FALSE;
}
}
gboolean
gst_opencv_parse_iplimage_params_from_caps (GstCaps * caps, gint * width,
gint * height, gint * ipldepth, gint * type, gint * channels, GError ** err)
{
GstStructure *structure = gst_caps_get_structure (caps, 0);
if (!gst_opencv_get_ipl_depth_and_channels (structure, ipldepth, channels,
err)) {
return FALSE;
}
if (!gst_structure_get_int (structure, "width", width) ||
!gst_structure_get_int (structure, "height", height)) {
g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
"No width/height in caps");
return FALSE;
}
return TRUE;
}