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
This commit is contained in:
Tim-Philipp Müller 2010-11-02 17:18:52 +00:00
parent ff0a34ce3d
commit 7ddd7f7809
2 changed files with 25 additions and 8 deletions

View file

@ -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);

View file

@ -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
@ -54,6 +55,8 @@ struct _GstZBar
gint width;
gint height;
GstVideoFormat format;
/* properties */
gboolean message;
gboolean cache;