diff --git a/gst/pnm/gstpnmdec.c b/gst/pnm/gstpnmdec.c index 0d2dd5a14e..4b6b15f049 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 c94ed17f35..3a9a98a848 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);