public override void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster) { Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8)); INyARRgbPixelDriver input = this._raster.getRgbPixelDriver(); int[] output = (int[])i_gsraster.getBuffer(); int th = i_th * 3; NyARIntSize s = i_gsraster.getSize(); int skip_dst = (s.w - i_w); int skip_src = skip_dst; //左上から1行づつ走査していく int pt_dst = (i_t * s.w + i_l); int[] rgb = this.__rgb; for (int y = 0; y < i_h; y++) { int x; for (x = 0; x < i_w; x++) { input.getPixel(x + i_l, y + i_t, rgb); output[pt_dst++] = (rgb[0] + rgb[1] + rgb[2]) <= th ? 0 : 1; } //スキップ pt_dst += skip_dst; } return; }
public override void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster) { Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8)); INyARRgbPixelDriver input = this._raster.getRgbPixelDriver(); int[] output = (int[])i_gsraster.getBuffer(); int th = i_th * 3; NyARIntSize s = i_gsraster.getSize(); int skip_dst = (s.w - i_w); int skip_src = skip_dst; //左上から1行づつ走査していく int pt_dst = (i_t * s.w + i_l); int[] rgb = this.__rgb; for (int y = 0; y <i_h; y++) { int x; for (x = 0; x < i_w; x++) { input.getPixel(x + i_l, y + i_t, rgb); output[pt_dst++] = (rgb[0] + rgb[1] + rgb[2]) <= th ? 0 : 1; } //スキップ pt_dst += skip_dst; } return; }
public void convertRect(int l, int t, int w, int h, INyARGrayscaleRaster o_raster) { NyARIntSize size = this._ref_raster.getSize(); int bp = (l + t * size.w); 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; int[] in_buf = (int[])this._ref_raster.getBuffer(); switch (o_raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int v; int[] out_buf = (int[])o_raster.getBuffer(); 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++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) >> 2; } for (; x >= 0; x -= 8) { v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; } bp += row_padding_dst; src_ptr += row_padding_src; } return; default: INyARGsPixelDriver out_drv = o_raster.getGsPixelDriver(); for (int y = t; y < b; y++) { for (int x = 0; x < pix_count; x++) { v = in_buf[src_ptr++]; out_drv.setPixel(x, y, (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3); } } return; } }
public void copyTo(int i_left, int i_top, int i_skip, INyARGrayscaleRaster o_output) { Debug.Assert(this._raster.getSize().isInnerSize(i_left + o_output.getWidth() * i_skip, i_top + o_output.getHeight() * i_skip)); int[] input = (int[])this._raster.getBuffer(); switch (o_output.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] output = (int[])o_output.getBuffer(); NyARIntSize dest_size = o_output.getSize(); NyARIntSize src_size = this._raster.getSize(); int skip_src_y = (src_size.w - dest_size.w * i_skip) + src_size.w * (i_skip - 1); int pix_count = dest_size.w; int pix_mod_part = pix_count - (pix_count % 8); // 左上から1行づつ走査していく int pt_dst = 0; int pt_src = (i_top * src_size.w + i_left); 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]; pt_src += i_skip; } for (; x >= 0; x -= 8) { output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; } // スキップ pt_src += skip_src_y; } return; default: throw new NyARException(); } }
public void copyTo(int i_left, int i_top, int i_skip, INyARGrayscaleRaster o_output) { Debug.Assert(this._raster.getSize().isInnerSize(i_left + o_output.getWidth() * i_skip, i_top + o_output.getHeight() * i_skip)); int[] input = (int[])this._raster.getBuffer(); switch (o_output.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] output = (int[])o_output.getBuffer(); NyARIntSize dest_size = o_output.getSize(); NyARIntSize src_size = this._raster.getSize(); int skip_src_y = (src_size.w - dest_size.w * i_skip) + src_size.w * (i_skip - 1); int pix_count = dest_size.w; int pix_mod_part = pix_count - (pix_count % 8); // 左上から1行づつ走査していく int pt_dst = 0; int pt_src = (i_top * src_size.w + i_left); 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]; pt_src += i_skip; } for (; x >= 0; x -= 8) { output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; output[pt_dst++] = input[pt_src]; pt_src += i_skip; } // スキップ pt_src += skip_src_y; } return; default: throw new NyARException(); } }
public void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster) { Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8)); BitmapData bm = this._raster.lockBitmap(); byte[] work = this._work; int[] output = (int[])i_gsraster.getBuffer(); NyARIntSize s = this._raster.getSize(); int th = i_th * 3; 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行づつ走査していく long pt_dst = (i_t * s.w + i_l); long pt_src = pt_dst * 4 + (long)bm.Scan0; for (int y = i_h - 1; y >= 0; y -= 1) { int x; int p; for (x = pix_count - 1; x >= pix_mod_part; x--) { p = Marshal.ReadInt32((IntPtr)pt_src); output[pt_dst++] = (((p >> 16) & 0xff) + ((p >> 8) & 0xff) + (p & 0xff)) <= th ? 0 : 1; pt_src += 4; } for (; x >= 0; x -= 8) { Marshal.Copy((IntPtr)pt_src, work, 0, 32); output[pt_dst] = (work[0] + work[1] + work[2]) <= th ? 0 : 1; output[pt_dst + 1] = (work[4] + work[5] + work[6]) <= th ? 0 : 1; output[pt_dst + 2] = (work[8] + work[9] + work[10]) <= th ? 0 : 1; output[pt_dst + 3] = (work[12] + work[13] + work[14]) <= th ? 0 : 1; output[pt_dst + 4] = (work[16] + work[17] + work[18]) <= th ? 0 : 1; output[pt_dst + 5] = (work[20] + work[21] + work[22]) <= th ? 0 : 1; output[pt_dst + 6] = (work[24] + work[25] + work[26]) <= th ? 0 : 1; output[pt_dst + 7] = (work[28] + work[29] + work[30]) <= th ? 0 : 1; pt_src += 32; pt_dst += 8; } //スキップ pt_src += skip_src; pt_dst += skip_dst; } this._raster.unlockBitmap(); return; }
public override void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster) { Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8)); byte[] input = (byte[])this._raster.getBuffer(); int[] output = (int[])i_gsraster.getBuffer(); int th = i_th * 3; NyARIntSize s = this._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 override void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster) { Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8)); byte[] input = (byte[])this._raster.getBuffer(); int[] output = (int[])i_gsraster.getBuffer(); int th = i_th * 3; NyARIntSize s = this._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 override void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster) { Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8)); short[] input = (short[])this._raster.getBuffer(); int[] output = (int[])i_gsraster.getBuffer(); int th = i_th * 3; NyARIntSize s = i_gsraster.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 convertRect(int l, int t, int w, int h, INyARGrayscaleRaster o_raster) { Color32[] c=(Color32[])(this._ref_raster.getBuffer()); NyARIntSize size = this._ref_raster.getSize(); int src = (l + t * size.w) * 4; int b = t + h; int row_padding_dst = (size.w - w); int row_padding_src = row_padding_dst * 4; int pix_count = w; int pix_mod_part = pix_count - (pix_count % 8); // in_buf = (byte[])this._ref_raster.getBuffer(); switch (o_raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] out_buf = (int[])o_raster.getBuffer(); int dst_ptr; if(this._is_inverse){ dst_ptr=(h-1-t) * size.w + l; row_padding_dst-=size.w*2; }else{ dst_ptr=t * size.w + l; } for (int y = t; y < b; y++) { int x = 0; Color32 p; for (x = pix_count - 1; x >= pix_mod_part; x--) { p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; } for (; x >= 0; x -= 8) { p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; p=c[src++]; out_buf[dst_ptr++] = (p.r+p.g+p.b) / 3; } dst_ptr+=row_padding_dst; src += row_padding_src; } return; default: INyARGsPixelDriver out_drv = o_raster.getGsPixelDriver(); for (int y = t; y < b; y++) { for (int x = 0; x < pix_count; x++) { Color32 p = c[src++]; out_drv.setPixel(x, y,(p.r+p.g+p.b) / 3); } src += row_padding_src; } return; } }
public void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster) { Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8)); BitmapData bm = this._raster.lockBitmap(); byte[] work = this._work; int[] output = (int[])i_gsraster.getBuffer(); NyARIntSize s = this._raster.getSize(); int th = i_th * 3; 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+(int)bm.Scan0; for (int y = i_h - 1; y >= 0; y -= 1) { int x; int p; for (x = pix_count - 1; x >= pix_mod_part; x--) { p = Marshal.ReadInt32((IntPtr)pt_src); output[pt_dst++] = (((p >> 16) & 0xff) + ((p >> 8) & 0xff) + (p & 0xff)) <= th ? 0 : 1; pt_src += 4; } for (; x >= 0; x -= 8) { Marshal.Copy((IntPtr)pt_src, work, 0, 32); output[pt_dst ] = (work[0]+work[1]+work[2]) <= th ? 0 : 1; output[pt_dst+1] = (work[4] + work[5] + work[6]) <= th ? 0 : 1; output[pt_dst+2] = (work[8] + work[9] + work[10]) <= th ? 0 : 1; output[pt_dst+3] = (work[12] + work[13] + work[14]) <= th ? 0 : 1; output[pt_dst+4] = (work[16] + work[17] + work[18]) <= th ? 0 : 1; output[pt_dst+5] = (work[20] + work[21] + work[22]) <= th ? 0 : 1; output[pt_dst+6] = (work[24] + work[25] + work[26]) <= th ? 0 : 1; output[pt_dst+7] = (work[28] + work[29] + work[30]) <= th ? 0 : 1; pt_src += 32; pt_dst += 8; } //スキップ pt_src += skip_src; pt_dst += skip_dst; } this._raster.unlockBitmap(); return; }
public void doFilter(INyARGrayscaleRaster i_output) { int[] in_ptr = (int[])this._raster.getBuffer(); int width = this._raster.getWidth(); int height = this._raster.getHeight(); int col0, col1, col2; int bptr = 0; switch (i_output.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] out_ptr = (int[])i_output.getBuffer(); 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; default: throw new NyARException(); } }
public void convertRect(int l, int t, int w, int h, INyARGrayscaleRaster o_raster) { Color32[] c = (Color32[])(this._ref_raster.getBuffer()); NyARIntSize size = this._ref_raster.getSize(); int src = (l + t * size.w) * 4; int b = t + h; int row_padding_dst = (size.w - w); int row_padding_src = row_padding_dst * 4; int pix_count = w; int pix_mod_part = pix_count - (pix_count % 8); // in_buf = (byte[])this._ref_raster.getBuffer(); switch (o_raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] out_buf = (int[])o_raster.getBuffer(); int dst_ptr; if (this._is_inverse) { dst_ptr = (h - 1 - t) * size.w + l; row_padding_dst -= size.w * 2; } else { dst_ptr = t * size.w + l; } for (int y = t; y < b; y++) { int x = 0; Color32 p; for (x = pix_count - 1; x >= pix_mod_part; x--) { p = c[src++]; out_buf[dst_ptr++] = (p.r + p.g + p.b) / 3; } for (; x >= 0; x -= 8) { p = c[src++]; out_buf[dst_ptr++] = (p.r + p.g + p.b) / 3; p = c[src++]; out_buf[dst_ptr++] = (p.r + p.g + p.b) / 3; p = c[src++]; out_buf[dst_ptr++] = (p.r + p.g + p.b) / 3; p = c[src++]; out_buf[dst_ptr++] = (p.r + p.g + p.b) / 3; p = c[src++]; out_buf[dst_ptr++] = (p.r + p.g + p.b) / 3; p = c[src++]; out_buf[dst_ptr++] = (p.r + p.g + p.b) / 3; p = c[src++]; out_buf[dst_ptr++] = (p.r + p.g + p.b) / 3; p = c[src++]; out_buf[dst_ptr++] = (p.r + p.g + p.b) / 3; } dst_ptr += row_padding_dst; src += row_padding_src; } return; default: for (int y = t; y < b; y++) { for (int x = 0; x < pix_count; x++) { Color32 p = c[src++]; o_raster.setPixel(x, y, (p.r + p.g + p.b) / 3); } src += row_padding_src; } return; } }
public void doFilter(INyARGrayscaleRaster i_output) { int[] in_ptr = (int[])this._raster.getBuffer(); int width = this._raster.getWidth(); int height = this._raster.getHeight(); int col0, col1, col2; int bptr = 0; switch (i_output.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] out_ptr = (int[])i_output.getBuffer(); 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; default: throw new NyARException(); } }
public void convertRect(int l, int t, int w, int h, INyARGrayscaleRaster o_raster) { NyARIntSize size = this._ref_raster.getSize(); int bp = (l + t * size.w); 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; int[] in_buf = (int[])this._ref_raster.getBuffer(); switch (o_raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int v; int[] out_buf = (int[])o_raster.getBuffer(); 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++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) >> 2; } for (; x >= 0; x -= 8) { v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; v = in_buf[src_ptr++]; out_buf[bp++] = (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3; } bp += row_padding_dst; src_ptr += row_padding_src; } return; default: INyARGsPixelDriver out_drv = o_raster.getGsPixelDriver(); for (int y = t; y < b; y++) { for (int x = 0; x < pix_count; x++) { v = in_buf[src_ptr++]; out_drv.setPixel(x, y, (((v >> 16) & 0xff) + ((v >> 8) & 0xff) + (v & 0xff)) / 3); } } return; } }
private void apply_filter(KpmImage dst, INyARGrayscaleRaster src) { Debug.Assert(src.isEqualBufferType(NyARBufferType.INT1D_GRAY_8)); binomial_4th_order((double[])dst.getBuffer(), this.mTemp_us16, (int[])src.getBuffer(), src.getWidth(), src.getHeight()); }
public override void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster) { Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8)); short[] input = (short[])this._raster.getBuffer(); int[] output = (int[])i_gsraster.getBuffer(); int th = i_th * 3; NyARIntSize s = i_gsraster.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(INyARGrayscaleRaster i_output) { Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8)); NyARIntSize size = this._raster.getSize(); int[] in_ptr = (int[])this._raster.getBuffer(); switch (this._raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] out_ptr = (int[])i_output.getBuffer(); int width = size.w; int idx = 0; int idx2 = width; int fx, fy; int mod_p = (width - 2) - (width - 2) % 8; for (int y = 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; default: //ANY未対応 throw new NyARException(); } }
public void doFilter(INyARGrayscaleRaster i_output) { Debug.Assert(i_output.isEqualBufferType(NyARBufferType.INT1D_GRAY_8)); NyARIntSize size = this._raster.getSize(); int[] in_ptr = (int[])this._raster.getBuffer(); switch (this._raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] out_ptr = (int[])i_output.getBuffer(); int width = size.w; int idx = 0; int idx2 = width; int fx, fy; int mod_p = (width - 2) - (width - 2) % 8; for (int y = 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; default: //ANY未対応 throw new NyARException(); } }
public void convertRect(int l, int t, int w, int h, INyARGrayscaleRaster o_raster) { byte[] work = this._work; BitmapData bm = this._ref_raster.lockBitmap(); NyARIntSize size = this._ref_raster.getSize(); int bp = (l + t * size.w) * 4 + (int)bm.Scan0; int b = t + h; int row_padding_dst = (size.w - w); int row_padding_src = row_padding_dst * 4; int pix_count = w; int pix_mod_part = pix_count - (pix_count % 8); int dst_ptr = t * size.w + l; // in_buf = (byte[])this._ref_raster.getBuffer(); switch (o_raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] out_buf = (int[])o_raster.getBuffer(); for (int y = t; y < b; y++) { int x = 0; for (x = pix_count - 1; x >= pix_mod_part; x--) { int p = Marshal.ReadInt32((IntPtr)bp); out_buf[dst_ptr++] = (((p >> 16) & 0xff) + ((p >> 8) & 0xff) + (p & 0xff)) / 3; bp += 4; } for (; x >= 0; x -= 8) { Marshal.Copy((IntPtr)bp, work, 0, 32); out_buf[dst_ptr++] = (work[0] + work[1] + work[2]) / 3; out_buf[dst_ptr++] = (work[4] + work[5] + work[6]) / 3; out_buf[dst_ptr++] = (work[8] + work[9] + work[10]) / 3; out_buf[dst_ptr++] = (work[12] + work[13] + work[14]) / 3; out_buf[dst_ptr++] = (work[16] + work[17] + work[18]) / 3; out_buf[dst_ptr++] = (work[20] + work[21] + work[22]) / 3; out_buf[dst_ptr++] = (work[24] + work[25] + work[26]) / 3; out_buf[dst_ptr++] = (work[28] + work[29] + work[30]) / 3; bp += 32; } bp += row_padding_src; dst_ptr += row_padding_dst; } this._ref_raster.unlockBitmap(); return; default: for (int y = t; y < b; y++) { for (int x = 0; x < pix_count; x++) { int p = Marshal.ReadInt32((IntPtr)bp); o_raster.setPixel(x, y, (((p >> 16) & 0xff) + ((p >> 8) & 0xff) + (p & 0xff)) / 3); bp += 4; } bp += row_padding_src; } this._ref_raster.unlockBitmap(); return; } }
public void convertRect(int l, int t, int w, int h, INyARGrayscaleRaster o_raster) { byte[] work = this._work; BitmapData bm = this._ref_raster.lockBitmap(); NyARIntSize size = this._ref_raster.getSize(); int bp = (l + t * size.w) * 4 + (int)bm.Scan0; int b = t + h; int row_padding_dst = (size.w - w); int row_padding_src = row_padding_dst * 4; int pix_count = w; int pix_mod_part = pix_count - (pix_count % 8); int dst_ptr = t * size.w + l; // in_buf = (byte[])this._ref_raster.getBuffer(); switch (o_raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] out_buf = (int[])o_raster.getBuffer(); for (int y = t; y < b; y++) { int x = 0; for (x = pix_count - 1; x >= pix_mod_part; x--) { int p = Marshal.ReadInt32((IntPtr)bp); out_buf[dst_ptr++] = (((p >> 16) & 0xff) + ((p >> 8) & 0xff) + (p & 0xff)) / 3; bp += 4; } for (; x >= 0; x -= 8) { Marshal.Copy((IntPtr)bp, work, 0, 32); out_buf[dst_ptr++] = (work[0] + work[1] + work[2]) / 3; out_buf[dst_ptr++] = (work[4] + work[5] + work[6]) / 3; out_buf[dst_ptr++] = (work[8] + work[9] + work[10]) / 3; out_buf[dst_ptr++] = (work[12] + work[13] + work[14]) / 3; out_buf[dst_ptr++] = (work[16] + work[17] + work[18]) / 3; out_buf[dst_ptr++] = (work[20] + work[21] + work[22]) / 3; out_buf[dst_ptr++] = (work[24] + work[25] + work[26]) / 3; out_buf[dst_ptr++] = (work[28] + work[29] + work[30]) / 3; bp += 32; } bp += row_padding_src; dst_ptr += row_padding_dst; } this._ref_raster.unlockBitmap(); return; default: INyARGsPixelDriver out_drv = o_raster.getGsPixelDriver(); for (int y = t; y < b; y++) { for (int x = 0; x < pix_count; x++) { int p = Marshal.ReadInt32((IntPtr)bp); out_drv.setPixel(x, y, (((p >> 16) & 0xff) + ((p >> 8) & 0xff) + (p & 0xff)) / 3); bp += 4; } bp += row_padding_src; } this._ref_raster.unlockBitmap(); return; } }
public void convertRect(int l, int t, int w, int h, INyARGrayscaleRaster o_raster) { NyARIntSize size = this._ref_raster.getSize(); 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 dst_ptr = t * size.w + l; byte[] in_buf = (byte[])this._ref_raster.getBuffer(); switch (o_raster.getBufferType()) { case NyARBufferType.INT1D_GRAY_8: int[] out_buf = (int[])o_raster.getBuffer(); for (int y = t; y < b; y++) { int x = 0; for (x = pix_count - 1; x >= pix_mod_part; x--) { out_buf[dst_ptr++] = ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) / 3; bp += 3; } for (; x >= 0; x -= 8) { out_buf[dst_ptr++] = ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) / 3; bp += 3; out_buf[dst_ptr++] = ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) / 3; bp += 3; out_buf[dst_ptr++] = ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) / 3; bp += 3; out_buf[dst_ptr++] = ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) / 3; bp += 3; out_buf[dst_ptr++] = ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) / 3; bp += 3; out_buf[dst_ptr++] = ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) / 3; bp += 3; out_buf[dst_ptr++] = ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) / 3; bp += 3; out_buf[dst_ptr++] = ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) / 3; bp += 3; } bp += row_padding_src; dst_ptr += row_padding_dst; } return; default: for (int y = t; y < b; y++) { for (int x = 0; x < pix_count; x++) { o_raster.setPixel(x, y, ((in_buf[bp] & 0xff) + (in_buf[bp + 1] & 0xff) + (in_buf[bp + 2] & 0xff)) / 3); bp += 3; } bp += row_padding_src; } return; } }