Rubyã§ç»åçæã¡ã¢
æ°ç¾æã®VGAç¨åº¦ã®è§£å度ã®ç»åã«ããããæ°åã®ã¢ã«ãã¡ãã£ã³ãã«ããç»åãcompositeãã¦æ¸ãåºãå¦çãªããRMagickããjavax.imageioãJRubyãã使ãã®ãããããããªãã®
- javax.imageioãJAIã¨ãã«Javaã§æ¸ãã¦ãJRubyãã使ã£ã¦ãé度差ã¯ç¡ãã£ãï¼ã¨ããããç»åã®èªã¿è¾¼ã¿ããã©ã¼ãããå¤æãæ¸ãåºããwidth heightãªã©ã®ãã©ã¡ã¼ã¿åå¾ã¯ç¢ºèªï¼
- Java1.5â1.6ã«ããã¨javax.imageioã®ç»åèªã¿è¾¼ã¿/æ¸ãåºãé度1.3ã1.5åã«ãªã
- Java1.6ãããªãã¨JAIã§ç»åãæ¸ãåºããªã
- Java1.6ãããªãã¨imageioã§pngå½¢å¼ã§ç»åãæ¸ãåºããªã(getTypeãã¨ã©ã¼ã«ãªã)
- javax.imageioã¨JAIã§ã¯ç¸¦æ¨ª1000ãã¯ã»ã«ãªã©ã®å¤§ããç»åã®æã¯èªã¿æ¸ãé度ã¯JAIã®æ¹ãéããã320x240ç¨åº¦xæ°ç¾æãªãå¤ãããªã
- ã§ãImageMagick(RMagick)ã®æ¹ãããã«2ã3åéã
ã¢ã«ãã¡å¤ããã®ç»åã®compositeã¯imageioãã¡ããã¡ãéããImageMagické
ãã
- 320x240ã250æã®ç»åã«50åã®40x40ã®ç»åãã©ã³ãã ã«compositeãã
- ImageMagick(Ruby1.8.7+RMagick2.13.1+ImageMagick6.5.2)â25ç§åå¾
- imageio(JRuby1.5.1+Java1.6+javax.imageio)â6ã7ç§
- 250æã«10åãã¤ã«æ¸ããã
- ImageMagickâ7ã8ç§
- imageioâ4ç§
- 大éã«compositeãããªãimageioãéã
- JAIã§compositeã®ä»æ¹ãããããããªã
JRuby+JAIã¯ä½¿ãã«ãã
- ParameterBlockã«java.lang.Floatå¤ãå
¥ããå¿
è¦ãããããRubyã§Number.to_fããã¨Doubleã«ãªããæ示çã«java.lang.Float.parseFloat("0.3");ã¨ããã¦ç´ã«å¤ã渡ãã¦ãJRubyãjava.lang.Doubleã¨ãã¦æ¸¡ãã¦ãã¾ãã
- Javaã§ParameterBlockãè¿ãã³ã¼ãæ¸ãã¦å ã«javacãã¦.classãä½ããJRubyã¹ã¯ãªããããimportããã°å¤æãèµ·ããªãã®ã§ãªãã¨ããªã
- ã¤ã¾ãJAI使ããã¨ããã¨å ¨é¨Rubyã§æ¸ãã¨ããããã«ã¯ãããªããªã
JRubyããJAI.create("filestore" ããã¨
java.lang.IllegalArgumentException: operation "FileStore" requires 1 source object(s).
ã¨ããã¨ã©ã¼ãã§ãã
ããããJAI.creaet "filestore"ãããJavaããã°ã©ã ãå
ã«ä½ã£ã¦classã«ãã¦importãã¦ä½¿ãã°åé¿ã§ãã
ãããã
ImageCopyJai.java
import javax.media.jai.Interpolation; import javax.media.jai.JAI; import javax.media.jai.RenderedOp; import com.sun.media.jai.codec.FileSeekableStream; public class ImageCopyJai{ public static void main(String args[]){ if(args.length < 2){ System.out.println("ImageCopyJai input.jpg output.bmp"); System.exit(1); } if(ImageCopyJai.copy(args[0], args[1])){ System.out.println(args[1]); } else System.out.println("error"); } public static boolean copy(String name_in, String name_out) { try{ RenderedOp img = JAI.create("fileload", name_in); System.out.println(name_in+" => "+img.getWidth()+", "+img.getHeight()); JAI.create("filestore", img, name_out, "BMP", null); } catch(Exception e){ e.printStackTrace(); return false; } return true; } }
JRubyãã使ã
image_copy.rb
#!/usr/bin/env jruby # -*- coding: utf-8 -*- require 'java' import 'ImageCopyJai' import 'javax.media.jai.Interpolation' import 'javax.media.jai.JAI' import 'javax.media.jai.RenderedOp' import 'com.sun.media.jai.codec.FileSeekableStream' import 'java.awt.image.renderable.ParameterBlock' if ARGV.size < 2 puts 'jruby iamge_copy.rb /dir/to/in/ /dir/to/out/' exit 1 end indir = ARGV.shift outdir = ARGV.shift indir += '/' if indir =~ /.+[^\/]$/ outdir += '/' if outdir =~ /.+[^\/]$/ Dir.mkdir(outdir) if !File.exists?(outdir) files = Dir.glob("#{indir}*") puts files.size start = Time.now files.each{|name| begin out_name = name.scan(/\/([^\/]+)\..+$/).first ImageCopyJai.copy(name, "#{outdir}#{out_name}.bmp") rescue => e puts "#{name} => error" puts e end } puts Time.now-start