summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim-Philipp Müller <tim.muller@collabora.co.uk>2010-11-02 17:18:52 +0000
committerTim-Philipp Müller <tim.muller@collabora.co.uk>2010-11-02 17:23:12 +0000
commit7ddd7f7809dafde556c7f9a16e53542722564d1c (patch)
treeb69cd80ff180b9be6d7079a9ae172414ea9da61f
parentff0a34ce3d3954783fc6784ac174d6a458644d54 (diff)
zbar: use correct stride
Fixes detection for images with a width that's not a multiple of four. Based on patch by: Kaj-Michael Lang <milang@tal.org> Based on patch by: Stefan Kost <ensonic@users.sf.net> https://bugzilla.gnome.org/show_bug.cgi?id=630830
-rw-r--r--ext/zbar/gstzbar.c26
-rw-r--r--ext/zbar/gstzbar.h7
2 files changed, 25 insertions, 8 deletions
diff --git a/ext/zbar/gstzbar.c b/ext/zbar/gstzbar.c
index d7e53fb0c..df5774421 100644
--- a/ext/zbar/gstzbar.c
+++ b/ext/zbar/gstzbar.c
@@ -254,14 +254,23 @@ gst_zbar_set_caps (GstBaseTransform * base, GstCaps * incaps, GstCaps * outcaps)
GstZBar *zbar = GST_ZBAR (base);
GstStructure *structure;
gboolean res;
+ guint32 fourcc;
+ gint width, height;
GST_DEBUG_OBJECT (zbar,
"set_caps: in %" GST_PTR_FORMAT " out %" GST_PTR_FORMAT, incaps, outcaps);
structure = gst_caps_get_structure (incaps, 0);
- res = gst_structure_get_int (structure, "width", &zbar->width);
- res &= gst_structure_get_int (structure, "height", &zbar->height);
+ res = gst_structure_get_int (structure, "width", &width);
+ res &= gst_structure_get_int (structure, "height", &height);
+ res &= gst_structure_get_fourcc (structure, "format", &fourcc);
+
+ if (res) {
+ zbar->width = width;
+ zbar->height = height;
+ zbar->format = gst_video_format_from_fourcc (fourcc);
+ }
return res;
}
@@ -271,7 +280,7 @@ gst_zbar_transform_ip (GstBaseTransform * base, GstBuffer * outbuf)
{
GstZBar *zbar = GST_ZBAR (base);
guint8 *data;
- guint size;
+ guint size, rowstride;
zbar_image_t *image;
const zbar_symbol_t *symbol;
int n;
@@ -283,10 +292,11 @@ gst_zbar_transform_ip (GstBaseTransform * base, GstBuffer * outbuf)
size = GST_BUFFER_SIZE (outbuf);
image = zbar_image_create ();
+
zbar_image_set_format (image, GST_MAKE_FOURCC ('Y', '8', '0', '0'));
- zbar_image_set_size (image, zbar->width, zbar->height);
- zbar_image_set_data (image, (gpointer) data, zbar->width * zbar->height,
- NULL);
+ rowstride = gst_video_format_get_row_stride (zbar->format, 0, zbar->width);
+ zbar_image_set_size (image, rowstride, zbar->height);
+ zbar_image_set_data (image, (gpointer) data, rowstride * zbar->height, NULL);
/* scan the image for barcodes */
n = zbar_scan_image (zbar->scanner, image);
@@ -336,6 +346,10 @@ gst_zbar_start (GstBaseTransform * base)
{
GstZBar *zbar = GST_ZBAR (base);
+ zbar->width = 0;
+ zbar->height = 0;
+ zbar->format = GST_VIDEO_FORMAT_UNKNOWN;
+
/* start the cache if enabled (e.g. for filtering dupes) */
zbar_image_scanner_enable_cache (zbar->scanner, zbar->cache);
diff --git a/ext/zbar/gstzbar.h b/ext/zbar/gstzbar.h
index eea1b4fab..b73c8b67e 100644
--- a/ext/zbar/gstzbar.h
+++ b/ext/zbar/gstzbar.h
@@ -22,6 +22,7 @@
#define __GST_VIDEO_ZBAR_H__
#include <gst/video/gstvideofilter.h>
+#include <gst/video/video.h>
#include <zbar.h>
G_BEGIN_DECLS
@@ -51,8 +52,10 @@ struct _GstZBar
GstVideoFilter videofilter;
/* format */
- gint width;
- gint height;
+ gint width;
+ gint height;
+
+ GstVideoFormat format;
/* properties */
gboolean message;