Example #1
0
            public void doFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
            {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                int[] in_ptr  = (int[])i_input.getBuffer();
                int[] out_ptr = (int[])i_output.getBuffer();
                int   width   = i_size.w;
                int   height  = i_size.h;

                for (int y = 0; y < height - 1; y++)
                {
                    int idx = y * width;
                    int p00 = in_ptr[idx];
                    int p10 = in_ptr[width + idx];
                    int p01, p11;
                    for (int x = 0; x < width - 1; x++)
                    {
                        p01 = in_ptr[idx + 1];
                        p11 = in_ptr[idx + width + 1];
                        int fx = p11 - p00;
                        int fy = p10 - p01;
                        out_ptr[idx] = (int)Math.Sqrt(fx * fx + fy * fy) >> 1;
                        p00          = p01;
                        p10          = p11;
                        idx++;
                    }
                }
                return;
            }
            public void createHistogram(INyARRaster i_raster, int i_l, int i_t, int i_w, int i_h, int[] o_histogram, int i_skip)
            {
                Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.WORD1D_R5G6B5_16LE));
                short[]     input        = (short[])i_raster.getBuffer();
                NyARIntSize s            = i_raster.getSize();
                int         skip         = (i_skip * s.w - i_w);
                int         pix_count    = i_w;
                int         pix_mod_part = pix_count - (pix_count % 8);
                //左上から1行づつ走査していく
                int pt = (i_t * s.w + i_l);

                for (int y = i_h - 1; y >= 0; y -= i_skip)
                {
                    int x, v;
                    for (x = pix_count - 1; x >= pix_mod_part; x--)
                    {
                        v = (int)input[pt++]; o_histogram[(((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3]++;
                    }
                    for (; x >= 0; x -= 8)
                    {
                        v = (int)input[pt++]; o_histogram[(((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3]++;
                        v = (int)input[pt++]; o_histogram[(((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3]++;
                        v = (int)input[pt++]; o_histogram[(((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3]++;
                        v = (int)input[pt++]; o_histogram[(((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3]++;
                        v = (int)input[pt++]; o_histogram[(((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3]++;
                        v = (int)input[pt++]; o_histogram[(((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3]++;
                        v = (int)input[pt++]; o_histogram[(((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3]++;
                        v = (int)input[pt++]; o_histogram[(((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3]++;
                    }
                    //スキップ
                    pt += skip;
                }
                return;
            }
        /**
         * XRGB[width*height]の配列から、パターンデータを構築。
         * @param i_buffer
         */
        public void setRaster(INyARRaster i_raster)
        {
            //i_buffer[XRGB]→差分[BW]変換			
            int i;
            int ave;//<PV/>
            int rgb;//<PV/>
            int[] linput = this._data;//<PV/>
            int[] buf = (int[])i_raster.getBuffer();

            // input配列のサイズとwhも更新// input=new int[height][width][3];
            int number_of_pixels = this._number_of_pixels;

            //<平均値計算(FORの1/8展開)/>
            ave = 0;
            for (i = number_of_pixels - 1; i >= 0; i--)
            {
                rgb = buf[i];
                ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);
            }
            ave = (number_of_pixels * 255 * 3 - ave) / (3 * number_of_pixels);
            //
            int sum = 0, w_sum;

            //<差分値計算/>
            for (i = number_of_pixels - 1; i >= 0; i--)
            {
                rgb = buf[i];
                w_sum = ((255 * 3 - (rgb & 0xff) - ((rgb >> 8) & 0xff) - ((rgb >> 16) & 0xff)) / 3) - ave;
                linput[i] = w_sum;
                sum += w_sum * w_sum;
            }
            double p = Math.Sqrt((double)sum);
            this._pow = p != 0.0 ? p : 0.0000001;
            return;
        }
		    public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size)
		    {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
			    int[] in_ptr =(int[])i_input.getBuffer();
			    int[] out_ptr=(int[])i_output.getBuffer();
			    int width=i_size.w;
			    int idx=0;
			    int idx2=width;
			    int fx,fy;
			    int mod_p=(width-2)-(width-2)%4;
			    for(int y=i_size.h-2;y>=0;y--){
				    int p00=in_ptr[idx++];
				    int p10=in_ptr[idx2++];
				    int p01,p11;
				    int x=width-2;
				    for(;x>=mod_p;x--){
					    p01=in_ptr[idx++];p11=in_ptr[idx2++];
					    fx=p11-p00;fy=p10-p01;
    //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
					    fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
					    p00=p01;
					    p10=p11;
				    }
				    for(;x>=0;x-=4){
					    p01=in_ptr[idx++];p11=in_ptr[idx2++];
					    fx=p11-p00;
					    fy=p10-p01;
    //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
					    fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
					    p00=p01;p10=p11;
					    p01=in_ptr[idx++];p11=in_ptr[idx2++];
					    fx=p11-p00;
					    fy=p10-p01;
    //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
					    fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
					    p00=p01;p10=p11;
					    p01=in_ptr[idx++];p11=in_ptr[idx2++];
    					
					    fx=p11-p00;
					    fy=p10-p01;
    //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
					    fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
					    p00=p01;p10=p11;

					    p01=in_ptr[idx++];p11=in_ptr[idx2++];
					    fx=p11-p00;
					    fy=p10-p01;
    //					out_ptr[idx-2]=255-(((fx<0?-fx:fx)+(fy<0?-fy:fy))>>1);
					    fx=(fx*fx+fy*fy)>>SH;out_ptr[idx-2]=(fx>255?0:255-fx);
					    p00=p01;p10=p11;

				    }
				    out_ptr[idx-1]=255;
			    }
			    for(int x=width-1;x>=0;x--){
				    out_ptr[idx++]=255;
			    }
			    return;
		    }
            public void doFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
            {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                int[] in_ptr = (int[])i_input.getBuffer();
                int[] out_ptr = (int[])i_output.getBuffer();
                int   width = i_size.w;
                int   idx = 0;
                int   idx2 = width;
                int   fx, fy;
                int   mod_p = (width - 2) - (width - 2) % 8;

                for (int y = i_size.h - 2; y >= 0; y--)
                {
                    int p00 = in_ptr[idx++];
                    int p10 = in_ptr[idx2++];
                    int p01, p11;
                    int x = width - 2;
                    for (; x >= mod_p; x--)
                    {
                        p01 = in_ptr[idx++]; p11 = in_ptr[idx2++];
                        fx  = p11 - p00; fy = p10 - p01;
                        out_ptr[idx - 2] = ((fx < 0?-fx:fx) + (fy < 0?-fy:fy)) >> 1;
                        p00 = p01;
                        p10 = p11;
                    }
                    for (; x >= 0; x -= 4)
                    {
                        p01 = in_ptr[idx++]; p11 = in_ptr[idx2++];
                        fx  = p11 - p00;
                        fy  = p10 - p01;
                        out_ptr[idx - 2] = ((fx < 0?-fx:fx) + (fy < 0?-fy:fy)) >> 1;
                        p00 = p01; p10 = p11;

                        p01 = in_ptr[idx++]; p11 = in_ptr[idx2++];
                        fx  = p11 - p00;
                        fy  = p10 - p01;
                        out_ptr[idx - 2] = ((fx < 0?-fx:fx) + (fy < 0?-fy:fy)) >> 1;
                        p00 = p01; p10 = p11;
                        p01 = in_ptr[idx++]; p11 = in_ptr[idx2++];

                        fx = p11 - p00;
                        fy = p10 - p01;
                        out_ptr[idx - 2] = ((fx < 0?-fx:fx) + (fy < 0?-fy:fy)) >> 1;
                        p00 = p01; p10 = p11;

                        p01 = in_ptr[idx++]; p11 = in_ptr[idx2++];
                        fx  = p11 - p00;
                        fy  = p10 - p01;
                        out_ptr[idx - 2] = ((fx < 0?-fx:fx) + (fy < 0?-fy:fy)) >> 1;
                        p00 = p01; p10 = p11;
                    }
                    out_ptr[idx - 1] = 0;
                }
                for (int x = width - 1; x >= 0; x--)
                {
                    out_ptr[idx++] = 0;
                }
                return;
            }
            public void createHistogram(INyARRaster i_raster, int i_l, int i_t, int i_w, int i_h, int[] o_histogram, int i_skip)
            {
                Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
                int[]       input        = (int[])i_raster.getBuffer();
                NyARIntSize s            = i_raster.getSize();
                int         skip         = (i_skip * s.w - i_w);
                int         pix_count    = i_w;
                int         pix_mod_part = pix_count - (pix_count % 8);
                //左上から1行づつ走査していく
                int pt = (i_t * s.w + i_l);

                for (int y = i_h - 1; y >= 0; y -= i_skip)
                {
                    int x, v;
                    for (x = pix_count - 1; x >= pix_mod_part; x--)
                    {
                        v = input[pt++]; o_histogram[((v & 0xff) + (v & 0xff) + (v & 0xff)) / 3]++;
                    }
                    for (; x >= 0; x -= 8)
                    {
                        v = input[pt++]; o_histogram[((v & 0xff) + (v & 0xff) + (v & 0xff)) / 3]++;
                        v = input[pt++]; o_histogram[((v & 0xff) + (v & 0xff) + (v & 0xff)) / 3]++;
                        v = input[pt++]; o_histogram[((v & 0xff) + (v & 0xff) + (v & 0xff)) / 3]++;
                        v = input[pt++]; o_histogram[((v & 0xff) + (v & 0xff) + (v & 0xff)) / 3]++;
                        v = input[pt++]; o_histogram[((v & 0xff) + (v & 0xff) + (v & 0xff)) / 3]++;
                        v = input[pt++]; o_histogram[((v & 0xff) + (v & 0xff) + (v & 0xff)) / 3]++;
                        v = input[pt++]; o_histogram[((v & 0xff) + (v & 0xff) + (v & 0xff)) / 3]++;
                        v = input[pt++]; o_histogram[((v & 0xff) + (v & 0xff) + (v & 0xff)) / 3]++;
                    }
                    //スキップ
                    pt += skip;
                }
                return;
            }
		    public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size)
		    {
			    Debug.Assert (i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
			    Debug.Assert (i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
			    int[] in_ptr =(int[])i_input.getBuffer();
			    int[] out_ptr=(int[])i_output.getBuffer();
			    int width=i_size.w;
			    int height=i_size.h;
			    for(int y=0;y<height-1;y++){
				    int idx=y*width;
				    int p00=in_ptr[idx];
				    int p10=in_ptr[width+idx];
				    int p01,p11;
				    for(int x=0;x<width-1;x++){
					    p01=in_ptr[idx+1];
					    p11=in_ptr[idx+width+1];
					    int fx=p11-p00;
					    int fy=p10-p01;
					    out_ptr[idx]=(int)Math.Sqrt(fx*fx+fy*fy)>>1;
					    p00=p01;
					    p10=p11;
					    idx++;
				    }
			    }
			    return;
		    }
		    public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size)
		    {
			    Debug.Assert (i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
			    Debug.Assert (i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
			    int[] in_ptr =(int[])i_input.getBuffer();
			    int[] out_ptr=(int[])i_output.getBuffer();
			    int width=i_size.w;
			    int height=i_size.h;
			    int col0,col1,col2;
			    int bptr=0;
			    //1行目
			    col1=in_ptr[bptr  ]*2+in_ptr[bptr+width  ];
			    col2=in_ptr[bptr+1]*2+in_ptr[bptr+width+1];
			    out_ptr[bptr]=(col1*2+col2)/9;
			    bptr++;
			    for(int x=0;x<width-2;x++){
				    col0=col1;
				    col1=col2;
				    col2=in_ptr[bptr+1]*2+in_ptr[bptr+width+1];
				    out_ptr[bptr]=(col0+col1*2+col2)/12;
				    bptr++;
			    }			
			    out_ptr[bptr]=(col1+col2)/9;
			    bptr++;
			    //2行目-末行-1

			    for(int y=0;y<height-2;y++){
				    //左端
				    col1=in_ptr[bptr  ]*2+in_ptr[bptr-width  ]+in_ptr[bptr+width  ];
				    col2=in_ptr[bptr+1]*2+in_ptr[bptr-width+1]+in_ptr[bptr+width+1];
				    out_ptr[bptr]=(col1+col2)/12;
				    bptr++;
				    for(int x=0;x<width-2;x++){
					    col0=col1;
					    col1=col2;
					    col2=in_ptr[bptr+1]*2+in_ptr[bptr-width+1]+in_ptr[bptr+width+1];
					    out_ptr[bptr]=(col0+col1*2+col2)/16;
					    bptr++;
				    }
				    //右端
				    out_ptr[bptr]=(col1*2+col2)/12;
				    bptr++;
			    }
			    //末行目
			    col1=in_ptr[bptr  ]*2+in_ptr[bptr-width  ];
			    col2=in_ptr[bptr+1]*2+in_ptr[bptr-width+1];
			    out_ptr[bptr]=(col1+col2)/9;
			    bptr++;
			    for(int x=0;x<width-2;x++){
				    col0=col1;
				    col1=col2;
				    col2=in_ptr[bptr+1]*2+in_ptr[bptr-width+1];
				    out_ptr[bptr]=(col0+col1*2+col2)/12;
				    bptr++;
			    }			
			    out_ptr[bptr]=(col1*2+col2)/9;
			    bptr++;
			    return;
		    }
Example #9
0
            public void doThFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size, int i_threshold)
            {
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_BIN_8));

                int[]  out_buf = (int[])i_output.getBuffer();
                byte[] in_buf  = (byte[])i_input.getBuffer();

                int th = i_threshold * 3;
                int bp = (i_size.w * i_size.h - 1) * 4;
                int w;
                int xy;
                int pix_count    = i_size.h * i_size.w;
                int pix_mod_part = pix_count - (pix_count % 8);

                for (xy = pix_count - 1; xy >= pix_mod_part; xy--)
                {
                    w           = ((in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
                    out_buf[xy] = w <= th?0:1;
                    bp         -= 4;
                }
                //タイリング
                for (; xy >= 0;)
                {
                    w           = ((in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
                    out_buf[xy] = w <= th?0:1;
                    bp         -= 4;
                    xy--;
                    w           = ((in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
                    out_buf[xy] = w <= th?0:1;
                    bp         -= 4;
                    xy--;
                    w           = ((in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
                    out_buf[xy] = w <= th?0:1;
                    bp         -= 4;
                    xy--;
                    w           = ((in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
                    out_buf[xy] = w <= th?0:1;
                    bp         -= 4;
                    xy--;
                    w           = ((in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
                    out_buf[xy] = w <= th?0:1;
                    bp         -= 4;
                    xy--;
                    w           = ((in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
                    out_buf[xy] = w <= th?0:1;
                    bp         -= 4;
                    xy--;
                    w           = ((in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
                    out_buf[xy] = w <= th?0:1;
                    bp         -= 4;
                    xy--;
                    w           = ((in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
                    out_buf[xy] = w <= th?0:1;
                    bp         -= 4;
                    xy--;
                }
                return;
            }
Example #10
0
            public void doThFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size, int i_threshold)
            {
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_BIN_8));

                int[]   out_buf = (int[])i_output.getBuffer();
                short[] in_buf  = (short[])i_input.getBuffer();

                int th = i_threshold * 3;
                int w;
                int xy;
                int pix_count    = i_size.h * i_size.w;
                int pix_mod_part = pix_count - (pix_count % 8);

                for (xy = pix_count - 1; xy >= pix_mod_part; xy--)
                {
                    w           = (int)in_buf[xy];
                    w           = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
                }
                //タイリング
                for (; xy >= 0;)
                {
                    w           = (int)in_buf[xy];
                    w           = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
                    xy--;
                    w           = (int)in_buf[xy];
                    w           = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
                    xy--;
                    w           = (int)in_buf[xy];
                    w           = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
                    xy--;
                    w           = (int)in_buf[xy];
                    w           = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
                    xy--;
                    w           = (int)in_buf[xy];
                    w           = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
                    xy--;
                    w           = (int)in_buf[xy];
                    w           = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
                    xy--;
                    w           = (int)in_buf[xy];
                    w           = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
                    xy--;
                    w           = (int)in_buf[xy];
                    w           = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
                    xy--;
                }
            }
		    public override void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size)
		    {
			   Debug. Assert(		i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
    			
			    int[] out_buf = (int[]) i_output.getBuffer();
			    int[] in_buf = (int[]) i_input.getBuffer();
			    for(int i=i_size.h*i_size.w-1;i>=0;i--)
			    {
				    out_buf[i]=this._table_ref[in_buf[i]];
			    }
			    return;
		    }
            public override void doFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
            {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));

                int[] out_buf = (int[])i_output.getBuffer();
                int[] in_buf  = (int[])i_input.getBuffer();
                for (int i = i_size.h * i_size.w - 1; i >= 0; i--)
                {
                    out_buf[i] = this._table_ref[in_buf[i]];
                }
                return;
            }
            public void doCutFilter(INyARRaster i_input, int l, int t, int i_st, NyARGrayscaleRaster o_output)
            {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24) || i_input.isEqualBufferType(NyARBufferType.BYTE1D_R8G8B8_24));
                Debug.Assert(i_input.getSize().isInnerSize(l + o_output.getWidth() * i_st, t + o_output.getHeight() * i_st));

                byte[]      input = (byte[])i_input.getBuffer();
                int[]       output = (int[])o_output.getBuffer();
                int         pt_src, pt_dst;
                NyARIntSize dest_size    = o_output.getSize();
                NyARIntSize src_size     = i_input.getSize();
                int         skip_src_y   = (src_size.w - dest_size.w * i_st) * 3 + src_size.w * (i_st - 1) * 3;
                int         skip_src_x   = 3 * i_st;
                int         pix_count    = dest_size.w;
                int         pix_mod_part = pix_count - (pix_count % 8);

                //左上から1行づつ走査していく
                pt_dst = 0;
                pt_src = (t * src_size.w + l) * 3;
                for (int y = dest_size.h - 1; y >= 0; y -= 1)
                {
                    int x;
                    for (x = pix_count - 1; x >= pix_mod_part; x--)
                    {
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) >> 2;
                        pt_src          += skip_src_x;
                    }
                    for (; x >= 0; x -= 8)
                    {
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) >> 2;
                        pt_src          += skip_src_x;
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) >> 2;
                        pt_src          += skip_src_x;
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) >> 2;
                        pt_src          += skip_src_x;
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) >> 2;
                        pt_src          += skip_src_x;
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) >> 2;
                        pt_src          += skip_src_x;
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) >> 2;
                        pt_src          += skip_src_x;
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) >> 2;
                        pt_src          += skip_src_x;
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) >> 2;
                        pt_src          += skip_src_x;
                    }
                    //スキップ
                    pt_src += skip_src_y;
                }
                return;
            }
            public void doThFilter(INyARRaster i_raster, int i_l, int i_t, int i_w, int i_h, int i_th, INyARRaster o_raster)
            {
                Debug.Assert(
                    i_raster.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24) ||
                    i_raster.isEqualBufferType(NyARBufferType.BYTE1D_R8G8B8_24));
                byte[]      input        = (byte[])i_raster.getBuffer();
                int[]       output       = (int[])o_raster.getBuffer();
                int         th           = i_th * 3;
                NyARIntSize s            = i_raster.getSize();
                int         skip_dst     = (s.w - i_w);
                int         skip_src     = skip_dst * 3;
                int         pix_count    = i_w;
                int         pix_mod_part = pix_count - (pix_count % 8);
                //左上から1行づつ走査していく
                int pt_dst = (i_t * s.w + i_l);
                int pt_src = pt_dst * 3;

                for (int y = i_h - 1; y >= 0; y -= 1)
                {
                    int x;
                    for (x = pix_count - 1; x >= pix_mod_part; x--)
                    {
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th?0:1;
                        pt_src          += 3;
                    }
                    for (; x >= 0; x -= 8)
                    {
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th?0:1;
                        pt_src          += 3;
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th?0:1;
                        pt_src          += 3;
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th?0:1;
                        pt_src          += 3;
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th?0:1;
                        pt_src          += 3;
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th?0:1;
                        pt_src          += 3;
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th?0:1;
                        pt_src          += 3;
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th?0:1;
                        pt_src          += 3;
                        output[pt_dst++] = ((input[pt_src + 0] & 0xff) + (input[pt_src + 1] & 0xff) + (input[pt_src + 2] & 0xff)) <= th?0:1;
                        pt_src          += 3;
                    }
                    //スキップ
                    pt_src += skip_src;
                    pt_dst += skip_dst;
                }
                return;
            }
            public int createHistogram(INyARRaster i_reader, NyARIntSize i_size, int[] o_histogram, int i_skip)
            {
                Debug.Assert(i_reader.isEqualBufferType(NyARBufferType.WORD1D_R5G6B5_16LE));
                short[] input        = (short[])i_reader.getBuffer();
                int     pix_count    = i_size.w;
                int     pix_mod_part = pix_count - (pix_count % 8);

                for (int y = i_size.h - 1; y >= 0; y -= i_skip)
                {
                    int pt = y * i_size.w;
                    int x, v;
                    for (x = pix_count - 1; x >= pix_mod_part; x--)
                    {
                        v = (int)input[pt];
                        v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3;
                        o_histogram[v]++;
                        pt++;
                    }
                    //タイリング
                    for (; x >= 0; x -= 8)
                    {
                        v = (int)input[pt]; pt++;
                        v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3;
                        o_histogram[v]++;
                        v = (int)input[pt]; pt++;
                        v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3;
                        o_histogram[v]++;
                        v = (int)input[pt]; pt++;
                        v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3;
                        o_histogram[v]++;
                        v = (int)input[pt]; pt++;
                        v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3;
                        o_histogram[v]++;
                        v = (int)input[pt]; pt++;
                        v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3;
                        o_histogram[v]++;
                        v = (int)input[pt]; pt++;
                        v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3;
                        o_histogram[v]++;
                        v = (int)input[pt]; pt++;
                        v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3;
                        o_histogram[v]++;
                        v = (int)input[pt]; pt++;
                        v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) / 3;
                        o_histogram[v]++;
                    }
                }
                return(i_size.w * i_size.h);
            }
            public void doFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
            {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                int[] in_ptr = (int[])i_input.getBuffer();
                int[] out_ptr = (int[])i_output.getBuffer();


                int number_of_pixel = i_size.h * i_size.w;
                for (int i = 0; i < number_of_pixel; i++)
                {
                    out_ptr[i] = 255 - in_ptr[i];
                }
                return;
            }
 public int createHistogram(INyARRaster i_reader, NyARIntSize i_size, int[] o_histogram, int i_skip)
 {
     Debug.Assert(i_reader.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
     int[] input = (int[])i_reader.getBuffer();
     for (int y = i_size.h - 1; y >= 0; y -= i_skip)
     {
         int pt = y * i_size.w;
         for (int x = i_size.w - 1; x >= 0; x--)
         {
             o_histogram[input[pt]]++;
             pt++;
         }
     }
     return(i_size.w * i_size.h);
 }
            public void doFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
            {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                int[] in_ptr  = (int[])i_input.getBuffer();
                int[] out_ptr = (int[])i_output.getBuffer();


                int number_of_pixel = i_size.h * i_size.w;

                for (int i = 0; i < number_of_pixel; i++)
                {
                    out_ptr[i] = 255 - in_ptr[i];
                }
                return;
            }
Example #19
0
            public void doFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
            {
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
                int[]  out_buf = (int[])i_output.getBuffer();
                byte[] in_buf  = (byte[])i_input.getBuffer();

                int bp = 0;

                for (int y = 0; y < i_size.h; y++)
                {
                    for (int x = 0; x < i_size.w; x++)
                    {
                        out_buf[y * i_size.w + x] = ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) / 3;
                        bp += 4;
                    }
                }
            }
		    /**
		     * This function is not optimized.
		     */
		    public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size)
		    {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24));
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
    			
			    int[] out_buf = (int[]) i_output.getBuffer();
			    byte[] in_buf = (byte[]) i_input.getBuffer();

			    int bp = 0;
			    for (int y = 0; y < i_size.h; y++){
				    for (int x = 0; x < i_size.w; x++){
					    out_buf[y*i_size.w+x]=(306*(in_buf[bp+2] & 0xff)+601*(in_buf[bp + 1] & 0xff)+117 * (in_buf[bp + 0] & 0xff))>>10;
					    bp += 3;
				    }
			    }
			    return;
		    }
            public int createHistogram(INyARRaster i_reader, NyARIntSize i_size, int[] o_histogram, int i_skip)
            {
                Debug.Assert(
                    i_reader.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24) ||
                    i_reader.isEqualBufferType(NyARBufferType.BYTE1D_R8G8B8_24));
                byte[] input        = (byte[])i_reader.getBuffer();
                int    pix_count    = i_size.w;
                int    pix_mod_part = pix_count - (pix_count % 8);

                for (int y = i_size.h - 1; y >= 0; y -= i_skip)
                {
                    int pt = y * i_size.w * 3;
                    int x, v;
                    for (x = pix_count - 1; x >= pix_mod_part; x--)
                    {
                        v = ((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3;
                        o_histogram[v]++;
                        pt += 3;
                    }
                    //タイリング
                    for (; x >= 0; x -= 8)
                    {
                        v = ((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3;
                        o_histogram[v]++;
                        v = ((input[pt + 3] & 0xff) + (input[pt + 4] & 0xff) + (input[pt + 5] & 0xff)) / 3;
                        o_histogram[v]++;
                        v = ((input[pt + 6] & 0xff) + (input[pt + 7] & 0xff) + (input[pt + 8] & 0xff)) / 3;
                        o_histogram[v]++;
                        v = ((input[pt + 9] & 0xff) + (input[pt + 10] & 0xff) + (input[pt + 11] & 0xff)) / 3;
                        o_histogram[v]++;
                        v = ((input[pt + 12] & 0xff) + (input[pt + 13] & 0xff) + (input[pt + 14] & 0xff)) / 3;
                        o_histogram[v]++;
                        v = ((input[pt + 15] & 0xff) + (input[pt + 16] & 0xff) + (input[pt + 17] & 0xff)) / 3;
                        o_histogram[v]++;
                        v = ((input[pt + 18] & 0xff) + (input[pt + 19] & 0xff) + (input[pt + 20] & 0xff)) / 3;
                        o_histogram[v]++;
                        v = ((input[pt + 21] & 0xff) + (input[pt + 22] & 0xff) + (input[pt + 23] & 0xff)) / 3;
                        o_histogram[v]++;
                        pt += 3 * 8;
                    }
                }
                return(i_size.w * i_size.h);
            }
            public void createHistogram(INyARRaster i_raster, int i_l, int i_t, int i_w, int i_h, int[] o_histogram, int i_skip)
            {
                Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8X8_32));
                byte[]      input        = (byte[])i_raster.getBuffer();
                NyARIntSize s            = i_raster.getSize();
                int         skip         = (i_skip * s.w - i_w) * 4;
                int         pix_count    = i_w;
                int         pix_mod_part = pix_count - (pix_count % 8);
                //左上から1行づつ走査していく
                int pt = (i_t * s.w + i_l) * 4;

                for (int y = i_h - 1; y >= 0; y -= i_skip)
                {
                    int x;
                    for (x = pix_count - 1; x >= pix_mod_part; x--)
                    {
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        pt += 4;
                    }
                    for (; x >= 0; x -= 8)
                    {
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        pt += 4;
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        pt += 4;
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        pt += 4;
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        pt += 4;
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        pt += 4;
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        pt += 4;
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        pt += 4;
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        pt += 4;
                    }
                    //スキップ
                    pt += skip;
                }
                return;
            }
Example #23
0
            /**
             * This function is not optimized.
             */
            public void doFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
            {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24));
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));

                int[]  out_buf = (int[])i_output.getBuffer();
                byte[] in_buf  = (byte[])i_input.getBuffer();

                int bp = 0;

                for (int y = 0; y < i_size.h; y++)
                {
                    for (int x = 0; x < i_size.w; x++)
                    {
                        out_buf[y * i_size.w + x] = (306 * (in_buf[bp + 2] & 0xff) + 601 * (in_buf[bp + 1] & 0xff) + 117 * (in_buf[bp + 0] & 0xff)) >> 10;
                        bp += 3;
                    }
                }
                return;
            }
            public void doFilter(INyARRaster i_input, int[] o_output, int l, int t, int w, int h)
            {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8X8_32));
                NyARIntSize size = i_input.getSize();

                byte[] in_buf = (byte[])i_input.getBuffer();

                int bp          = (l + t * size.w) * 4;
                int b           = t + h;
                int row_padding = (size.w - w) * 4;

                for (int y = t; y < b; y++)
                {
                    for (int x = 0; x < w; x++)
                    {
                        o_output[y * size.w + x + l] = ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) >> 2;
                        bp += 4;
                    }
                    bp += row_padding;
                }
            }
            public void doThFilter(INyARRaster i_raster, int i_l, int i_t, int i_w, int i_h, int i_th, INyARRaster o_raster)
            {
                Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
                int[] input  = (int[])i_raster.getBuffer();
                int[] output = (int[])o_raster.getBuffer();
                int   th     = i_th * 3;

                NyARIntSize s            = i_raster.getSize();
                int         skip_src     = (s.w - i_w);
                int         skip_dst     = skip_src;
                int         pix_count    = i_w;
                int         pix_mod_part = pix_count - (pix_count % 8);
                //左上から1行づつ走査していく
                int pt_dst = (i_t * s.w + i_l);
                int pt_src = pt_dst;

                for (int y = i_h - 1; y >= 0; y -= 1)
                {
                    int x, v;
                    for (x = pix_count - 1; x >= pix_mod_part; x--)
                    {
                        v = input[pt_src++]; output[pt_dst++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) <= th?0:1;
                    }
                    for (; x >= 0; x -= 8)
                    {
                        v = input[pt_src++]; output[pt_dst++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) <= th?0:1;
                        v = input[pt_src++]; output[pt_dst++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) <= th?0:1;
                        v = input[pt_src++]; output[pt_dst++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) <= th?0:1;
                        v = input[pt_src++]; output[pt_dst++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) <= th?0:1;
                        v = input[pt_src++]; output[pt_dst++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) <= th?0:1;
                        v = input[pt_src++]; output[pt_dst++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) <= th?0:1;
                        v = input[pt_src++]; output[pt_dst++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) <= th?0:1;
                        v = input[pt_src++]; output[pt_dst++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) <= th?0:1;
                    }
                    //スキップ
                    pt_src += skip_src;
                    pt_dst += skip_dst;
                }
                return;
            }
            public void doFilter(INyARRaster i_input, int[] o_output, int l, int t, int w, int h)
            {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24) || i_input.isEqualBufferType(NyARBufferType.BYTE1D_R8G8B8_24));

                NyARIntSize size = i_input.getSize();

                byte[] in_buf          = (byte[])i_input.getBuffer();
                int    bp              = (l + t * size.w) * 3;
                int    b               = t + h;
                int    row_padding_dst = (size.w - w);
                int    row_padding_src = row_padding_dst * 3;
                int    pix_count       = w;
                int    pix_mod_part    = pix_count - (pix_count % 8);
                int    src_ptr         = t * size.w + l;

                for (int y = t; y < b; y++)
                {
                    int x = 0;
                    for (x = pix_count - 1; x >= pix_mod_part; x--)
                    {
                        o_output[src_ptr++] = ((in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff)) >> 2;
                    }
                    for (; x >= 0; x -= 8)
                    {
                        o_output[src_ptr++] = ((in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff)) >> 2;
                        o_output[src_ptr++] = ((in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff)) >> 2;
                        o_output[src_ptr++] = ((in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff)) >> 2;
                        o_output[src_ptr++] = ((in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff)) >> 2;
                        o_output[src_ptr++] = ((in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff)) >> 2;
                        o_output[src_ptr++] = ((in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff)) >> 2;
                        o_output[src_ptr++] = ((in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff)) >> 2;
                        o_output[src_ptr++] = ((in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff) + (in_buf[bp++] & 0xff)) >> 2;
                    }

                    bp      += row_padding_dst;
                    src_ptr += row_padding_src;
                }
                return;
            }
            public void doThFilter(INyARRaster i_raster, int i_l, int i_t, int i_w, int i_h, int i_th, INyARRaster o_raster)
            {
                Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.WORD1D_R5G6B5_16LE));
                short[]     input        = (short[])i_raster.getBuffer();
                int[]       output       = (int[])o_raster.getBuffer();
                int         th           = i_th * 3;
                NyARIntSize s            = i_raster.getSize();
                int         skip_dst     = (s.w - i_w);
                int         skip_src     = skip_dst;
                int         pix_count    = i_w;
                int         pix_mod_part = pix_count - (pix_count % 8);
                //左上から1行づつ走査していく
                int pt_dst = (i_t * s.w + i_l);
                int pt_src = pt_dst;

                for (int y = i_h - 1; y >= 0; y -= 1)
                {
                    int x, v;
                    for (x = pix_count - 1; x >= pix_mod_part; x--)
                    {
                        v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th?0:1;
                    }
                    for (; x >= 0; x -= 8)
                    {
                        v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th?0:1;
                        v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th?0:1;
                        v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th?0:1;
                        v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th?0:1;
                        v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th?0:1;
                        v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th?0:1;
                        v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th?0:1;
                        v = (int)input[pt_src++]; output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) <= th?0:1;
                    }
                    //スキップ
                    pt_src += skip_src;
                    pt_dst += skip_dst;
                }
                return;
            }
            public void doFilter(INyARRaster i_input, int[] o_output, int l, int t, int w, int h)
            {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
                NyARIntSize size = i_input.getSize();

                int[] in_buf = (int[])i_input.getBuffer();
                int   bp     = (l + t * size.w);
                int   v;
                int   b = t + h;
                int   row_padding_dst = (size.w - w);
                int   row_padding_src = row_padding_dst;
                int   pix_count       = w;
                int   pix_mod_part    = pix_count - (pix_count % 8);
                int   src_ptr         = t * size.w + l;

                for (int y = t; y < b; y++)
                {
                    int x = 0;
                    for (x = pix_count - 1; x >= pix_mod_part; x--)
                    {
                        v = in_buf[src_ptr++]; o_output[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) >> 2;
                    }
                    for (; x >= 0; x -= 8)
                    {
                        v = in_buf[src_ptr++]; o_output[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) >> 2;
                        v = in_buf[src_ptr++]; o_output[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) >> 2;
                        v = in_buf[src_ptr++]; o_output[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) >> 2;
                        v = in_buf[src_ptr++]; o_output[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) >> 2;
                        v = in_buf[src_ptr++]; o_output[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) >> 2;
                        v = in_buf[src_ptr++]; o_output[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) >> 2;
                        v = in_buf[src_ptr++]; o_output[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) >> 2;
                        v = in_buf[src_ptr++]; o_output[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) >> 2;
                    }
                    bp      += row_padding_dst;
                    src_ptr += row_padding_src;
                }
                return;
            }
        /**
         * XRGB[width*height]の配列から、パターンデータを構築。
         * @param i_buffer
         */
        public void setRaster(INyARRaster i_raster)
        {
            //i_buffer[XRGB]→差分[BW]変換
            int i;
            int ave;                   //<PV/>
            int rgb;                   //<PV/>

            int[] linput = this._data; //<PV/>
            int[] buf    = (int[])i_raster.getBuffer();

            // input配列のサイズとwhも更新// input=new int[height][width][3];
            int number_of_pixels = this._number_of_pixels;

            //<平均値計算(FORの1/8展開)/>
            ave = 0;
            for (i = number_of_pixels - 1; i >= 0; i--)
            {
                rgb  = buf[i];
                ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);
            }
            ave = (number_of_pixels * 255 * 3 - ave) / (3 * number_of_pixels);
            //
            int sum = 0, w_sum;

            //<差分値計算/>
            for (i = number_of_pixels - 1; i >= 0; i--)
            {
                rgb       = buf[i];
                w_sum     = ((255 * 3 - (rgb & 0xff) - ((rgb >> 8) & 0xff) - ((rgb >> 16) & 0xff)) / 3) - ave;
                linput[i] = w_sum;
                sum      += w_sum * w_sum;
            }
            double p = Math.Sqrt((double)sum);

            this._pow = p != 0.0 ? p : 0.0000001;
            return;
        }
            public void doFilter(INyARRaster i_input, int[] o_output, int l, int t, int w, int h)
            {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.WORD1D_R5G6B5_16LE));
                short[]     input        = (short[])i_input.getBuffer();
                NyARIntSize s            = i_input.getSize();
                int         skip_dst     = (s.w - w);
                int         skip_src     = skip_dst;
                int         pix_count    = w;
                int         pix_mod_part = pix_count - (pix_count % 8);
                //左上から1行づつ走査していく
                int pt_dst = (t * s.w + l);
                int pt_src = pt_dst;

                for (int y = h - 1; y >= 0; y -= 1)
                {
                    int x, v;
                    for (x = pix_count - 1; x >= pix_mod_part; x--)
                    {
                        v = (int)input[pt_src++]; o_output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) >> 2;
                    }
                    for (; x >= 0; x -= 8)
                    {
                        v = (int)input[pt_src++]; o_output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) >> 2;
                        v = (int)input[pt_src++]; o_output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) >> 2;
                        v = (int)input[pt_src++]; o_output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) >> 2;
                        v = (int)input[pt_src++]; o_output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) >> 2;
                        v = (int)input[pt_src++]; o_output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) >> 2;
                        v = (int)input[pt_src++]; o_output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) >> 2;
                        v = (int)input[pt_src++]; o_output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) >> 2;
                        v = (int)input[pt_src++]; o_output[pt_dst++] = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3)) >> 2;
                    }
                    //スキップ
                    pt_src += skip_src;
                    pt_dst += skip_dst;
                }
                return;
            }
		    public void doThFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size,int i_threshold)
		    {
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_BIN_8));
    			
			    int[] out_buf = (int[]) i_output.getBuffer();
			    byte[] in_buf = (byte[]) i_input.getBuffer();
    			
			    int th=i_threshold*3;
			    int bp =(i_size.w*i_size.h-1)*4;
			    int w;
			    int xy;
			    int pix_count   =i_size.h*i_size.w;
			    int pix_mod_part=pix_count-(pix_count%8);
			    for(xy=pix_count-1;xy>=pix_mod_part;xy--){
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
			    }
			    //タイリング
			    for (;xy>=0;) {
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
				    w= ((in_buf[bp+1] & 0xff) + (in_buf[bp + 2] & 0xff) + (in_buf[bp + 3] & 0xff));
				    out_buf[xy]=w<=th?0:1;
				    bp -= 4;
				    xy--;
			    }
			    return;			
		    }
            public void doFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
            {
                Debug.Assert(i_input.isEqualBufferType(NyARBufferType.INT1D_X7H9S8V8_32));

                int[]  out_buf = (int[])i_output.getBuffer();
                byte[] in_buf  = (byte[])i_input.getBuffer();
                int    s;

                for (int i = i_size.h * i_size.w - 1; i >= 0; i--)
                {
                    int r = (in_buf[i * 3 + 2] & 0xff);
                    int g = (in_buf[i * 3 + 1] & 0xff);
                    int b = (in_buf[i * 3 + 0] & 0xff);
                    int cmax, cmin;
                    //最大値と最小値を計算
                    if (r > g)
                    {
                        cmax = r;
                        cmin = g;
                    }
                    else
                    {
                        cmax = g;
                        cmin = r;
                    }
                    if (b > cmax)
                    {
                        cmax = b;
                    }
                    if (b < cmin)
                    {
                        cmin = b;
                    }
                    int h;
                    if (cmax == 0)
                    {
                        s = 0;
                        h = 0;
                    }
                    else
                    {
                        s = (cmax - cmin) * 255 / cmax;
                        int cdes = cmax - cmin;
                        //H成分を計算
                        if (cdes != 0)
                        {
                            if (cmax == r)
                            {
                                h = (g - b) * 60 / cdes;
                            }
                            else if (cmax == g)
                            {
                                h = (b - r) * 60 / cdes + 2 * 60;
                            }
                            else
                            {
                                h = (r - g) * 60 / cdes + 4 * 60;
                            }
                        }
                        else
                        {
                            h = 0;
                        }
                    }
                    if (h < 0)
                    {
                        h += 360;
                    }
                    //hsv変換(h9s8v8)
                    out_buf[i] = (0x1ff0000 & (h << 16)) | (0x00ff00 & (s << 8)) | (cmax & 0xff);
                }
                return;
            }
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            Color32[] in_pixs = (Color32[])this._ref_raster.getBuffer();
            int       in_w    = this._ref_raster.getWidth();
            int       in_h    = this._ref_raster.getHeight();

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];

            int    out_w      = o_out.getWidth();
            int    out_h      = o_out.getHeight();
            double cp7_cy_1   = cp7 * pk_t + 1.0 + cp6 * pk_l;
            double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l;
            double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l;
            int    p;

            int step, offset;

            //flip Virtical
            switch (o_out.getBufferType())
            {
            case NyARBufferType.INT1D_X8R8G8B8_32:
                int[] pat_data = (int[])o_out.getBuffer();
                p = 0;
                if (this._is_inv_v)
                {
                    offset = in_w * (in_h - 1);
                    step   = -in_w;
                }
                else
                {
                    offset = 0;
                    step   = in_w;
                }
                for (int iy = 0; iy < out_h; iy++)
                {
                    //解像度分の点を取る。
                    double cp7_cy_1_cp6_cx   = cp7_cy_1;
                    double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                    double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                    for (int ix = 0; ix < out_w; ix++)
                    {
                        //1ピクセルを作成
                        double d = 1 / (cp7_cy_1_cp6_cx);
                        int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                        int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                        if (x < 0)
                        {
                            x = 0;
                        }
                        else if (x >= in_w)
                        {
                            x = in_w - 1;
                        }
                        if (y < 0)
                        {
                            y = 0;
                        }
                        else if (y >= in_h)
                        {
                            y = in_h - 1;
                        }

                        Color32 pix = in_pixs[x + offset + step * y];
                        //
                        pat_data[p]        = ((pix.r << 16) & 0xff) | ((pix.g << 8) & 0xff) | pix.b;
                        cp7_cy_1_cp6_cx   += cp6;
                        cp1_cy_cp2_cp0_cx += cp0;
                        cp4_cy_cp5_cp3_cx += cp3;
                        p++;
                    }
                    cp7_cy_1   += cp7;
                    cp1_cy_cp2 += cp1;
                    cp4_cy_cp5 += cp4;
                }
                return(true);

            case NyARBufferType.OBJECT_CS_Unity:
                Color32[] out_buf = (Color32[])(((INyARRgbRaster)o_out).getBuffer());
                if (this._is_inv_v == ((NyARUnityRaster)o_out).isFlipVirtical())
                {
                    offset = in_w * (in_h - 1);
                    step   = -in_w;
                }
                else
                {
                    offset = 0;
                    step   = in_w;
                }
                for (int iy = 0; iy < out_h; iy++)
                {
                    //解像度分の点を取る。
                    double cp7_cy_1_cp6_cx   = cp7_cy_1;
                    double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                    double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;
                    int    ys = out_h - 1 - iy;
                    for (int ix = 0; ix < out_w; ix++)
                    {
                        //1ピクセルを作成
                        double d = 1 / (cp7_cy_1_cp6_cx);
                        int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                        int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                        if (x < 0)
                        {
                            x = 0;
                        }
                        else if (x >= in_w)
                        {
                            x = in_w - 1;
                        }
                        if (y < 0)
                        {
                            y = 0;
                        }
                        else if (y >= in_h)
                        {
                            y = in_h - 1;
                        }

                        out_buf[ix + ys * out_w] = in_pixs[x + offset + step * y];
                        //
                        cp7_cy_1_cp6_cx   += cp6;
                        cp1_cy_cp2_cp0_cx += cp0;
                        cp4_cy_cp5_cp3_cx += cp3;
                    }
                    cp7_cy_1   += cp7;
                    cp1_cy_cp2 += cp1;
                    cp4_cy_cp5 += cp4;
                }
                return(true);

            default:
                //ANY to RGBx
                if (o_out is INyARRgbRaster)
                {
                    INyARRgbRaster out_raster = ((INyARRgbRaster)o_out);
                    if (this._is_inv_v)
                    {
                        offset = in_w * (in_h - 1);
                        step   = -in_w;
                    }
                    else
                    {
                        offset = 0;
                        step   = in_w;
                    }
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx   = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0)
                            {
                                x = 0;
                            }
                            else if (x >= in_w)
                            {
                                x = in_w - 1;
                            }
                            if (y < 0)
                            {
                                y = 0;
                            }
                            else if (y >= in_h)
                            {
                                y = in_h - 1;
                            }
                            Color32 px = in_pixs[x + offset + step * y];
                            cp7_cy_1_cp6_cx   += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;
                            out_raster.setPixel(ix, iy, px.r, px.g, px.b);
                        }
                        cp7_cy_1   += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    return(true);
                }
                break;
            }
            return(false);
        }
        /**
         * NyARRasterからパターンデータをセットします。
         * この関数は、データを元に所有するデータ領域を更新します。
         * @param i_buffer
         */
        public void setRaster(INyARRaster i_raster)
        {
            //画素フォーマット、サイズ制限
            Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
            Debug.Assert(i_raster.getSize().isEqualSize(i_raster.getSize()));

            int[] buf = (int[])i_raster.getBuffer();
            //i_buffer[XRGB]→差分[R,G,B]変換			
            int i;
            int ave;//<PV/>
            int rgb;//<PV/>
            int[] linput = this._data;//<PV/>

            // input配列のサイズとwhも更新// input=new int[height][width][3];
            int number_of_pixels = this._number_of_pixels;
            int for_mod = this._optimize_for_mod;

            //<平均値計算(FORの1/8展開)>
            ave = 0;
            for (i = number_of_pixels - 1; i >= for_mod; i--)
            {
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);
            }
            for (; i >= 0; )
            {
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
            }
            //<平均値計算(FORの1/8展開)/>
            ave = number_of_pixels * 255 * 3 - ave;
            ave = 255 - (ave / (number_of_pixels * 3));//(255-R)-ave を分解するための事前計算

            int sum = 0, w_sum;
            int input_ptr = number_of_pixels * 3 - 1;
            //<差分値計算(FORの1/8展開)>
            for (i = number_of_pixels - 1; i >= for_mod; i--)
            {
                rgb = buf[i];
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//R
            }
            for (; i >= 0; )
            {
                rgb = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//R
                rgb = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//R
                rgb = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//R
                rgb = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//R
                rgb = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//R
                rgb = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//R
                rgb = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//R
                rgb = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;//R
            }
            //<差分値計算(FORの1/8展開)/>
            double p = Math.Sqrt((double)sum);
            this._pow = p != 0.0 ? p : 0.0000001;
            return;
        }
 public NyARVectorReader_INT1D_GRAY_8(INyARRaster i_ref_raster)
 {
     Debug.Assert(i_ref_raster.getBufferType() == NyARBufferType.INT1D_GRAY_8);
     this._ref_buf = (int[])(i_ref_raster.getBuffer());
     this._ref_size = i_ref_raster.getSize();
 }
