diff --git a/ChangeLog b/ChangeLog index f5ca7a79dc..680de4fe22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,15 @@ +2005-01-09 Gergely Nagy + + Reviewed by: Ronald S. Bultje + + * ext/libpng/gstpngdec.c: (gst_pngdec_src_getcaps), + (gst_pngdec_chain): + Handle only 8-bppc (bits-per-pixel-component) images, better + error handling and correct strides. Fixes #163177. + * ext/libpng/gstpngenc.c: (gst_pngenc_sinklink), + (gst_pngenc_chain): + Better error handling. Fixes #163348. + 2005-01-09 Ronald S. Bultje * ext/dvdnav/dvdnavsrc.c: (dvdnavsrc_get_type), diff --git a/ext/libpng/gstpngdec.c b/ext/libpng/gstpngdec.c index 1cb4158271..7f860e3881 100644 --- a/ext/libpng/gstpngdec.c +++ b/ext/libpng/gstpngdec.c @@ -185,6 +185,12 @@ gst_pngdec_src_getcaps (GstPad * pad) if (pngdec->color_type != -1) { GstCaps *to_inter = NULL; + if (pngdec->info && pngdec->info->bit_depth != 8) { + GST_ELEMENT_ERROR (pngdec, STREAM, NOT_IMPLEMENTED, (NULL), + ("pngdec only supports 8 bit images for now")); + return NULL; + } + switch (pngdec->color_type) { case PNG_COLOR_TYPE_RGB: to_inter = gst_caps_new_simple ("video/x-raw-rgb", @@ -269,30 +275,38 @@ gst_pngdec_chain (GstPad * pad, GstData * _data) pngdec->png = png_create_read_struct (PNG_LIBPNG_VER_STRING, (png_voidp) NULL, user_error_fn, user_warning_fn); - /* FIXME: better error handling */ if (pngdec->png == NULL) { - g_warning ("Failed to initialize png structure"); + gst_buffer_unref (buf); + GST_ELEMENT_ERROR (pngdec, LIBRARY, INIT, (NULL), + ("Failed to initialize png structure")); return; } pngdec->info = png_create_info_struct (pngdec->png); if (pngdec->info == NULL) { - g_warning ("Failed to initialize info structure"); + gst_buffer_unref (buf); png_destroy_read_struct (&(pngdec->png), (png_infopp) NULL, (png_infopp) NULL); + GST_ELEMENT_ERROR (pngdec, LIBRARY, INIT, (NULL), + ("Failed to initialize info structure")); return; } pngdec->endinfo = png_create_info_struct (pngdec->png); if (pngdec->endinfo == NULL) { - g_warning ("Failed to initialize endinfo structure"); + gst_buffer_unref (buf); + png_destroy_read_struct (&pngdec->png, &pngdec->info, (png_infopp) NULL); + GST_ELEMENT_ERROR (pngdec, LIBRARY, INIT, (NULL), + ("Failed to initialize endinfo structure")); return; } /* non-0 return is from a longjmp inside of libpng */ if (setjmp (pngdec->png->jmpbuf) != 0) { - GST_DEBUG ("returning from longjmp"); + gst_buffer_unref (buf); png_destroy_read_struct (&pngdec->png, &pngdec->info, &pngdec->endinfo); + GST_ELEMENT_ERROR (pngdec, LIBRARY, FAILED, (NULL), + ("returning from longjmp")); return; } @@ -302,8 +316,6 @@ gst_pngdec_chain (GstPad * pad, GstData * _data) png_get_IHDR (pngdec->png, pngdec->info, &width, &height, &depth, &color, NULL, NULL, NULL); - GST_LOG ("color type: %d\n", pngdec->info->color_type); - if (pngdec->width != width || pngdec->height != height || pngdec->color_type != pngdec->info->color_type) { @@ -312,6 +324,8 @@ gst_pngdec_chain (GstPad * pad, GstData * _data) pngdec->color_type = pngdec->info->color_type; if (GST_PAD_LINK_FAILED (gst_pad_renegotiate (pngdec->srcpad))) { + gst_buffer_unref (buf); + png_destroy_read_struct (&pngdec->png, &pngdec->info, &pngdec->endinfo); GST_ELEMENT_ERROR (pngdec, CORE, NEGOTIATION, (NULL), (NULL)); return; } @@ -319,14 +333,13 @@ gst_pngdec_chain (GstPad * pad, GstData * _data) rows = (png_bytep *) g_malloc (sizeof (png_bytep) * height); - out = - gst_pad_alloc_buffer (pngdec->srcpad, GST_BUFFER_OFFSET_NONE, - width * height * 4); + out = gst_pad_alloc_buffer (pngdec->srcpad, GST_BUFFER_OFFSET_NONE, + height * pngdec->info->rowbytes); inp = GST_BUFFER_DATA (out); for (i = 0; i < height; i++) { rows[i] = inp; - inp += width * 4; + inp += pngdec->info->rowbytes; } png_read_image (pngdec->png, rows); diff --git a/ext/libpng/gstpngenc.c b/ext/libpng/gstpngenc.c index e958dfeff2..5b357e923c 100644 --- a/ext/libpng/gstpngenc.c +++ b/ext/libpng/gstpngenc.c @@ -160,6 +160,8 @@ gst_pngenc_sinklink (GstPad * pad, const GstCaps * caps) GstPngEnc *pngenc; gdouble fps; GstStructure *structure; + GstCaps *pcaps; + GstPadLinkReturn ret; pngenc = GST_PNGENC (gst_pad_get_parent (pad)); @@ -169,12 +171,14 @@ gst_pngenc_sinklink (GstPad * pad, const GstCaps * caps) gst_structure_get_double (structure, "framerate", &fps); gst_structure_get_int (structure, "bpp", &pngenc->bpp); - caps = gst_caps_new_simple ("image/png", + pcaps = gst_caps_new_simple ("image/png", "framerate", G_TYPE_DOUBLE, fps, "width", G_TYPE_INT, pngenc->width, "height", G_TYPE_INT, pngenc->height, NULL); - return gst_pad_try_set_caps (pngenc->srcpad, caps); + ret = gst_pad_try_set_caps (pngenc->srcpad, pcaps); + gst_caps_free (pcaps); + return ret; } static void @@ -250,20 +254,28 @@ gst_pngenc_chain (GstPad * pad, GstData * _data) /* initialize png struct stuff */ pngenc->png_struct_ptr = png_create_write_struct (PNG_LIBPNG_VER_STRING, (png_voidp) NULL, user_error_fn, user_warning_fn); - /* FIXME: better error handling */ - if (pngenc->png_struct_ptr == NULL) - g_warning ("Failed to initialize png structure"); + if (pngenc->png_struct_ptr == NULL) { + gst_buffer_unref (buf); + GST_ELEMENT_ERROR (pngenc, LIBRARY, INIT, (NULL), + ("Failed to initialize png structure")); + return; + } pngenc->png_info_ptr = png_create_info_struct (pngenc->png_struct_ptr); if (!pngenc->png_info_ptr) { - png_destroy_read_struct (&(pngenc->png_struct_ptr), (png_infopp) NULL, - (png_infopp) NULL); + gst_buffer_unref (buf); + png_destroy_write_struct (&(pngenc->png_struct_ptr), (png_infopp) NULL); + GST_ELEMENT_ERROR (pngenc, LIBRARY, INIT, (NULL), + ("Failed to initialize the png info structure")); + return; } /* non-0 return is from a longjmp inside of libpng */ if (setjmp (pngenc->png_struct_ptr->jmpbuf) != 0) { - GST_DEBUG ("returning from longjmp"); + gst_buffer_unref (buf); png_destroy_write_struct (&pngenc->png_struct_ptr, &pngenc->png_info_ptr); + GST_ELEMENT_ERROR (pngenc, LIBRARY, FAILED, (NULL), + ("returning from longjmp")); return; } @@ -285,7 +297,7 @@ gst_pngenc_chain (GstPad * pad, GstData * _data) for (row_index = 0; row_index < pngenc->height; row_index++) row_pointers[row_index] = GST_BUFFER_DATA (buf) + - (pngenc->width * row_index * pngenc->bpp / 8); + (row_index * pngenc->png_info_ptr->rowbytes); png_write_info (pngenc->png_struct_ptr, pngenc->png_info_ptr); png_write_image (pngenc->png_struct_ptr, row_pointers);