[gst-cvs] gst-plugins-bad: pnm: Use correct rowstride for 8 bit grayscale too

Sebastian Dröge slomo at kemper.freedesktop.org
Sun Sep 13 10:40:15 PDT 2009


Module: gst-plugins-bad
Branch: master
Commit: 5b5ff07c2810d0668ce12a52826a260b39c0c1fd
URL:    http://cgit.freedesktop.org/gstreamer/gst-plugins-bad/commit/?id=5b5ff07c2810d0668ce12a52826a260b39c0c1fd

Author: Sebastian Dröge <sebastian.droege at collabora.co.uk>
Date:   Sun Sep 13 19:39:59 2009 +0200

pnm: Use correct rowstride for 8 bit grayscale too

---

 gst/pnm/gstpnmdec.c |   22 +++++++++++++++-------
 gst/pnm/gstpnmenc.c |   17 +++++++++++++----
 2 files changed, 28 insertions(+), 11 deletions(-)

diff --git a/gst/pnm/gstpnmdec.c b/gst/pnm/gstpnmdec.c
index 0d2dd5a..4b6b15f 100644
--- a/gst/pnm/gstpnmdec.c
+++ b/gst/pnm/gstpnmdec.c
@@ -62,15 +62,23 @@ static GstFlowReturn
 gst_pnmdec_push (GstPnmdec * s, GstPad * src, GstBuffer * buf)
 {
   /* Need to convert from PNM rowstride to GStreamer rowstride */
-  if ((s->mngr.info.type == GST_PNM_TYPE_PIXMAP_ASCII ||
-          s->mngr.info.type == GST_PNM_TYPE_PIXMAP_RAW)
-      && s->mngr.info.width % 4 != 0) {
-    guint i_rowstride = 3 * s->mngr.info.width;
-    guint o_rowstride = GST_ROUND_UP_4 (3 * s->mngr.info.width);
-    GstBuffer *obuf =
-        gst_buffer_new_and_alloc (o_rowstride * s->mngr.info.height);
+  if (s->mngr.info.width % 4 != 0) {
+    guint i_rowstride;
+    guint o_rowstride;
+    GstBuffer *obuf;
     guint i;
 
+    if (s->mngr.info.type == GST_PNM_TYPE_PIXMAP_RAW ||
+        s->mngr.info.type == GST_PNM_TYPE_PIXMAP_ASCII) {
+      i_rowstride = 3 * s->mngr.info.width;
+      o_rowstride = GST_ROUND_UP_4 (i_rowstride);
+    } else {
+      i_rowstride = s->mngr.info.width;
+      o_rowstride = GST_ROUND_UP_4 (i_rowstride);
+    }
+
+    obuf = gst_buffer_new_and_alloc (o_rowstride * s->mngr.info.height);
+
     gst_buffer_copy_metadata (obuf, buf, GST_BUFFER_COPY_ALL);
 
     for (i = 0; i < s->mngr.info.height; i++)
diff --git a/gst/pnm/gstpnmenc.c b/gst/pnm/gstpnmenc.c
index c94ed17..3a9a98a 100644
--- a/gst/pnm/gstpnmenc.c
+++ b/gst/pnm/gstpnmenc.c
@@ -80,12 +80,21 @@ gst_pnmenc_chain (GstPad * pad, GstBuffer * buf)
     goto out;
 
   /* Need to convert from GStreamer rowstride to PNM rowstride */
-  if (s->info.type == GST_PNM_TYPE_PIXMAP_RAW && s->info.width % 4 != 0) {
-    guint i_rowstride = GST_ROUND_UP_4 (s->info.width * 3);
-    guint o_rowstride = s->info.width * 3;
-    GstBuffer *obuf = gst_buffer_new_and_alloc (o_rowstride * s->info.height);
+  if (s->info.width % 4 != 0) {
+    guint i_rowstride;
+    guint o_rowstride;
+    GstBuffer *obuf;
     guint i;
 
+    if (s->info.type == GST_PNM_TYPE_PIXMAP_RAW) {
+      o_rowstride = 3 * s->info.width;
+      i_rowstride = GST_ROUND_UP_4 (o_rowstride);
+    } else {
+      o_rowstride = s->info.width;
+      i_rowstride = GST_ROUND_UP_4 (o_rowstride);
+    }
+
+    obuf = gst_buffer_new_and_alloc (o_rowstride * s->info.height);
     for (i = 0; i < s->info.height; i++)
       memcpy (GST_BUFFER_DATA (obuf) + o_rowstride * i,
           GST_BUFFER_DATA (buf) + i_rowstride * i, o_rowstride);





More information about the Gstreamer-commits mailing list