[687/906] bumper: error out properly if we cannot load the png file

This commit is contained in:
Matthew Waters 2013-04-24 14:24:27 +10:00
parent 8fe4849860
commit 3960306218

View file

@ -139,7 +139,7 @@ static const gchar *bumper_f_src =
" gl_FragColor = vec4(irradiance * textureColor.rgb, textureColor.w);\n" " gl_FragColor = vec4(irradiance * textureColor.rgb, textureColor.w);\n"
"}\n"; "}\n";
#define LOAD_ERROR(msg) { GST_WARNING ("unable to load %s: %s", bumper->location, msg); display->isAlive = FALSE; return; } #define LOAD_ERROR(display, msg) { gst_gl_display_set_error (display, "unable to load %s: %s", bumper->location, msg); display->isAlive = FALSE; return; }
//png reading error handler //png reading error handler
static void static void
@ -169,32 +169,32 @@ gst_gl_bumper_init_resources (GstGLFilter * filter)
png_byte magic[8]; png_byte magic[8];
gint n_read; gint n_read;
if (!filter->display) if (!display)
return; return;
/* BEGIN load png image file */ /* BEGIN load png image file */
if ((fp = fopen (bumper->location, "rb")) == NULL) if ((fp = fopen (bumper->location, "rb")) == NULL)
LOAD_ERROR ("file not found"); LOAD_ERROR (display, "file not found");
/* Read magic number */ /* Read magic number */
n_read = fread (magic, 1, sizeof (magic), fp); n_read = fread (magic, 1, sizeof (magic), fp);
if (n_read != sizeof (magic)) { if (n_read != sizeof (magic)) {
fclose (fp); fclose (fp);
LOAD_ERROR ("can't read PNG magic number"); LOAD_ERROR (display, "can't read PNG magic number");
} }
/* Check for valid magic number */ /* Check for valid magic number */
if (png_sig_cmp (magic, 0, sizeof (magic))) { if (png_sig_cmp (magic, 0, sizeof (magic))) {
fclose (fp); fclose (fp);
LOAD_ERROR ("not a valid PNG image"); LOAD_ERROR (display, "not a valid PNG image");
} }
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
if (png_ptr == NULL) { if (png_ptr == NULL) {
fclose (fp); fclose (fp);
LOAD_ERROR ("failed to initialize the png_struct"); LOAD_ERROR (display, "failed to initialize the png_struct");
} }
png_set_error_fn (png_ptr, NULL, NULL, user_warning_fn); png_set_error_fn (png_ptr, NULL, NULL, user_warning_fn);
@ -203,7 +203,8 @@ gst_gl_bumper_init_resources (GstGLFilter * filter)
if (info_ptr == NULL) { if (info_ptr == NULL) {
fclose (fp); fclose (fp);
png_destroy_read_struct (&png_ptr, png_infopp_NULL, png_infopp_NULL); png_destroy_read_struct (&png_ptr, png_infopp_NULL, png_infopp_NULL);
LOAD_ERROR ("failed to initialize the memory for image information"); LOAD_ERROR (display,
"failed to initialize the memory for image information");
} }
png_init_io (png_ptr, fp); png_init_io (png_ptr, fp);
@ -218,7 +219,7 @@ gst_gl_bumper_init_resources (GstGLFilter * filter)
if (color_type != PNG_COLOR_TYPE_RGB) { if (color_type != PNG_COLOR_TYPE_RGB) {
fclose (fp); fclose (fp);
png_destroy_read_struct (&png_ptr, png_infopp_NULL, png_infopp_NULL); png_destroy_read_struct (&png_ptr, png_infopp_NULL, png_infopp_NULL);
LOAD_ERROR ("color type is not rgb"); LOAD_ERROR (display, "color type is not rgb");
} }
raw_data = (guchar *) malloc (sizeof (guchar) * width * height * 3); raw_data = (guchar *) malloc (sizeof (guchar) * width * height * 3);