2 * Copyright (C) <2010> Thiago Santos <thiago.sousa.santos@collabora.co.uk>
4 * gstopencvutils.c: miscellaneous utility functions
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 #include "gstopencvutils.h"
25 gst_opencv_get_ipl_depth_and_channels (GstStructure * structure,
26 gint * ipldepth, gint * channels, GError ** err)
30 if (!gst_structure_get_int (structure, "depth", &depth) ||
31 !gst_structure_get_int (structure, "bpp", &bpp)) {
32 g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
33 "No depth/bpp in caps");
38 g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
39 "Depth and bpp should be equal");
43 if (gst_structure_has_name (structure, "video/x-raw-rgb")) {
45 } else if (gst_structure_has_name (structure, "video/x-raw-gray")) {
48 g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
49 "Unsupported caps %s", gst_structure_get_name (structure));
53 if (depth / *channels == 8) {
55 *ipldepth = IPL_DEPTH_8U;
56 } else if (depth / *channels == 16) {
57 *ipldepth = IPL_DEPTH_16U;
59 g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
60 "Unsupported depth/channels %d/%d", depth, *channels);
68 gst_opencv_parse_iplimage_params_from_structure (GstStructure * structure,
69 gint * width, gint * height, gint * ipldepth, gint * channels,
72 if (!gst_opencv_get_ipl_depth_and_channels (structure, ipldepth, channels,
77 if (!gst_structure_get_int (structure, "width", width) ||
78 !gst_structure_get_int (structure, "height", height)) {
79 g_set_error (err, GST_CORE_ERROR, GST_CORE_ERROR_NEGOTIATION,
80 "No width/height in caps");
88 gst_opencv_parse_iplimage_params_from_caps (GstCaps * caps, gint * width,
89 gint * height, gint * ipldepth, gint * channels, GError ** err)
92 gst_opencv_parse_iplimage_params_from_structure (gst_caps_get_structure
93 (caps, 0), width, height, ipldepth, channels, err);
97 gst_opencv_caps_from_cv_image_type (int cv_type)
99 GstCaps *caps = gst_caps_new_empty ();
102 gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_GRAY8));
105 gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_RGB));
106 gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_BGR));
109 gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_RGBx));
110 gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_xRGB));
111 gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_BGRx));
112 gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_xBGR));
113 gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_RGBA));
114 gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_ARGB));
115 gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_BGRA));
116 gst_caps_append (caps, gst_caps_from_string (GST_VIDEO_CAPS_ABGR));
119 gst_caps_append (caps,
120 gst_caps_from_string (GST_VIDEO_CAPS_GRAY16 ("1234")));
121 gst_caps_append (caps,
122 gst_caps_from_string (GST_VIDEO_CAPS_GRAY16 ("4321")));