Example #36
0
        private void imple_labeling(INyARRaster i_raster, int i_th, int i_left, int i_top, int i_width, int i_height)
        {
            //ラスタのサイズを確認
            Debug.Assert(i_raster.getSize().isEqualSize(this._raster_size));

            RleElement[] rle_prev    = this._rle1;
            RleElement[] rle_current = this._rle2;
            // リセット処理
            RleInfoStack rlestack = this._rlestack;

            rlestack.clear();

            //
            int len_prev    = 0;
            int len_current = 0;
            int bottom      = i_top + i_height;
            int row_stride  = this._raster_size.w;

            int[] in_buf = (int[])i_raster.getBuffer();

            int id_max        = 0;
            int label_count   = 0;
            int rle_top_index = i_left + row_stride * i_top;

            // 初段登録

            len_prev = toRel(in_buf, rle_top_index, i_width, rle_prev, i_th);
            for (int i = 0; i < len_prev; i++)
            {
                // フラグメントID=フラグメント初期値、POS=Y値、RELインデクス=行
                if (addFragment(rle_prev[i], id_max, i_top, rlestack))
                {
                    id_max++;
                    // nofの最大値チェック
                    label_count++;
                }
            }
            NyARRleLabelFragmentInfo[] f_array = rlestack.getArray();
            // 次段結合
            for (int y = i_top + 1; y < bottom; y++)
            {
                // カレント行の読込
                rle_top_index += row_stride;
                len_current    = toRel(in_buf, rle_top_index, i_width, rle_current, i_th);
                int index_prev = 0;

                for (int i = 0; i < len_current; i++)
                {
                    // index_prev,len_prevの位置を調整する
                    int id = -1;
                    // チェックすべきprevがあれば確認
                    while (index_prev < len_prev)
                    {
                        if (rle_current[i].l - rle_prev[index_prev].r > 0)                      // 0なら8方位ラベリング
                        // prevがcurの左方にある→次のフラグメントを探索
                        {
                            index_prev++;
                            continue;
                        }
                        else if (rle_prev[index_prev].l - rle_current[i].r > 0)                        // 0なら8方位ラベリングになる
                        // prevがcur右方にある→独立フラグメント
                        {
                            if (addFragment(rle_current[i], id_max, y, rlestack))
                            {
                                id_max++;
                                label_count++;
                            }
                            // 次のindexをしらべる
                            goto SCAN_CUR;
                        }
                        id = rle_prev[index_prev].fid;                  //ルートフラグメントid
                        NyARRleLabelFragmentInfo id_ptr = f_array[id];
                        //結合対象(初回)->prevのIDをコピーして、ルートフラグメントの情報を更新
                        rle_current[i].fid = id;                    //フラグメントIDを保存
                        //
                        int l   = rle_current[i].l;
                        int r   = rle_current[i].r;
                        int len = r - l;
                        //結合先フラグメントの情報を更新する。
                        id_ptr.area += len;
                        //tとentry_xは、結合先のを使うので更新しない。
                        id_ptr.clip_l = l < id_ptr.clip_l?l:id_ptr.clip_l;
                        id_ptr.clip_r = r > id_ptr.clip_r?r - 1:id_ptr.clip_r;
                        id_ptr.clip_b = y;
                        id_ptr.pos_x += (len * (2 * l + (len - 1))) / 2;
                        id_ptr.pos_y += y * len;
                        //多重結合の確認(2個目以降)
                        index_prev++;
                        while (index_prev < len_prev)
                        {
                            if (rle_current[i].l - rle_prev[index_prev].r > 0)                          // 0なら8方位ラベリング
                            // prevがcurの左方にある→prevはcurに連結していない。
                            {
                                goto SCAN_PREV;
                            }
                            else if (rle_prev[index_prev].l - rle_current[i].r > 0)                            // 0なら8方位ラベリングになる
                            // prevがcurの右方にある→prevはcurに連結していない。
                            {
                                index_prev--;
                                goto SCAN_CUR;
                            }
                            // prevとcurは連結している→ルートフラグメントの統合

                            //結合するルートフラグメントを取得
                            int prev_id = rle_prev[index_prev].fid;
                            NyARRleLabelFragmentInfo prev_ptr = f_array[prev_id];
                            if (id != prev_id)
                            {
                                label_count--;
                                //prevとcurrentのフラグメントidを書き換える。
                                for (int i2 = index_prev; i2 < len_prev; i2++)
                                {
                                    //prevは現在のidから最後まで
                                    if (rle_prev[i2].fid == prev_id)
                                    {
                                        rle_prev[i2].fid = id;
                                    }
                                }
                                for (int i2 = 0; i2 < i; i2++)
                                {
                                    //currentは0から現在-1まで
                                    if (rle_current[i2].fid == prev_id)
                                    {
                                        rle_current[i2].fid = id;
                                    }
                                }

                                //現在のルートフラグメントに情報を集約
                                id_ptr.area  += prev_ptr.area;
                                id_ptr.pos_x += prev_ptr.pos_x;
                                id_ptr.pos_y += prev_ptr.pos_y;
                                //tとentry_xの決定
                                if (id_ptr.clip_t > prev_ptr.clip_t)
                                {
                                    // 現在の方が下にある。
                                    id_ptr.clip_t  = prev_ptr.clip_t;
                                    id_ptr.entry_x = prev_ptr.entry_x;
                                }
                                else if (id_ptr.clip_t < prev_ptr.clip_t)
                                {
                                    // 現在の方が上にある。prevにフィードバック
                                }
                                else
                                {
                                    // 水平方向で小さい方がエントリポイント。
                                    if (id_ptr.entry_x > prev_ptr.entry_x)
                                    {
                                        id_ptr.entry_x = prev_ptr.entry_x;
                                    }
                                    else
                                    {
                                    }
                                }
                                //lの決定
                                if (id_ptr.clip_l > prev_ptr.clip_l)
                                {
                                    id_ptr.clip_l = prev_ptr.clip_l;
                                }
                                else
                                {
                                }
                                //rの決定
                                if (id_ptr.clip_r < prev_ptr.clip_r)
                                {
                                    id_ptr.clip_r = prev_ptr.clip_r;
                                }
                                else
                                {
                                }
                                //bの決定

                                //結合済のルートフラグメントを無効化する。
                                prev_ptr.area = 0;
                            }


                            index_prev++;
                        }
                        index_prev--;
                        break;
                        SCAN_PREV :;
                    }
                    // curにidが割り当てられたかを確認
                    // 右端独立フラグメントを追加
                    if (id < 0)
                    {
                        if (addFragment(rle_current[i], id_max, y, rlestack))
                        {
                            id_max++;
                            label_count++;
                        }
                    }
                    SCAN_CUR :;
                }
                // prevとrelの交換
                RleElement[] tmp = rle_prev;
                rle_prev    = rle_current;
                len_prev    = len_current;
                rle_current = tmp;
            }
            //対象のラベルだけを追記
            int max = this._max_area;
            int min = this._min_area;

            for (int i = id_max - 1; i >= 0; i--)
            {
                NyARRleLabelFragmentInfo src_info = f_array[i];
                int area = src_info.area;
                if (area < min || area > max)        //対象外のエリア0のもminではじく
                {
                    continue;
                }
                //値を相対位置に補正
                src_info.clip_l  += i_left;
                src_info.clip_r  += i_left;
                src_info.entry_x += i_left;
                src_info.pos_x   /= area;
                src_info.pos_y   /= area;
                //コールバック関数コール
                this.onLabelFound(src_info);
            }
        }
            public void doThFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
            {
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_BIN_8));

                int[] out_buf = (int[])i_output.getBuffer();
                byte[] in_buf = (byte[])i_input.getBuffer();

                byte[] grey = new byte[i_size.w * i_size.h];
                ulong[] integralImg = new ulong[i_size.w * i_size.h];

                ulong sum = 0;
                float T = 0.15f;
                double s = i_size.w / 8;
                int x1, x2, y1, y2;
                int index, s2 = (int)(s / 2);
                int count = 0;

                // greyscale
                for (int i = 0, j = 0; i < in_buf.Length; )
                {
                    grey[j++] = (byte)
                        ((in_buf[i + 1] & 0xff) * 0.11 + // b
                        (in_buf[i + 2] & 0xff) * 0.59 + // g
                        (in_buf[i + 3] & 0xff) * 0.3); // r
                    i += 4; // skip alpha
                }

                // integral image
                for (int i = 0; i < i_size.w; i++)
                {
                    sum = 0; // cumulative row sum
                    for (int j = 0; j < i_size.h; j++)
                    {
                        index = j * i_size.w + i;
                        sum += grey[index];
                        if (i == 0)
                            integralImg[index] = (ulong)sum;
                        else
                            integralImg[index] = integralImg[index - 1] + (ulong)sum;
                    }
                }

                for (int i = 0; i < i_size.w; i++)
                {
                    for (int j = 0; j < i_size.h; j++)
                    {
                        index = j * i_size.w + i;

                        // set the SxS region
                        x1 = i - s2; x2 = i + s2;
                        y1 = j - s2; y2 = j + s2;

                        // check the border
                        if (x1 < 0) x1 = 0;
                        if (x2 >= i_size.w) x2 = i_size.w - 1;
                        if (y1 < 0) y1 = 0;
                        if (y2 >= i_size.h) y2 = i_size.h - 1;

                        count = (x2 - x1) * (y2 - y1);

                        sum = integralImg[y2 * i_size.w + x2] -
                              integralImg[y1 * i_size.w + x2] -
                              integralImg[y2 * i_size.w + x1] +
                              integralImg[y1 * i_size.w + x1];

                        if ((long)(grey[index] * count) < (long)(sum * (1.0 - T)))
                            out_buf[index] = 0;
                        else
                            out_buf[index] = 1;
                    }
                }

                return;
            }
		    public int createHistogram(INyARRaster i_reader,NyARIntSize i_size, int[] o_histogram,int i_skip)
		    {
	            Debug.Assert(i_reader.isEqualBufferType(NyARBufferType.BYTE1D_X8R8G8B8_32));
	            byte[] input = (byte[])i_reader.getBuffer();
	            int pix_count = i_size.w;
	            int pix_mod_part = pix_count - (pix_count % 8);
	       	    for (int y = i_size.h - 1; y >= 0; y -=i_skip)
	            {
	                int pt = y * i_size.w * 4;
	                int x, v;
	                for (x = pix_count - 1; x >= pix_mod_part; x--)
	                {
	                    v = ((input[pt + 1] & 0xff) + (input[pt + 2] & 0xff) + (input[pt + 3] & 0xff)) / 3;
	                    o_histogram[v]++;
	                    pt += 4;
	                }
	                //タイリング
	                for (; x >= 0; x -= 8)
	                {
	                    v = ((input[pt + 1] & 0xff) + (input[pt + 2] & 0xff) + (input[pt + 3] & 0xff)) / 3;
	                    o_histogram[v]++;
	                    v = ((input[pt + 5] & 0xff) + (input[pt + 6] & 0xff) + (input[pt + 7] & 0xff)) / 3;
	                    o_histogram[v]++;
	                    v = ((input[pt + 9] & 0xff) + (input[pt + 10] & 0xff) + (input[pt + 11] & 0xff)) / 3;
	                    o_histogram[v]++;
	                    v = ((input[pt + 13] & 0xff) + (input[pt + 14] & 0xff) + (input[pt + 15] & 0xff)) / 3;
	                    o_histogram[v]++;
	                    v = ((input[pt + 17] & 0xff) + (input[pt + 18] & 0xff) + (input[pt + 19] & 0xff)) / 3;
	                    o_histogram[v]++;
	                    v = ((input[pt + 21] & 0xff) + (input[pt + 22] & 0xff) + (input[pt + 23] & 0xff)) / 3;
	                    o_histogram[v]++;
	                    v = ((input[pt + 25] & 0xff) + (input[pt + 26] & 0xff) + (input[pt + 27] & 0xff)) / 3;
	                    o_histogram[v]++;
	                    v = ((input[pt + 29] & 0xff) + (input[pt + 30] & 0xff) + (input[pt + 31] & 0xff)) / 3;
	                    o_histogram[v]++;
	                    pt += 4 * 8;
	                }
	            }
	       	    return i_size.w*i_size.h;
	        }
