pnmdec: Patch to handle max value

Convert the image values from 0-maxvalue to 0-255 when
'decoding' the pnm image

https://bugzilla.gnome.org/show_bug.cgi?id=731773
This commit is contained in:
Sanjay NM 2014-06-18 11:44:54 +05:30 committed by Thiago Santos
parent e26e112e80
commit 15a2da8ba7
2 changed files with 25 additions and 1 deletions

View file

@ -193,7 +193,7 @@ gst_pnmdec_handle_frame (GstVideoDecoder * decoder, GstVideoCodecFrame * frame)
guint i_rowstride;
guint o_rowstride;
GstFlowReturn r = GST_FLOW_OK;
gint bytes, i;
gint bytes, i, total_bytes = 0;
r = gst_video_decoder_allocate_output_frame (decoder, frame);
if (r != GST_FLOW_OK) {
@ -224,6 +224,7 @@ gst_pnmdec_handle_frame (GstVideoDecoder * decoder, GstVideoCodecFrame * frame)
omap.data[i * 8 + 6] = (imap.data[i] & 0x02) ? 0 : 255;
omap.data[i * 8 + 7] = (imap.data[i] & 0x01) ? 0 : 255;
}
total_bytes = bytes * 8;
} else
/* Need to convert from PNM rowstride to GStreamer rowstride */
if (s->mngr.info.width % 4 != 0) {
@ -238,8 +239,26 @@ gst_pnmdec_handle_frame (GstVideoDecoder * decoder, GstVideoCodecFrame * frame)
for (i = 0; i < s->mngr.info.height; i++)
memcpy (omap.data + i * o_rowstride, imap.data + i * i_rowstride,
i_rowstride);
total_bytes = o_rowstride * s->mngr.info.height;
} else {
memcpy (omap.data, imap.data, s->size);
total_bytes = s->size;
}
if (s->mngr.info.type != GST_PNM_TYPE_BITMAP) {
/* Convert the pixels from 0 - max range to 0 - 255 range */
if (s->mngr.info.max < 255) {
gint max = s->mngr.info.max;
for (i = 0; i < total_bytes; i++) {
if (omap.data[i] <= max) {
omap.data[i] = 255 * omap.data[i] / max;
} else {
/* This is an error case, wherein value in the data stream is
more than max. Clamp such values to 255 */
omap.data[i] = 255;
}
}
}
}
if (s->mngr.info.encoding == GST_PNM_ENCODING_ASCII) {

View file

@ -176,6 +176,11 @@ gst_pnm_info_mngr_scan (GstPnmInfoMngr * mngr, const guint8 * buf,
case '\n':
case '\t':
case ' ':
/* Check for maximum and minimum supported bit depth and
return error if its out of range */
if ((mngr->info.max > 255) || (mngr->info.max < 1)) {
return GST_PNM_INFO_MNGR_RESULT_FAILED;
}
mngr->info.fields |= GST_PNM_INFO_FIELDS_MAX;
mngr->data_offset += i + 1;
return GST_PNM_INFO_MNGR_RESULT_FINISHED;