1 package jp.nyatla.nyartoolkit.core.rasterfilter.gs2bin;
\r
3 import jp.nyatla.nyartoolkit.NyARException;
\r
4 import jp.nyatla.nyartoolkit.core.raster.NyARBinRaster;
\r
5 import jp.nyatla.nyartoolkit.core.raster.NyARGrayscaleRaster;
\r
6 import jp.nyatla.nyartoolkit.core.rasterreader.INyARBufferReader;
\r
7 import jp.nyatla.nyartoolkit.core.types.NyARIntSize;
\r
9 public class NyARRasterFilter_ConstantThrshold implements INyARRasterFilter_Gs2Bin
\r
11 public int _threshold;
\r
12 public NyARRasterFilter_ConstantThrshold(int i_initial_threshold,int i_in_raster_type,int i_out_raster_type) throws NyARException
\r
14 assert(i_in_raster_type==INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8);
\r
15 assert(i_out_raster_type==INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8);
\r
17 this._threshold=i_initial_threshold;
\r
23 * @throws NyARException
\r
25 public NyARRasterFilter_ConstantThrshold() throws NyARException
\r
31 public void setThreshold(int i_threshold)
\r
33 this._threshold = i_threshold;
\r
35 public void doFilter(NyARGrayscaleRaster i_input, NyARBinRaster i_output) throws NyARException
\r
37 assert(i_input.getBufferReader().getBufferType()==INyARBufferReader.BUFFERFORMAT_INT1D_GRAY_8);
\r
38 assert(i_output.getBufferReader().getBufferType()==INyARBufferReader.BUFFERFORMAT_INT1D_BIN_8);
\r
39 int[] out_buf = (int[]) i_output.getBufferReader().getBuffer();
\r
40 int[] in_buf = (int[]) i_input.getBufferReader().getBuffer();
\r
41 NyARIntSize s=i_input.getSize();
\r
43 final int th=this._threshold;
\r
45 final int pix_count =s.h*s.w;
\r
46 final int pix_mod_part=pix_count-(pix_count%8);
\r
47 for(bp=pix_count-1;bp>=pix_mod_part;bp--){
\r
48 out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;
\r
52 out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;
\r
54 out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;
\r
56 out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;
\r
58 out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;
\r
60 out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;
\r
62 out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;
\r
64 out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;
\r
66 out_buf[bp]=(in_buf[bp] & 0xff)<=th?0:1;
\r