*
* 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.
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
*
* March 2008
* Logic enhanced by William Brack <wbrack@mmm.com.hk>
/**
* SECTION:element-bayer2rgb
+ * @title: bayer2rgb
*
* Decodes raw camera bayer (fourcc BA81) to RGB.
*/
* "nearest neighbor" principal, with some additional complexity for the
* calculation of the "green" element, where an "adaptive" pairing is used.
*
- * For purposes of documentation and indentification, each element of the
+ * For purposes of documentation and identification, each element of the
* original array can be put into one of four classes:
* R A red element
* B A blue element
#include <gst/video/video.h>
#include <string.h>
#include <stdlib.h>
-#include <_stdint.h>
+
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+
#include "gstbayerorc.h"
#define GST_CAT_DEFAULT gst_bayer2rgb_debug
};
#define SRC_CAPS \
- GST_VIDEO_CAPS_MAKE ("RGBx, xRGB, BGRx, xBGR, RGBA, ARGB, BGRA, ABGR")
+ GST_VIDEO_CAPS_MAKE ("{ RGBx, xRGB, BGRx, xBGR, RGBA, ARGB, BGRA, ABGR }")
-#define SINK_CAPS "video/x-raw-bayer,format=(string){bggr,grbg,gbrg,rggb}," \
+#define SINK_CAPS "video/x-bayer,format=(string){bggr,grbg,gbrg,rggb}," \
"width=(int)[1,MAX],height=(int)[1,MAX],framerate=(fraction)[0/1,MAX]"
enum
gobject_class->set_property = gst_bayer2rgb_set_property;
gobject_class->get_property = gst_bayer2rgb_get_property;
- gst_element_class_set_details_simple (gstelement_class,
+ gst_element_class_set_static_metadata (gstelement_class,
"Bayer to RGB decoder for cameras", "Filter/Converter/Video",
- "Converts video/x-raw-bayer to video/x-raw",
+ "Converts video/x-bayer to video/x-raw",
"William Brack <wbrack@mmm.com.hk>");
gst_element_class_add_pad_template (gstelement_class,
gst_bayer2rgb_transform_caps (GstBaseTransform * base,
GstPadDirection direction, GstCaps * caps, GstCaps * filter)
{
+ GstBayer2RGB *bayer2rgb;
+ GstCaps *res_caps, *tmp_caps;
GstStructure *structure;
- GstCaps *newcaps;
- GstStructure *newstruct;
+ guint i, caps_size;
- GST_DEBUG_OBJECT (caps, "transforming caps (from)");
-
- structure = gst_caps_get_structure (caps, 0);
+ bayer2rgb = GST_BAYER2RGB (base);
- if (direction == GST_PAD_SRC) {
- newcaps = gst_caps_from_string ("video/x-raw-bayer,"
- "format=(string){bggr,grbg,gbrg,rggb}");
- } else {
- newcaps = gst_caps_new_simple ("video/x-raw", NULL);
+ res_caps = gst_caps_copy (caps);
+ caps_size = gst_caps_get_size (res_caps);
+ for (i = 0; i < caps_size; i++) {
+ structure = gst_caps_get_structure (res_caps, i);
+ if (direction == GST_PAD_SINK) {
+ gst_structure_set_name (structure, "video/x-raw");
+ gst_structure_remove_field (structure, "format");
+ } else {
+ gst_structure_set_name (structure, "video/x-bayer");
+ gst_structure_remove_fields (structure, "format", "colorimetry",
+ "chroma-site", NULL);
+ }
}
- newstruct = gst_caps_get_structure (newcaps, 0);
-
- gst_structure_set_value (newstruct, "width",
- gst_structure_get_value (structure, "width"));
- gst_structure_set_value (newstruct, "height",
- gst_structure_get_value (structure, "height"));
- gst_structure_set_value (newstruct, "framerate",
- gst_structure_get_value (structure, "framerate"));
-
- GST_DEBUG_OBJECT (newcaps, "transforming caps (into)");
-
- return newcaps;
+ if (filter) {
+ tmp_caps = res_caps;
+ res_caps =
+ gst_caps_intersect_full (filter, tmp_caps, GST_CAPS_INTERSECT_FIRST);
+ gst_caps_unref (tmp_caps);
+ }
+ GST_DEBUG_OBJECT (bayer2rgb, "transformed %" GST_PTR_FORMAT " into %"
+ GST_PTR_FORMAT, caps, res_caps);
+ return res_caps;
}
static gboolean
if (gst_structure_get_int (structure, "width", &width) &&
gst_structure_get_int (structure, "height", &height)) {
name = gst_structure_get_name (structure);
- /* Our name must be either video/x-raw-bayer video/x-raw-rgb */
+ /* Our name must be either video/x-bayer video/x-raw */
if (strcmp (name, "video/x-raw")) {
*size = GST_ROUND_UP_4 (width) * height;
return TRUE;
dest1[1] = src[1];
#if defined(__i386__) || defined(__amd64__)
- gst_bayer_horiz_upsample_unaligned (dest0 + 2, dest1 + 2, src + 1,
+ bayer_orc_horiz_upsample_unaligned (dest0 + 2, dest1 + 2, src + 1,
(n - 4) >> 1);
#else
- gst_bayer_horiz_upsample (dest0 + 2, dest1 + 2, src + 2, (n - 4) >> 1);
+ bayer_orc_horiz_upsample (dest0 + 2, dest1 + 2, src + 2, (n - 4) >> 1);
#endif
for (i = n - 2; i < n; i++) {
}
if (r_off == 2 && g_off == 1 && b_off == 0) {
- merge[0] = gst_bayer_merge_bg_bgra;
- merge[1] = gst_bayer_merge_gr_bgra;
+ merge[0] = bayer_orc_merge_bg_bgra;
+ merge[1] = bayer_orc_merge_gr_bgra;
} else if (r_off == 3 && g_off == 2 && b_off == 1) {
- merge[0] = gst_bayer_merge_bg_abgr;
- merge[1] = gst_bayer_merge_gr_abgr;
+ merge[0] = bayer_orc_merge_bg_abgr;
+ merge[1] = bayer_orc_merge_gr_abgr;
} else if (r_off == 1 && g_off == 2 && b_off == 3) {
- merge[0] = gst_bayer_merge_bg_argb;
- merge[1] = gst_bayer_merge_gr_argb;
+ merge[0] = bayer_orc_merge_bg_argb;
+ merge[1] = bayer_orc_merge_gr_argb;
} else if (r_off == 0 && g_off == 1 && b_off == 2) {
- merge[0] = gst_bayer_merge_bg_rgba;
- merge[1] = gst_bayer_merge_gr_rgba;
+ merge[0] = bayer_orc_merge_bg_rgba;
+ merge[1] = bayer_orc_merge_gr_rgba;
}
if (bayer2rgb->format == GST_BAYER_2_RGB_FORMAT_GRBG ||
bayer2rgb->format == GST_BAYER_2_RGB_FORMAT_GBRG) {
GstBuffer * outbuf)
{
GstBayer2RGB *filter = GST_BAYER2RGB (base);
- uint8_t *input, *output;
+ GstMapInfo map;
+ uint8_t *output;
GstVideoFrame frame;
GST_DEBUG ("transforming buffer");
- input = gst_buffer_map (inbuf, NULL, NULL, GST_MAP_READ);
- gst_video_frame_map (&frame, &filter->info, inbuf, GST_MAP_WRITE);
+
+ if (!gst_buffer_map (inbuf, &map, GST_MAP_READ))
+ goto map_failed;
+
+ if (!gst_video_frame_map (&frame, &filter->info, outbuf, GST_MAP_WRITE)) {
+ gst_buffer_unmap (inbuf, &map);
+ goto map_failed;
+ }
output = GST_VIDEO_FRAME_PLANE_DATA (&frame, 0);
- gst_bayer2rgb_process (filter, output, filter->width * 4,
- input, filter->width);
+ gst_bayer2rgb_process (filter, output, frame.info.stride[0],
+ map.data, GST_ROUND_UP_4 (filter->width));
+
gst_video_frame_unmap (&frame);
- gst_buffer_unmap (inbuf, input, -1);
+ gst_buffer_unmap (inbuf, &map);
+
+ return GST_FLOW_OK;
+map_failed:
+ GST_WARNING_OBJECT (base, "Could not map buffer, skipping");
return GST_FLOW_OK;
}