Title: [893] trunk/image_voodoo: Add a greyscale method to turn image into greyscale, along with a sample ( we need to start adding tests, though)
Revision
893
Author
headius
Date
2008-02-08 10:42:02 -0500 (Fri, 08 Feb 2008)

Log Message

Add a greyscale method to turn image into greyscale, along with a sample (we need to start adding tests, though)

Modified Paths

Added Paths

Diff

Modified: trunk/image_voodoo/lib/image_voodoo.rb (892 => 893)


--- trunk/image_voodoo/lib/image_voodoo.rb	2008-02-08 15:41:30 UTC (rev 892)
+++ trunk/image_voodoo/lib/image_voodoo.rb	2008-02-08 15:42:02 UTC (rev 893)
@@ -41,9 +41,6 @@
     graphics.set_rendering_hint(
       RenderingHints::KEY_INTERPOLATION,
       RenderingHints::VALUE_INTERPOLATION_BICUBIC)
-    graphics.set_rendering_hint(
-      RenderingHints::KEY_COLOR_RENDERING,
-      RenderingHints::VALUE_COLOR_RENDER_QUALITY)
     
     w_scale = width.to_f/@src.width
     h_scale = height.to_f/@src.height
@@ -56,6 +53,20 @@
       
     yield ImageVoodoo.new(target)
   end
+  
+  def greyscale
+    target = BufferedImage.new(
+      width, height, BufferedImage::TYPE_USHORT_GRAY)
+    graphics = target.graphics
+    graphics.set_rendering_hint(
+      RenderingHints::KEY_INTERPOLATION,
+      RenderingHints::VALUE_INTERPOLATION_BICUBIC)
+    
+    graphics.draw_rendered_image @src, nil
+    graphics.dispose
+      
+    yield ImageVoodoo.new(target)
+  end
 
   def save(file)
     return false if file !~ /\.(.*)$/

Added: trunk/image_voodoo/samples/file_greyscale.rb (0 => 893)


--- trunk/image_voodoo/samples/file_greyscale.rb	                        (rev 0)
+++ trunk/image_voodoo/samples/file_greyscale.rb	2008-02-08 15:42:02 UTC (rev 893)
@@ -0,0 +1,9 @@
+require 'image_voodoo'
+
+# reads in the file specified by ARGV[0], transforming to greyscale and
+# writing to the file specified by ARGV[1]
+ImageVoodoo.with_image(ARGV[0]) do |img|
+  img.greyscale do |img2|
+    img2.save(ARGV[1])
+  end
+end
_______________________________________________
Jruby-extras-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/jruby-extras-devel

Reply via email to