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;
            }
Ejemplo n.º 2
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.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 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.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;
            }
		    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;
		    }
Ejemplo n.º 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;
            }
		    /**
		     * 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)
					    ||	i_input.isEqualBufferType(NyARBufferType.BYTE1D_R8G8B8_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] = ((in_buf[bp] & 0xff) * (in_buf[bp + 1] & 0xff) * (in_buf[bp + 2] & 0xff)) >> 16;
					    bp += 3;
				    }
			    }
			    return;
		    }
Ejemplo n.º 11
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 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 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;
            }
            /**
             * 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) ||
                             i_input.isEqualBufferType(NyARBufferType.BYTE1D_R8G8B8_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] = ((in_buf[bp] & 0xff) * (in_buf[bp + 1] & 0xff) * (in_buf[bp + 2] & 0xff)) >> 16;
                        bp += 3;
                    }
                }
                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 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_B8G8R8_24) ||
                    i_raster.isEqualBufferType(NyARBufferType.BYTE1D_R8G8B8_24));
                byte[]      input        = (byte[])i_raster.getBuffer();
                NyARIntSize s            = i_raster.getSize();
                int         skip         = (i_skip * s.w - i_w) * 3;
                int         pix_count    = i_w;
                int         pix_mod_part = pix_count - (pix_count % 8);
                //左上から1行づつ走査していく
                int pt = (i_t * s.w + i_l) * 3;

                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 += 3;
                    }
                    for (; x >= 0; x -= 8)
                    {
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        o_histogram[((input[pt + 0] & 0xff) + (input[pt + 1] & 0xff) + (input[pt + 2] & 0xff)) / 3]++;
                        pt += 3 * 8;
                    }
                    //スキップ
                    pt += skip;
                }
                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 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;
            }
Ejemplo n.º 22
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;
                    }
                }
            }
            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 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.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 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;
            }
            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 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;
	        }
 public NyARRgb2GsFilterRgbAve_INT1D_X8R8G8B8_32(INyARRaster i_ref_raster)
 {
     Debug.Assert(i_ref_raster.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
     this._ref_raster = i_ref_raster;
 }
        /**
         * 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 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 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;
				    }
			    }
		    }
 public bool isSupport(INyARRaster i_in, INyARRaster i_out)
 {
     return i_in.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24) && i_out.isEqualBufferType(NyARBufferType.INT1D_X7H9S8V8_32);
 }
Ejemplo n.º 35
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;
                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;
            }
Ejemplo n.º 36
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;
        }
Ejemplo n.º 37
0
 public bool isCompatibleRaster(INyARRaster i_raster)
 {
     return(i_raster.isEqualBufferType(NyARBufferType.INT1D_GRAY_8));
 }
            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;
            }
		    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 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 bool isSupport(INyARRaster i_in, INyARRaster i_out)
 {
     return(i_in.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24) && i_out.isEqualBufferType(NyARBufferType.INT1D_X7H9S8V8_32));
 }
 public NyARRgb2GsFilterRgbAve_BYTE1D_C8C8C8_24(INyARRaster i_ref_raster)
 {
     Debug.Assert(i_ref_raster.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24) || i_ref_raster.isEqualBufferType(NyARBufferType.BYTE1D_R8G8B8_24));
     this._ref_raster = i_ref_raster;
 }
		    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 NyARRgb2GsFilterRgbAve_INT1D_X8R8G8B8_32(INyARRaster i_ref_raster)
 {
     Debug.Assert(i_ref_raster.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
     this._ref_raster = i_ref_raster;
 }
 public bool isCompatibleRaster(INyARRaster i_raster)
 {
     return i_raster.isEqualBufferType(NyARBufferType.INT1D_GRAY_8);
 }
 public NyARRgb2GsFilterRgbAve_BYTE1D_B8G8R8X8_32(INyARRaster i_ref_raster)
 {
     Debug.Assert(i_ref_raster.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8X8_32));
     this._ref_raster = i_ref_raster;
 }
		    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 NyARRgb2GsFilterRgbAve_BYTE1D_B8G8R8X8_32(INyARRaster i_ref_raster)
 {
     Debug.Assert(i_ref_raster.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8X8_32));
     this._ref_raster = i_ref_raster;
 }
        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;
        }
 public NyARRgb2GsFilterRgbAve_BYTE1D_C8C8C8_24(INyARRaster i_ref_raster)
 {
     Debug.Assert(i_ref_raster.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8_24) || i_ref_raster.isEqualBufferType(NyARBufferType.BYTE1D_R8G8B8_24));
     this._ref_raster = i_ref_raster;
 }