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.nyartoolkit.sandbox.quadx2;
\r
34 import jp.nyatla.nyartoolkit.NyARException;
\r
35 import jp.nyatla.nyartoolkit.core.raster.*;
\r
36 import jp.nyatla.nyartoolkit.core.raster.rgb.INyARRgbRaster;
\r
37 import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;
\r
38 import jp.nyatla.nyartoolkit.core.types.*;
\r
39 import jp.nyatla.nyartoolkit.core.rasterfilter.rgb2bin.*;
\r
42 * 1/4のサイズの画像に変換しながら閾値判定する関数
\r
45 public class NyARRasterFilter_ARTTh_Quad implements INyARRasterFilter_RgbToBin
\r
47 private int _threshold;
\r
49 public NyARRasterFilter_ARTTh_Quad(int i_threshold)
\r
51 this._threshold = i_threshold;
\r
53 public void setThreshold(int i_threshold)
\r
55 this._threshold = i_threshold;
\r
58 public void doFilter(INyARRgbRaster i_input, NyARBinRaster i_output) throws NyARException
\r
60 INyARBufferReader in_buffer_reader=i_input.getBufferReader();
\r
61 INyARBufferReader out_buffer_reader=i_output.getBufferReader();
\r
62 int in_buf_type=in_buffer_reader.getBufferType();
\r
64 NyARIntSize size = i_output.getSize();
\r
65 assert (out_buffer_reader.isEqualBufferType(INyARBufferReader.BUFFERFORMAT_INT2D_BIN_8));
\r
66 assert (checkInputType(in_buf_type)==true);
\r
67 assert (i_input.getSize().isEqualSize(size.w*2,size.h*2) == true);
\r
69 int[][] out_buf = (int[][]) out_buffer_reader.getBuffer();
\r
70 byte[] in_buf = (byte[]) in_buffer_reader.getBuffer();
\r
72 switch (in_buffer_reader.getBufferType()) {
\r
73 case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:
\r
74 case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:
\r
75 convert24BitRgb(in_buf, out_buf, size);
\r
77 // case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32:
\r
78 // convert32BitRgbx(in_buf, out_buf, size);
\r
81 throw new NyARException();
\r
86 private void convert24BitRgb(byte[] i_in, int[][] i_out, NyARIntSize i_size)
\r
88 final int size_w=i_size.w*2;
\r
89 final int x_mod_end= size_w-(size_w%8);
\r
90 final int th=this._threshold*3;
\r
91 int bp =(size_w*i_size.h*2-1)*3;
\r
94 for (int y =i_size.h-1; y>=0 ; y--){
\r
96 final int[] row_ptr=i_out[y];
\r
97 for (x = i_size.w-1;x>=x_mod_end;x--) {
\r
98 w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
99 row_ptr[x]=w<=th?0:1;
\r
104 w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
105 row_ptr[x]=w<=th?0:1;
\r
107 w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
108 row_ptr[x-1]=w<=th?0:1;
\r
110 w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
111 row_ptr[x-2]=w<=th?0:1;
\r
113 w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
114 row_ptr[x-3]=w<=th?0:1;
\r
116 w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
117 row_ptr[x-4]=w<=th?0:1;
\r
119 w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
120 row_ptr[x-5]=w<=th?0:1;
\r
122 w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
123 row_ptr[x-6]=w<=th?0:1;
\r
125 w=((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
126 row_ptr[x-7]=w<=th?0:1;
\r
134 private void convert32BitRgbx(byte[] i_in, int[][] i_out, NyARIntSize i_size)
\r
136 final int size_w=i_size.w;
\r
137 final int x_mod_end= size_w-(size_w%8);
\r
138 final int th=this._threshold*3;
\r
139 int bp =(size_w*i_size.h-1)*4;
\r
142 for (int y =i_size.h-1; y>=0 ; y--){
\r
143 final int[] row_ptr=i_out[y];
\r
146 for (x = size_w-1;x>=x_mod_end;x--) {
\r
147 w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
148 row_ptr[x]=w<=th?0:1;
\r
153 w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
154 row_ptr[x]=w<=th?0:1;
\r
156 w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
157 row_ptr[x-1]=w<=th?0:1;
\r
159 w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
160 row_ptr[x-2]=w<=th?0:1;
\r
162 w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
163 row_ptr[x-3]=w<=th?0:1;
\r
165 w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
166 row_ptr[x-4]=w<=th?0:1;
\r
168 w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
169 row_ptr[x-5]=w<=th?0:1;
\r
171 w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
172 row_ptr[x-6]=w<=th?0:1;
\r
174 w= ((i_in[bp] & 0xff) + (i_in[bp + 1] & 0xff) + (i_in[bp + 2] & 0xff));
\r
175 row_ptr[x-7]=w<=th?0:1;
\r
182 private boolean checkInputType(int i_input_type) throws NyARException
\r
184 switch(i_input_type){
\r
185 case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8_24:
\r
186 case INyARBufferReader.BUFFERFORMAT_BYTE1D_R8G8B8_24:
\r
187 // case INyARBufferReader.BUFFERFORMAT_BYTE1D_B8G8R8X8_32:
\r
188 // case INyARBufferReader.BUFFERFORMAT_BYTE1D_R5G6B5_16LE:
\r