Example #39
0
 public void switchRaster(INyARRaster i_ref_raster)
 {
     this._ref_buf  = (int[])i_ref_raster.getBuffer();
     this._ref_size = i_ref_raster.getSize();
 }
		    public void doFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size)
		    {
			    Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
			    int[] out_buf = (int[]) i_output.getBuffer();
			    byte[] in_buf = (byte[]) i_input.getBuffer();

			    int bp = 0;
			    for (int y = 0; y < i_size.h; y++) {
				    for (int x = 0; x < i_size.w; x++) {
					    out_buf[y*i_size.w+x] = ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) / 3;
					    bp += 4;
				    }
			    }
		    }
Example #41
0
 public void doThFilter(INyARRaster i_raster, int i_l, int i_t, int i_w, int i_h, int i_th, INyARRaster o_raster)
 {
     byte[] input = (byte[])i_raster.getBuffer();
     int[] output = (int[])o_raster.getBuffer();
     NyARIntSize s = i_raster.getSize();
     int th = i_th;
     int skip_dst = (s.w - i_w);
     int skip_src = skip_dst * 4;
     int pix_count = i_w;
     int pix_mod_part = pix_count - (pix_count % 8);
     //左上から1行づつ走査していく
     int pt_dst = (i_t * s.w + i_l);
     int pt_src = pt_dst * 4;
     for (int y = i_h - 1; y >= 0; y -= 1)
     {
         int x;
         for (x = pix_count - 1; x >= pix_mod_part; x--)
         {
             output[pt_dst++] = input[pt_src + 0] <= th ? 0 : 1;
             pt_src += 4;
         }
         for (; x >= 0; x -= 8)
         {
             output[pt_dst++] = input[pt_src + 0] <= th ? 0 : 1;
             pt_src += 4;
             output[pt_dst++] = input[pt_src + 0] <= th ? 0 : 1;
             pt_src += 4;
             output[pt_dst++] = input[pt_src + 0] <= th ? 0 : 1;
             pt_src += 4;
             output[pt_dst++] = input[pt_src + 0] <= th ? 0 : 1;
             pt_src += 4;
             output[pt_dst++] = input[pt_src + 0] <= th ? 0 : 1;
             pt_src += 4;
             output[pt_dst++] = input[pt_src + 0] <= th ? 0 : 1;
             pt_src += 4;
             output[pt_dst++] = input[pt_src + 0] <= th ? 0 : 1;
             pt_src += 4;
             output[pt_dst++] = input[pt_src + 0] <= th ? 0 : 1;
             pt_src += 4;
         }
         //スキップ
         pt_src += skip_src;
         pt_dst += skip_dst;
     }
     return;
 }
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            byte[] i_in_buf = (byte[])this._ref_raster.getBuffer();
            int in_w = this._ref_raster.getWidth();
            int in_h = this._ref_raster.getHeight();
            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();
            double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l;
            double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l;
            double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l;
            int r, g, b;
            switch (this._ref_raster.getBufferType())
            {
                case NyARBufferType.INT1D_X8R8G8B8_32:
                    int p = 0;
                    int[] pat_data = (int[])o_out.getBuffer();
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                            if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }

                            int bp = (x + y * in_w) * 3;
                            r = (i_in_buf[bp + 0] & 0xff);
                            g = (i_in_buf[bp + 1] & 0xff);
                            b = (i_in_buf[bp + 2] & 0xff);
                            cp7_cy_1_cp6_cx += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;
                            pat_data[p] = (r << 16) | (g << 8) | ((b & 0xff));
                            p++;
                        }
                        cp7_cy_1 += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    return true;
                default:
                    if (o_out is INyARRgbRaster)
                    {
                        INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                        for (int iy = 0; iy < out_h; iy++)
                        {
                            //解像度分の点を取る。
                            double cp7_cy_1_cp6_cx = cp7_cy_1;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                            for (int ix = 0; ix < out_w; ix++)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                                if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }

                                int bp = (x + y * in_w) * 3;
                                r = (i_in_buf[bp + 0] & 0xff);
                                g = (i_in_buf[bp + 1] & 0xff);
                                b = (i_in_buf[bp + 2] & 0xff);
                                cp7_cy_1_cp6_cx += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;

                                out_reader.setPixel(ix, iy, r, g, b);
                            }
                            cp7_cy_1 += cp7;
                            cp1_cy_cp2 += cp1;
                            cp4_cy_cp5 += cp4;
                        }
                        return true;
                    }
                    break;
            }
            return false;
        }
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            int[] rgb_tmp = this.__pickFromRaster_rgb_tmp;
            int in_w = this._ref_raster.getWidth();
            int in_h = this._ref_raster.getHeight();

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();
            double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l;
            double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l;
            double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l;

            INyARRgbPixelDriver i_in_reader = this._ref_raster.getRgbPixelDriver();
            switch (o_out.getBufferType())
            {
                case NyARBufferType.INT1D_X8R8G8B8_32:
                    int[] pat_data = (int[])o_out.getBuffer();
                    int p = 0;
                    for (int iy = out_h - 1; iy >= 0; iy--)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                        for (int ix = out_w - 1; ix >= 0; ix--)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                            if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }

                            i_in_reader.getPixel(x, y, rgb_tmp);
                            cp7_cy_1_cp6_cx += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;

                            pat_data[p] = (rgb_tmp[0] << 16) | (rgb_tmp[1] << 8) | ((rgb_tmp[2] & 0xff));
                            p++;
                        }
                        cp7_cy_1 += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    return true;
                default:
                    //ANY to RGBx
                    if (o_out is INyARRgbRaster)
                    {
                        INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                        for (int iy = 0; iy < out_h; iy++)
                        {
                            //解像度分の点を取る。
                            double cp7_cy_1_cp6_cx = cp7_cy_1;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;
                            for (int ix = 0; ix < out_w; ix++)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                                if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }

                                i_in_reader.getPixel(x, y, rgb_tmp);
                                cp7_cy_1_cp6_cx += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;

                                out_reader.setPixel(ix, iy, rgb_tmp);
                            }
                            cp7_cy_1 += cp7;
                            cp1_cy_cp2 += cp1;
                            cp4_cy_cp5 += cp4;
                        }
                        return true;
                    }
                    break;
            }
            return false;
        }
		    public void doThFilter(INyARRaster i_input, INyARRaster i_output,NyARIntSize i_size,int i_threshold)
		    {
                Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_BIN_8));
    			
			    int[] out_buf = (int[]) i_output.getBuffer();
			    short[] in_buf = (short[]) i_input.getBuffer();
    			
			    int th=i_threshold*3;
			    int w;
			    int xy;
			    int pix_count   =i_size.h*i_size.w;
			    int pix_mod_part=pix_count-(pix_count%8);

			    for(xy=pix_count-1;xy>=pix_mod_part;xy--){				
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
			    }
			    //タイリング
			    for (;xy>=0;) {
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
                    w =(int)in_buf[xy];
                    w = ((w & 0xf800) >> 8) + ((w & 0x07e0) >> 3) + ((w & 0x001f) << 3);
                    out_buf[xy] = w <= th ? 0 : 1;
				    xy--;
			    }
		    }		
		    public int createHistogram(INyARRaster i_reader,NyARIntSize i_size, int[] o_histogram,int i_skip)
		    {
			    Debug.Assert (i_reader.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
			    int[] input=(int[]) i_reader.getBuffer();
			    for (int y = i_size.h-1; y >=0 ; y-=i_skip){
				    int pt=y*i_size.w;
				    for (int x = i_size.w-1; x >=0; x--) {
					    int p=input[pt];
					    o_histogram[((p& 0xff)+(p& 0xff)+(p& 0xff))/3]++;
					    pt++;
				    }
			    }
			    return i_size.w*i_size.h;
		    }	
 public void switchRaster(INyARRaster i_ref_raster)
 {
     this._ref_buf = (int[])i_ref_raster.getBuffer();
     this._ref_size = i_ref_raster.getSize();
 }
        /**
         * ラスタのエントリポイントから辿れる輪郭線を配列に返します。
         * @param i_raster
         * @param i_th
         * 暗点<=th<明点
         * @param i_entry_x
         * @param i_entry_y
         * @param i_array_size
         * @param o_coord_x
         * @param o_coord_y
         * @return
         * 輪郭線の長さを返します。
         * @throws NyARException
         */
        private int impl_getContour(INyARRaster i_raster, int i_th, int i_entry_x, int i_entry_y, int i_array_size, int[] o_coord_x, int[] o_coord_y)
        {
            int[] xdir = _getContour_xdir;// static int xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1};
            int[] ydir = _getContour_ydir;// static int ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1};

            int[] i_buf = (int[])i_raster.getBuffer();
            int width = i_raster.getWidth();
            int height = i_raster.getHeight();
            //クリップ領域の上端に接しているポイントを得る。


            int coord_num = 1;
            o_coord_x[0] = i_entry_x;
            o_coord_y[0] = i_entry_y;
            int dir = 5;

            int c = i_entry_x;
            int r = i_entry_y;
            for (; ; )
            {
                dir = (dir + 5) % 8;//dirの正規化
                //ここは頑張ればもっと最適化できると思うよ。
                //4隅以外の境界接地の場合に、境界チェックを省略するとかね。
                if (c >= 1 && c < width - 1 && r >= 1 && r < height - 1)
                {
                    for (; ; )
                    {//gotoのエミュレート用のfor文
                        //境界に接していないとき(暗点判定)
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        /*
                                            try{
                                                BufferedImage b=new BufferedImage(width,height,ColorSpace.TYPE_RGB);
                                                NyARRasterImageIO.copy(i_raster, b);
                                            ImageIO.write(b,"png",new File("bug.png"));
                                            }catch(Exception e){
						
                                            }*/
                        //8方向全て調べたけどラベルが無いよ?
                        throw new NyARException();
                    }
                }
                else
                {
                    //境界に接しているとき				
                    int i;
                    for (i = 0; i < 8; i++)
                    {
                        int x = c + xdir[dir];
                        int y = r + ydir[dir];
                        //境界チェック
                        if (x >= 0 && x < width && y >= 0 && y < height)
                        {
                            if (i_buf[(y) * width + (x)] <= i_th)
                            {
                                break;
                            }
                        }
                        dir++;//倍長テーブルを参照するので問題なし
                    }
                    if (i == 8)
                    {
                        //8方向全て調べたけどラベルが無いよ?
                        throw new NyARException();// return(-1);
                    }
                }

                dir = dir % 8;//dirの正規化

                // xcoordとycoordをc,rにも保存
                c = c + xdir[dir];
                r = r + ydir[dir];
                o_coord_x[coord_num] = c;
                o_coord_y[coord_num] = r;
                // 終了条件判定
                if (c == i_entry_x && r == i_entry_y)
                {
                    coord_num++;
                    break;
                }
                coord_num++;
                if (coord_num == i_array_size)
                {
                    //輪郭が末端に達した
                    return coord_num;
                }
            }
            return coord_num;
        }
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            BitmapData in_bmp = this._ref_raster.lockBitmap();
            int        in_w   = this._ref_raster.getWidth();
            int        in_h   = this._ref_raster.getHeight();

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];

            int    out_w = o_out.getWidth();
            int    out_h = o_out.getHeight();
            double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l;
            double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l;
            double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l;
            int    r, g, b, p;

            switch (o_out.getBufferType())
            {
            case NyARBufferType.INT1D_X8R8G8B8_32:
                int[] pat_data = (int[])o_out.getBuffer();
                p = 0;
                for (int iy = 0; iy < out_h; iy++)
                {
                    //解像度分の点を取る。
                    double cp7_cy_1_cp6_cx   = cp7_cy_1;
                    double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                    double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                    for (int ix = 0; ix < out_w; ix++)
                    {
                        //1ピクセルを作成
                        double d = 1 / (cp7_cy_1_cp6_cx);
                        int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                        int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                        if (x < 0)
                        {
                            x = 0;
                        }
                        else if (x >= in_w)
                        {
                            x = in_w - 1;
                        }
                        if (y < 0)
                        {
                            y = 0;
                        }
                        else if (y >= in_h)
                        {
                            y = in_h - 1;
                        }

                        //
                        pat_data[p] = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                        //r = (px >> 16) & 0xff;// R
                        //g = (px >> 8) & 0xff; // G
                        //b = (px) & 0xff;    // B
                        cp7_cy_1_cp6_cx   += cp6;
                        cp1_cy_cp2_cp0_cx += cp0;
                        cp4_cy_cp5_cp3_cx += cp3;
                        //pat_data[p] = (r << 16) | (g << 8) | ((b & 0xff));
                        //pat_data[p] = px;

                        p++;
                    }
                    cp7_cy_1   += cp7;
                    cp1_cy_cp2 += cp1;
                    cp4_cy_cp5 += cp4;
                }
                this._ref_raster.unlockBitmap();
                return(true);

            default:
                if (o_out is NyARBitmapRaster)
                {
                    NyARBitmapRaster bmr = (NyARBitmapRaster)o_out;
                    BitmapData       bm  = bmr.lockBitmap();
                    p = 0;
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx   = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0)
                            {
                                x = 0;
                            }
                            else if (x >= in_w)
                            {
                                x = in_w - 1;
                            }
                            if (y < 0)
                            {
                                y = 0;
                            }
                            else if (y >= in_h)
                            {
                                y = in_h - 1;
                            }
                            int pix = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                            Marshal.WriteInt32(bm.Scan0, ix * 4 + iy * bm.Stride, pix);
                            cp7_cy_1_cp6_cx   += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;
                            p++;
                        }
                        cp7_cy_1   += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    bmr.unlockBitmap();
                    this._ref_raster.unlockBitmap();
                    return(true);
                }
                else if (o_out is INyARRgbRaster)
                {
                    //ANY to RGBx
                    INyARRgbRaster out_raster = ((INyARRgbRaster)o_out);
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx   = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0)
                            {
                                x = 0;
                            }
                            else if (x >= in_w)
                            {
                                x = in_w - 1;
                            }
                            if (y < 0)
                            {
                                y = 0;
                            }
                            else if (y >= in_h)
                            {
                                y = in_h - 1;
                            }

                            int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                            r = (px >> 16) & 0xff;  // R
                            g = (px >> 8) & 0xff;   // G
                            b = (px) & 0xff;        // B
                            cp7_cy_1_cp6_cx   += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;
                            out_raster.setPixel(ix, iy, r, g, b);
                        }
                        cp7_cy_1   += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    this._ref_raster.unlockBitmap();
                    return(true);
                }
                break;
            }
            this._ref_raster.unlockBitmap();
            return(false);
        }
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            Color32[] in_pixs = (Color32[])this._ref_raster.getBuffer();
            int in_w = this._ref_raster.getWidth();
            int in_h = this._ref_raster.getHeight();

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();
            double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l;
            double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l;
            double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l;
            int p;
			
			int step,offset;
			//flip Virtical
            switch (o_out.getBufferType())
            {
            case NyARBufferType.INT1D_X8R8G8B8_32:
	            int[] pat_data = (int[])o_out.getBuffer();
                p = 0;
				if(this._is_inv_v){
					offset=in_w*(in_h-1);
					step=-in_w;
				}else{
					offset=0;
					step=in_w;
				}				
                for (int iy = 0; iy < out_h; iy++)
                {
                    //解像度分の点を取る。
                    double cp7_cy_1_cp6_cx = cp7_cy_1;
                    double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                    double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                    for (int ix = 0; ix < out_w; ix++)
                    {
                        //1ピクセルを作成
                        double d = 1 / (cp7_cy_1_cp6_cx);
                        int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                        int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                        if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                        if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }
					
						Color32 pix=in_pixs[x + offset+step*y];
                        //
                        pat_data[p] = ((pix.r << 16) & 0xff)|((pix.g << 8) & 0xff)| pix.b;
                        cp7_cy_1_cp6_cx += cp6;
                        cp1_cy_cp2_cp0_cx += cp0;
                        cp4_cy_cp5_cp3_cx += cp3;
                        p++;
                    }
                    cp7_cy_1 += cp7;
                    cp1_cy_cp2 += cp1;
                    cp4_cy_cp5 += cp4;
                }
                return true;		
            case NyARBufferType.OBJECT_CS_Unity:
				Color32[] out_buf = (Color32[])(((INyARRgbRaster)o_out).getBuffer());
				if(this._is_inv_v==((NyARUnityRaster)o_out).isFlipVirtical()){
					offset=in_w*(in_h-1);
					step=-in_w;
				}else{
					offset=0;
					step=in_w;
				}				
                for (int iy = 0; iy < out_h; iy++)
                {
                    //解像度分の点を取る。
                    double cp7_cy_1_cp6_cx = cp7_cy_1;
                    double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                    double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;
					int ys=out_h-1-iy;
                    for (int ix = 0; ix < out_w; ix++)
                    {
                        //1ピクセルを作成
                        double d = 1 / (cp7_cy_1_cp6_cx);
                        int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                        int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                        if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                        if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }
					
						out_buf[ix+ys*out_w]=in_pixs[x + offset+step*y];
                        //
                        cp7_cy_1_cp6_cx += cp6;
                        cp1_cy_cp2_cp0_cx += cp0;
                        cp4_cy_cp5_cp3_cx += cp3;
                    }
                    cp7_cy_1 += cp7;
                    cp1_cy_cp2 += cp1;
                    cp4_cy_cp5 += cp4;
                }
                return true;
            default:
                //ANY to RGBx
                if (o_out is INyARRgbRaster)
                {
                    INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
					if(this._is_inv_v){
						offset=in_w*(in_h-1);
						step=-in_w;
					}else{
						offset=0;
						step=in_w;
					}
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                            if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }
                        	Color32 px = in_pixs[x + offset+step*y];
                            cp7_cy_1_cp6_cx += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;
                            out_reader.setPixel(ix, iy,px.r,px.g,px.b);
                        }
                        cp7_cy_1 += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
	                return true;
				}
				break;
			}
            return false;
        }
		    public int createHistogram(INyARRaster i_reader,NyARIntSize i_size, int[] o_histogram,int i_skip)
		    {
	            Debug.Assert(i_reader.isEqualBufferType(NyARBufferType.WORD1D_R5G6B5_16LE));
	            short[] input = (short[])i_reader.getBuffer();
	            int pix_count = i_size.w;
	            int pix_mod_part = pix_count - (pix_count % 8);
	            for (int y = i_size.h - 1; y >= 0; y -= i_skip)
	            {
	                int pt = y * i_size.w;
	                int x, v;
	                for (x = pix_count - 1; x >= pix_mod_part; x--)
	                {
	                    v =(int)input[pt];
	                    v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;
	                    o_histogram[v]++;
	                    pt++;
	                }
	                //タイリング
	                for (; x >= 0; x -= 8)
	                {
	                    v =(int)input[pt];pt++;
	                    v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;
	                    o_histogram[v]++;
	                    v =(int)input[pt];pt++;
	                    v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;
	                    o_histogram[v]++;
	                    v =(int)input[pt];pt++;
	                    v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;
	                    o_histogram[v]++;
	                    v =(int)input[pt];pt++;
	                    v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;
	                    o_histogram[v]++;
	                    v =(int)input[pt];pt++;
	                    v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;
	                    o_histogram[v]++;
	                    v =(int)input[pt];pt++;
	                    v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;
	                    o_histogram[v]++;
	                    v =(int)input[pt];pt++;
	                    v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;
	                    o_histogram[v]++;
	                    v =(int)input[pt];pt++;
	                    v = (((v & 0xf800) >> 8) + ((v & 0x07e0) >> 3) + ((v & 0x001f) << 3))/3;
	                    o_histogram[v]++;
	                }
	            }
	            return i_size.w*i_size.h;
	        }
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            BitmapData in_bmp = this._ref_raster.lockBitmap();
            int in_w = this._ref_raster.getWidth();
            int in_h = this._ref_raster.getHeight();

             //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();
            double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l;
            double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l;
            double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l;
            int r, g, b, p;
            switch (o_out.getBufferType())
            {
                case NyARBufferType.INT1D_X8R8G8B8_32:
                    int[] pat_data = (int[])o_out.getBuffer();
                    p = 0;
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                            if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }

                            //
                            pat_data[p] = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                            //r = (px >> 16) & 0xff;// R
                            //g = (px >> 8) & 0xff; // G
                            //b = (px) & 0xff;    // B
                            cp7_cy_1_cp6_cx += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;
                            //pat_data[p] = (r << 16) | (g << 8) | ((b & 0xff));
                            //pat_data[p] = px;

                            p++;
                        }
                        cp7_cy_1 += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    this._ref_raster.unlockBitmap();
                    return true;
                default:
                    if (o_out is NyARBitmapRaster)
                    {
                        NyARBitmapRaster bmr = (NyARBitmapRaster)o_out;
                        BitmapData bm = bmr.lockBitmap();
                        p = 0;
                        for (int iy = 0; iy < out_h; iy++)
                        {
                            //解像度分の点を取る。
                            double cp7_cy_1_cp6_cx = cp7_cy_1;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                            for (int ix = 0; ix < out_w; ix++)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                                if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }
                                int pix = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                                Marshal.WriteInt32(bm.Scan0, ix * 4 + iy * bm.Stride, pix);
                                cp7_cy_1_cp6_cx += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                                p++;
                            }
                            cp7_cy_1 += cp7;
                            cp1_cy_cp2 += cp1;
                            cp4_cy_cp5 += cp4;
                        }
                        bmr.unlockBitmap();
                        this._ref_raster.unlockBitmap();
                        return true;
                    }
                    else if (o_out is INyARRgbRaster)
                    {
                        //ANY to RGBx
                        INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                        for (int iy = 0; iy < out_h; iy++)
                        {
                            //解像度分の点を取る。
                            double cp7_cy_1_cp6_cx = cp7_cy_1;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

                            for (int ix = 0; ix < out_w; ix++)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                                if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }

                                int px = Marshal.ReadInt32(in_bmp.Scan0, (x*4 + y * in_bmp.Stride));
                                r = (px >> 16) & 0xff;// R
                                g = (px >> 8) & 0xff; // G
                                b = (px) & 0xff;    // B
                                cp7_cy_1_cp6_cx += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                                out_reader.setPixel(ix, iy, r, g, b);
                            }
                            cp7_cy_1 += cp7;
                            cp1_cy_cp2 += cp1;
                            cp4_cy_cp5 += cp4;
                        }
                        this._ref_raster.unlockBitmap();
                        return true;
                    }
                    break;
            }
            this._ref_raster.unlockBitmap();
            return false;
        }
        public void doFilter(INyARRaster i_input, INyARRaster i_output, NyARIntSize i_size)
        {
            Debug.Assert(i_input.isEqualBufferType(NyARBufferType.INT1D_X7H9S8V8_32));

            int[] out_buf = (int[])i_output.getBuffer();
            byte[] in_buf = (byte[])i_input.getBuffer();
            int s;
            for (int i = i_size.h * i_size.w - 1; i >= 0; i--)
            {
                int r = (in_buf[i * 3 + 2] & 0xff);
                int g = (in_buf[i * 3 + 1] & 0xff);
                int b = (in_buf[i * 3 + 0] & 0xff);
                int cmax, cmin;
                //最大値と最小値を計算
                if (r > g)
                {
                    cmax = r;
                    cmin = g;
                }
                else
                {
                    cmax = g;
                    cmin = r;
                }
                if (b > cmax)
                {
                    cmax = b;
                }
                if (b < cmin)
                {
                    cmin = b;
                }
                int h;
                if (cmax == 0)
                {
                    s = 0;
                    h = 0;
                }
                else
                {
                    s = (cmax - cmin) * 255 / cmax;
                    int cdes = cmax - cmin;
                    //H成分を計算
                    if (cdes != 0)
                    {
                        if (cmax == r)
                        {
                            h = (g - b) * 60 / cdes;
                        }
                        else if (cmax == g)
                        {
                            h = (b - r) * 60 / cdes + 2 * 60;
                        }
                        else
                        {
                            h = (r - g) * 60 / cdes + 4 * 60;
                        }
                    }
                    else
                    {
                        h = 0;
                    }
                }
                if (h < 0)
                {
                    h += 360;
                }
                //hsv変換(h9s8v8)
                out_buf[i] = (0x1ff0000 & (h << 16)) | (0x00ff00 & (s << 8)) | (cmax & 0xff);
            }
            return;
        }
        protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out)
        {
            int res_pix = i_resolution * i_resolution;

            int[] rgb_tmp = this.__pickFromRaster_rgb_tmp;
            int in_w = this._ref_raster.getWidth();
            int in_h = this._ref_raster.getHeight();
            INyARRgbPixelDriver i_in_reader = this._ref_raster.getRgbPixelDriver();

            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];
            double cp2 = cpara[2];
            double cp5 = cpara[5];

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();
            switch (o_out.getBufferType())
            {
                case NyARBufferType.INT1D_X8R8G8B8_32:
                    int[] pat_data = (int[])o_out.getBuffer();
                    int p = (out_w * out_h - 1);
                    for (int iy = out_h - 1; iy >= 0; iy--)
                    {
                        //解像度分の点を取る。
                        for (int ix = out_w - 1; ix >= 0; ix--)
                        {
                            int r, g, b;
                            r = g = b = 0;
                            int cy = pk_t + iy * i_resolution;
                            int cx = pk_l + ix * i_resolution;
                            double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx;
                            double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                            double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                            for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                            {
                                double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b;
                                double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                                double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                                for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                                {
                                    //1ピクセルを作成
                                    double d = 1 / (cp7_cy_1_cp6_cx);
                                    int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                    int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                    if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                                    if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }

                                    i_in_reader.getPixel(x, y, rgb_tmp);
                                    r += rgb_tmp[0];
                                    g += rgb_tmp[1];
                                    b += rgb_tmp[2];
                                    cp7_cy_1_cp6_cx += cp6;
                                    cp1_cy_cp2_cp0_cx += cp0;
                                    cp4_cy_cp5_cp3_cx += cp3;
                                }
                                cp7_cy_1_cp6_cx_b += cp7;
                                cp1_cy_cp2_cp0_cx_b += cp1;
                                cp4_cy_cp5_cp3_cx_b += cp4;
                            }
                            r /= res_pix;
                            g /= res_pix;
                            b /= res_pix;
                            pat_data[p] = ((r & 0xff) << 16) | ((g & 0xff) << 8) | ((b & 0xff));
                            p--;
                        }
                    }
                    return true;
                default:
                    //ANY to RGBx
                    if (o_out is INyARRgbRaster)
                    {
                        INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                        for (int iy = out_h - 1; iy >= 0; iy--)
                        {
                            //解像度分の点を取る。
                            for (int ix = out_w - 1; ix >= 0; ix--)
                            {
                                int r, g, b;
                                r = g = b = 0;
                                int cy = pk_t + iy * i_resolution;
                                int cx = pk_l + ix * i_resolution;
                                double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx;
                                double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                                double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                                for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                                {
                                    double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b;
                                    double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                                    double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                                    for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                                    {
                                        //1ピクセルを作成
                                        double d = 1 / (cp7_cy_1_cp6_cx);
                                        int x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                        int y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                        if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; }
                                        if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; }

                                        i_in_reader.getPixel(x, y, rgb_tmp);
                                        r += rgb_tmp[0];
                                        g += rgb_tmp[1];
                                        b += rgb_tmp[2];
                                        cp7_cy_1_cp6_cx += cp6;
                                        cp1_cy_cp2_cp0_cx += cp0;
                                        cp4_cy_cp5_cp3_cx += cp3;
                                    }
                                    cp7_cy_1_cp6_cx_b += cp7;
                                    cp1_cy_cp2_cp0_cx_b += cp1;
                                    cp4_cy_cp5_cp3_cx_b += cp4;
                                }
                                out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix);
                            }
                        }
                        return true;
                    }
                    break;
            }
            return false;
        }
        /**
         * ラスタのエントリポイントから辿れる輪郭線を配列に返します。
         * @param i_raster
         * @param i_th
         * 暗点<=th<明点
         * @param i_entry_x
         * @param i_entry_y
         * @param i_array_size
         * @param o_coord_x
         * @param o_coord_y
         * @return
         * 輪郭線の長さを返します。
         * @throws NyARException
         */
        private int impl_getContour(INyARRaster i_raster, int i_th, int i_entry_x, int i_entry_y, int i_array_size, int[] o_coord_x, int[] o_coord_y)
        {
            int[] xdir = _getContour_xdir; // static int xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1};
            int[] ydir = _getContour_ydir; // static int ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1};

            int[] i_buf  = (int[])i_raster.getBuffer();
            int   width  = i_raster.getWidth();
            int   height = i_raster.getHeight();
            //クリップ領域の上端に接しているポイントを得る。


            int coord_num = 1;

            o_coord_x[0] = i_entry_x;
            o_coord_y[0] = i_entry_y;
            int dir = 5;

            int c = i_entry_x;
            int r = i_entry_y;

            for (; ;)
            {
                dir = (dir + 5) % 8;//dirの正規化
                //ここは頑張ればもっと最適化できると思うよ。
                //4隅以外の境界接地の場合に、境界チェックを省略するとかね。
                if (c >= 1 && c < width - 1 && r >= 1 && r < height - 1)
                {
                    for (; ;)
                    {//gotoのエミュレート用のfor文
                        //境界に接していないとき(暗点判定)
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }
                        dir++;
                        if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th)
                        {
                            break;
                        }

                        /*
                         *                  try{
                         *                      BufferedImage b=new BufferedImage(width,height,ColorSpace.TYPE_RGB);
                         *                      NyARRasterImageIO.copy(i_raster, b);
                         *                  ImageIO.write(b,"png",new File("bug.png"));
                         *                  }catch(Exception e){
                         *
                         *                  }*/
                        //8方向全て調べたけどラベルが無いよ?
                        throw new NyARException();
                    }
                }
                else
                {
                    //境界に接しているとき
                    int i;
                    for (i = 0; i < 8; i++)
                    {
                        int x = c + xdir[dir];
                        int y = r + ydir[dir];
                        //境界チェック
                        if (x >= 0 && x < width && y >= 0 && y < height)
                        {
                            if (i_buf[(y) * width + (x)] <= i_th)
                            {
                                break;
                            }
                        }
                        dir++;//倍長テーブルを参照するので問題なし
                    }
                    if (i == 8)
                    {
                        //8方向全て調べたけどラベルが無いよ?
                        throw new NyARException();// return(-1);
                    }
                }

                dir = dir % 8;//dirの正規化

                // xcoordとycoordをc,rにも保存
                c = c + xdir[dir];
                r = r + ydir[dir];
                o_coord_x[coord_num] = c;
                o_coord_y[coord_num] = r;
                // 終了条件判定
                if (c == i_entry_x && r == i_entry_y)
                {
                    coord_num++;
                    break;
                }
                coord_num++;
                if (coord_num == i_array_size)
                {
                    //輪郭が末端に達した
                    return(coord_num);
                }
            }
            return(coord_num);
        }
