add image enhance support
authorgc <gc>
Mon, 11 Apr 2005 22:31:28 +0000 (22:31 +0000)
committergc <gc>
Mon, 11 Apr 2005 22:31:28 +0000 (22:31 +0000)
bin/booh-gui
data/booh/images/stock-channels-16.png [new file with mode: 0644]
lib/booh/booh-lib.rb

index fda76ca9e574a084cb1e115540df5a27943b31e9..6b707340f9137cb800eaadd0fa7dcd436964852b 100755 (executable)
@@ -126,10 +126,9 @@ def write_config
 end
 
 def set_mousecursor(widget, what)
-    if !widget.window
-        widget.realize
+    if widget.window
+        widget.window.set_cursor(Gdk::Cursor.new(what))
     end
-    widget.window.set_cursor(Gdk::Cursor.new(what))
 end
 def set_mousecursor_wait(widget)
     set_mousecursor(widget, Gdk::Cursor::WATCH)
@@ -269,8 +268,10 @@ end
 def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
 
     img = nil
+    frame1 = Gtk::Frame.new
     gen_real_thumbnail = Proc.new {
         Thread.new {
+            set_mousecursor_wait(frame1)
             gen_thumbnails_element(from_utf8("#{$current_path}/#{filename}"), $xmldir, false, [ { 'filename' => thumbnail_img, 'size' => $default_size['thumbnails'] } ])
             img.set(thumbnail_img)
             $rotated_pixbufs[thumbnail_img] = { :orig => img.pixbuf, :pixbuf => img.pixbuf, :angle_to_orig => 0 }
@@ -278,10 +279,10 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
                 #- cleanup temp for videos
                 system("rm -f #{current_dest_dir}/screenshot.jpg00000*")
             end
+            set_mousecursor_normal(frame1)
         }
     }
 
-    frame1 = Gtk::Frame.new
     #- generate the thumbnail if missing (if image was rotated but booh was not relaunched)
     if !$rotated_pixbufs[thumbnail_img] && !File.exists?(thumbnail_img)
         frame1.add(img = Gtk::Image.new)
@@ -310,17 +311,22 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
     #- to be able to find widgets by name
     $name2widgets[filename] = { :textview => textview }
 
