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
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;
\r
68 private int _number_of_color;
\r
71 * i_width x i_heightの大きさのイメージを作成します。
\r
76 public LabelingBufferdImage(int i_width, int i_height, int i_color_mode)
\r
78 super(i_width, i_height, ColorSpace.TYPE_RGB);
\r
80 switch (i_color_mode) {
\r
81 case COLOR_125_COLOR:
\r
82 this._rgb_table = new int[125];
\r
83 this._number_of_color = 125;
\r
84 for (int i = 0; i < 5; i++) {
\r
85 for (int i2 = 0; i2 < 5; i2++) {
\r
86 for (int i3 = 0; i3 < 5; i3++) {
\r
87 this._rgb_table[((i * 5) + i2) * 5 + i3] = ((((i * 63) << 8) | (i2 * 63)) << 8) | (i3 * 63);
\r
92 case COLOR_256_MONO:
\r
93 this._rgb_table = new int[256];
\r
94 this._number_of_color = 256;
\r
95 for (int i = 0; i < 256; i++) {
\r
96 this._rgb_table[i] = (i << 16) | (i << 8) | i;
\r
100 this._rgb_table = new int[64];
\r
101 this._number_of_color = 64;
\r
102 for (int i = 0; i < 64; i++) {
\r
104 this._rgb_table[i] = (m << 16) | (m << 8) | m;
\r
107 case COLOR_32_MONO:
\r
108 this._rgb_table = new int[32];
\r
109 this._number_of_color = 32;
\r
110 for (int i = 0; i < 32; i++) {
\r
112 this._rgb_table[i] = (m << 16) | (m << 8) | m;
\r
115 case COLOR_16_MONO:
\r
116 this._rgb_table = new int[32];
\r
117 this._number_of_color = 16;
\r
118 for (int i = 0; i < 16; i++) {
\r
120 this._rgb_table[i] = (m << 16) | (m << 8) | m;
\r
128 public void drawImage(NyARGlayscaleRaster i_raster) throws NyARException
\r
130 assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT2D_GLAY_8);
\r
132 int w = this.getWidth();
\r
133 int h = this.getHeight();
\r
135 NyARIntSize size = i_raster.getSize();
\r
136 if (size.h > h || size.w > w) {
\r
137 throw new NyARException();
\r
142 limg = (int[][]) i_raster.getBufferReader().getBuffer();
\r
143 for (int i = 0; i < h; i++) {
\r
144 for (int i2 = 0; i2 < w; i2++) {
\r
145 this.setRGB(i2, i, this._rgb_table[limg[i][i2] % this._number_of_color]);
\r
151 public void drawImage(NyARBinRaster i_raster) throws NyARException
\r
153 assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT2D_BIN_8);
\r
155 int w = this.getWidth();
\r
156 int h = this.getHeight();
\r
158 NyARIntSize size = i_raster.getSize();
\r
159 if (size.h > h || size.w > w) {
\r
160 throw new NyARException();
\r
165 limg = (int[][]) i_raster.getBufferReader().getBuffer();
\r
166 for (int i = 0; i < h; i++) {
\r
167 for (int i2 = 0; i2 < w; i2++) {
\r
168 this.setRGB(i2, i, limg[i][i2] > 0 ? 255 : 0);
\r
174 public void overlayData(NyARIntPointStack i_stack)
\r
176 int count = i_stack.getLength();
\r
177 NyARIntPoint[] items = i_stack.getArray();
\r
178 Graphics g = this.getGraphics();
\r
179 for (int i = 0; i < count; i++) {
\r
180 int x = items[i].x;
\r
181 int y = items[i].y;
\r
182 g.setColor(Color.red);
\r
183 g.drawLine(x - 5, y, x + 5, y);
\r
184 g.drawLine(x, y + 5, x, y - 5);
\r
188 public void overlayData(NyARIntRectStack i_stack)
\r
190 Color[] c=new Color[]{Color.cyan,Color.red,Color.green};
\r
191 int count = i_stack.getLength();
\r
192 NyARIntRect[] items = i_stack.getArray();
\r
193 Graphics g = this.getGraphics();
\r
194 for (int i = 0; i < count; i++) {
\r
195 int x = items[i].x;
\r
196 int y = items[i].y;
\r
197 g.setColor(c[i%1]);
\r
198 g.drawRect(x,y,items[i].w,items[i].h);
\r