Example #55
0
        /**
         * NyARRasterからパターンデータをセットします。
         * この関数は、データを元に所有するデータ領域を更新します。
         * @param i_buffer
         */
        public void setRaster(INyARRaster i_raster)
        {
            //画素フォーマット、サイズ制限
            Debug.Assert(i_raster.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
            Debug.Assert(i_raster.getSize().isEqualSize(i_raster.getSize()));

            int[] buf = (int[])i_raster.getBuffer();
            //i_buffer[XRGB]→差分[R,G,B]変換
            int i;
            int ave;                   //<PV/>
            int rgb;                   //<PV/>

            int[] linput = this._data; //<PV/>

            // input配列のサイズとwhも更新// input=new int[height][width][3];
            int number_of_pixels = this._number_of_pixels;
            int for_mod          = this._optimize_for_mod;

            //<平均値計算(FORの1/8展開)>
            ave = 0;
            for (i = number_of_pixels - 1; i >= for_mod; i--)
            {
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff);
            }
            for (; i >= 0;)
            {
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
                rgb = buf[i]; ave += ((rgb >> 16) & 0xff) + ((rgb >> 8) & 0xff) + (rgb & 0xff); i--;
            }
            //<平均値計算(FORの1/8展開)/>
            ave = number_of_pixels * 255 * 3 - ave;
            ave = 255 - (ave / (number_of_pixels * 3));//(255-R)-ave を分解するための事前計算

            int sum = 0, w_sum;
            int input_ptr = number_of_pixels * 3 - 1;

            //<差分値計算(FORの1/8展開)>
            for (i = number_of_pixels - 1; i >= for_mod; i--)
            {
                rgb   = buf[i];
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
            }
            for (; i >= 0;)
            {
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                rgb   = buf[i]; i--;
                w_sum = (ave - (rgb & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;         //B
                w_sum = (ave - ((rgb >> 8) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum;  //G
                w_sum = (ave - ((rgb >> 16) & 0xff)); linput[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
            }
            //<差分値計算(FORの1/8展開)/>
            double p = Math.Sqrt((double)sum);

            this._pow = p != 0.0 ? p : 0.0000001;
            return;
        }