add ability to choose to optimize for 3/2 aspect ratio
authorgc <gc>
Thu, 28 Jul 2005 20:57:52 +0000 (20:57 +0000)
committergc <gc>
Thu, 28 Jul 2005 20:57:52 +0000 (20:57 +0000)
bin/booh
bin/booh-backend
data/booh/themes/simple/metadata/parameters.rb
lib/booh/booh-lib.rb

index 5b9163e..4943d57 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -2087,9 +2087,10 @@ def open_file(filename)
     end
 
     limit_sizes = $xmldoc.root.attributes['limit-sizes']
+    optimizefor32 = !$xmldoc.root.attributes['optimize-for-32'].nil?
 
     $filename = filename
-    select_theme(theme, limit_sizes)
+    select_theme(theme, limit_sizes, optimizefor32)
     $default_size['thumbnails'] =~ /(.*)x(.*)/
     $default_thumbnails = { :x => $1.to_i, :y => $2.to_i }
     $albums_thumbnail_size =~ /(.*)x(.*)/
@@ -2196,15 +2197,14 @@ def new_album
     tbl.attach(conf_browse = Gtk::Button.new(utf8(_("browse..."))),
                2, 3, 3, 4, Gtk::SHRINK, Gtk::SHRINK, 2, 2)
 
-    frame2 = Gtk::Frame.new(utf8(_("Configuration"))).add(tbl = Gtk::Table.new(0, 0, false))
-    tbl.attach(Gtk::Label.new(utf8(_("Theme: "))),
-               0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 2, 2)
-    tbl.attach(theme_button = Gtk::Button.new($config['default-theme'] || 'simple'),
-               1, 2, 0, 1, Gtk::FILL, Gtk::SHRINK, 2, 2)
-    tbl.attach(Gtk::Label.new(utf8(_("Sizes of images to generate: "))),
-               0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 2, 2)
-    tbl.attach(sizes = Gtk::HBox.new,
-               1, 3, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 2, 2)
+    tooltips = Gtk::Tooltips.new
+    frame2 = Gtk::Frame.new(utf8(_("Configuration"))).add(vb = Gtk::VBox.new)
+    vb.add(Gtk::HBox.new(false, 3).pack_start(Gtk::Label.new(utf8(_("Theme: "))), false, false, 0).
+                         pack_start(theme_button = Gtk::Button.new($config['default-theme'] || 'simple'), false, false, 0))
+    vb.add(Gtk::HBox.new(false, 3).pack_start(Gtk::Label.new(utf8(_("Sizes of images to generate: "))), false, false, 0).
+                                   pack_start(sizes = Gtk::HBox.new, false, false, 0))
+    vb.add(optimize432 = Gtk::CheckButton.new(utf8(_("Optimize for 3/2 aspect ratio"))))
+    tooltips.set_tip(optimize432, utf8(_("Resize images with optimized sizes for 3/2 aspect ratio rather than 4/3 (typical aspect ratio of pictures from non digital cameras are 3/2 when pictures from digital cameras are 4/3)")), nil)
 
     src_nb_calculated_for = ''
     src_nb_thread = nil
