OSDN Git Service

Merge branch 'git-svn'
[nyartoolkit-and/nyartoolkit-and.git] / tags / 2.4.0 / src / jp / nyatla / utils / j2se / NyARRasterImageIO.java
1 /* \r
2  * PROJECT: NyARToolkit\r
3  * --------------------------------------------------------------------------------\r
4  * This work is based on the original ARToolKit developed by\r
5  *   Hirokazu Kato\r
6  *   Mark Billinghurst\r
7  *   HITLab, University of Washington, Seattle\r
8  * http://www.hitl.washington.edu/artoolkit/\r
9  *\r
10  * The NyARToolkit is Java edition ARToolKit class library.\r
11  * Copyright (C)2008-2009 Ryo Iizuka\r
12  *\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
17  * \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
22  *\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
25  * \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
29  * \r
30  */\r
31 package jp.nyatla.utils.j2se;\r
32 \r
33 import java.awt.image.*;\r
34 import jp.nyatla.nyartoolkit.*;\r
35 import jp.nyatla.nyartoolkit.core.raster.rgb.*;\r
36 import jp.nyatla.nyartoolkit.core.raster.*;\r
37 import jp.nyatla.nyartoolkit.core.rasterreader.*;\r
38 \r
39 public class NyARRasterImageIO\r
40 {\r
41         /**\r
42          * i_inの内容を、このイメージにコピーします。\r
43          * @param i_in\r
44          * @throws NyARException\r
45          */\r
46         public static void copy(INyARRgbRaster i_in,BufferedImage o_out) throws NyARException\r
47         {\r
48                 assert i_in.getSize().isEqualSize(o_out.getWidth(), o_out.getHeight());\r
49                 \r
50                 //thisへ転写\r
51                 INyARRgbPixelReader reader=i_in.getRgbPixelReader();\r
52                 int[] rgb=new int[3];\r
53 \r
54                 for(int y=o_out.getHeight()-1;y>=0;y--){\r
55                         for(int x=o_out.getWidth()-1;x>=0;x--){\r
56                                 reader.getPixel(x,y,rgb);\r
57                                 o_out.setRGB(x,y,(rgb[0]<<16)|(rgb[1]<<8)|rgb[2]);\r
58                         }\r
59                 }\r
60                 return;\r
61         }\r
62         /**\r
63          * BIN_8用\r
64          * @param i_in\r
65          * @throws NyARException\r
66          */\r
67         public static void copy(INyARRaster i_in,BufferedImage o_out) throws NyARException\r
68         {\r
69                 assert i_in.getSize().isEqualSize(o_out.getWidth(), o_out.getHeight());\r
70                 if(i_in.getBufferReader().isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8))\r
71                 {\r
72                         final int[] buf=(int[])i_in.getBufferReader().getBuffer();\r
73                         final int w=o_out.getWidth();\r
74                         final int h=o_out.getHeight();\r
75                         for(int y=h-1;y>=0;y--){\r
76                                 for(int x=w-1;x>=0;x--){\r
77                                         o_out.setRGB(x, y,buf[x+y*w]==0?0:0xffffff);\r
78                                 }\r
79                         }\r
80                 }\r
81                 return;\r
82         }       \r
83         /**\r
84          * i_outへこのイメージを出力します。\r
85          * \r
86          * @param i_out\r
87          * @throws NyARException\r
88          */\r
89         public static void copy(BufferedImage i_in,INyARRgbRaster o_out) throws NyARException\r
90         {\r
91                 assert o_out.getSize().isEqualSize(i_in.getWidth(), i_in.getHeight());\r
92                 \r
93                 //thisへ転写\r
94                 INyARRgbPixelReader reader=o_out.getRgbPixelReader();\r
95                 int[] rgb=new int[3];\r
96                 for(int y=i_in.getHeight()-1;y>=0;y--){\r
97                         for(int x=i_in.getWidth()-1;x>=0;x--){\r
98                                 int pix=i_in.getRGB(x, y);\r
99                                 rgb[0]=(pix>>16)&0xff;\r
100                                 rgb[1]=(pix>>8)&0xff;\r
101                                 rgb[2]=(pix)&0xff;\r
102                                 reader.setPixel(x,y,rgb);\r
103                         }\r
104                 }\r
105                 return;\r
106         }\r
107         /**\r
108          * BIN_8用\r
109          * @param i_in\r
110          * @throws NyARException\r
111          */\r
112         public static void copy(BufferedImage i_in,INyARRaster o_out) throws NyARException\r
113         {\r
114                 assert o_out.getSize().isEqualSize(i_in.getWidth(), i_in.getHeight());\r
115                 if(o_out.getBufferReader().isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8))\r
116                 {\r
117                         final int[] buf=(int[])o_out.getBufferReader().getBuffer();\r
118                         final int w=i_in.getWidth();\r
119                         final int h=i_in.getHeight();\r
120                         for(int y=h-1;y>=0;y--){\r
121                                 for(int x=w-1;x>=0;x--){\r
122                                         buf[x+y*w]=(i_in.getRGB(x, y)&0xffffff)>0?1:0;\r
123                                 }\r
124                         }\r
125                 }\r
126                 return;\r
127         }       \r
128 }\r