+    cleanup_all_thumbnails = Proc.new {
+        #- remove out of sync images
+        dest_img_base = build_full_dest_filename(filename).sub(/\.[^\.]+$/, '')
+        for sizeobj in $images_size
+            system("rm -f #{dest_img_base}-#{sizeobj['fullscreen']}.jpg #{dest_img_base}-#{sizeobj['thumbnails']}.jpg")
+        end
+
+    }
+
     rotate_and_cleanup = Proc.new { |angle|
         perform_rotate_and_cleanup = Proc.new { |angle|
             rotate(angle, thumbnail_img, img, $xmldir.elements["[@filename='#{filename}']"], '', $default_thumbnails[:x], $default_thumbnails[:y])
         }
         perform_rotate_and_cleanup.call(angle)
 
-        #- remove out of sync images
-        dest_img_base = build_full_dest_filename(filename).sub(/\.[^\.]+$/, '')
-        for sizeobj in $images_size
-            system("rm -f #{dest_img_base}-#{sizeobj['fullscreen']}.jpg #{dest_img_base}-#{sizeobj['thumbnails']}.jpg")
-        end
+        cleanup_all_thumbnails.call
 
         save_undo(Proc.new { |angle|
                       perform_rotate_and_cleanup.call(angle)
@@ -343,13 +349,9 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
             system("rm -f '#{thumbnail_img}'")
             gen_real_thumbnail.call
         }
-        perform_color_swap_and_cleanup.call
 
-        #- remove out of sync images
-        dest_img_base = build_full_dest_filename(filename).sub(/\.[^\.]+$/, '')
-        for sizeobj in $images_size
-            system("rm -f #{dest_img_base}-#{sizeobj['thumbnails']}.jpg")
-        end
+        cleanup_all_thumbnails.call
+        perform_color_swap_and_cleanup.call
 
         save_undo(Proc.new {
                       perform_color_swap_and_cleanup.call
@@ -361,6 +363,32 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
                   })
     }
 
+    enhance_and_cleanup = Proc.new {
+        perform_enhance_and_cleanup = Proc.new {
+            xmlelem = $xmldir.elements["[@filename='#{filename}']"]
+            if xmlelem.attributes['enhance']
+                xmlelem.delete_attribute('enhance')
+            else
+                xmlelem.add_attribute('enhance', '1')
+            end
+            system("rm -f '#{thumbnail_img}'")
+            gen_real_thumbnail.call
+        }
+
+        cleanup_all_thumbnails.call
+        perform_enhance_and_cleanup.call
+
+        #- remove out of sync images
+        save_undo(Proc.new {
+                      perform_enhance_and_cleanup.call
+                      $notebook.set_page(1)
+                      Proc.new {
+                          perform_enhance_and_cleanup
+                          $notebook.set_page(1)
+                      }
+                  })
+    }
+
     delete = Proc.new {
         perform_delete = Proc.new {
             after = autotable.get_next_widget(vbox)
@@ -485,6 +513,11 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
                 flip.signal_connect('activate') { rotate_and_cleanup.call(180) }
             end
             menu.append(               Gtk::SeparatorMenuItem.new)
+            menu.append(enhance      = Gtk::ImageMenuItem.new(utf8($xmldir.elements["[@filename='#{filename}']"].attributes['enhance'] ? _("Original contrast") :
+                                                                                                                                         _("Enhance constrast"))))
+            enhance.image = Gtk::Image.new("#{$FPATH}/images/stock-channels-16.png")
+            enhance.signal_connect('activate') { enhance_and_cleanup.call }
+            menu.append(               Gtk::SeparatorMenuItem.new)
             menu.append(delete_item  = Gtk::ImageMenuItem.new(Gtk::Stock::DELETE))
             delete_item.signal_connect('activate') { delete.call }
             menu.show_all
@@ -654,18 +687,16 @@ def change_dir
     $xmldir = $xmldoc.elements["//dir[@path='#{$current_path}']"]
     $subalbums_edits = {}
 
-    find_infotype = Proc.new { |xmldir|
-        xmldir == $xmldir ? 'thumbnails' : find_subalbum_info_type(xmldir)
-    }
-
     add_subalbum = Proc.new { |xmldir|
         if xmldir == $xmldir
             thumbnail_file = "#{current_dest_dir}/thumbnails-thumbnail.jpg"
             caption = xmldir.attributes['thumbnails-caption']
             captionfile, dummy = find_subalbum_caption_info(xmldir)
+            infotype = 'thumbnails'
         else
             thumbnail_file = "#{current_dest_dir}/thumbnails-#{from_utf8(File.basename(xmldir.attributes['path']))}.jpg"
             captionfile, caption = find_subalbum_caption_info(xmldir)
+            infotype = find_subalbum_info_type(xmldir)
         end
         msg 3, "add subdir: #{xmldir.attributes['path']} with file: #{thumbnail_file}"
         hbox = Gtk::HBox.new
@@ -678,7 +709,7 @@ def change_dir
             Thread.new {
                 system("rm -f '#{thumbnail_file}'")
                 gen_thumbnails_subdir(from_utf8(captionfile), xmldir, false,
-                                      [ { 'filename' => thumbnail_file, 'size' => $albums_thumbnail_size } ], find_infotype.call(xmldir))
+                                      [ { 'filename' => thumbnail_file, 'size' => $albums_thumbnail_size } ], infotype)
                 img.set(thumbnail_file)
                 $rotated_pixbufs[thumbnail_file] = { :orig => img.pixbuf, :pixbuf => img.pixbuf, :angle_to_orig => 0 }
                 if entry2type(captionfile) == 'video'
@@ -722,9 +753,9 @@ def change_dir
                 msg 3, "new captionfile is: #{fc.filename}"
                 $subalbums_edits[xmldir.attributes['path']][:captionfile] = captionfile = utf8(fc.filename)
                 $rotated_pixbufs.delete(thumbnail_file)
-                infotype = find_infotype.call(xmldir)
                 xmldir.delete_attribute("#{infotype}-rotate")
                 xmldir.delete_attribute("#{infotype}-color-swap")
+                xmldir.delete_attribute("#{infotype}-enhance")
                 gen_real_thumbnail.call
             end
             fc.destroy
@@ -732,7 +763,7 @@ def change_dir
 
         rotate_and_cleanup = Proc.new { |angle|
             perform_rotate_and_cleanup = Proc.new { |angle|
-                rotate(angle, thumbnail_file, img, xmldir, find_infotype.call(xmldir) + '-',
+                rotate(angle, thumbnail_file, img, xmldir, "#{infotype}-",
                        $default_albums_thumbnails[:x], $default_albums_thumbnails[:y])
             }
             perform_rotate_and_cleanup.call(angle)
@@ -750,7 +781,6 @@ def change_dir
 
         color_swap_and_cleanup = Proc.new {
             perform_color_swap_and_cleanup = Proc.new {
-                infotype = find_infotype.call(xmldir)
                 if xmldir.attributes["#{infotype}-color-swap"]
                     xmldir.delete_attribute("#{infotype}-color-swap")
                 else
@@ -770,6 +800,29 @@ def change_dir
                       })
         }
 
+        enhance_and_cleanup = Proc.new {
+            perform_enhance_and_cleanup = Proc.new {
+                if xmldir.attributes["#{infotype}-enhance"]
+                    xmldir.delete_attribute("#{infotype}-enhance")
+                else
+                    xmldir.add_attribute("#{infotype}-enhance", '1')
+                end
+                gen_real_thumbnail.call
+            }
+            
+            perform_enhance_and_cleanup.call
+            
+            #- remove out of sync images
+            save_undo(Proc.new {
+                          perform_enhance_and_cleanup.call
+                          $notebook.set_page(1)
+                          Proc.new {
+                              perform_enhance_and_cleanup
+                              $notebook.set_page(1)
+                          }
+                      })
+        }
+
         evtbox.signal_connect('button-press-event') { |w, event|
             if event.event_type == Gdk::Event::BUTTON_PRESS && event.button == 1
                 if $r90.active?
@@ -800,6 +853,11 @@ def change_dir
                     flip.image = Gtk::Image.new("#{$FPATH}/images/stock-rotate-180-16.png")
                     flip.signal_connect('activate') { rotate_and_cleanup.call(180) }
                 end
+                menu.append(               Gtk::SeparatorMenuItem.new)
+                menu.append(enhance      = Gtk::ImageMenuItem.new(utf8(xmldir.attributes["#{infotype}-enhance"] ? _("Original contrast") :
+                                                                                                                  _("Enhance constrast"))))
+                enhance.image = Gtk::Image.new("#{$FPATH}/images/stock-channels-16.png")
+                enhance.signal_connect('activate') { enhance_and_cleanup.call }
                 menu.show_all
                 menu.popup(nil, nil, event.button, event.time)
             end
diff --git a/data/booh/images/stock-channels-16.png b/data/booh/images/stock-channels-16.png
new file mode 100644 (file)
index 0000000..ab492fa
Binary files /dev/null and b/data/booh/images/stock-channels-16.png differ
index d8ed41d4bc54f95dddf4c31b26e463624cbbecf5..ab58ef34cde247a1e7ac02d800bb950172512e2a 100644 (file)
@@ -202,6 +202,9 @@ module Booh
                     felem.add_attribute("#{attributes_prefix}rotate", rotate = guess_rotate(orig).to_i)
                 end
                 convert_options += "-rotate #{rotate} "
+                if felem.attributes["#{attributes_prefix}enhance"]
+                    convert_options += "-contrast -enhance -normalize "
+                end
             end
             for dest in dests
                 if !File.exists?(dest['filename'])
@@ -223,6 +226,9 @@ module Booh
                 if rotate = felem.attributes["#{attributes_prefix}rotate"]
                     convert_options += "-rotate #{rotate} "
                 end
+                if felem.attributes["#{attributes_prefix}enhance"]
+                    convert_options += "-contrast -enhance -normalize "
+                end
             end
             frame_offset = (frame_offset || 5).to_i
             for dest in dests