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 version ARToolkit class library.
\r
11 * Copyright (C)2008 R.Iizuka
\r
13 * This program is free software; you can redistribute it and/or
\r
14 * modify it under the terms of the GNU General Public License
\r
15 * as published by the Free Software Foundation; either version 2
\r
16 * of the License, or (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 framework; if not, write to the Free Software
\r
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
\r
27 * For further information please contact.
\r
28 * http://nyatla.jp/nyatoolkit/
\r
29 * <airmail(at)ebony.plala.or.jp>
\r
32 package jp.nyatla.utils.j2se;
\r
34 import java.awt.Graphics;
\r
35 import java.awt.image.*;
\r
36 import java.awt.color.*;
\r
40 import jp.nyatla.nyartoolkit.NyARException;
\r
41 import jp.nyatla.nyartoolkit.core.types.*;
\r
42 import jp.nyatla.nyartoolkit.core.rasterreader.*;
\r
43 import jp.nyatla.nyartoolkit.core.raster.*;
\r
44 import jp.nyatla.nyartoolkit.core.types.stack.*;
\r
45 import jp.nyatla.nyartoolkit.core.labeling.*;
\r
48 * bitmapとして利用可能なラベリングイメージです。
\r
52 public class LabelingBufferdImage extends BufferedImage
\r
54 public final static int COLOR_125_COLOR = 0;// 125色ラベルモード
\r
56 public final static int COLOR_256_MONO = 1;// 64階調モノクロモード
\r
58 public final static int COLOR_64_MONO = 2;// 64階調モノクロモード
\r
60 public final static int COLOR_32_MONO = 3;// 32階調モノクロモード
\r
62 public final static int COLOR_16_MONO = 4;// 16階調モノクロモード
\r
64 public final static int COLOR_8_MONO = 5;// 16階調モノクロモード
\r
66 private int[] _rgb_table_125;
\r
70 * i_width x i_heightの大きさのイメージを作成します。
\r
75 public LabelingBufferdImage(int i_width, int i_height)
\r
77 super(i_width, i_height, ColorSpace.TYPE_RGB);
\r
79 this._rgb_table_125 = new int[125];
\r
80 for (int i = 0; i < 5; i++) {
\r
81 for (int i2 = 0; i2 < 5; i2++) {
\r
82 for (int i3 = 0; i3 < 5; i3++) {
\r
83 this._rgb_table_125[((i * 5) + i2) * 5 + i3] = ((((i * 63) << 8) | (i2 * 63)) << 8) | (i3 * 63);
\r
87 /* case COLOR_256_MONO:
\r
88 this._rgb_table = new int[256];
\r
89 this._number_of_color = 256;
\r
90 for (int i = 0; i < 256; i++) {
\r
91 this._rgb_table[i] = (i << 16) | (i << 8) | i;
\r
95 this._rgb_table = new int[64];
\r
96 this._number_of_color = 64;
\r
97 for (int i = 0; i < 64; i++) {
\r
99 this._rgb_table[i] = (m << 16) | (m << 8) | m;
\r
102 case COLOR_32_MONO:
\r
103 this._rgb_table = new int[32];
\r
104 this._number_of_color = 32;
\r
105 for (int i = 0; i < 32; i++) {
\r
107 this._rgb_table[i] = (m << 16) | (m << 8) | m;
\r
110 case COLOR_16_MONO:
\r
111 this._rgb_table = new int[32];
\r
112 this._number_of_color = 16;
\r
113 for (int i = 0; i < 16; i++) {
\r
115 this._rgb_table[i] = (m << 16) | (m << 8) | m;
\r
123 public void drawImage(NyARGrayscaleRaster i_raster) throws NyARException
\r
125 assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT1D_GLAY_8);
\r
127 int w = this.getWidth();
\r
128 int h = this.getHeight();
\r
130 NyARIntSize size = i_raster.getSize();
\r
131 if (size.h > h || size.w > w) {
\r
132 throw new NyARException();
\r
137 limg = (int[]) i_raster.getBufferReader().getBuffer();
\r
138 for (int i = 0; i < h; i++) {
\r
139 for (int i2 = 0; i2 < w; i2++) {
\r
140 this.setRGB(i2, i,limg[i*w+i2]);
\r
148 * @throws NyARException
\r
150 public void drawImage(NyARBinRaster i_raster) throws NyARException
\r
152 assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8);
\r
154 int w = this.getWidth();
\r
155 int h = this.getHeight();
\r
157 NyARIntSize size = i_raster.getSize();
\r
158 if (size.h > h || size.w > w) {
\r
159 throw new NyARException();
\r
164 limg = (int[]) i_raster.getBufferReader().getBuffer();
\r
165 for (int i = 0; i < h; i++) {
\r
166 for (int i2 = 0; i2 < w; i2++) {
\r
167 this.setRGB(i2, i, limg[i*w+i2] > 0 ? 255 : 0);
\r
176 * @throws NyARException
\r
178 public void drawLabel(NyARLabelingImage i_image) throws NyARException
\r
180 int w = this.getWidth();
\r
181 int h = this.getHeight();
\r
183 NyARIntSize size = i_image.getSize();
\r
184 if (size.h > h || size.w > w) {
\r
185 throw new NyARException();
\r
187 int[] index_array=i_image.getIndexArray();
\r
191 limg = (int[]) i_image.getBufferReader().getBuffer();
\r
192 for (int i = 0; i < h; i++) {
\r
193 for (int i2 = 0; i2 < w; i2++) {
\r
194 int t=limg[i*w+i2]-1;
\r
200 this.setRGB(i2, i,_rgb_table_125[t% _rgb_table_125.length]);
\r
210 public void overlayData(NyARLabelingLabel i_label)
\r
212 Graphics g = this.getGraphics();
\r
213 g.setColor(Color.red);
\r
214 g.drawRect(i_label.clip_l,i_label.clip_t,i_label.clip_r-i_label.clip_l,i_label.clip_b-i_label.clip_t);
\r
222 public void overlayData(NyARIntPointStack i_stack)
\r
224 int count = i_stack.getLength();
\r
225 NyARIntPoint[] items = (NyARIntPoint[])i_stack.getArray();
\r
226 Graphics g = this.getGraphics();
\r
227 for (int i = 0; i < count; i++) {
\r
228 int x = items[i].x;
\r
229 int y = items[i].y;
\r
230 g.setColor(Color.red);
\r
231 g.drawLine(x - 5, y, x + 5, y);
\r
232 g.drawLine(x, y + 5, x, y - 5);
\r
236 public void overlayData(NyARIntRectStack i_stack)
\r
238 Color[] c=new Color[]{Color.cyan,Color.red,Color.green};
\r
239 int count = i_stack.getLength();
\r
240 NyARIntRect[] items = (NyARIntRect[])i_stack.getArray();
\r
241 Graphics g = this.getGraphics();
\r
242 for (int i = 0; i < count; i++) {
\r
243 int x = items[i].x;
\r
244 int y = items[i].y;
\r
245 g.setColor(c[i%1]);
\r
246 g.drawRect(x,y,items[i].w,items[i].h);
\r