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.nyartoolkit.utils.j2se;
\r
33 import java.awt.Graphics;
\r
34 import java.awt.image.*;
\r
35 import java.awt.color.*;
\r
39 import jp.nyatla.nyartoolkit.NyARException;
\r
40 import jp.nyatla.nyartoolkit.core.types.*;
\r
41 import jp.nyatla.nyartoolkit.core.rasterreader.*;
\r
42 import jp.nyatla.nyartoolkit.core.raster.*;
\r
43 import jp.nyatla.nyartoolkit.core.types.stack.*;
\r
44 import jp.nyatla.nyartoolkit.core.labeling.*;
\r
45 import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage;
\r
46 import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabel;
\r
49 * bitmapとして利用可能なラベリングイメージです。
\r
53 public class LabelingBufferdImage extends BufferedImage
\r
55 public final static int COLOR_125_COLOR = 0;// 125色ラベルモード
\r
57 public final static int COLOR_256_MONO = 1;// 64階調モノクロモード
\r
59 public final static int COLOR_64_MONO = 2;// 64階調モノクロモード
\r
61 public final static int COLOR_32_MONO = 3;// 32階調モノクロモード
\r
63 public final static int COLOR_16_MONO = 4;// 16階調モノクロモード
\r
65 public final static int COLOR_8_MONO = 5;// 16階調モノクロモード
\r
67 private int[] _rgb_table_125;
\r
71 * i_width x i_heightの大きさのイメージを作成します。
\r
76 public LabelingBufferdImage(int i_width, int i_height)
\r
78 super(i_width, i_height, ColorSpace.TYPE_RGB);
\r
80 this._rgb_table_125 = new int[125];
\r
81 for (int i = 0; i < 5; i++) {
\r
82 for (int i2 = 0; i2 < 5; i2++) {
\r
83 for (int i3 = 0; i3 < 5; i3++) {
\r
84 this._rgb_table_125[((i * 5) + i2) * 5 + i3] = ((((i * 63) << 8) | (i2 * 63)) << 8) | (i3 * 63);
\r
88 /* case COLOR_256_MONO:
\r
89 this._rgb_table = new int[256];
\r
90 this._number_of_color = 256;
\r
91 for (int i = 0; i < 256; i++) {
\r
92 this._rgb_table[i] = (i << 16) | (i << 8) | i;
\r
96 this._rgb_table = new int[64];
\r
97 this._number_of_color = 64;
\r
98 for (int i = 0; i < 64; i++) {
\r
100 this._rgb_table[i] = (m << 16) | (m << 8) | m;
\r
103 case COLOR_32_MONO:
\r
104 this._rgb_table = new int[32];
\r
105 this._number_of_color = 32;
\r
106 for (int i = 0; i < 32; i++) {
\r
108 this._rgb_table[i] = (m << 16) | (m << 8) | m;
\r
111 case COLOR_16_MONO:
\r
112 this._rgb_table = new int[32];
\r
113 this._number_of_color = 16;
\r
114 for (int i = 0; i < 16; i++) {
\r
116 this._rgb_table[i] = (m << 16) | (m << 8) | m;
\r
124 public void drawImage(NyARGrayscaleRaster i_raster) throws NyARException
\r
126 assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8);
\r
128 int w = this.getWidth();
\r
129 int h = this.getHeight();
\r
131 NyARIntSize size = i_raster.getSize();
\r
132 if (size.h > h || size.w > w) {
\r
133 throw new NyARException();
\r
138 limg = (int[]) i_raster.getBufferReader().getBuffer();
\r
139 for (int i = 0; i < h; i++) {
\r
140 for (int i2 = 0; i2 < w; i2++) {
\r
141 this.setRGB(i2, i,limg[i*w+i2]);
\r
149 * @throws NyARException
\r
151 public void drawImage(NyARBinRaster i_raster) throws NyARException
\r
153 assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT1D_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*w+i2] > 0 ? 255 : 0);
\r
177 * @throws NyARException
\r
179 public void drawLabel(NyARLabelingImage i_image) throws NyARException
\r
181 int w = this.getWidth();
\r
182 int h = this.getHeight();
\r
184 NyARIntSize size = i_image.getSize();
\r
185 if (size.h > h || size.w > w) {
\r
186 throw new NyARException();
\r
188 int[] index_array=i_image.getIndexArray();
\r
192 limg = (int[]) i_image.getBufferReader().getBuffer();
\r
193 for (int i = 0; i < h; i++) {
\r
194 for (int i2 = 0; i2 < w; i2++) {
\r
195 int t=limg[i*w+i2]-1;
\r
201 this.setRGB(i2, i,_rgb_table_125[t% _rgb_table_125.length]);
\r
211 public void overlayData(NyARLabelingLabel i_label)
\r
213 Graphics g = this.getGraphics();
\r
214 g.setColor(Color.red);
\r
215 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
223 public void overlayData(NyARIntPointStack i_stack)
\r
225 int count = i_stack.getLength();
\r
226 NyARIntPoint2d[] items = i_stack.getArray();
\r
227 Graphics g = this.getGraphics();
\r
228 for (int i = 0; i < count; i++) {
\r
229 int x = items[i].x;
\r
230 int y = items[i].y;
\r
231 g.setColor(Color.red);
\r
232 g.drawLine(x - 5, y, x + 5, y);
\r
233 g.drawLine(x, y + 5, x, y - 5);
\r
237 public void overlayData(NyARIntRectStack i_stack)
\r
239 Color[] c=new Color[]{Color.cyan,Color.red,Color.green};
\r
240 int count = i_stack.getLength();
\r
241 NyARIntRect[] items = i_stack.getArray();
\r
242 Graphics g = this.getGraphics();
\r
243 for (int i = 0; i < count; i++) {
\r
244 int x = items[i].x;
\r
245 int y = items[i].y;
\r
246 g.setColor(c[i%1]);
\r
247 g.drawRect(x,y,items[i].w,items[i].h);
\r