class Entry
@@thumbnails_height = 64
- @@max_height = nil
+ @@max_width = nil
def Entry.thumbnails_height
return @@thumbnails_height
end
def initialize(path, type)
@path = path
@type = type
- if @@max_height.nil?
- @@max_height = $main_window.root_window.size[1]
+ if @@max_width.nil?
+ @@max_width = $main_window.root_window.size[0] - $labels_vbox.allocation.width
end
@protect_cleanup = Mutex.new
end
image_path = @path
end
begin
- @pixbuf_full = Gdk::Pixbuf.new(image_path)
+ #- use a pixbuf loader to allow the loading thread to be interrupted by the main thread more often, to keep the UI responsive even
+ #- if loaded pictures are several MBs large
+ loader = Gdk::PixbufLoader.new
+ loader.signal_connect('size-prepared') { |l,w,h|
+ maxdim = w > h ? w : h
+ if maxdim > @@max_width
+ #- save memory and speedup (+35%) loading
+ loader.set_size(w * (factor = @@max_width.to_f/maxdim), h * factor)
+ puts factor
+ end
+ }
+ loader.signal_connect('area-prepared') { @pixbuf_full = loader.pixbuf }
+ file = File.new(image_path)
+ while (chunk = file.read(4096)) != nil
+ loader.write(chunk)
+ end
+ file.close
+ loader.close
+ if @pixbuf_full.nil?
+ raise "Loaded pixbuf nil - #{path} #{image_path}"
+ end
rescue Gdk::PixbufError
msg 0, "Cannot load #{image_path}: #{$!}"
return
msg 3, ">>> load_into_pixbuf_full #{image_path} => rotate #{@angle}"
@pixbuf_full = rotate_pixbuf(@pixbuf_full, @angle)
end
- if @pixbuf_full.height > @@max_height
- #- save a lot of memory, don't store in actual full size
- @pixbuf_full = @pixbuf_full.scale(@pixbuf_full.width * (@@max_height.to_f/@pixbuf_full.height), @@max_height, Gdk::Pixbuf::INTERP_BILINEAR)
- end
end
if @type == 'video'
cleanup_dir(dest_dir)
@preloader = Thread.new {
#- background preloading
while true
- msg 3, "background main preloading triggered..."
+ msg 3, "*** >> background main preloading triggered..."
if ! @entry.nil?
index = $allentries.index(@entry)
w, h = window.size
end
check_memory_free_cache_if_needed
end
+ msg 3, "*** << background main preloading stopping"
Thread.stop
end
}