protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out) { Color32[] in_pixs = (Color32[])this._ref_raster.getBuffer(); int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l; double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l; double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l; int p; int step,offset; //flip Virtical switch (o_out.getBufferType()) { case NyARBufferType.INT1D_X8R8G8B8_32: int[] pat_data = (int[])o_out.getBuffer(); p = 0; if(this._is_inv_v){ offset=in_w*(in_h-1); step=-in_w; }else{ offset=0; step=in_w; } for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } Color32 pix=in_pixs[x + offset+step*y]; // pat_data[p] = ((pix.r << 16) & 0xff)|((pix.g << 8) & 0xff)| pix.b; cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; p++; } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } return true; case NyARBufferType.OBJECT_CS_Unity: Color32[] out_buf = (Color32[])(((INyARRgbRaster)o_out).getBuffer()); if(this._is_inv_v==((NyARUnityRaster)o_out).isFlipVirtical()){ offset=in_w*(in_h-1); step=-in_w; }else{ offset=0; step=in_w; } for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; int ys=out_h-1-iy; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } out_buf[ix+ys*out_w]=in_pixs[x + offset+step*y]; // cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } return true; default: //ANY to RGBx if (o_out is INyARRgbRaster) { INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver(); if(this._is_inv_v){ offset=in_w*(in_h-1); step=-in_w; }else{ offset=0; step=in_w; } for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } Color32 px = in_pixs[x + offset+step*y]; cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; out_reader.setPixel(ix, iy,px.r,px.g,px.b); } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } return true; } break; } return false; }
protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out) { BitmapData in_bmp = this._ref_raster.lockBitmap(); int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l; double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l; double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l; int r, g, b, p; switch (o_out.getBufferType()) { case NyARBufferType.INT1D_X8R8G8B8_32: int[] pat_data = (int[])o_out.getBuffer(); p = 0; for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } // pat_data[p] = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride)); //r = (px >> 16) & 0xff;// R //g = (px >> 8) & 0xff; // G //b = (px) & 0xff; // B cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; //pat_data[p] = (r << 16) | (g << 8) | ((b & 0xff)); //pat_data[p] = px; p++; } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } this._ref_raster.unlockBitmap(); return(true); default: if (o_out is NyARBitmapRaster) { NyARBitmapRaster bmr = (NyARBitmapRaster)o_out; BitmapData bm = bmr.lockBitmap(); p = 0; for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } int pix = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride)); Marshal.WriteInt32(bm.Scan0, ix * 4 + iy * bm.Stride, pix); cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; p++; } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } bmr.unlockBitmap(); this._ref_raster.unlockBitmap(); return(true); } else if (o_out is INyARRgbRaster) { //ANY to RGBx INyARRgbRaster out_raster = ((INyARRgbRaster)o_out); for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride)); r = (px >> 16) & 0xff; // R g = (px >> 8) & 0xff; // G b = (px) & 0xff; // B cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; out_raster.setPixel(ix, iy, r, g, b); } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } this._ref_raster.unlockBitmap(); return(true); } break; } this._ref_raster.unlockBitmap(); return(false); }
protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out) { BitmapData in_bmp = this._ref_raster.lockBitmap(); int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); int res_pix = i_resolution * i_resolution; //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; double cp2 = cpara[2]; double cp5 = cpara[5]; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); if (o_out is NyARBitmapRaster) { NyARBitmapRaster bmr = ((NyARBitmapRaster)o_out); BitmapData bm = bmr.lockBitmap(); for (int iy = out_h - 1; iy >= 0; iy--) { //解像度分の点を取る。 for (int ix = out_w - 1; ix >= 0; ix--) { int r, g, b; r = g = b = 0; int cy = pk_t + iy * i_resolution; int cx = pk_l + ix * i_resolution; double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx; double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx; double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx; for (int i2y = i_resolution - 1; i2y >= 0; i2y--) { double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b; for (int i2x = i_resolution - 1; i2x >= 0; i2x--) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride)); r += (px >> 16) & 0xff; // R g += (px >> 8) & 0xff; // G b += (px) & 0xff; // B cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; } cp7_cy_1_cp6_cx_b += cp7; cp1_cy_cp2_cp0_cx_b += cp1; cp4_cy_cp5_cp3_cx_b += cp4; } Marshal.WriteInt32(bm.Scan0, ix * 4 + iy * bm.Stride, (0x00ff0000 & ((r / res_pix) << 16)) | (0x0000ff00 & ((g / res_pix) << 8)) | (0x0000ff & (b / res_pix))); } } bmr.unlockBitmap(); this._ref_raster.unlockBitmap(); return(true); } else if (o_out is INyARRgbRaster) { INyARRgbRaster out_raster = ((INyARRgbRaster)o_out); for (int iy = out_h - 1; iy >= 0; iy--) { //解像度分の点を取る。 for (int ix = out_w - 1; ix >= 0; ix--) { int r, g, b; r = g = b = 0; int cy = pk_t + iy * i_resolution; int cx = pk_l + ix * i_resolution; double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx; double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx; double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx; for (int i2y = i_resolution - 1; i2y >= 0; i2y--) { double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b; for (int i2x = i_resolution - 1; i2x >= 0; i2x--) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride)); r += (px >> 16) & 0xff; // R g += (px >> 8) & 0xff; // G b += (px) & 0xff; // B cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; } cp7_cy_1_cp6_cx_b += cp7; cp1_cy_cp2_cp0_cx_b += cp1; cp4_cy_cp5_cp3_cx_b += cp4; } out_raster.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix); } } this._ref_raster.unlockBitmap(); return(true); } else { throw new NyARRuntimeException(); } }
protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out) { Color32[] in_pixs = (Color32[])this._ref_raster.getBuffer(); int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l; double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l; double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l; int p; int step, offset; //flip Virtical switch (o_out.getBufferType()) { case NyARBufferType.INT1D_X8R8G8B8_32: int[] pat_data = (int[])o_out.getBuffer(); p = 0; if (this._is_inv_v) { offset = in_w * (in_h - 1); step = -in_w; } else { offset = 0; step = in_w; } for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } Color32 pix = in_pixs[x + offset + step * y]; // pat_data[p] = ((pix.r << 16) & 0xff) | ((pix.g << 8) & 0xff) | pix.b; cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; p++; } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } return(true); case NyARBufferType.OBJECT_CS_Unity: Color32[] out_buf = (Color32[])(((INyARRgbRaster)o_out).getBuffer()); if (this._is_inv_v == ((NyARUnityRaster)o_out).isFlipVirtical()) { offset = in_w * (in_h - 1); step = -in_w; } else { offset = 0; step = in_w; } for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; int ys = out_h - 1 - iy; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } out_buf[ix + ys * out_w] = in_pixs[x + offset + step * y]; // cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } return(true); default: //ANY to RGBx if (o_out is INyARRgbRaster) { INyARRgbRaster out_raster = ((INyARRgbRaster)o_out); if (this._is_inv_v) { offset = in_w * (in_h - 1); step = -in_w; } else { offset = 0; step = in_w; } for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } Color32 px = in_pixs[x + offset + step * y]; cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; out_raster.setPixel(ix, iy, px.r, px.g, px.b); } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } return(true); } break; } return(false); }
protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out) { Color32[] in_pixs = (Color32[])this._ref_raster.getBuffer(); int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); int res_pix = i_resolution * i_resolution; //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; double cp2 = cpara[2]; double cp5 = cpara[5]; int step, offset; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); if (o_out is INyARRgbRaster) { INyARRgbRaster out_raster = ((INyARRgbRaster)o_out); if (this._is_inv_v) { offset = in_w * (in_h - 1); step = -in_w; } else { offset = 0; step = in_w; } for (int iy = out_h - 1; iy >= 0; iy--) { //解像度分の点を取る。 for (int ix = out_w - 1; ix >= 0; ix--) { int r, g, b; r = g = b = 0; int cy = pk_t + iy * i_resolution; int cx = pk_l + ix * i_resolution; double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx; double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx; double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx; for (int i2y = i_resolution - 1; i2y >= 0; i2y--) { double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b; for (int i2x = i_resolution - 1; i2x >= 0; i2x--) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } Color32 px = in_pixs[x + offset + step * y]; r += px.r; // R g += px.g; // G b += px.b; // B cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; } cp7_cy_1_cp6_cx_b += cp7; cp1_cy_cp2_cp0_cx_b += cp1; cp4_cy_cp5_cp3_cx_b += cp4; } out_raster.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix); } } return(true); } return(false); }
protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out) { BitmapData in_bmp = this._ref_raster.lockBitmap(); int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l; double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l; double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l; int r, g, b, p; switch (o_out.getBufferType()) { case NyARBufferType.INT1D_X8R8G8B8_32: int[] pat_data = (int[])o_out.getBuffer(); p = 0; for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } // pat_data[p] = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride)); //r = (px >> 16) & 0xff;// R //g = (px >> 8) & 0xff; // G //b = (px) & 0xff; // B cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; //pat_data[p] = (r << 16) | (g << 8) | ((b & 0xff)); //pat_data[p] = px; p++; } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } this._ref_raster.unlockBitmap(); return true; default: if (o_out is NyARBitmapRaster) { NyARBitmapRaster bmr = (NyARBitmapRaster)o_out; BitmapData bm = bmr.lockBitmap(); p = 0; for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } int pix = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride)); Marshal.WriteInt32(bm.Scan0, ix * 4 + iy * bm.Stride, pix); cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; p++; } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } bmr.unlockBitmap(); this._ref_raster.unlockBitmap(); return true; } else if (o_out is INyARRgbRaster) { //ANY to RGBx INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver(); for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } int px = Marshal.ReadInt32(in_bmp.Scan0, (x*4 + y * in_bmp.Stride)); r = (px >> 16) & 0xff;// R g = (px >> 8) & 0xff; // G b = (px) & 0xff; // B cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; out_reader.setPixel(ix, iy, r, g, b); } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } this._ref_raster.unlockBitmap(); return true; } break; } this._ref_raster.unlockBitmap(); return false; }
private int imple_labeling(INyARRaster i_raster, int i_th, int i_top, int i_bottom, RleLabelFragmentInfoStack o_stack) { // リセット処理 RleInfoStack rlestack = this._rlestack; rlestack.clear(); // RleElement[] rle_prev = this._rle1; RleElement[] rle_current = this._rle2; int len_prev = 0; int len_current = 0; int width = i_raster.getWidth(); int[] in_buf = (int[])i_raster.getBuffer(); int id_max = 0; int label_count = 0; // 初段登録 len_prev = toRel(in_buf, i_top, width, rle_prev, i_th); for (int i = 0; i < len_prev; i++) { // フラグメントID=フラグメント初期値、POS=Y値、RELインデクス=行 addFragment(rle_prev[i], id_max, i_top, rlestack); id_max++; // nofの最大値チェック label_count++; } RleInfoStack.RleInfo[] f_array = rlestack.getArray(); // 次段結合 for (int y = i_top + 1; y < i_bottom; y++) { // カレント行の読込 len_current = toRel(in_buf, y * width, width, rle_current, i_th); int index_prev = 0; for (int i = 0; i < len_current; i++) { // index_prev,len_prevの位置を調整する int id = -1; // チェックすべきprevがあれば確認 while (index_prev < len_prev) { if (rle_current[i].l - rle_prev[index_prev].r > 0) {// 0なら8方位ラベリング // prevがcurの左方にある→次のフラグメントを探索 index_prev++; continue; } else if (rle_prev[index_prev].l - rle_current[i].r > 0) {// 0なら8方位ラベリングになる // prevがcur右方にある→独立フラグメント addFragment(rle_current[i], id_max, y, rlestack); id_max++; label_count++; // 次のindexをしらべる goto SCAN_CUR; } id = rle_prev[index_prev].fid;//ルートフラグメントid RleInfoStack.RleInfo id_ptr = f_array[id]; //結合対象(初回)->prevのIDをコピーして、ルートフラグメントの情報を更新 rle_current[i].fid = id;//フラグメントIDを保存 // int l = rle_current[i].l; int r = rle_current[i].r; int len = r - l; //結合先フラグメントの情報を更新する。 id_ptr.area += len; //tとentry_xは、結合先のを使うので更新しない。 id_ptr.clip_l = l < id_ptr.clip_l ? l : id_ptr.clip_l; id_ptr.clip_r = r > id_ptr.clip_r ? r - 1 : id_ptr.clip_r; id_ptr.clip_b = y; id_ptr.pos_x += (len * (2 * l + (len - 1))) / 2; id_ptr.pos_y += y * len; //多重結合の確認(2個目以降) index_prev++; while (index_prev < len_prev) { if (rle_current[i].l - rle_prev[index_prev].r > 0) {// 0なら8方位ラベリング // prevがcurの左方にある→prevはcurに連結していない。 goto SCAN_PREV; } else if (rle_prev[index_prev].l - rle_current[i].r > 0) {// 0なら8方位ラベリングになる // prevがcurの右方にある→prevはcurに連結していない。 index_prev--; goto SCAN_CUR; } // prevとcurは連結している→ルートフラグメントの統合 //結合するルートフラグメントを取得 int prev_id = rle_prev[index_prev].fid; RleInfoStack.RleInfo prev_ptr = f_array[prev_id]; if (id != prev_id) { label_count--; //prevとcurrentのフラグメントidを書き換える。 for (int i2 = index_prev; i2 < len_prev; i2++) { //prevは現在のidから最後まで if (rle_prev[i2].fid == prev_id) { rle_prev[i2].fid = id; } } for (int i2 = 0; i2 < i; i2++) { //currentは0から現在-1まで if (rle_current[i2].fid == prev_id) { rle_current[i2].fid = id; } } //現在のルートフラグメントに情報を集約 id_ptr.area += prev_ptr.area; id_ptr.pos_x += prev_ptr.pos_x; id_ptr.pos_y += prev_ptr.pos_y; //tとentry_xの決定 if (id_ptr.clip_t > prev_ptr.clip_t) { // 現在の方が下にある。 id_ptr.clip_t = prev_ptr.clip_t; id_ptr.entry_x = prev_ptr.entry_x; } else if (id_ptr.clip_t < prev_ptr.clip_t) { // 現在の方が上にある。prevにフィードバック } else { // 水平方向で小さい方がエントリポイント。 if (id_ptr.entry_x > prev_ptr.entry_x) { id_ptr.entry_x = prev_ptr.entry_x; } else { } } //lの決定 if (id_ptr.clip_l > prev_ptr.clip_l) { id_ptr.clip_l = prev_ptr.clip_l; } else { } //rの決定 if (id_ptr.clip_r < prev_ptr.clip_r) { id_ptr.clip_r = prev_ptr.clip_r; } else { } //bの決定 //結合済のルートフラグメントを無効化する。 prev_ptr.area = 0; } index_prev++; } index_prev--; break; SCAN_PREV :; } // curにidが割り当てられたかを確認 // 右端独立フラグメントを追加 if (id < 0) { addFragment(rle_current[i], id_max, y, rlestack); id_max++; label_count++; } SCAN_CUR :; } // prevとrelの交換 RleElement[] tmp = rle_prev; rle_prev = rle_current; len_prev = len_current; rle_current = tmp; } //対象のラベルだけ転写 o_stack.init(label_count); RleLabelFragmentInfoStack.RleLabelFragmentInfo[] o_dest_array = o_stack.getArray(); int max = this._max_area; int min = this._min_area; int active_labels = 0; for (int i = id_max - 1; i >= 0; i--) { int area = f_array[i].area; if (area < min || area > max) {//対象外のエリア0のもminではじく continue; } // RleInfoStack.RleInfo src_info = f_array[i]; RleLabelFragmentInfoStack.RleLabelFragmentInfo dest_info = o_dest_array[active_labels]; dest_info.area = area; dest_info.clip_b = src_info.clip_b; dest_info.clip_r = src_info.clip_r; dest_info.clip_t = src_info.clip_t; dest_info.clip_l = src_info.clip_l; dest_info.entry_x = src_info.entry_x; dest_info.pos_x = src_info.pos_x / src_info.area; dest_info.pos_y = src_info.pos_y / src_info.area; active_labels++; } //ラベル数を再設定 o_stack.pops(label_count - active_labels); //ラベル数を返却 return(active_labels); }
protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out) { int res_pix = i_resolution * i_resolution; int[] rgb_tmp = this.__pickFromRaster_rgb_tmp; int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); INyARRgbPixelDriver i_in_reader = this._ref_raster.getRgbPixelDriver(); //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; double cp2 = cpara[2]; double cp5 = cpara[5]; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); switch (o_out.getBufferType()) { case NyARBufferType.INT1D_X8R8G8B8_32: int[] pat_data = (int[])o_out.getBuffer(); int p = (out_w * out_h - 1); for (int iy = out_h - 1; iy >= 0; iy--) { //解像度分の点を取る。 for (int ix = out_w - 1; ix >= 0; ix--) { int r, g, b; r = g = b = 0; int cy = pk_t + iy * i_resolution; int cx = pk_l + ix * i_resolution; double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx; double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx; double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx; for (int i2y = i_resolution - 1; i2y >= 0; i2y--) { double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b; for (int i2x = i_resolution - 1; i2x >= 0; i2x--) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } i_in_reader.getPixel(x, y, rgb_tmp); r += rgb_tmp[0]; g += rgb_tmp[1]; b += rgb_tmp[2]; cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; } cp7_cy_1_cp6_cx_b += cp7; cp1_cy_cp2_cp0_cx_b += cp1; cp4_cy_cp5_cp3_cx_b += cp4; } r /= res_pix; g /= res_pix; b /= res_pix; pat_data[p] = ((r & 0xff) << 16) | ((g & 0xff) << 8) | ((b & 0xff)); p--; } } return true; default: //ANY to RGBx if (o_out is INyARRgbRaster) { INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver(); for (int iy = out_h - 1; iy >= 0; iy--) { //解像度分の点を取る。 for (int ix = out_w - 1; ix >= 0; ix--) { int r, g, b; r = g = b = 0; int cy = pk_t + iy * i_resolution; int cx = pk_l + ix * i_resolution; double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx; double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx; double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx; for (int i2y = i_resolution - 1; i2y >= 0; i2y--) { double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b; for (int i2x = i_resolution - 1; i2x >= 0; i2x--) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } i_in_reader.getPixel(x, y, rgb_tmp); r += rgb_tmp[0]; g += rgb_tmp[1]; b += rgb_tmp[2]; cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; } cp7_cy_1_cp6_cx_b += cp7; cp1_cy_cp2_cp0_cx_b += cp1; cp4_cy_cp5_cp3_cx_b += cp4; } out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix); } } return true; } break; } return false; }
protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out) { int[] rgb_tmp = this.__pickFromRaster_rgb_tmp; int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l; double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l; double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l; INyARRgbPixelDriver i_in_reader = this._ref_raster.getRgbPixelDriver(); switch (o_out.getBufferType()) { case NyARBufferType.INT1D_X8R8G8B8_32: int[] pat_data = (int[])o_out.getBuffer(); int p = 0; for (int iy = out_h - 1; iy >= 0; iy--) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = out_w - 1; ix >= 0; ix--) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } i_in_reader.getPixel(x, y, rgb_tmp); cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; pat_data[p] = (rgb_tmp[0] << 16) | (rgb_tmp[1] << 8) | ((rgb_tmp[2] & 0xff)); p++; } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } return true; default: //ANY to RGBx if (o_out is INyARRgbRaster) { INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver(); for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } i_in_reader.getPixel(x, y, rgb_tmp); cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; out_reader.setPixel(ix, iy, rgb_tmp); } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } return true; } break; } return false; }
protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out) { int res_pix = i_resolution * i_resolution; byte[] i_in_buf = (byte[])this._ref_raster.getBuffer(); int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; double cp2 = cpara[2]; double cp5 = cpara[5]; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); if (o_out is INyARRgbRaster) { INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver(); for (int iy = out_h - 1; iy >= 0; iy--) { //解像度分の点を取る。 for (int ix = out_w - 1; ix >= 0; ix--) { int r, g, b; r = g = b = 0; int cy = pk_t + iy * i_resolution; int cx = pk_l + ix * i_resolution; double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx; double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx; double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx; for (int i2y = i_resolution - 1; i2y >= 0; i2y--) { double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b; for (int i2x = i_resolution - 1; i2x >= 0; i2x--) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } int bp = (x + y * in_w) * 3; r += (i_in_buf[bp + 0] & 0xff); g += (i_in_buf[bp + 1] & 0xff); b += (i_in_buf[bp + 2] & 0xff); cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; } cp7_cy_1_cp6_cx_b += cp7; cp1_cy_cp2_cp0_cx_b += cp1; cp4_cy_cp5_cp3_cx_b += cp4; } out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix); } } return(true); } return(false); }
/** * ラスタのエントリポイントから辿れる輪郭線を配列に返します。 * @param i_raster * @param i_th * 暗点<=th<明点 * @param i_entry_x * @param i_entry_y * @param i_array_size * @param o_coord_x * @param o_coord_y * @return * 輪郭線の長さを返します。 * @throws NyARException */ private int impl_getContour(INyARRaster i_raster, int i_th, int i_entry_x, int i_entry_y, int i_array_size, int[] o_coord_x, int[] o_coord_y) { int[] xdir = _getContour_xdir;// static int xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1}; int[] ydir = _getContour_ydir;// static int ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1}; int[] i_buf = (int[])i_raster.getBuffer(); int width = i_raster.getWidth(); int height = i_raster.getHeight(); //クリップ領域の上端に接しているポイントを得る。 int coord_num = 1; o_coord_x[0] = i_entry_x; o_coord_y[0] = i_entry_y; int dir = 5; int c = i_entry_x; int r = i_entry_y; for (; ; ) { dir = (dir + 5) % 8;//dirの正規化 //ここは頑張ればもっと最適化できると思うよ。 //4隅以外の境界接地の場合に、境界チェックを省略するとかね。 if (c >= 1 && c < width - 1 && r >= 1 && r < height - 1) { for (; ; ) {//gotoのエミュレート用のfor文 //境界に接していないとき(暗点判定) if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } /* try{ BufferedImage b=new BufferedImage(width,height,ColorSpace.TYPE_RGB); NyARRasterImageIO.copy(i_raster, b); ImageIO.write(b,"png",new File("bug.png")); }catch(Exception e){ }*/ //8方向全て調べたけどラベルが無いよ? throw new NyARException(); } } else { //境界に接しているとき int i; for (i = 0; i < 8; i++) { int x = c + xdir[dir]; int y = r + ydir[dir]; //境界チェック if (x >= 0 && x < width && y >= 0 && y < height) { if (i_buf[(y) * width + (x)] <= i_th) { break; } } dir++;//倍長テーブルを参照するので問題なし } if (i == 8) { //8方向全て調べたけどラベルが無いよ? throw new NyARException();// return(-1); } } dir = dir % 8;//dirの正規化 // xcoordとycoordをc,rにも保存 c = c + xdir[dir]; r = r + ydir[dir]; o_coord_x[coord_num] = c; o_coord_y[coord_num] = r; // 終了条件判定 if (c == i_entry_x && r == i_entry_y) { coord_num++; break; } coord_num++; if (coord_num == i_array_size) { //輪郭が末端に達した return coord_num; } } return coord_num; }
protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out) { int[] rgb_tmp = this.__pickFromRaster_rgb_tmp; int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l; double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l; double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l; INyARRgbPixelDriver i_in_reader = this._ref_raster.getRgbPixelDriver(); switch (o_out.getBufferType()) { case NyARBufferType.INT1D_X8R8G8B8_32: int[] pat_data = (int[])o_out.getBuffer(); int p = 0; for (int iy = out_h - 1; iy >= 0; iy--) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = out_w - 1; ix >= 0; ix--) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } i_in_reader.getPixel(x, y, rgb_tmp); cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; pat_data[p] = (rgb_tmp[0] << 16) | (rgb_tmp[1] << 8) | ((rgb_tmp[2] & 0xff)); p++; } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } return(true); default: //ANY to RGBx if (o_out is INyARRgbRaster) { INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver(); for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } i_in_reader.getPixel(x, y, rgb_tmp); cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; out_reader.setPixel(ix, iy, rgb_tmp); } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } return(true); } break; } return(false); }
protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out) { byte[] i_in_buf = (byte[])this._ref_raster.getBuffer(); int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l; double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l; double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l; int r, g, b; switch (this._ref_raster.getBufferType()) { case NyARBufferType.INT1D_X8R8G8B8_32: int p = 0; int[] pat_data = (int[])o_out.getBuffer(); for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } int bp = (x + y * in_w) * 3; r = (i_in_buf[bp + 0] & 0xff); g = (i_in_buf[bp + 1] & 0xff); b = (i_in_buf[bp + 2] & 0xff); cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; pat_data[p] = (r << 16) | (g << 8) | ((b & 0xff)); p++; } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } return(true); default: if (o_out is INyARRgbRaster) { INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver(); for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } int bp = (x + y * in_w) * 3; r = (i_in_buf[bp + 0] & 0xff); g = (i_in_buf[bp + 1] & 0xff); b = (i_in_buf[bp + 2] & 0xff); cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; out_reader.setPixel(ix, iy, r, g, b); } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } return(true); } break; } return(false); }
protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out) { int res_pix = i_resolution * i_resolution; int[] rgb_tmp = this.__pickFromRaster_rgb_tmp; int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); INyARRgbPixelDriver i_in_reader = this._ref_raster.getRgbPixelDriver(); //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; double cp2 = cpara[2]; double cp5 = cpara[5]; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); switch (o_out.getBufferType()) { case NyARBufferType.INT1D_X8R8G8B8_32: int[] pat_data = (int[])o_out.getBuffer(); int p = (out_w * out_h - 1); for (int iy = out_h - 1; iy >= 0; iy--) { //解像度分の点を取る。 for (int ix = out_w - 1; ix >= 0; ix--) { int r, g, b; r = g = b = 0; int cy = pk_t + iy * i_resolution; int cx = pk_l + ix * i_resolution; double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx; double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx; double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx; for (int i2y = i_resolution - 1; i2y >= 0; i2y--) { double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b; for (int i2x = i_resolution - 1; i2x >= 0; i2x--) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } i_in_reader.getPixel(x, y, rgb_tmp); r += rgb_tmp[0]; g += rgb_tmp[1]; b += rgb_tmp[2]; cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; } cp7_cy_1_cp6_cx_b += cp7; cp1_cy_cp2_cp0_cx_b += cp1; cp4_cy_cp5_cp3_cx_b += cp4; } r /= res_pix; g /= res_pix; b /= res_pix; pat_data[p] = ((r & 0xff) << 16) | ((g & 0xff) << 8) | ((b & 0xff)); p--; } } return(true); default: //ANY to RGBx if (o_out is INyARRgbRaster) { INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver(); for (int iy = out_h - 1; iy >= 0; iy--) { //解像度分の点を取る。 for (int ix = out_w - 1; ix >= 0; ix--) { int r, g, b; r = g = b = 0; int cy = pk_t + iy * i_resolution; int cx = pk_l + ix * i_resolution; double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx; double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx; double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx; for (int i2y = i_resolution - 1; i2y >= 0; i2y--) { double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b; for (int i2x = i_resolution - 1; i2x >= 0; i2x--) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } i_in_reader.getPixel(x, y, rgb_tmp); r += rgb_tmp[0]; g += rgb_tmp[1]; b += rgb_tmp[2]; cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; } cp7_cy_1_cp6_cx_b += cp7; cp1_cy_cp2_cp0_cx_b += cp1; cp4_cy_cp5_cp3_cx_b += cp4; } out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix); } } return(true); } break; } return(false); }
protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out) { Color32[] in_pixs = (Color32[])this._ref_raster.getBuffer(); int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); int res_pix = i_resolution * i_resolution; //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; double cp2 = cpara[2]; double cp5 = cpara[5]; int step,offset; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); if (o_out is INyARRgbRaster) { INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver(); if(this._is_inv_v){ offset=in_w*(in_h-1); step=-in_w; }else{ offset=0; step=in_w; } for (int iy = out_h - 1; iy >= 0; iy--) { //解像度分の点を取る。 for (int ix = out_w - 1; ix >= 0; ix--) { int r, g, b; r = g = b = 0; int cy = pk_t + iy * i_resolution; int cx = pk_l + ix * i_resolution; double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx; double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx; double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx; for (int i2y = i_resolution - 1; i2y >= 0; i2y--) { double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b; for (int i2x = i_resolution - 1; i2x >= 0; i2x--) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } Color32 px = in_pixs[x + offset+step*y]; r+= px.r;// R g+= px.g;// G b+= px.b;// B cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; } cp7_cy_1_cp6_cx_b += cp7; cp1_cy_cp2_cp0_cx_b += cp1; cp4_cy_cp5_cp3_cx_b += cp4; } out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix); } } return true; } return false; }
protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out) { int res_pix = i_resolution * i_resolution; byte[] i_in_buf = (byte[])this._ref_raster.getBuffer(); int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; double cp2 = cpara[2]; double cp5 = cpara[5]; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); if (o_out is INyARRgbRaster) { INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver(); for (int iy = out_h - 1; iy >= 0; iy--) { //解像度分の点を取る。 for (int ix = out_w - 1; ix >= 0; ix--) { int r, g, b; r = g = b = 0; int cy = pk_t + iy * i_resolution; int cx = pk_l + ix * i_resolution; double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx; double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx; double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx; for (int i2y = i_resolution - 1; i2y >= 0; i2y--) { double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b; for (int i2x = i_resolution - 1; i2x >= 0; i2x--) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } int bp = (x + y * in_w) * 3; r += (i_in_buf[bp + 0] & 0xff); g += (i_in_buf[bp + 1] & 0xff); b += (i_in_buf[bp + 2] & 0xff); cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; } cp7_cy_1_cp6_cx_b += cp7; cp1_cy_cp2_cp0_cx_b += cp1; cp4_cy_cp5_cp3_cx_b += cp4; } out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix); } } return true; } return false; }
protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out) { BitmapData in_bmp = this._ref_raster.lockBitmap(); int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); int res_pix = i_resolution * i_resolution; //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; double cp2 = cpara[2]; double cp5 = cpara[5]; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); if (o_out is NyARBitmapRaster) { NyARBitmapRaster bmr=((NyARBitmapRaster)o_out); BitmapData bm=bmr.lockBitmap(); for (int iy = out_h - 1; iy >= 0; iy--) { //解像度分の点を取る。 for (int ix = out_w - 1; ix >= 0; ix--) { int r, g, b; r = g = b = 0; int cy = pk_t + iy * i_resolution; int cx = pk_l + ix * i_resolution; double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx; double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx; double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx; for (int i2y = i_resolution - 1; i2y >= 0; i2y--) { double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b; for (int i2x = i_resolution - 1; i2x >= 0; i2x--) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride)); r += (px >> 16) & 0xff;// R g += (px >> 8) & 0xff; // G b += (px) & 0xff; // B cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; } cp7_cy_1_cp6_cx_b += cp7; cp1_cy_cp2_cp0_cx_b += cp1; cp4_cy_cp5_cp3_cx_b += cp4; } Marshal.WriteInt32(bm.Scan0, ix * 4 + iy * bm.Stride, (0x00ff0000 & ((r / res_pix) << 16)) | (0x0000ff00 & ((g / res_pix) << 8)) | (0x0000ff & (b / res_pix))); } } bmr.unlockBitmap(); this._ref_raster.unlockBitmap(); return true; } else if (o_out is INyARRgbRaster) { INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver(); for (int iy = out_h - 1; iy >= 0; iy--) { //解像度分の点を取る。 for (int ix = out_w - 1; ix >= 0; ix--) { int r, g, b; r = g = b = 0; int cy = pk_t + iy * i_resolution; int cx = pk_l + ix * i_resolution; double cp7_cy_1_cp6_cx_b = cp7 * cy + 1.0 + cp6 * cx; double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx; double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx; for (int i2y = i_resolution - 1; i2y >= 0; i2y--) { double cp7_cy_1_cp6_cx = cp7_cy_1_cp6_cx_b; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b; for (int i2x = i_resolution - 1; i2x >= 0; i2x--) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride)); r += (px >> 16) & 0xff;// R g += (px >> 8) & 0xff; // G b += (px) & 0xff; // B cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; } cp7_cy_1_cp6_cx_b += cp7; cp1_cy_cp2_cp0_cx_b += cp1; cp4_cy_cp5_cp3_cx_b += cp4; } out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix); } } this._ref_raster.unlockBitmap(); return true; } else { throw new NyARException(); } }
protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out) { byte[] i_in_buf = (byte[])this._ref_raster.getBuffer(); int in_w = this._ref_raster.getWidth(); int in_h = this._ref_raster.getHeight(); //ピクセルリーダーを取得 double cp0 = cpara[0]; double cp3 = cpara[3]; double cp6 = cpara[6]; double cp1 = cpara[1]; double cp4 = cpara[4]; double cp7 = cpara[7]; int out_w = o_out.getWidth(); int out_h = o_out.getHeight(); double cp7_cy_1 = cp7 * pk_t + 1.0 + cp6 * pk_l; double cp1_cy_cp2 = cp1 * pk_t + cpara[2] + cp0 * pk_l; double cp4_cy_cp5 = cp4 * pk_t + cpara[5] + cp3 * pk_l; int r, g, b; switch (this._ref_raster.getBufferType()) { case NyARBufferType.INT1D_X8R8G8B8_32: int p = 0; int[] pat_data = (int[])o_out.getBuffer(); for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } int bp = (x + y * in_w) * 3; r = (i_in_buf[bp + 0] & 0xff); g = (i_in_buf[bp + 1] & 0xff); b = (i_in_buf[bp + 2] & 0xff); cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; pat_data[p] = (r << 16) | (g << 8) | ((b & 0xff)); p++; } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } return true; default: if (o_out is INyARRgbRaster) { INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver(); for (int iy = 0; iy < out_h; iy++) { //解像度分の点を取る。 double cp7_cy_1_cp6_cx = cp7_cy_1; double cp1_cy_cp2_cp0_cx = cp1_cy_cp2; double cp4_cy_cp5_cp3_cx = cp4_cy_cp5; for (int ix = 0; ix < out_w; ix++) { //1ピクセルを作成 double d = 1 / (cp7_cy_1_cp6_cx); int x = (int)((cp1_cy_cp2_cp0_cx) * d); int y = (int)((cp4_cy_cp5_cp3_cx) * d); if (x < 0) { x = 0; } else if (x >= in_w) { x = in_w - 1; } if (y < 0) { y = 0; } else if (y >= in_h) { y = in_h - 1; } int bp = (x + y * in_w) * 3; r = (i_in_buf[bp + 0] & 0xff); g = (i_in_buf[bp + 1] & 0xff); b = (i_in_buf[bp + 2] & 0xff); cp7_cy_1_cp6_cx += cp6; cp1_cy_cp2_cp0_cx += cp0; cp4_cy_cp5_cp3_cx += cp3; out_reader.setPixel(ix, iy, r, g, b); } cp7_cy_1 += cp7; cp1_cy_cp2 += cp1; cp4_cy_cp5 += cp4; } return true; } break; } return false; }
/** * ラスタのエントリポイントから辿れる輪郭線を配列に返します。 * @param i_raster * @param i_th * 暗点<=th<明点 * @param i_entry_x * @param i_entry_y * @param i_array_size * @param o_coord_x * @param o_coord_y * @return * 輪郭線の長さを返します。 * @throws NyARException */ private int impl_getContour(INyARRaster i_raster, int i_th, int i_entry_x, int i_entry_y, int i_array_size, int[] o_coord_x, int[] o_coord_y) { int[] xdir = _getContour_xdir; // static int xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1}; int[] ydir = _getContour_ydir; // static int ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1}; int[] i_buf = (int[])i_raster.getBuffer(); int width = i_raster.getWidth(); int height = i_raster.getHeight(); //クリップ領域の上端に接しているポイントを得る。 int coord_num = 1; o_coord_x[0] = i_entry_x; o_coord_y[0] = i_entry_y; int dir = 5; int c = i_entry_x; int r = i_entry_y; for (; ;) { dir = (dir + 5) % 8;//dirの正規化 //ここは頑張ればもっと最適化できると思うよ。 //4隅以外の境界接地の場合に、境界チェックを省略するとかね。 if (c >= 1 && c < width - 1 && r >= 1 && r < height - 1) { for (; ;) {//gotoのエミュレート用のfor文 //境界に接していないとき(暗点判定) if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (i_buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } /* * try{ * BufferedImage b=new BufferedImage(width,height,ColorSpace.TYPE_RGB); * NyARRasterImageIO.copy(i_raster, b); * ImageIO.write(b,"png",new File("bug.png")); * }catch(Exception e){ * * }*/ //8方向全て調べたけどラベルが無いよ? throw new NyARException(); } } else { //境界に接しているとき int i; for (i = 0; i < 8; i++) { int x = c + xdir[dir]; int y = r + ydir[dir]; //境界チェック if (x >= 0 && x < width && y >= 0 && y < height) { if (i_buf[(y) * width + (x)] <= i_th) { break; } } dir++;//倍長テーブルを参照するので問題なし } if (i == 8) { //8方向全て調べたけどラベルが無いよ? throw new NyARException();// return(-1); } } dir = dir % 8;//dirの正規化 // xcoordとycoordをc,rにも保存 c = c + xdir[dir]; r = r + ydir[dir]; o_coord_x[coord_num] = c; o_coord_y[coord_num] = r; // 終了条件判定 if (c == i_entry_x && r == i_entry_y) { coord_num++; break; } coord_num++; if (coord_num == i_array_size) { //輪郭が末端に達した return(coord_num); } } return(coord_num); }
/** * 輪郭線抽出関数の実体です。 * @param i_raster * @param i_l * @param i_t * @param i_r * @param i_b * @param i_th * @param i_entry_x * @param i_entry_y * @param o_coord * @return * @throws NyARException */ private bool impl_getContour(INyARRaster i_raster, int i_l, int i_t, int i_r, int i_b, int i_th, int i_entry_x, int i_entry_y, NyARIntCoordinates o_coord) { Debug.Assert(i_t <= i_entry_x); NyARIntPoint2d[] coord = o_coord.items; int[] xdir = _getContour_xdir; // static int xdir[8] = { 0, 1, 1, 1, 0,-1,-1,-1}; int[] ydir = _getContour_ydir; // static int ydir[8] = {-1,-1, 0, 1, 1, 1, 0,-1}; int[] buf = (int[])i_raster.getBuffer(); int width = i_raster.getWidth(); //クリップ領域の上端に接しているポイントを得る。 int max_coord = o_coord.items.Length; int coord_num = 1; coord[0].x = i_entry_x; coord[0].y = i_entry_y; int dir = 5; int c = i_entry_x; int r = i_entry_y; for (;;) { dir = (dir + 5) % 8; //dirの正規化 //ここは頑張ればもっと最適化できると思うよ。 //4隅以外の境界接地の場合に、境界チェックを省略するとかね。 if (c > i_l && c < i_r && r > i_t && r < i_b) { for (;;) //gotoのエミュレート用のfor文 //境界に接していないとき(暗点判定) { if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } dir++; if (buf[(r + ydir[dir]) * width + (c + xdir[dir])] <= i_th) { break; } //8方向全て調べたけどラベルが無いよ? throw new NyARException(); } } else { //境界に接しているとき int i; for (i = 0; i < 8; i++) { int x = c + xdir[dir]; int y = r + ydir[dir]; //境界チェック if (x >= i_l && x <= i_r && y >= i_t && y <= i_b) { if (buf[(y) * width + (x)] <= i_th) { break; } } dir++; //倍長テーブルを参照するので問題なし } if (i == 8) { //8方向全て調べたけどラベルが無いよ? throw new NyARException(); // return(-1); } } // xcoordとycoordをc,rにも保存 c = c + xdir[dir]; r = r + ydir[dir]; coord[coord_num].x = c; coord[coord_num].y = r; //終了条件判定 if (c == i_entry_x && r == i_entry_y) { //開始点と同じピクセルに到達したら、終点の可能性がある。 coord_num++; //末端のチェック if (coord_num == max_coord) { //輪郭bufが末端に達した return(false); } //末端候補の次のピクセルを調べる dir = (dir + 5) % 8; //dirの正規化 int i; for (i = 0; i < 8; i++) { int x = c + xdir[dir]; int y = r + ydir[dir]; //境界チェック if (x >= i_l && x <= i_r && y >= i_t && y <= i_b) { if (buf[(y) * width + (x)] <= i_th) { break; } } dir++; //倍長テーブルを参照するので問題なし } if (i == 8) { //8方向全て調べたけどラベルが無いよ? throw new NyARException(); } //得たピクセルが、[1]と同じならば、末端である。 c = c + xdir[dir]; r = r + ydir[dir]; if (coord[1].x == c && coord[1].y == r) { //終点に達している。 o_coord.length = coord_num; break; } else { //終点ではない。 coord[coord_num].x = c; coord[coord_num].y = r; } } coord_num++; //末端のチェック if (coord_num == max_coord) { //輪郭が末端に達した return(false); } } return(true); }