comparison src/image-load.c @ 1497:2c54f3f71634

report pixbuf loader errors https://sourceforge.net/tracker/?func=detail&aid=2720577&group_id=222125&atid=1054680
author nadvornik
date Tue, 31 Mar 2009 19:34:39 +0000
parents 9141908e0609
children 5f49f305a6b6
comparison
equal deleted inserted replaced
1496:03c22c05c6b6 1497:2c54f3f71634
153 { 153 {
154 ImageLoader *il = (ImageLoader *)object; 154 ImageLoader *il = (ImageLoader *)object;
155 155
156 image_loader_stop(il); 156 image_loader_stop(il);
157 157
158 if (il->error) DEBUG_1("%s", image_loader_get_error(il));
159
158 DEBUG_1("freeing image loader %p bytes_read=%d", il, il->bytes_read); 160 DEBUG_1("freeing image loader %p bytes_read=%d", il, il->bytes_read);
159 161
160 if (il->idle_done_id != -1) g_source_remove(il->idle_done_id); 162 if (il->idle_done_id != -1) g_source_remove(il->idle_done_id);
161 163
162 while (g_source_remove_by_user_data(il)) 164 while (g_source_remove_by_user_data(il))
177 g_free(il->area_param_delayed_list->data); 179 g_free(il->area_param_delayed_list->data);
178 il->area_param_delayed_list = g_list_delete_link(il->area_param_delayed_list, il->area_param_delayed_list); 180 il->area_param_delayed_list = g_list_delete_link(il->area_param_delayed_list, il->area_param_delayed_list);
179 } 181 }
180 182
181 if (il->pixbuf) g_object_unref(il->pixbuf); 183 if (il->pixbuf) g_object_unref(il->pixbuf);
184
185 if (il->error) g_error_free(il->error);
182 186
183 file_data_unref(il->fd); 187 file_data_unref(il->fd);
184 #ifdef HAVE_GTHREAD 188 #ifdef HAVE_GTHREAD
185 g_mutex_free(il->data_mutex); 189 g_mutex_free(il->data_mutex);
186 g_cond_free(il->can_destroy_cond); 190 g_cond_free(il->can_destroy_cond);
458 if (!il) return; 462 if (!il) return;
459 463
460 if (il->loader) 464 if (il->loader)
461 { 465 {
462 /* some loaders do not have a pixbuf till close, order is important here */ 466 /* some loaders do not have a pixbuf till close, order is important here */
463 gdk_pixbuf_loader_close(il->loader, NULL); 467 gdk_pixbuf_loader_close(il->loader, il->error ? NULL : &il->error); /* we are interested in the first error only */
464 image_loader_sync_pixbuf(il); 468 image_loader_sync_pixbuf(il);
465 g_object_unref(G_OBJECT(il->loader)); 469 g_object_unref(G_OBJECT(il->loader));
466 il->loader = NULL; 470 il->loader = NULL;
467 } 471 }
468 g_mutex_lock(il->data_mutex); 472 g_mutex_lock(il->data_mutex);
517 { 521 {
518 image_loader_done(il); 522 image_loader_done(il);
519 return FALSE; 523 return FALSE;
520 } 524 }
521 525
522 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL))) 526 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, &il->error)))
523 { 527 {
524 image_loader_error(il); 528 image_loader_error(il);
525 return FALSE; 529 return FALSE;
526 } 530 }
527 531
547 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read); 551 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
548 if (b < 1) return FALSE; 552 if (b < 1) return FALSE;
549 553
550 image_loader_setup_loader(il); 554 image_loader_setup_loader(il);
551 555
552 if (!gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL)) 556 if (!gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, &il->error))
553 { 557 {
554 image_loader_stop_loader(il); 558 image_loader_stop_loader(il);
555 return FALSE; 559 return FALSE;
556 } 560 }
557 561
559 563
560 /* read until size is known */ 564 /* read until size is known */
561 while (il->loader && !gdk_pixbuf_loader_get_pixbuf(il->loader) && b > 0 && !image_loader_get_stopping(il)) 565 while (il->loader && !gdk_pixbuf_loader_get_pixbuf(il->loader) && b > 0 && !image_loader_get_stopping(il))
562 { 566 {
563 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read); 567 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read);
564 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, NULL))) 568 if (b < 0 || (b > 0 && !gdk_pixbuf_loader_write(il->loader, il->mapped_file + il->bytes_read, b, &il->error)))
565 { 569 {
566 image_loader_stop_loader(il); 570 image_loader_stop_loader(il);
567 return FALSE; 571 return FALSE;
568 } 572 }
569 il->bytes_read += b; 573 il->bytes_read += b;
1011 ret = il->shrunk; 1015 ret = il->shrunk;
1012 g_mutex_unlock(il->data_mutex); 1016 g_mutex_unlock(il->data_mutex);
1013 return ret; 1017 return ret;
1014 } 1018 }
1015 1019
1020 const gchar *image_loader_get_error(ImageLoader *il)
1021 {
1022 const gchar *ret = NULL;
1023 if (!il) return NULL;
1024 g_mutex_lock(il->data_mutex);
1025 if (il->error) ret = il->error->message;
1026 g_mutex_unlock(il->data_mutex);
1027 return ret;
1028 }
1029
1016 1030
1017 /* FIXME - this can be rather slow and blocks until the size is known */ 1031 /* FIXME - this can be rather slow and blocks until the size is known */
1018 gboolean image_load_dimensions(FileData *fd, gint *width, gint *height) 1032 gboolean image_load_dimensions(FileData *fd, gint *width, gint *height)
1019 { 1033 {
1020 ImageLoader *il; 1034 ImageLoader *il;