From: nyatla Date: Sun, 6 Dec 2009 16:19:43 +0000 (+0000) Subject: [backup]NyARToolkitCS/2.4.2 X-Git-Tag: 2.4.2~5 X-Git-Url: http://git.osdn.net/view?p=nyartoolkit-and%2Fnyartoolkit-and.git;a=commitdiff_plain;h=0891bc2aa76913a07b410eb1d42e4b35b13fda5b [backup]NyARToolkitCS/2.4.2 2.4.1のバグフィクス --- diff --git a/src/jp/nyatla/nyartoolkit/utils/TransformedBitmapPickup.java b/src/jp/nyatla/nyartoolkit/utils/TransformedBitmapPickup.java index 2cb47ad..c7d4154 100644 --- a/src/jp/nyatla/nyartoolkit/utils/TransformedBitmapPickup.java +++ b/src/jp/nyatla/nyartoolkit/utils/TransformedBitmapPickup.java @@ -53,7 +53,7 @@ class TransformedBitmapPickup extends NyARColorPatt_Perspective_O2 * @param i_base_mat * @return 画像の取得の成否を返す。 */ - boolean pickupImage2d(INyARRgbRaster i_src_imege, double i_l, double i_t, double i_r, double i_b, NyARTransMatResult i_base_mat) throws NyARException + public boolean pickupImage2d(INyARRgbRaster i_src_imege, double i_l, double i_t, double i_r, double i_b, NyARTransMatResult i_base_mat) throws NyARException { double cp00, cp01, cp02, cp11, cp12; cp00 = this._ref_perspective.m00; diff --git a/src/jp/nyatla/nyartoolkit/utils/j2se/LabelingBufferdImage.java b/src/jp/nyatla/nyartoolkit/utils/j2se/LabelingBufferdImage.java new file mode 100644 index 0000000..0642dba --- /dev/null +++ b/src/jp/nyatla/nyartoolkit/utils/j2se/LabelingBufferdImage.java @@ -0,0 +1,251 @@ +/* + * PROJECT: NyARToolkit + * -------------------------------------------------------------------------------- + * This work is based on the original ARToolKit developed by + * Hirokazu Kato + * Mark Billinghurst + * HITLab, University of Washington, Seattle + * http://www.hitl.washington.edu/artoolkit/ + * + * The NyARToolkit is Java edition ARToolKit class library. + * Copyright (C)2008-2009 Ryo Iizuka + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * For further information please contact. + * http://nyatla.jp/nyatoolkit/ + * or + * + */ +package jp.nyatla.nyartoolkit.utils.j2se; + +import java.awt.Graphics; +import java.awt.image.*; +import java.awt.color.*; +import java.awt.*; + + +import jp.nyatla.nyartoolkit.NyARException; +import jp.nyatla.nyartoolkit.core.types.*; +import jp.nyatla.nyartoolkit.core.rasterreader.*; +import jp.nyatla.nyartoolkit.core.raster.*; +import jp.nyatla.nyartoolkit.core.types.stack.*; +import jp.nyatla.nyartoolkit.core.labeling.*; +import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingImage; +import jp.nyatla.nyartoolkit.core.labeling.artoolkit.NyARLabelingLabel; + +/** + * bitmapとして利用可能なラベリングイメージです。 + * + * + */ +public class LabelingBufferdImage extends BufferedImage +{ + public final static int COLOR_125_COLOR = 0;// 125色ラベルモード + + public final static int COLOR_256_MONO = 1;// 64階調モノクロモード + + public final static int COLOR_64_MONO = 2;// 64階調モノクロモード + + public final static int COLOR_32_MONO = 3;// 32階調モノクロモード + + public final static int COLOR_16_MONO = 4;// 16階調モノクロモード + + public final static int COLOR_8_MONO = 5;// 16階調モノクロモード + + private int[] _rgb_table_125; + + + /** + * i_width x i_heightの大きさのイメージを作成します。 + * + * @param i_width + * @param i_height + */ + public LabelingBufferdImage(int i_width, int i_height) + { + super(i_width, i_height, ColorSpace.TYPE_RGB); + // RGBテーブルを作成 + this._rgb_table_125 = new int[125]; + for (int i = 0; i < 5; i++) { + for (int i2 = 0; i2 < 5; i2++) { + for (int i3 = 0; i3 < 5; i3++) { + this._rgb_table_125[((i * 5) + i2) * 5 + i3] = ((((i * 63) << 8) | (i2 * 63)) << 8) | (i3 * 63); + } + } + } +/* case COLOR_256_MONO: + this._rgb_table = new int[256]; + this._number_of_color = 256; + for (int i = 0; i < 256; i++) { + this._rgb_table[i] = (i << 16) | (i << 8) | i; + } + break; + case COLOR_64_MONO: + this._rgb_table = new int[64]; + this._number_of_color = 64; + for (int i = 0; i < 64; i++) { + int m = (i * 4); + this._rgb_table[i] = (m << 16) | (m << 8) | m; + } + break; + case COLOR_32_MONO: + this._rgb_table = new int[32]; + this._number_of_color = 32; + for (int i = 0; i < 32; i++) { + int m = (i * 8); + this._rgb_table[i] = (m << 16) | (m << 8) | m; + } + break; + case COLOR_16_MONO: + this._rgb_table = new int[32]; + this._number_of_color = 16; + for (int i = 0; i < 16; i++) { + int m = (i * 8); + this._rgb_table[i] = (m << 16) | (m << 8) | m; + } + break; + }*/ + } + + + + public void drawImage(NyARGrayscaleRaster i_raster) throws NyARException + { + assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8); + + int w = this.getWidth(); + int h = this.getHeight(); + // サイズをチェック + NyARIntSize size = i_raster.getSize(); + if (size.h > h || size.w > w) { + throw new NyARException(); + } + + int[] limg; + // イメージの描画 + limg = (int[]) i_raster.getBufferReader().getBuffer(); + for (int i = 0; i < h; i++) { + for (int i2 = 0; i2 < w; i2++) { + this.setRGB(i2, i,limg[i*w+i2]); + } + } + return; + } + /** + * バイナリラスタ + * @param i_raster + * @throws NyARException + */ + public void drawImage(NyARBinRaster i_raster) throws NyARException + { + assert (i_raster.getBufferReader().getBufferType() == INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8); + + int w = this.getWidth(); + int h = this.getHeight(); + // サイズをチェック + NyARIntSize size = i_raster.getSize(); + if (size.h > h || size.w > w) { + throw new NyARException(); + } + + int[] limg; + // イメージの描画 + limg = (int[]) i_raster.getBufferReader().getBuffer(); + for (int i = 0; i < h; i++) { + for (int i2 = 0; i2 < w; i2++) { + this.setRGB(i2, i, limg[i*w+i2] > 0 ? 255 : 0); + } + } + return; + } + + /** + * ラベリングイメージを書く + * @param i_raster + * @throws NyARException + */ + public void drawLabel(NyARLabelingImage i_image) throws NyARException + { + int w = this.getWidth(); + int h = this.getHeight(); + // サイズをチェック + NyARIntSize size = i_image.getSize(); + if (size.h > h || size.w > w) { + throw new NyARException(); + } + int[] index_array=i_image.getIndexArray(); + + int[] limg; + // イメージの描画 + limg = (int[]) i_image.getBufferReader().getBuffer(); + for (int i = 0; i < h; i++) { + for (int i2 = 0; i2 < w; i2++) { + int t=limg[i*w+i2]-1; + if(t<0){ + t=0; + }else{ + t=index_array[t]; + } + this.setRGB(i2, i,_rgb_table_125[t% _rgb_table_125.length]); + } + } + return; + } + /** + * + * @param i_stack + */ + + public void overlayData(NyARLabelingLabel i_label) + { + Graphics g = this.getGraphics(); + g.setColor(Color.red); + 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); + return; + } + /** + * + * @param i_stack + */ + + public void overlayData(NyARIntPointStack i_stack) + { + int count = i_stack.getLength(); + NyARIntPoint2d[] items = i_stack.getArray(); + Graphics g = this.getGraphics(); + for (int i = 0; i < count; i++) { + int x = items[i].x; + int y = items[i].y; + g.setColor(Color.red); + g.drawLine(x - 5, y, x + 5, y); + g.drawLine(x, y + 5, x, y - 5); + } + return; + } + public void overlayData(NyARIntRectStack i_stack) + { + Color[] c=new Color[]{Color.cyan,Color.red,Color.green}; + int count = i_stack.getLength(); + NyARIntRect[] items = i_stack.getArray(); + Graphics g = this.getGraphics(); + for (int i = 0; i < count; i++) { + int x = items[i].x; + int y = items[i].y; + g.setColor(c[i%1]); + g.drawRect(x,y,items[i].w,items[i].h); + } + return; + } +} diff --git a/src/jp/nyatla/nyartoolkit/utils/j2se/NyARRasterImageIO.java b/src/jp/nyatla/nyartoolkit/utils/j2se/NyARRasterImageIO.java new file mode 100644 index 0000000..6b87aba --- /dev/null +++ b/src/jp/nyatla/nyartoolkit/utils/j2se/NyARRasterImageIO.java @@ -0,0 +1,179 @@ +/* + * PROJECT: NyARToolkit + * -------------------------------------------------------------------------------- + * This work is based on the original ARToolKit developed by + * Hirokazu Kato + * Mark Billinghurst + * HITLab, University of Washington, Seattle + * http://www.hitl.washington.edu/artoolkit/ + * + * The NyARToolkit is Java edition ARToolKit class library. + * Copyright (C)2008-2009 Ryo Iizuka + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * For further information please contact. + * http://nyatla.jp/nyatoolkit/ + * or + * + */ +package jp.nyatla.nyartoolkit.utils.j2se; + +import java.awt.Graphics.*; +import java.awt.image.*; +import java.awt.*; +import jp.nyatla.nyartoolkit.*; +import jp.nyatla.nyartoolkit.core.raster.rgb.*; +import jp.nyatla.nyartoolkit.core.raster.*; +import jp.nyatla.nyartoolkit.core.rasterreader.*; +import jp.nyatla.nyartoolkit.core.types.*; + +/** + * BufferdImageとRasterイメージ間で、ビットマップをコピーします。 + */ +public class NyARRasterImageIO +{ + /** + * i_inの内容を、このイメージにコピーします。 + * @param i_in + * @throws NyARException + */ + public static void copy(INyARRgbRaster i_in,BufferedImage o_out) throws NyARException + { + assert i_in.getSize().isEqualSize(o_out.getWidth(), o_out.getHeight()); + + //thisへ転写 + INyARRgbPixelReader reader=i_in.getRgbPixelReader(); + int[] rgb=new int[3]; + + for(int y=o_out.getHeight()-1;y>=0;y--){ + for(int x=o_out.getWidth()-1;x>=0;x--){ + reader.getPixel(x,y,rgb); + o_out.setRGB(x,y,(rgb[0]<<16)|(rgb[1]<<8)|rgb[2]); + } + } + return; + } + /** + * GrayScale用 + * @param i_in + * @throws NyARException + */ + public static void copy(NyARGrayscaleRaster i_in,BufferedImage o_out) throws NyARException + { + assert i_in.getSize().isEqualSize(o_out.getWidth(), o_out.getHeight()); + if(i_in.getBufferReader().isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8)) + { + final int[] buf=(int[])i_in.getBufferReader().getBuffer(); + final int w=o_out.getWidth(); + final int h=o_out.getHeight(); + for(int y=h-1;y>=0;y--){ + for(int x=w-1;x>=0;x--){ + int v=buf[x+y*w]; + o_out.setRGB(x, y,v*(1+0x100+0x10000)); + } + } + } + return; + } + /** + * BIN_8用 + * @param i_in + * @throws NyARException + */ + public static void copy(INyARRaster i_in,BufferedImage o_out) throws NyARException + { + assert i_in.getSize().isEqualSize(o_out.getWidth(), o_out.getHeight()); + if(i_in.getBufferReader().isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8)) + { + final int[] buf=(int[])i_in.getBufferReader().getBuffer(); + final int w=o_out.getWidth(); + final int h=o_out.getHeight(); + for(int y=h-1;y>=0;y--){ + for(int x=w-1;x>=0;x--){ + o_out.setRGB(x, y,buf[x+y*w]==0?0:0xffffff); + } + } + } + return; + } + /** + * ヒストグラムを書き出します。 + * @param i_in + * @param o_out + * @throws NyARException + */ + public static void copy(NyARHistgram i_in,int i_l,int i_t,int i_h,Graphics i_g) throws NyARException + { + //正規化のための定数を出す。 + int max=0; + for(int i=0;i=0;y--){ + for(int x=i_in.getWidth()-1;x>=0;x--){ + int pix=i_in.getRGB(x, y); + rgb[0]=(pix>>16)&0xff; + rgb[1]=(pix>>8)&0xff; + rgb[2]=(pix)&0xff; + reader.setPixel(x,y,rgb); + } + } + return; + } + /** + * BIN_8用 + * @param i_in + * @throws NyARException + */ + public static void copy(BufferedImage i_in,INyARRaster o_out) throws NyARException + { + assert o_out.getSize().isEqualSize(i_in.getWidth(), i_in.getHeight()); + if(o_out.getBufferReader().isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8)) + { + final int[] buf=(int[])o_out.getBufferReader().getBuffer(); + final int w=i_in.getWidth(); + final int h=i_in.getHeight(); + for(int y=h-1;y>=0;y--){ + for(int x=w-1;x>=0;x--){ + buf[x+y*w]=(i_in.getRGB(x, y)&0xffffff)>0?1:0; + } + } + } + return; + } + +}