Mercurial > geeqie.yaz
comparison src/image-load.c @ 1433:b4ad1d201279
Use gboolean where applicable, minor cleanup and indentations fixes.
author | zas_ |
---|---|
date | Sat, 14 Mar 2009 19:25:21 +0000 |
parents | c9949c19a6d0 |
children | 9141908e0609 |
comparison
equal
deleted
inserted
replaced
1432:cf4029d10d38 | 1433:b4ad1d201279 |
---|---|
218 guint w; | 218 guint w; |
219 guint h; | 219 guint h; |
220 }; | 220 }; |
221 | 221 |
222 | 222 |
223 static gint image_loader_emit_area_ready_cb(gpointer data) | 223 static gboolean image_loader_emit_area_ready_cb(gpointer data) |
224 { | 224 { |
225 ImageLoaderAreaParam *par = data; | 225 ImageLoaderAreaParam *par = data; |
226 ImageLoader *il = par->il; | 226 ImageLoader *il = par->il; |
227 g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, par->x, par->y, par->w, par->h); | 227 g_signal_emit(il, signals[SIGNAL_AREA_READY], 0, par->x, par->y, par->w, par->h); |
228 g_mutex_lock(il->data_mutex); | 228 g_mutex_lock(il->data_mutex); |
231 g_mutex_unlock(il->data_mutex); | 231 g_mutex_unlock(il->data_mutex); |
232 | 232 |
233 return FALSE; | 233 return FALSE; |
234 } | 234 } |
235 | 235 |
236 static gint image_loader_emit_done_cb(gpointer data) | 236 static gboolean image_loader_emit_done_cb(gpointer data) |
237 { | 237 { |
238 ImageLoader *il = data; | 238 ImageLoader *il = data; |
239 g_signal_emit(il, signals[SIGNAL_DONE], 0); | 239 g_signal_emit(il, signals[SIGNAL_DONE], 0); |
240 return FALSE; | 240 return FALSE; |
241 } | 241 } |
242 | 242 |
243 static gint image_loader_emit_error_cb(gpointer data) | 243 static gboolean image_loader_emit_error_cb(gpointer data) |
244 { | 244 { |
245 ImageLoader *il = data; | 245 ImageLoader *il = data; |
246 g_signal_emit(il, signals[SIGNAL_ERROR], 0); | 246 g_signal_emit(il, signals[SIGNAL_ERROR], 0); |
247 return FALSE; | 247 return FALSE; |
248 } | 248 } |
249 | 249 |
250 static gint image_loader_emit_percent_cb(gpointer data) | 250 static gboolean image_loader_emit_percent_cb(gpointer data) |
251 { | 251 { |
252 ImageLoader *il = data; | 252 ImageLoader *il = data; |
253 g_signal_emit(il, signals[SIGNAL_PERCENT], 0, image_loader_get_percent(il)); | 253 g_signal_emit(il, signals[SIGNAL_PERCENT], 0, image_loader_get_percent(il)); |
254 return FALSE; | 254 return FALSE; |
255 } | 255 } |
304 il->area_param_delayed_list = g_list_prepend(il->area_param_delayed_list, par); | 304 il->area_param_delayed_list = g_list_prepend(il->area_param_delayed_list, par); |
305 } | 305 } |
306 | 306 |
307 | 307 |
308 | 308 |
309 static gint image_loader_get_stopping(ImageLoader *il) | 309 static gboolean image_loader_get_stopping(ImageLoader *il) |
310 { | 310 { |
311 gint ret; | 311 gboolean ret; |
312 if (!il) return FALSE; | 312 if (!il) return FALSE; |
313 | 313 |
314 g_mutex_lock(il->data_mutex); | 314 g_mutex_lock(il->data_mutex); |
315 ret = il->stopping; | 315 ret = il->stopping; |
316 g_mutex_unlock(il->data_mutex); | 316 g_mutex_unlock(il->data_mutex); |
400 gint width, gint height, gpointer data) | 400 gint width, gint height, gpointer data) |
401 { | 401 { |
402 ImageLoader *il = data; | 402 ImageLoader *il = data; |
403 GdkPixbufFormat *format; | 403 GdkPixbufFormat *format; |
404 gchar **mime_types; | 404 gchar **mime_types; |
405 gint scale = FALSE; | 405 gboolean scale = FALSE; |
406 gint n; | 406 gint n; |
407 | 407 |
408 g_mutex_lock(il->data_mutex); | 408 g_mutex_lock(il->data_mutex); |
409 if (il->requested_width < 1 || il->requested_height < 1) | 409 if (il->requested_width < 1 || il->requested_height < 1) |
410 { | 410 { |
499 DEBUG_1("pixbuf_loader reported load error for: %s", il->fd->path); | 499 DEBUG_1("pixbuf_loader reported load error for: %s", il->fd->path); |
500 | 500 |
501 image_loader_emit_error(il); | 501 image_loader_emit_error(il); |
502 } | 502 } |
503 | 503 |
504 static gint image_loader_continue(ImageLoader *il) | 504 static gboolean image_loader_continue(ImageLoader *il) |
505 { | 505 { |
506 gint b; | 506 gint b; |
507 gint c; | 507 gint c; |
508 | 508 |
509 if (!il) return FALSE; | 509 if (!il) return FALSE; |
536 } | 536 } |
537 | 537 |
538 return TRUE; | 538 return TRUE; |
539 } | 539 } |
540 | 540 |
541 static gint image_loader_begin(ImageLoader *il) | 541 static gboolean image_loader_begin(ImageLoader *il) |
542 { | 542 { |
543 gint b; | 543 gssize b; |
544 | 544 |
545 if (il->pixbuf) return FALSE; | 545 if (il->pixbuf) return FALSE; |
546 | 546 |
547 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read); | 547 b = MIN(il->read_buffer_size, il->bytes_total - il->bytes_read); |
548 if (b < 1) return FALSE; | 548 if (b < 1) return FALSE; |
592 | 592 |
593 /**************************************************************************************/ | 593 /**************************************************************************************/ |
594 /* the following functions are always executed in the main thread */ | 594 /* the following functions are always executed in the main thread */ |
595 | 595 |
596 | 596 |
597 static gint image_loader_setup_source(ImageLoader *il) | 597 static gboolean image_loader_setup_source(ImageLoader *il) |
598 { | 598 { |
599 struct stat st; | 599 struct stat st; |
600 gchar *pathl; | 600 gchar *pathl; |
601 | 601 |
602 if (!il || il->loader || il->mapped_file) return FALSE; | 602 if (!il || il->loader || il->mapped_file) return FALSE; |
694 image_loader_stop_loader(il); | 694 image_loader_stop_loader(il); |
695 image_loader_stop_source(il); | 695 image_loader_stop_source(il); |
696 | 696 |
697 } | 697 } |
698 | 698 |
699 void image_loader_delay_area_ready(ImageLoader *il, gint enable) | 699 void image_loader_delay_area_ready(ImageLoader *il, gboolean enable) |
700 { | 700 { |
701 g_mutex_lock(il->data_mutex); | 701 g_mutex_lock(il->data_mutex); |
702 il->delay_area_ready = enable; | 702 il->delay_area_ready = enable; |
703 if (!enable) | 703 if (!enable) |
704 { | 704 { |
729 | 729 |
730 | 730 |
731 /**************************************************************************************/ | 731 /**************************************************************************************/ |
732 /* execution via idle calls */ | 732 /* execution via idle calls */ |
733 | 733 |
734 static gint image_loader_idle_cb(gpointer data) | 734 static gboolean image_loader_idle_cb(gpointer data) |
735 { | 735 { |
736 gint ret = FALSE; | 736 gboolean ret = FALSE; |
737 ImageLoader *il = data; | 737 ImageLoader *il = data; |
738 | |
738 if (il->idle_id != -1) | 739 if (il->idle_id != -1) |
739 { | 740 { |
740 ret = image_loader_continue(il); | 741 ret = image_loader_continue(il); |
741 } | 742 } |
743 | |
742 if (!ret) | 744 if (!ret) |
743 { | 745 { |
744 image_loader_stop_source(il); | 746 image_loader_stop_source(il); |
745 } | 747 } |
748 | |
746 return ret; | 749 return ret; |
747 } | 750 } |
748 | 751 |
749 | 752 |
750 gint image_loader_start_idle(ImageLoader *il) | 753 static gboolean image_loader_start_idle(ImageLoader *il) |
751 { | 754 { |
752 gint ret; | 755 gboolean ret; |
756 | |
753 if (!il) return FALSE; | 757 if (!il) return FALSE; |
754 | 758 |
755 if (!il->fd) return FALSE; | 759 if (!il->fd) return FALSE; |
756 | 760 |
757 if (!image_loader_setup_source(il)) return FALSE; | 761 if (!image_loader_setup_source(il)) return FALSE; |
796 | 800 |
797 g_mutex_unlock(image_loader_prio_mutex); | 801 g_mutex_unlock(image_loader_prio_mutex); |
798 } | 802 } |
799 | 803 |
800 | 804 |
801 void image_loader_thread_run(gpointer data, gpointer user_data) | 805 static void image_loader_thread_run(gpointer data, gpointer user_data) |
802 { | 806 { |
803 ImageLoader *il = data; | 807 ImageLoader *il = data; |
804 gint cont; | 808 gboolean cont; |
805 | 809 |
806 if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE) | 810 if (il->idle_priority > G_PRIORITY_DEFAULT_IDLE) |
807 { | 811 { |
808 /* low prio, wait untill high prio tasks finishes */ | 812 /* low prio, wait untill high prio tasks finishes */ |
809 image_loader_thread_wait_high(); | 813 image_loader_thread_wait_high(); |
849 g_mutex_unlock(il->data_mutex); | 853 g_mutex_unlock(il->data_mutex); |
850 | 854 |
851 } | 855 } |
852 | 856 |
853 | 857 |
854 gint image_loader_start_thread(ImageLoader *il) | 858 static gboolean image_loader_start_thread(ImageLoader *il) |
855 { | 859 { |
856 if (!il) return FALSE; | 860 if (!il) return FALSE; |
857 | 861 |
858 if (!il->fd) return FALSE; | 862 if (!il->fd) return FALSE; |
859 | 863 |
879 | 883 |
880 /**************************************************************************************/ | 884 /**************************************************************************************/ |
881 /* public interface */ | 885 /* public interface */ |
882 | 886 |
883 | 887 |
884 gint image_loader_start(ImageLoader *il) | 888 gboolean image_loader_start(ImageLoader *il) |
885 { | 889 { |
886 if (!il) return FALSE; | 890 if (!il) return FALSE; |
887 | 891 |
888 if (!il->fd) return FALSE; | 892 if (!il->fd) return FALSE; |
889 | 893 |
972 } | 976 } |
973 g_mutex_unlock(il->data_mutex); | 977 g_mutex_unlock(il->data_mutex); |
974 return ret; | 978 return ret; |
975 } | 979 } |
976 | 980 |
977 gint image_loader_get_is_done(ImageLoader *il) | 981 gboolean image_loader_get_is_done(ImageLoader *il) |
978 { | 982 { |
979 gint ret; | 983 gboolean ret; |
980 if (!il) return FALSE; | 984 if (!il) return FALSE; |
981 | 985 |
982 g_mutex_lock(il->data_mutex); | 986 g_mutex_lock(il->data_mutex); |
983 ret = il->done; | 987 ret = il->done; |
984 g_mutex_unlock(il->data_mutex); | 988 g_mutex_unlock(il->data_mutex); |
996 g_mutex_unlock(il->data_mutex); | 1000 g_mutex_unlock(il->data_mutex); |
997 | 1001 |
998 return ret; | 1002 return ret; |
999 } | 1003 } |
1000 | 1004 |
1001 gint image_loader_get_shrunk(ImageLoader *il) | 1005 gboolean image_loader_get_shrunk(ImageLoader *il) |
1002 { | 1006 { |
1003 gint ret; | 1007 gboolean ret; |
1004 if (!il) return FALSE; | 1008 if (!il) return FALSE; |
1005 | 1009 |
1006 g_mutex_lock(il->data_mutex); | 1010 g_mutex_lock(il->data_mutex); |
1007 ret = il->shrunk; | 1011 ret = il->shrunk; |
1008 g_mutex_unlock(il->data_mutex); | 1012 g_mutex_unlock(il->data_mutex); |
1009 return ret; | 1013 return ret; |
1010 } | 1014 } |
1011 | 1015 |
1012 | 1016 |
1013 /* FIXME - this can be rather slow and blocks until the size is known */ | 1017 /* FIXME - this can be rather slow and blocks until the size is known */ |
1014 gint image_load_dimensions(FileData *fd, gint *width, gint *height) | 1018 gboolean image_load_dimensions(FileData *fd, gint *width, gint *height) |
1015 { | 1019 { |
1016 ImageLoader *il; | 1020 ImageLoader *il; |
1017 gint success; | 1021 gboolean success; |
1018 | 1022 |
1019 il = image_loader_new(fd); | 1023 il = image_loader_new(fd); |
1020 | 1024 |
1021 success = image_loader_start_idle(il); | 1025 success = image_loader_start_idle(il); |
1022 | 1026 |