2 * PROJECT: NyARToolkit(Extension)
\r
3 * --------------------------------------------------------------------------------
\r
4 * The NyARToolkit is Java edition ARToolKit class library.
\r
5 * Copyright (C)2008-2010 Ryo Iizuka
\r
7 * This program is free software: you can redistribute it and/or modify
\r
8 * it under the terms of the GNU General Public License as published by
\r
9 * the Free Software Foundation, either version 3 of the License, or
\r
10 * (at your option) any later version.
\r
12 * This program is distributed in the hope that it will be useful,
\r
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 * GNU General Public License for more details.
\r
17 * You should have received a copy of the GNU General Public License
\r
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
\r
20 * For further information please contact.
\r
21 * http://nyatla.jp/nyatoolkit/
\r
22 * <airmail(at)ebony.plala.or.jp> or <nyatla(at)nyatla.jp>
\r
25 package jp.nyatla.nyartoolkit.utils.j2se;
\r
27 import jp.nyatla.nyartoolkit.NyARException;
\r
28 import jp.nyatla.nyartoolkit.core.types.NyARBufferType;
\r
29 import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
\r
30 import jp.nyatla.nyartoolkit.core.raster.rgb.*;
\r
31 import jp.nyatla.nyartoolkit.core.raster.*;
\r
32 import jp.nyatla.nyartoolkit.core.rasterreader.*;
\r
34 import java.awt.color.ColorSpace;
\r
35 import java.awt.image.BufferedImage;
\r
38 public class NyARRGBRaster_BufferedImage extends NyARRgbRaster_BasicClass
\r
40 private INyARRgbPixelReader _reader;
\r
41 private BufferedImage _buf;
\r
44 * バッファオブジェクトがアタッチされていればtrue
\r
46 protected boolean _is_attached_buffer;
\r
47 public NyARRGBRaster_BufferedImage(int i_width, int i_height,boolean i_is_alloc) throws NyARException
\r
49 super( new NyARIntSize(i_width,i_height),NyARBufferType.OBJECT_Java_BufferedImage);
\r
50 if(!initInstance(this._size,i_is_alloc)){
\r
51 throw new NyARException();
\r
54 public NyARRGBRaster_BufferedImage(int i_width, int i_height) throws NyARException
\r
56 super( new NyARIntSize(i_width,i_height),NyARBufferType.OBJECT_Java_BufferedImage);
\r
57 if(!initInstance(this._size,true)){
\r
58 throw new NyARException();
\r
61 protected boolean initInstance(NyARIntSize i_size,boolean i_is_alloc)
\r
63 this._buf=i_is_alloc?new BufferedImage(i_size.w,i_size.h, ColorSpace.TYPE_RGB):null;
\r
64 this._reader=new PixelReader((BufferedImage)this._buf);
\r
65 this._is_attached_buffer=i_is_alloc;
\r
70 public INyARRgbPixelReader getRgbPixelReader() throws NyARException
\r
72 return this._reader;
\r
74 public Object getBuffer()
\r
78 public boolean hasBuffer()
\r
80 return this._buf!=null;
\r
82 public void wrapBuffer(Object i_ref_buf) throws NyARException
\r
84 assert(!this._is_attached_buffer);//バッファがアタッチされていたら機能しない。
\r
85 BufferedImage buf=(BufferedImage)i_ref_buf;
\r
86 assert(buf.getWidth()==this._size.w && buf.getHeight()==this._size.h);
\r
88 //ピクセルリーダーの参照バッファを切り替える。
\r
89 this._reader.switchBuffer(i_ref_buf);
\r
94 * byte[]配列に、パディング無しの8bit画素値が、RGBRGBの順で並んでいる
\r
95 * バッファに使用できるピクセルリーダー
\r
98 private class PixelReader implements INyARRgbPixelReader
\r
100 protected BufferedImage _ref_buf;
\r
102 public PixelReader(BufferedImage i_buf)
\r
104 this._ref_buf = i_buf;
\r
107 public void getPixel(int i_x, int i_y, int[] o_rgb)
\r
109 final BufferedImage ref_buf = this._ref_buf;
\r
110 int p=ref_buf.getRGB(i_x, i_y);
\r
111 o_rgb[0] = (p>>16) & 0xff;// R
\r
112 o_rgb[1] = (p>>8) & 0xff;// G
\r
113 o_rgb[2] = (p>>0) & 0xff;// B
\r
117 public void getPixelSet(int[] i_x, int[] i_y, int i_num, int[] o_rgb)
\r
119 final BufferedImage ref_buf = this._ref_buf;
\r
120 for (int i = i_num - 1; i >= 0; i--) {
\r
121 int p=ref_buf.getRGB(i_x[i], i_y[i]);
\r
122 o_rgb[i * 3 + 0] = (p>>16) & 0xff;// R
\r
123 o_rgb[i * 3 + 1] = (p>>8) & 0xff;// G
\r
124 o_rgb[i * 3 + 2] = (p>>0) & 0xff;// B
\r
128 public void setPixel(int i_x, int i_y, int[] i_rgb) throws NyARException
\r
130 NyARException.notImplement();
\r
132 public void setPixels(int[] i_x, int[] i_y, int i_num, int[] i_intrgb) throws NyARException
\r
134 NyARException.notImplement();
\r
136 public void switchBuffer(Object i_ref_buffer) throws NyARException
\r
138 this._ref_buf = (BufferedImage)i_ref_buffer;
\r