2 * PROJECT: NyARToolkit
\r
3 * --------------------------------------------------------------------------------
\r
4 * This work is based on the original ARToolKit developed by
\r
7 * HITLab, University of Washington, Seattle
\r
8 * http://www.hitl.washington.edu/artoolkit/
\r
10 * The NyARToolkit is Java edition ARToolKit class library.
\r
11 * Copyright (C)2008-2009 Ryo Iizuka
\r
13 * This program is free software: you can redistribute it and/or modify
\r
14 * it under the terms of the GNU General Public License as published by
\r
15 * the Free Software Foundation, either version 3 of the License, or
\r
16 * (at your option) any later version.
\r
18 * This program is distributed in the hope that it will be useful,
\r
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
21 * GNU General Public License for more details.
\r
23 * You should have received a copy of the GNU General Public License
\r
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
26 * For further information please contact.
\r
27 * http://nyatla.jp/nyatoolkit/
\r
28 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
31 package jp.nyatla.utils.j2se;
\r
33 import java.awt.Graphics.*;
\r
34 import java.awt.image.*;
\r
36 import jp.nyatla.nyartoolkit.*;
\r
37 import jp.nyatla.nyartoolkit.core.raster.rgb.*;
\r
38 import jp.nyatla.nyartoolkit.core.raster.*;
\r
39 import jp.nyatla.nyartoolkit.core.rasterreader.*;
\r
40 import jp.nyatla.nyartoolkit.core.types.*;
\r
43 * BufferdImageとRasterイメージ間で、ビットマップをコピーします。
\r
45 public class NyARRasterImageIO
\r
48 * i_inの内容を、このイメージにコピーします。
\r
50 * @throws NyARException
\r
52 public static void copy(INyARRgbRaster i_in,BufferedImage o_out) throws NyARException
\r
54 assert i_in.getSize().isEqualSize(o_out.getWidth(), o_out.getHeight());
\r
57 INyARRgbPixelReader reader=i_in.getRgbPixelReader();
\r
58 int[] rgb=new int[3];
\r
60 for(int y=o_out.getHeight()-1;y>=0;y--){
\r
61 for(int x=o_out.getWidth()-1;x>=0;x--){
\r
62 reader.getPixel(x,y,rgb);
\r
63 o_out.setRGB(x,y,(rgb[0]<<16)|(rgb[1]<<8)|rgb[2]);
\r
71 * @throws NyARException
\r
73 public static void copy(NyARGrayscaleRaster i_in,BufferedImage o_out) throws NyARException
\r
75 assert i_in.getSize().isEqualSize(o_out.getWidth(), o_out.getHeight());
\r
76 if(i_in.getBufferReader().isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8))
\r
78 final int[] buf=(int[])i_in.getBufferReader().getBuffer();
\r
79 final int w=o_out.getWidth();
\r
80 final int h=o_out.getHeight();
\r
81 for(int y=h-1;y>=0;y--){
\r
82 for(int x=w-1;x>=0;x--){
\r
84 o_out.setRGB(x, y,v*(1+0x100+0x10000));
\r
93 * @throws NyARException
\r
95 public static void copy(INyARRaster i_in,BufferedImage o_out) throws NyARException
\r
97 assert i_in.getSize().isEqualSize(o_out.getWidth(), o_out.getHeight());
\r
98 if(i_in.getBufferReader().isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8))
\r
100 final int[] buf=(int[])i_in.getBufferReader().getBuffer();
\r
101 final int w=o_out.getWidth();
\r
102 final int h=o_out.getHeight();
\r
103 for(int y=h-1;y>=0;y--){
\r
104 for(int x=w-1;x>=0;x--){
\r
105 o_out.setRGB(x, y,buf[x+y*w]==0?0:0xffffff);
\r
115 * @throws NyARException
\r
117 public static void copy(NyARHistgram i_in,Graphics i_g,int i_l,int i_t,int i_h) throws NyARException
\r
121 for(int i=0;i<i_in.length;i++){
\r
122 max=max<i_in.data[i]?i_in.data[i]:max;
\r
128 for(int i=0;i<i_in.length;i++){
\r
129 i_g.drawLine(i_l+i,i_t,i_l+i,i_h-i_h*i_in.data[i]/max);
\r
134 * i_outへこのイメージを出力します。
\r
137 * @throws NyARException
\r
139 public static void copy(BufferedImage i_in,INyARRgbRaster o_out) throws NyARException
\r
141 assert o_out.getSize().isEqualSize(i_in.getWidth(), i_in.getHeight());
\r
144 INyARRgbPixelReader reader=o_out.getRgbPixelReader();
\r
145 int[] rgb=new int[3];
\r
146 for(int y=i_in.getHeight()-1;y>=0;y--){
\r
147 for(int x=i_in.getWidth()-1;x>=0;x--){
\r
148 int pix=i_in.getRGB(x, y);
\r
149 rgb[0]=(pix>>16)&0xff;
\r
150 rgb[1]=(pix>>8)&0xff;
\r
152 reader.setPixel(x,y,rgb);
\r
160 * @throws NyARException
\r
162 public static void copy(BufferedImage i_in,INyARRaster o_out) throws NyARException
\r
164 assert o_out.getSize().isEqualSize(i_in.getWidth(), i_in.getHeight());
\r
165 if(o_out.getBufferReader().isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8))
\r
167 final int[] buf=(int[])o_out.getBufferReader().getBuffer();
\r
168 final int w=i_in.getWidth();
\r
169 final int h=i_in.getHeight();
\r
170 for(int y=h-1;y>=0;y--){
\r
171 for(int x=w-1;x>=0;x--){
\r
172 buf[x+y*w]=(i_in.getRGB(x, y)&0xffffff)>0?1:0;
\r