@@ -2295,13 +2295,12 @@ def new_album
     recreate_theme_config = proc {
         theme_sizes.each { |e| sizes.remove(e[:widget]) }
         theme_sizes = []
-        select_theme(theme_button.label, 'all')
+        select_theme(theme_button.label, 'all', optimize432.active?)
         $images_size.each { |s|
             sizes.add(cb = Gtk::CheckButton.new(sizename(s['name'])))
             if !s['optional']
                 cb.active = true
             end
-            tooltips = Gtk::Tooltips.new
             tooltips.set_tip(cb, utf8(s['description']), nil)
             theme_sizes << { :widget => cb, :value => s['name'] }
         }
@@ -2368,6 +2367,7 @@ def new_album
     configskel = File.expand_path(from_utf8(conf.text))
     theme = theme_button.label
     sizes = theme_sizes.find_all { |e| e[:widget].active? }.collect { |e| e[:value] }.join(',')
+    opt432 = optimize432.active?
     if src_nb_thread
         Thread.kill(src_nb_thread)
         gtk_thread_abandon  #- needed because we're about to destroy widgets in dialog, for which they may be some pending gtk calls
@@ -2377,7 +2377,7 @@ def new_album
 
     if ok
         call_backend("booh-backend --source '#{srcdir}' --destination '#{destdir}' --config-skel '#{configskel}' --for-gui " +
-                     "--verbose-level #{$verbose_level} --theme #{theme} --sizes #{sizes} #{additional_booh_options}",
+                     "--verbose-level #{$verbose_level} --theme #{theme} --sizes #{sizes} #{opt432 ? '--optimize-for-32' : ''} #{additional_booh_options}",
                      utf8(_("Please wait while scanning source directory...")),
                      'full scan',
                      { :closure_after => proc { open_file(configskel) } })
@@ -2394,11 +2394,13 @@ def properties
     source = $xmldoc.root.attributes['source']
     dest = $xmldoc.root.attributes['destination']
     theme = $xmldoc.root.attributes['theme']
+    opt432 = !$xmldoc.root.attributes['optimize-for-32'].nil?
     limit_sizes = $xmldoc.root.attributes['limit-sizes']
     if limit_sizes
         limit_sizes = limit_sizes.split(/,/)
     end
 
+    tooltips = Gtk::Tooltips.new
     frame1 = Gtk::Frame.new(utf8(_("Locations"))).add(tbl = Gtk::Table.new(0, 0, false))
     tbl.attach(Gtk::Label.new(utf8(_("Directory of source images/videos: "))),
                0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 2, 2)
@@ -2413,21 +2415,19 @@ def properties
     tbl.attach(Gtk::Alignment.new(0, 0.5, 0, 0).add(Gtk::Label.new.set_markup('<i>' + $orig_filename + '</i>')),
                1, 2, 3, 4, Gtk::FILL, Gtk::SHRINK, 2, 2)
 
-    frame2 = Gtk::Frame.new(utf8(_("Configuration"))).add(tbl = Gtk::Table.new(0, 0, false))
-    tbl.attach(Gtk::Label.new(utf8(_("Theme: "))),
-               0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 2, 2)
-    tbl.attach(theme_button = Gtk::Button.new(theme),
-               1, 2, 0, 1, Gtk::FILL, Gtk::SHRINK, 2, 2)
-    tbl.attach(Gtk::Label.new(utf8(_("Sizes of images to generate: "))),
-               0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 2, 2)
-    tbl.attach(sizes = Gtk::HBox.new,
-               1, 3, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 2, 2)
+    frame2 = Gtk::Frame.new(utf8(_("Configuration"))).add(vb = Gtk::VBox.new)
+    vb.add(Gtk::HBox.new(false, 3).pack_start(Gtk::Label.new(utf8(_("Theme: "))), false, false, 0).
+                         pack_start(theme_button = Gtk::Button.new(theme), false, false, 0))
+    vb.add(Gtk::HBox.new(false, 3).pack_start(Gtk::Label.new(utf8(_("Sizes of images to generate: "))), false, false, 0).
+                                   pack_start(sizes = Gtk::HBox.new, false, false, 0))
+    vb.add(optimize432 = Gtk::CheckButton.new(utf8(_("Optimize for 3/2 aspect ratio"))).set_active(opt432))
+    tooltips.set_tip(optimize432, utf8(_("Resize images with optimized sizes for 3/2 aspect ratio rather than 4/3 (typical aspect ratio of pictures from non digital cameras are 3/2 when pictures from digital cameras are 4/3)")), nil)
 
     theme_sizes = []
     recreate_theme_config = proc {
         theme_sizes.each { |e| sizes.remove(e[:widget]) }
         theme_sizes = []
-        select_theme(theme_button.label, 'all')
+        select_theme(theme_button.label, 'all', optimize432.active?)
         $images_size.each { |s|
             sizes.add(cb = Gtk::CheckButton.new(sizename(s['name'])))
             if limit_sizes
@@ -2439,7 +2439,6 @@ def properties
                     cb.active = true
                 end
             end
-            tooltips = Gtk::Tooltips.new
             tooltips.set_tip(cb, utf8(s['description']), nil)
             theme_sizes << { :widget => cb, :value => s['name'] }
         }
@@ -2484,12 +2483,16 @@ def properties
     end
     save_theme = theme_button.label
     save_limit_sizes = theme_sizes.find_all { |e| e[:widget].active? }.collect { |e| e[:value] }
+    save_opt432 = optimize432.active?
     dialog.destroy
 
-    if ok && (save_theme != theme || save_limit_sizes != limit_sizes)
+    if ok && (save_theme != theme || save_limit_sizes != limit_sizes || save_opt432 != opt432)
+        $xmldoc.elements.each('//dir') { |elem|
+            elem.delete_attribute('already-generated')
+        }
         save_current_file
-        call_backend("booh-backend --use-config '#{$filename}' --for-gui " +
-                     "--verbose-level #{$verbose_level} --theme #{theme} --sizes #{save_limit_sizes.join(',')} #{additional_booh_options}",
+        call_backend("booh-backend --use-config '#{$filename}' --for-gui --verbose-level #{$verbose_level} " +
+                     "--theme #{theme} --sizes #{save_limit_sizes.join(',')} #{save_opt432 ? '--optimize-for-32' : ''} #{additional_booh_options}",
                      utf8(_("Please wait while scanning source directory...")),
                      'full scan',
                      { :closure_after => proc { open_file($filename) } })
index 30c2a5c..35eddd6 100755 (executable)
@@ -52,6 +52,7 @@ $options = [
     [ '--force',         '-f', GetoptLong::NO_ARGUMENT,       _("Force generation of album even if the GUI marked some directories as already generated") ],
 
     [ '--sizes',         '-S', GetoptLong::REQUIRED_ARGUMENT, _("Specify the list of images sizes to use instead of all specified in the theme (this is a comma-separated list)") ],
+    [ '--optimize-for-32', '-o', GetoptLong::NO_ARGUMENT,       _("Resize images with optimized sizes for 3/2 aspect ratio rather than 4/3 (typical aspect ratio of pictures from non digital cameras are 3/2 when pictures from digital cameras are 4/3)") ],
     [ '--empty-comments','-e', GetoptLong::NO_ARGUMENT,       _("Prefer empty comments over filename when creating new albums") ],
 
     [ '--mproc',         '-m', GetoptLong::REQUIRED_ARGUMENT, _("Specify the number of processors for multi-processors machines") ],
@@ -173,6 +174,9 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
             when '--sizes'
                 $limit_sizes = arg
 
+            when '--optimize-for-32'
+                $optimize_for_32 = true
+
             when '--empty-comments'
                 $empty_comments = true
 
@@ -205,6 +209,9 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
         $dest = from_utf8($xmldoc.root.attributes['destination'])
         $theme = $xmldoc.root.attributes['theme']
         $limit_sizes ||= $xmldoc.root.attributes['limit-sizes']
+        if $mode == 'use_config'
+            $optimize_for_32 = !$xmldoc.root.attributes['optimize-for-32'].nil?
+        end
     end
 
     if $mode == 'merge_config_onedir' && !$onedir
@@ -222,13 +229,16 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
         $theme = 'simple'
     end
 
-    select_theme($theme, $limit_sizes)
+    select_theme($theme, $limit_sizes, $optimize_for_32)
 
     if !$xmldoc
         additional_params = ''
         if $limit_sizes
             additional_params += "limit-sizes='#{$limit_sizes}'"
         end
+        if $optimize_for_32
+            additional_params += " optimize-for-32='true'"
+        end
         $xmldoc = Document.new "<booh version='#{$VERSION}' source='#{utf8($source)}' destination='#{utf8($dest)}' theme='#{$theme}' #{additional_params}/>"
         $xmldoc << XMLDecl.new(XMLDecl::DEFAULT_VERSION, $CURRENT_CHARSET)
         $mode = 'gen_config'
@@ -241,6 +251,11 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.") %
         else
             $xmldoc.root.delete_attribute('limit-sizes')
         end
+        if $optimize_for_32
+            $xmldoc.root.add_attribute('optimize-for-32', 'true')
+        else
+            $xmldoc.root.delete_attribute('optimize-for-32')
+        end
     end
 end
 
index ecd7f0d..5dfe518 100644 (file)
@@ -24,6 +24,8 @@ bindtextdomain("booh")
 #- one for 1024x768 and one for 1280x1024
 #- it's necessary to fit according to the typical space taken by
 #- widgets defined in the skeleton of the theme
+#-
+#- ***IMPORTANT***: CHOOSE 4/3 ASPECT RATIO SIZES!
 $images_size = [
     {
         'name' => 'small',
index 6b0b691..36ed034 100644 (file)
@@ -87,7 +87,7 @@ module Booh
         exit 1
     end
 
-    def select_theme(name, limit_sizes)
+    def select_theme(name, limit_sizes, optimizefor32)
         $theme = name
         msg 3, _("Selecting theme `%s'") % $theme
         themedir = "#{$FPATH}/themes/#{$theme}"
@@ -108,6 +108,14 @@ module Booh
             $images_size = $images_size.find_all { |e| !e['optional'] }
         end
 
+        if optimizefor32
+            $images_size.each { |e|
+                e['fullscreen'].gsub!(/(\d+x)(\d+)/) { $1 + ($2.to_f*8/9).to_i.to_s }
+                e['thumbnails'].gsub!(/(\d+x)(\d+)/) { $1 + ($2.to_f*8/9).to_i.to_s }
+            }
+            $albums_thumbnail_size.gsub!(/(\d+x)(\d+)/) { $1 + ($2.to_f*8/9).to_i.to_s }
+        end
+
         $default_size = $images_size.detect { |sizeobj| sizeobj['default'] }
         if $default_size == nil
             $default_size = $images_size[0]