public void multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRgbRaster i_in_raster, INyARRgbRaster o_out)
        {
            //出力形式による分岐
            switch (o_out.getBufferType())
            {
            case NyARBufferType.INT1D_X8R8G8B8_32:
                multiPixel_INT1D_X8R8G8B8_32(pk_l, pk_t, i_in_raster.getWidth(), i_in_raster.getHeight(), i_resolution, cpara, i_in_raster.getRgbPixelReader(), o_out);
                break;

            default:
                multiPixel_ANY(pk_l, pk_t, i_in_raster.getWidth(), i_in_raster.getHeight(), i_resolution, cpara, i_in_raster.getRgbPixelReader(), o_out);
                break;
            }
            return;
        }
 public void multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRgbRaster i_in_raster, INyARRgbRaster o_out)
 {
     Debug.Assert(i_in_raster.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8X8_32));
     //出力形式による分岐(分解能が高い時は大した差が出ないから、ANYだけ。)
     multiPixel_ANY(pk_l, pk_t, i_in_raster.getWidth(), i_in_raster.getHeight(), i_resolution, cpara, (byte[])i_in_raster.getBuffer(), o_out);
     return;
 }
        public void onePixel(int pk_l, int pk_t, double[] cpara, INyARRgbRaster i_in_raster, INyARRgbRaster o_out)
        {
            Debug.Assert(i_in_raster.isEqualBufferType(NyARBufferType.BYTE1D_B8G8R8X8_32));
            //出力形式による分岐
            switch (o_out.getBufferType())
            {
            case NyARBufferType.INT1D_X8R8G8B8_32:
                onePixel_INT1D_X8R8G8B8_32(pk_l, pk_t, i_in_raster.getWidth(), i_in_raster.getHeight(), cpara, (byte[])i_in_raster.getBuffer(), o_out);
                break;

            default:
                onePixel_ANY(pk_l, pk_t, i_in_raster.getWidth(), i_in_raster.getHeight(), cpara, (byte[])i_in_raster.getBuffer(), o_out);
                break;
            }
            return;
        }
 /**
  * ラスタのコピーを実行します。
  * この関数は暫定です。低速なので注意してください。
  * @param i_input
  * @param o_output
  * @
  */
 public static void copy(INyARRgbRaster i_input, INyARRgbRaster o_output)
 {
     Debug.Assert(i_input.getSize().isEqualSize(o_output.getSize()));
     int width = i_input.getWidth();
     int height = i_input.getHeight();
     int[] rgb = new int[3];
     INyARRgbPixelDriver inr = i_input.getRgbPixelDriver();
     INyARRgbPixelDriver outr = o_output.getRgbPixelDriver();
     for (int i = height - 1; i >= 0; i--)
     {
         for (int i2 = width - 1; i2 >= 0; i2--)
         {
             inr.getPixel(i2, i, rgb);
             outr.setPixel(i2, i, rgb);
         }
     }
 }
        /**
         * ラスタのコピーを実行します。
         * この関数は暫定です。低速なので注意してください。
         * @param i_input
         * @param o_output
         * @
         */
        public static void copy(INyARRgbRaster i_input, INyARRgbRaster o_output)
        {
            Debug.Assert(i_input.getSize().isEqualSize(o_output.getSize()));
            int width  = i_input.getWidth();
            int height = i_input.getHeight();

            int[] rgb = new int[3];
            INyARRgbPixelDriver inr  = i_input.getRgbPixelDriver();
            INyARRgbPixelDriver outr = o_output.getRgbPixelDriver();

            for (int i = height - 1; i >= 0; i--)
            {
                for (int i2 = width - 1; i2 >= 0; i2--)
                {
                    inr.getPixel(i2, i, rgb);
                    outr.setPixel(i2, i, rgb);
                }
            }
        }
	    /**
	     * @see INyARColorPatt#pickFromRaster
	     */
	    public virtual bool pickFromRaster(INyARRgbRaster image,NyARIntPoint2d[] i_vertexs)
	    {
		    //遠近法のパラメータを計算
		    double[] cpara = this.__pickFromRaster_cpara;
		    if (!this._perspective_gen.getParam(i_vertexs, cpara)) {
			    return false;
		    }
    		
		    int resolution=this._resolution;
		    int img_x = image.getWidth();
		    int img_y = image.getHeight();
		    int res_pix=resolution*resolution;

		    int[] rgb_tmp = this.__pickFromRaster_rgb_tmp;

		    //ピクセルリーダーを取得
		    INyARRgbPixelReader reader=image.getRgbPixelReader();
		    int p=0;
		    for(int iy=0;iy<this._size.h*resolution;iy+=resolution){
			    //解像度分の点を取る。
			    for(int ix=0;ix<this._size.w*resolution;ix+=resolution){
				    int r,g,b;
				    r=g=b=0;
				    for(int i2y=iy;i2y<iy+resolution;i2y++){
					    int cy=this._pickup_lt.y+i2y;
					    for(int i2x=ix;i2x<ix+resolution;i2x++){
						    //1ピクセルを作成
						    int cx=this._pickup_lt.x+i2x;
						    double d=cpara[6]*cx+cpara[7]*cy+1.0;
						    int x=(int)((cpara[0]*cx+cpara[1]*cy+cpara[2])/d);
						    int y=(int)((cpara[3]*cx+cpara[4]*cy+cpara[5])/d);
						    if(x<0){x=0;}
						    if(x>=img_x){x=img_x-1;}
						    if(y<0){y=0;}
						    if(y>=img_y){y=img_y-1;}
    						
						    reader.getPixel(x, y, rgb_tmp);
						    r+=rgb_tmp[0];
						    g+=rgb_tmp[1];
						    b+=rgb_tmp[2];
					    }
				    }
				    r/=res_pix;
				    g/=res_pix;
				    b/=res_pix;
				    this._patdata[p]=((r&0xff)<<16)|((g&0xff)<<8)|((b&0xff));
				    p++;
			    }
		    }
			    //ピクセル問い合わせ
			    //ピクセルセット
		    return true;
	    }
Exemple #7
0
        public void pickFromRaster(double[] i_cpara, INyARRgbRaster image, int[] o_patt)
        {
            int    x, y;
            double d, m;
            double cp6cx, cp0cx, cp3cx;

            int[] rgb_px = this._rgb_px;
            int[] rgb_py = this._rgb_py;

            int r, g, b;
            //遠近法のパラメータを計算

            int img_x = image.getWidth();
            int img_y = image.getHeight();

            int[]  rgb_tmp = this._rgb_temp;
            double cp0     = i_cpara[0];
            double cp3     = i_cpara[3];
            double cp6     = i_cpara[6];
            double cp1     = i_cpara[1];
            double cp2     = i_cpara[2];
            double cp4     = i_cpara[4];
            double cp5     = i_cpara[5];
            double cp7     = i_cpara[7];


            int pick_lt_x = this._lt_ref.x;
            //ピクセルリーダーを取得
            INyARRgbPixelReader reader = image.getRgbPixelReader();


            int p  = 0;
            int py = this._lt_ref.y;

            for (int iy = this._size_ref.h - 1; iy >= 0; iy--, py += 4)
            {
                double cp1cy_cp2_0 = cp1 * py + cp2;
                double cp4cy_cp5_0 = cp4 * py + cp5;
                double cp7cy_1_0   = cp7 * py + 1.0;

                double cp1cy_cp2_1 = cp1cy_cp2_0 + cp1;
                double cp1cy_cp2_2 = cp1cy_cp2_1 + cp1;
                double cp1cy_cp2_3 = cp1cy_cp2_2 + cp1;

                double cp4cy_cp5_1 = cp4cy_cp5_0 + cp4;
                double cp4cy_cp5_2 = cp4cy_cp5_1 + cp4;
                double cp4cy_cp5_3 = cp4cy_cp5_2 + cp4;

                int px = pick_lt_x;
                //解像度分の点を取る。
                for (int ix = this._size_ref.w - 1; ix >= 0; ix--, px += 4)
                {
                    cp6cx = cp6 * px;
                    cp0cx = cp0 * px;
                    cp3cx = cp3 * px;

                    cp6cx += cp7cy_1_0;
                    m      = 1 / cp6cx;
                    d      = -cp7 / ((cp6cx + cp7) * cp6cx);

                    //1ピクセルを作成[0,0]
                    x = rgb_px[0] = (int)((cp0cx + cp1cy_cp2_0) * m);
                    y = rgb_py[0] = (int)((cp3cx + cp4cy_cp5_0) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[0] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[0] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[0] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[0] = img_y - 1;
                        }
                    }

                    //1ピクセルを作成[0,1]
                    m += d;
                    x  = rgb_px[4] = (int)((cp0cx + cp1cy_cp2_1) * m);
                    y  = rgb_py[4] = (int)((cp3cx + cp4cy_cp5_1) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[4] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[4] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[4] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[4] = img_y - 1;
                        }
                    }
                    //1ピクセルを作成[0,2]
                    m += d;
                    x  = rgb_px[8] = (int)((cp0cx + cp1cy_cp2_2) * m);
                    y  = rgb_py[8] = (int)((cp3cx + cp4cy_cp5_2) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[8] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[8] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[8] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[8] = img_y - 1;
                        }
                    }

                    //1ピクセルを作成[0,3]
                    m += d;
                    x  = rgb_px[12] = (int)((cp0cx + cp1cy_cp2_3) * m);
                    y  = rgb_py[12] = (int)((cp3cx + cp4cy_cp5_3) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[12] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[12] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[12] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[12] = img_y - 1;
                        }
                    }

                    cp6cx += cp6;
                    cp0cx += cp0;
                    cp3cx += cp3;

                    m = 1 / cp6cx;
                    d = -cp7 / ((cp6cx + cp7) * cp6cx);

                    //1ピクセルを作成[1,0]
                    x = rgb_px[1] = (int)((cp0cx + cp1cy_cp2_0) * m);
                    y = rgb_py[1] = (int)((cp3cx + cp4cy_cp5_0) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[1] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[1] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[1] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[1] = img_y - 1;
                        }
                    }
                    //1ピクセルを作成[1,1]
                    m += d;
                    x  = rgb_px[5] = (int)((cp0cx + cp1cy_cp2_1) * m);
                    y  = rgb_py[5] = (int)((cp3cx + cp4cy_cp5_1) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[5] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[5] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[5] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[5] = img_y - 1;
                        }
                    }
                    //1ピクセルを作成[1,2]
                    m += d;
                    x  = rgb_px[9] = (int)((cp0cx + cp1cy_cp2_2) * m);
                    y  = rgb_py[9] = (int)((cp3cx + cp4cy_cp5_2) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[9] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[9] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[9] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[9] = img_y - 1;
                        }
                    }
                    //1ピクセルを作成[1,3]
                    m += d;
                    x  = rgb_px[13] = (int)((cp0cx + cp1cy_cp2_3) * m);
                    y  = rgb_py[13] = (int)((cp3cx + cp4cy_cp5_3) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[13] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[13] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[13] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[13] = img_y - 1;
                        }
                    }

                    cp6cx += cp6;
                    cp0cx += cp0;
                    cp3cx += cp3;

                    m = 1 / cp6cx;
                    d = -cp7 / ((cp6cx + cp7) * cp6cx);

                    //1ピクセルを作成[2,0]
                    x = rgb_px[2] = (int)((cp0cx + cp1cy_cp2_0) * m);
                    y = rgb_py[2] = (int)((cp3cx + cp4cy_cp5_0) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[2] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[2] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[2] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[2] = img_y - 1;
                        }
                    }
                    //1ピクセルを作成[2,1]
                    m += d;
                    x  = rgb_px[6] = (int)((cp0cx + cp1cy_cp2_1) * m);
                    y  = rgb_py[6] = (int)((cp3cx + cp4cy_cp5_1) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[6] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[6] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[6] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[6] = img_y - 1;
                        }
                    }
                    //1ピクセルを作成[2,2]
                    m += d;
                    x  = rgb_px[10] = (int)((cp0cx + cp1cy_cp2_2) * m);
                    y  = rgb_py[10] = (int)((cp3cx + cp4cy_cp5_2) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[10] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[10] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[10] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[10] = img_y - 1;
                        }
                    }
                    //1ピクセルを作成[2,3](ここ計算ずれします。)
                    m += d;
                    x  = rgb_px[14] = (int)((cp0cx + cp1cy_cp2_3) * m);
                    y  = rgb_py[14] = (int)((cp3cx + cp4cy_cp5_3) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[14] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[14] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[14] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[14] = img_y - 1;
                        }
                    }
                    cp6cx += cp6;
                    cp0cx += cp0;
                    cp3cx += cp3;

                    m = 1 / cp6cx;
                    d = -cp7 / ((cp6cx + cp7) * cp6cx);

                    //1ピクセルを作成[3,0]
                    x = rgb_px[3] = (int)((cp0cx + cp1cy_cp2_0) * m);
                    y = rgb_py[3] = (int)((cp3cx + cp4cy_cp5_0) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[3] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[3] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[3] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[3] = img_y - 1;
                        }
                    }
                    //1ピクセルを作成[3,1]
                    m += d;
                    x  = rgb_px[7] = (int)((cp0cx + cp1cy_cp2_1) * m);
                    y  = rgb_py[7] = (int)((cp3cx + cp4cy_cp5_1) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[7] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[7] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[7] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[7] = img_y - 1;
                        }
                    }
                    //1ピクセルを作成[3,2]
                    m += d;
                    x  = rgb_px[11] = (int)((cp0cx + cp1cy_cp2_2) * m);
                    y  = rgb_py[11] = (int)((cp3cx + cp4cy_cp5_2) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[11] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[11] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[11] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[11] = img_y - 1;
                        }
                    }
                    //1ピクセルを作成[3,3]
                    m += d;
                    x  = rgb_px[15] = (int)((cp0cx + cp1cy_cp2_3) * m);
                    y  = rgb_py[15] = (int)((cp3cx + cp4cy_cp5_3) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[15] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[15] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[15] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[15] = img_y - 1;
                        }
                    }

                    reader.getPixelSet(rgb_px, rgb_py, 4 * 4, rgb_tmp);

                    r         = (rgb_tmp[0] + rgb_tmp[3] + rgb_tmp[6] + rgb_tmp[9] + rgb_tmp[12] + rgb_tmp[15] + rgb_tmp[18] + rgb_tmp[21] + rgb_tmp[24] + rgb_tmp[27] + rgb_tmp[30] + rgb_tmp[33] + rgb_tmp[36] + rgb_tmp[39] + rgb_tmp[42] + rgb_tmp[45]) / 16;
                    g         = (rgb_tmp[1] + rgb_tmp[4] + rgb_tmp[7] + rgb_tmp[10] + rgb_tmp[13] + rgb_tmp[16] + rgb_tmp[19] + rgb_tmp[22] + rgb_tmp[25] + rgb_tmp[28] + rgb_tmp[31] + rgb_tmp[34] + rgb_tmp[37] + rgb_tmp[40] + rgb_tmp[43] + rgb_tmp[46]) / 16;
                    b         = (rgb_tmp[2] + rgb_tmp[5] + rgb_tmp[8] + rgb_tmp[11] + rgb_tmp[14] + rgb_tmp[17] + rgb_tmp[20] + rgb_tmp[23] + rgb_tmp[26] + rgb_tmp[29] + rgb_tmp[32] + rgb_tmp[35] + rgb_tmp[38] + rgb_tmp[41] + rgb_tmp[44] + rgb_tmp[47]) / 16;
                    o_patt[p] = ((r & 0xff) << 16) | ((g & 0xff) << 8) | ((b & 0xff));
                    p++;
                }
            }
            return;
        }
        /**
         * この関数は、ラスタのi_vertexsで定義される四角形からパターンを取得して、インスタンスに格納します。
         */
        public virtual bool pickFromRaster(INyARRgbRaster image, NyARIntPoint2d[] i_vertexs)
        {
            // パターンの切り出しに失敗することもある。
            NyARMat cpara = new NyARMat(8, 1);
            if (!get_cpara(i_vertexs, cpara))
            {
                return false;
            }
            double[][] para = cpara.getArray();
            double para00 = para[0 * 3 + 0][0];
            double para01 = para[0 * 3 + 1][0];
            double para02 = para[0 * 3 + 2][0];
            double para10 = para[1 * 3 + 0][0];
            double para11 = para[1 * 3 + 1][0];
            double para12 = para[1 * 3 + 2][0];
            double para20 = para[2 * 3 + 0][0];
            double para21 = para[2 * 3 + 1][0];
            double para22 = 1.0;

            int lx1 = (int)((i_vertexs[0].x - i_vertexs[1].x) * (i_vertexs[0].x - i_vertexs[1].x) + (i_vertexs[0].y - i_vertexs[1].y) * (i_vertexs[0].y - i_vertexs[1].y));
            int lx2 = (int)((i_vertexs[2].x - i_vertexs[3].x) * (i_vertexs[2].x - i_vertexs[3].x) + (i_vertexs[2].y - i_vertexs[3].y) * (i_vertexs[2].y - i_vertexs[3].y));
            int ly1 = (int)((i_vertexs[1].x - i_vertexs[2].x) * (i_vertexs[1].x - i_vertexs[2].x) + (i_vertexs[1].y - i_vertexs[2].y) * (i_vertexs[1].y - i_vertexs[2].y));
            int ly2 = (int)((i_vertexs[3].x - i_vertexs[0].x) * (i_vertexs[3].x - i_vertexs[0].x) + (i_vertexs[3].y - i_vertexs[0].y) * (i_vertexs[3].y - i_vertexs[0].y));
            if (lx2 > lx1)
            {
                lx1 = lx2;
            }
            if (ly2 > ly1)
            {
                ly1 = ly2;
            }

            int sample_pixel_x = this._size.w;
            int sample_pixel_y = this._size.h;
            while (sample_pixel_x * sample_pixel_x < lx1 / 4)
            {
                sample_pixel_x *= 2;
            }
            while (sample_pixel_y * sample_pixel_y < ly1 / 4)
            {
                sample_pixel_y *= 2;
            }

            if (sample_pixel_x > AR_PATT_SAMPLE_NUM)
            {
                sample_pixel_x = AR_PATT_SAMPLE_NUM;
            }
            if (sample_pixel_y > AR_PATT_SAMPLE_NUM)
            {
                sample_pixel_y = AR_PATT_SAMPLE_NUM;
            }

            int xdiv = sample_pixel_x / this._size.w;// xdiv = xdiv2/Config.AR_PATT_SIZE_X;
            int ydiv = sample_pixel_y / this._size.h;// ydiv = ydiv2/Config.AR_PATT_SIZE_Y;


            int img_x = image.getWidth();
            int img_y = image.getHeight();

            double xdiv2_reciprocal = 1.0 / sample_pixel_x;
            double ydiv2_reciprocal = 1.0 / sample_pixel_y;
            int r, g, b;
            int[] rgb_tmp = new int[3];

            //ピクセルリーダーを取得
            INyARRgbPixelDriver reader = image.getRgbPixelDriver();
            int xdiv_x_ydiv = xdiv * ydiv;

            for (int iy = 0; iy < this._size.h; iy++)
            {
                for (int ix = 0; ix < this._size.w; ix++)
                {
                    r = g = b = 0;
                    //1ピクセルを作成
                    for (int j = 0; j < ydiv; j++)
                    {
                        double yw = 102.5 + 5.0 * (iy * ydiv + j + 0.5) * ydiv2_reciprocal;
                        for (int i = 0; i < xdiv; i++)
                        {
                            double xw = 102.5 + 5.0 * (ix * xdiv + i + 0.5) * xdiv2_reciprocal;
                            double d = para20 * xw + para21 * yw + para22;
                            if (d == 0)
                            {
                                throw new NyARException();
                            }
                            int xc = (int)((para00 * xw + para01 * yw + para02) / d);
                            int yc = (int)((para10 * xw + para11 * yw + para12) / d);

                            if (xc >= 0 && xc < img_x && yc >= 0 && yc < img_y)
                            {
                                reader.getPixel(xc, yc, rgb_tmp);
                                r += rgb_tmp[0];// R
                                g += rgb_tmp[1];// G
                                b += rgb_tmp[2];// B
                                // System.out.println(xc+":"+yc+":"+rgb_tmp[0]+":"+rgb_tmp[1]+":"+rgb_tmp[2]);
                            }
                        }
                    }
                    this._patdata[iy * this._size.w + ix] = (((r / xdiv_x_ydiv) & 0xff) << 16) | (((g / xdiv_x_ydiv) & 0xff) << 8) | (((b / xdiv_x_ydiv) & 0xff));
                }
            }
            return true;
        }
        public void pickFromRaster(double[] i_cpara, INyARRgbRaster image, int[] o_patt)
        {
            int x, y;
            double d, m;
            double cp6cx, cp0cx, cp3cx;
            int[] rgb_px = this._rgb_px;
            int[] rgb_py = this._rgb_py;

            int r, g, b;
            //遠近法のパラメータを計算

            int img_x = image.getWidth();
            int img_y = image.getHeight();
            int[] rgb_tmp = this._rgb_temp;
            double cp0 = i_cpara[0];
            double cp3 = i_cpara[3];
            double cp6 = i_cpara[6];
            double cp1 = i_cpara[1];
            double cp2 = i_cpara[2];
            double cp4 = i_cpara[4];
            double cp5 = i_cpara[5];
            double cp7 = i_cpara[7];


            int pick_lt_x = this._lt_ref.x;
            //ピクセルリーダーを取得
            INyARRgbPixelReader reader = image.getRgbPixelReader();


            int p = 0;
            int py = this._lt_ref.y;
            for (int iy = this._size_ref.h - 1; iy >= 0; iy--, py += 4)
            {
                double cp1cy_cp2_0 = cp1 * py + cp2;
                double cp4cy_cp5_0 = cp4 * py + cp5;
                double cp7cy_1_0 = cp7 * py + 1.0;

                double cp1cy_cp2_1 = cp1cy_cp2_0 + cp1;
                double cp1cy_cp2_2 = cp1cy_cp2_1 + cp1;
                double cp1cy_cp2_3 = cp1cy_cp2_2 + cp1;

                double cp4cy_cp5_1 = cp4cy_cp5_0 + cp4;
                double cp4cy_cp5_2 = cp4cy_cp5_1 + cp4;
                double cp4cy_cp5_3 = cp4cy_cp5_2 + cp4;

                int px = pick_lt_x;
                //解像度分の点を取る。
                for (int ix = this._size_ref.w - 1; ix >= 0; ix--, px += 4)
                {

                    cp6cx = cp6 * px;
                    cp0cx = cp0 * px;
                    cp3cx = cp3 * px;

                    cp6cx += cp7cy_1_0;
                    m = 1 / cp6cx;
                    d = -cp7 / ((cp6cx + cp7) * cp6cx);

                    //1ピクセルを作成[0,0]
                    x = rgb_px[0] = (int)((cp0cx + cp1cy_cp2_0) * m);
                    y = rgb_py[0] = (int)((cp3cx + cp4cy_cp5_0) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[0] = 0; } else if (x >= img_x) { rgb_px[0] = img_x - 1; }
                        if (y < 0) { rgb_py[0] = 0; } else if (y >= img_y) { rgb_py[0] = img_y - 1; }
                    }

                    //1ピクセルを作成[0,1]
                    m += d;
                    x = rgb_px[4] = (int)((cp0cx + cp1cy_cp2_1) * m);
                    y = rgb_py[4] = (int)((cp3cx + cp4cy_cp5_1) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[4] = 0; } else if (x >= img_x) { rgb_px[4] = img_x - 1; }
                        if (y < 0) { rgb_py[4] = 0; } else if (y >= img_y) { rgb_py[4] = img_y - 1; }
                    }
                    //1ピクセルを作成[0,2]
                    m += d;
                    x = rgb_px[8] = (int)((cp0cx + cp1cy_cp2_2) * m);
                    y = rgb_py[8] = (int)((cp3cx + cp4cy_cp5_2) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[8] = 0; } else if (x >= img_x) { rgb_px[8] = img_x - 1; }
                        if (y < 0) { rgb_py[8] = 0; } else if (y >= img_y) { rgb_py[8] = img_y - 1; }
                    }

                    //1ピクセルを作成[0,3]
                    m += d;
                    x = rgb_px[12] = (int)((cp0cx + cp1cy_cp2_3) * m);
                    y = rgb_py[12] = (int)((cp3cx + cp4cy_cp5_3) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[12] = 0; } else if (x >= img_x) { rgb_px[12] = img_x - 1; }
                        if (y < 0) { rgb_py[12] = 0; } else if (y >= img_y) { rgb_py[12] = img_y - 1; }
                    }

                    cp6cx += cp6;
                    cp0cx += cp0;
                    cp3cx += cp3;

                    m = 1 / cp6cx;
                    d = -cp7 / ((cp6cx + cp7) * cp6cx);

                    //1ピクセルを作成[1,0]
                    x = rgb_px[1] = (int)((cp0cx + cp1cy_cp2_0) * m);
                    y = rgb_py[1] = (int)((cp3cx + cp4cy_cp5_0) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[1] = 0; } else if (x >= img_x) { rgb_px[1] = img_x - 1; }
                        if (y < 0) { rgb_py[1] = 0; } else if (y >= img_y) { rgb_py[1] = img_y - 1; }
                    }
                    //1ピクセルを作成[1,1]
                    m += d;
                    x = rgb_px[5] = (int)((cp0cx + cp1cy_cp2_1) * m);
                    y = rgb_py[5] = (int)((cp3cx + cp4cy_cp5_1) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[5] = 0; } else if (x >= img_x) { rgb_px[5] = img_x - 1; }
                        if (y < 0) { rgb_py[5] = 0; } else if (y >= img_y) { rgb_py[5] = img_y - 1; }
                    }
                    //1ピクセルを作成[1,2]
                    m += d;
                    x = rgb_px[9] = (int)((cp0cx + cp1cy_cp2_2) * m);
                    y = rgb_py[9] = (int)((cp3cx + cp4cy_cp5_2) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[9] = 0; } else if (x >= img_x) { rgb_px[9] = img_x - 1; }
                        if (y < 0) { rgb_py[9] = 0; } else if (y >= img_y) { rgb_py[9] = img_y - 1; }
                    }
                    //1ピクセルを作成[1,3]
                    m += d;
                    x = rgb_px[13] = (int)((cp0cx + cp1cy_cp2_3) * m);
                    y = rgb_py[13] = (int)((cp3cx + cp4cy_cp5_3) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[13] = 0; } else if (x >= img_x) { rgb_px[13] = img_x - 1; }
                        if (y < 0) { rgb_py[13] = 0; } else if (y >= img_y) { rgb_py[13] = img_y - 1; }
                    }

                    cp6cx += cp6;
                    cp0cx += cp0;
                    cp3cx += cp3;

                    m = 1 / cp6cx;
                    d = -cp7 / ((cp6cx + cp7) * cp6cx);

                    //1ピクセルを作成[2,0]
                    x = rgb_px[2] = (int)((cp0cx + cp1cy_cp2_0) * m);
                    y = rgb_py[2] = (int)((cp3cx + cp4cy_cp5_0) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[2] = 0; } else if (x >= img_x) { rgb_px[2] = img_x - 1; }
                        if (y < 0) { rgb_py[2] = 0; } else if (y >= img_y) { rgb_py[2] = img_y - 1; }
                    }
                    //1ピクセルを作成[2,1]
                    m += d;
                    x = rgb_px[6] = (int)((cp0cx + cp1cy_cp2_1) * m);
                    y = rgb_py[6] = (int)((cp3cx + cp4cy_cp5_1) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[6] = 0; } else if (x >= img_x) { rgb_px[6] = img_x - 1; }
                        if (y < 0) { rgb_py[6] = 0; } else if (y >= img_y) { rgb_py[6] = img_y - 1; }
                    }
                    //1ピクセルを作成[2,2]
                    m += d;
                    x = rgb_px[10] = (int)((cp0cx + cp1cy_cp2_2) * m);
                    y = rgb_py[10] = (int)((cp3cx + cp4cy_cp5_2) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[10] = 0; } else if (x >= img_x) { rgb_px[10] = img_x - 1; }
                        if (y < 0) { rgb_py[10] = 0; } else if (y >= img_y) { rgb_py[10] = img_y - 1; }
                    }
                    //1ピクセルを作成[2,3](ここ計算ずれします。)
                    m += d;
                    x = rgb_px[14] = (int)((cp0cx + cp1cy_cp2_3) * m);
                    y = rgb_py[14] = (int)((cp3cx + cp4cy_cp5_3) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[14] = 0; } else if (x >= img_x) { rgb_px[14] = img_x - 1; }
                        if (y < 0) { rgb_py[14] = 0; } else if (y >= img_y) { rgb_py[14] = img_y - 1; }
                    }
                    cp6cx += cp6;
                    cp0cx += cp0;
                    cp3cx += cp3;

                    m = 1 / cp6cx;
                    d = -cp7 / ((cp6cx + cp7) * cp6cx);

                    //1ピクセルを作成[3,0]
                    x = rgb_px[3] = (int)((cp0cx + cp1cy_cp2_0) * m);
                    y = rgb_py[3] = (int)((cp3cx + cp4cy_cp5_0) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[3] = 0; } else if (x >= img_x) { rgb_px[3] = img_x - 1; }
                        if (y < 0) { rgb_py[3] = 0; } else if (y >= img_y) { rgb_py[3] = img_y - 1; }
                    }
                    //1ピクセルを作成[3,1]
                    m += d;
                    x = rgb_px[7] = (int)((cp0cx + cp1cy_cp2_1) * m);
                    y = rgb_py[7] = (int)((cp3cx + cp4cy_cp5_1) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[7] = 0; } else if (x >= img_x) { rgb_px[7] = img_x - 1; }
                        if (y < 0) { rgb_py[7] = 0; } else if (y >= img_y) { rgb_py[7] = img_y - 1; }
                    }
                    //1ピクセルを作成[3,2]
                    m += d;
                    x = rgb_px[11] = (int)((cp0cx + cp1cy_cp2_2) * m);
                    y = rgb_py[11] = (int)((cp3cx + cp4cy_cp5_2) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[11] = 0; } else if (x >= img_x) { rgb_px[11] = img_x - 1; }
                        if (y < 0) { rgb_py[11] = 0; } else if (y >= img_y) { rgb_py[11] = img_y - 1; }
                    }
                    //1ピクセルを作成[3,3]
                    m += d;
                    x = rgb_px[15] = (int)((cp0cx + cp1cy_cp2_3) * m);
                    y = rgb_py[15] = (int)((cp3cx + cp4cy_cp5_3) * m);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[15] = 0; } else if (x >= img_x) { rgb_px[15] = img_x - 1; }
                        if (y < 0) { rgb_py[15] = 0; } else if (y >= img_y) { rgb_py[15] = img_y - 1; }
                    }

                    reader.getPixelSet(rgb_px, rgb_py, 4 * 4, rgb_tmp);

                    r = (rgb_tmp[0] + rgb_tmp[3] + rgb_tmp[6] + rgb_tmp[9] + rgb_tmp[12] + rgb_tmp[15] + rgb_tmp[18] + rgb_tmp[21] + rgb_tmp[24] + rgb_tmp[27] + rgb_tmp[30] + rgb_tmp[33] + rgb_tmp[36] + rgb_tmp[39] + rgb_tmp[42] + rgb_tmp[45]) / 16;
                    g = (rgb_tmp[1] + rgb_tmp[4] + rgb_tmp[7] + rgb_tmp[10] + rgb_tmp[13] + rgb_tmp[16] + rgb_tmp[19] + rgb_tmp[22] + rgb_tmp[25] + rgb_tmp[28] + rgb_tmp[31] + rgb_tmp[34] + rgb_tmp[37] + rgb_tmp[40] + rgb_tmp[43] + rgb_tmp[46]) / 16;
                    b = (rgb_tmp[2] + rgb_tmp[5] + rgb_tmp[8] + rgb_tmp[11] + rgb_tmp[14] + rgb_tmp[17] + rgb_tmp[20] + rgb_tmp[23] + rgb_tmp[26] + rgb_tmp[29] + rgb_tmp[32] + rgb_tmp[35] + rgb_tmp[38] + rgb_tmp[41] + rgb_tmp[44] + rgb_tmp[47]) / 16;
                    o_patt[p] = ((r & 0xff) << 16) | ((g & 0xff) << 8) | ((b & 0xff));
                    p++;

                }
            }
            return;
        }
        public void pickFromRaster(double[] i_cpara, INyARRgbRaster image, int[] o_patt)
        {
            int i2x, i2y;//プライム変数
            int x, y;
            int w;
            int r, g, b;

            int resolution = this._resolution;
            int res_pix = resolution * resolution;
            int img_x = image.getWidth();
            int img_y = image.getHeight();

            int[] rgb_tmp = this._rgb_temp;
            int[] rgb_px = this._rgb_px;
            int[] rgb_py = this._rgb_py;

            double[] cp1cy_cp2 = this._cp1cy_cp2;
            double[] cp4cy_cp5 = this._cp4cy_cp5;
            double[] cp7cy_1 = this._cp7cy_1;

            double cp0 = i_cpara[0];
            double cp3 = i_cpara[3];
            double cp6 = i_cpara[6];
            double cp1 = i_cpara[1];
            double cp2 = i_cpara[2];
            double cp4 = i_cpara[4];
            double cp5 = i_cpara[5];
            double cp7 = i_cpara[7];


            int pick_y = this._lt_ref.y;
            int pick_x = this._lt_ref.x;
            //ピクセルリーダーを取得
            INyARRgbPixelReader reader = image.getRgbPixelReader();
            int p = 0;


            for (int iy = 0; iy < this._size_ref.h * resolution; iy += resolution)
            {
                w = pick_y + iy;
                cp1cy_cp2[0] = cp1 * w + cp2;
                cp4cy_cp5[0] = cp4 * w + cp5;
                cp7cy_1[0] = cp7 * w + 1.0;
                for (i2y = 1; i2y < resolution; i2y++)
                {
                    cp1cy_cp2[i2y] = cp1cy_cp2[i2y - 1] + cp1;
                    cp4cy_cp5[i2y] = cp4cy_cp5[i2y - 1] + cp4;
                    cp7cy_1[i2y] = cp7cy_1[i2y - 1] + cp7;
                }
                //解像度分の点を取る。

                for (int ix = 0; ix < this._size_ref.w * resolution; ix += resolution)
                {
                    int n = 0;
                    w = pick_x + ix;
                    for (i2y = resolution - 1; i2y >= 0; i2y--)
                    {
                        double cp0cx = cp0 * w + cp1cy_cp2[i2y];
                        double cp6cx = cp6 * w + cp7cy_1[i2y];
                        double cp3cx = cp3 * w + cp4cy_cp5[i2y];

                        double m = 1 / (cp6cx);
                        double d = -cp6 / (cp6cx * (cp6cx + cp6));

                        double m2 = cp0cx * m;
                        double m3 = cp3cx * m;
                        double d2 = cp0cx * d + cp0 * (m + d);
                        double d3 = cp3cx * d + cp3 * (m + d);
                        for (i2x = resolution - 1; i2x >= 0; i2x--)
                        {
                            //1ピクセルを作成
                            x = rgb_px[n] = (int)(m2);
                            y = rgb_py[n] = (int)(m3);
                            if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                            {
                                if (x < 0) { rgb_px[n] = 0; } else if (x >= img_x) { rgb_px[n] = img_x - 1; }
                                if (y < 0) { rgb_py[n] = 0; } else if (y >= img_y) { rgb_py[n] = img_y - 1; }
                            }
                            n++;
                            m2 += d2;
                            m3 += d3;
                        }
                    }
                    reader.getPixelSet(rgb_px, rgb_py, res_pix, rgb_tmp);
                    r = g = b = 0;
                    for (int i = res_pix * 3 - 1; i > 0; )
                    {
                        b += rgb_tmp[i--];
                        g += rgb_tmp[i--];
                        r += rgb_tmp[i--];
                    }
                    r /= res_pix;
                    g /= res_pix;
                    b /= res_pix;
                    o_patt[p] = ((r & 0xff) << 16) | ((g & 0xff) << 8) | ((b & 0xff));
                    p++;
                }
            }
            return;
        }
        private void onePixel_ANY(int pk_l, int pk_t, int in_w, int in_h, double[] cpara, INyARRgbPixelReader i_in_reader, INyARRgbRaster o_out)
        {
            int[] rgb_tmp = this.__pickFromRaster_rgb_tmp;
            INyARRgbPixelReader out_reader = o_out.getRgbPixelReader();

            //ピクセルリーダーを取得
            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;

            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;
        }
        public void pickFromRaster(double[] i_cpara, INyARRgbRaster image,  int[] o_patt)
        {
            double d0, m0, d1, m1;
            int x, y;

            int img_x = image.getWidth();
            int img_y = image.getHeight();
            int patt_w = this._size_ref.w;

            int[] rgb_tmp = this._rgb_temp;
            int[] rgb_px = this._rgb_px;
            int[] rgb_py = this._rgb_py;



            double cp0 = i_cpara[0];
            double cp3 = i_cpara[3];
            double cp6 = i_cpara[6];
            double cp1 = i_cpara[1];
            double cp4 = i_cpara[4];
            double cp7 = i_cpara[7];


            int pick_y = this._lt_ref.y;
            int pick_x = this._lt_ref.x;
            //ピクセルリーダーを取得
            INyARRgbPixelReader reader = image.getRgbPixelReader();
            int p = 0;


            double cp0cx0, cp3cx0;
            double cp1cy_cp20 = cp1 * pick_y + i_cpara[2] + cp0 * pick_x;
            double cp4cy_cp50 = cp4 * pick_y + i_cpara[5] + cp3 * pick_x;
            double cp7cy_10 = cp7 * pick_y + 1.0 + cp6 * pick_x;


            double cp0cx1, cp3cx1;
            double cp1cy_cp21 = cp1cy_cp20 + cp1;
            double cp4cy_cp51 = cp4cy_cp50 + cp4;
            double cp7cy_11 = cp7cy_10 + cp7;

            double cw0 = cp1 + cp1;
            double cw7 = cp7 + cp7;
            double cw4 = cp4 + cp4;

            for (int iy = this._size_ref.h - 1; iy >= 0; iy--)
            {
                cp0cx0 = cp1cy_cp20;
                cp3cx0 = cp4cy_cp50;
                cp0cx1 = cp1cy_cp21;
                cp3cx1 = cp4cy_cp51;

                m0 = 1 / (cp7cy_10);
                d0 = -cp6 / (cp7cy_10 * (cp7cy_10 + cp6));
                m1 = 1 / (cp7cy_11);
                d1 = -cp6 / (cp7cy_11 * (cp7cy_11 + cp6));

                int n = patt_w * 2 * 2 - 1;

                for (int ix = patt_w * 2 - 1; ix >= 0; ix--)
                {
                    //[n,0]
                    x = rgb_px[n] = (int)(cp0cx0 * m0);
                    y = rgb_py[n] = (int)(cp3cx0 * m0);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[n] = 0; } else if (x >= img_x) { rgb_px[n] = img_x - 1; }
                        if (y < 0) { rgb_py[n] = 0; } else if (y >= img_y) { rgb_py[n] = img_y - 1; }
                    }
                    cp0cx0 += cp0;
                    cp3cx0 += cp3;
                    m0 += d0;
                    n--;
                    //[n,1]
                    x = rgb_px[n] = (int)(cp0cx1 * m1);
                    y = rgb_py[n] = (int)(cp3cx1 * m1);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[n] = 0; } else if (x >= img_x) { rgb_px[n] = img_x - 1; }
                        if (y < 0) { rgb_py[n] = 0; } else if (y >= img_y) { rgb_py[n] = img_y - 1; }
                    }
                    cp0cx1 += cp0;
                    cp3cx1 += cp3;
                    m1 += d1;
                    n--;
                }
                cp7cy_10 += cw7;
                cp7cy_11 += cw7;

                cp1cy_cp20 += cw0;
                cp4cy_cp50 += cw4;
                cp1cy_cp21 += cw0;
                cp4cy_cp51 += cw4;



                reader.getPixelSet(rgb_px, rgb_py, patt_w * 4, rgb_tmp);
                for (int ix = patt_w - 1; ix >= 0; ix--)
                {
                    int idx = ix * 12;//3*2*2
                    int r = (rgb_tmp[idx + 0] + rgb_tmp[idx + 3] + rgb_tmp[idx + 6] + rgb_tmp[idx + 9]) / 4;
                    int g = (rgb_tmp[idx + 1] + rgb_tmp[idx + 4] + rgb_tmp[idx + 7] + rgb_tmp[idx + 10]) / 4;
                    int b = (rgb_tmp[idx + 2] + rgb_tmp[idx + 5] + rgb_tmp[idx + 8] + rgb_tmp[idx + 11]) / 4;
                    o_patt[p] = (r << 16) | (g << 8) | ((b & 0xff));
                    p++;
                }
            }

            return;
        }
Exemple #13
0
        public void pickFromRaster(double[] i_cpara, INyARRgbRaster image, int[] o_patt)
        {
            double d0, m0, d1, m1;
            int    x, y;

            int img_x  = image.getWidth();
            int img_y  = image.getHeight();
            int patt_w = this._size_ref.w;

            int[] rgb_tmp = this._rgb_temp;
            int[] rgb_px  = this._rgb_px;
            int[] rgb_py  = this._rgb_py;



            double cp0 = i_cpara[0];
            double cp3 = i_cpara[3];
            double cp6 = i_cpara[6];
            double cp1 = i_cpara[1];
            double cp4 = i_cpara[4];
            double cp7 = i_cpara[7];


            int pick_y = this._lt_ref.y;
            int pick_x = this._lt_ref.x;
            //ピクセルリーダーを取得
            INyARRgbPixelReader reader = image.getRgbPixelReader();
            int p = 0;


            double cp0cx0, cp3cx0;
            double cp1cy_cp20 = cp1 * pick_y + i_cpara[2] + cp0 * pick_x;
            double cp4cy_cp50 = cp4 * pick_y + i_cpara[5] + cp3 * pick_x;
            double cp7cy_10   = cp7 * pick_y + 1.0 + cp6 * pick_x;


            double cp0cx1, cp3cx1;
            double cp1cy_cp21 = cp1cy_cp20 + cp1;
            double cp4cy_cp51 = cp4cy_cp50 + cp4;
            double cp7cy_11   = cp7cy_10 + cp7;

            double cw0 = cp1 + cp1;
            double cw7 = cp7 + cp7;
            double cw4 = cp4 + cp4;

            for (int iy = this._size_ref.h - 1; iy >= 0; iy--)
            {
                cp0cx0 = cp1cy_cp20;
                cp3cx0 = cp4cy_cp50;
                cp0cx1 = cp1cy_cp21;
                cp3cx1 = cp4cy_cp51;

                m0 = 1 / (cp7cy_10);
                d0 = -cp6 / (cp7cy_10 * (cp7cy_10 + cp6));
                m1 = 1 / (cp7cy_11);
                d1 = -cp6 / (cp7cy_11 * (cp7cy_11 + cp6));

                int n = patt_w * 2 * 2 - 1;

                for (int ix = patt_w * 2 - 1; ix >= 0; ix--)
                {
                    //[n,0]
                    x = rgb_px[n] = (int)(cp0cx0 * m0);
                    y = rgb_py[n] = (int)(cp3cx0 * m0);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[n] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[n] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[n] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[n] = img_y - 1;
                        }
                    }
                    cp0cx0 += cp0;
                    cp3cx0 += cp3;
                    m0     += d0;
                    n--;
                    //[n,1]
                    x = rgb_px[n] = (int)(cp0cx1 * m1);
                    y = rgb_py[n] = (int)(cp3cx1 * m1);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[n] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[n] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[n] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[n] = img_y - 1;
                        }
                    }
                    cp0cx1 += cp0;
                    cp3cx1 += cp3;
                    m1     += d1;
                    n--;
                }
                cp7cy_10 += cw7;
                cp7cy_11 += cw7;

                cp1cy_cp20 += cw0;
                cp4cy_cp50 += cw4;
                cp1cy_cp21 += cw0;
                cp4cy_cp51 += cw4;



                reader.getPixelSet(rgb_px, rgb_py, patt_w * 4, rgb_tmp);
                for (int ix = patt_w - 1; ix >= 0; ix--)
                {
                    int idx = ix * 12;//3*2*2
                    int r   = (rgb_tmp[idx + 0] + rgb_tmp[idx + 3] + rgb_tmp[idx + 6] + rgb_tmp[idx + 9]) / 4;
                    int g   = (rgb_tmp[idx + 1] + rgb_tmp[idx + 4] + rgb_tmp[idx + 7] + rgb_tmp[idx + 10]) / 4;
                    int b   = (rgb_tmp[idx + 2] + rgb_tmp[idx + 5] + rgb_tmp[idx + 8] + rgb_tmp[idx + 11]) / 4;
                    o_patt[p] = (r << 16) | (g << 8) | ((b & 0xff));
                    p++;
                }
            }

            return;
        }
        //分割数16未満になると少し遅くなるかも。
        private void updateExtpat(INyARRgbRaster image, NyARMat i_cpara, int i_xdiv2, int i_ydiv2)
        {

            int i, j;
            int r, g, b;
            //ピクセルリーダーを取得
            int pat_size_w = this._size.w;
            int xdiv = i_xdiv2 / pat_size_w;// xdiv = xdiv2/Config.AR_PATT_SIZE_X;
            int ydiv = i_ydiv2 / this._size.h;// ydiv = ydiv2/Config.AR_PATT_SIZE_Y;
            int xdiv_x_ydiv = xdiv * ydiv;
            double reciprocal;
            double[][] para = i_cpara.getArray();
            double para00 = para[0 * 3 + 0][0];
            double para01 = para[0 * 3 + 1][0];
            double para02 = para[0 * 3 + 2][0];
            double para10 = para[1 * 3 + 0][0];
            double para11 = para[1 * 3 + 1][0];
            double para12 = para[1 * 3 + 2][0];
            double para20 = para[2 * 3 + 0][0];
            double para21 = para[2 * 3 + 1][0];

            INyARRgbPixelDriver reader = image.getRgbPixelDriver();
            int img_width = image.getWidth();
            int img_height = image.getHeight();

            //ワークバッファの準備
            reservWorkBuffers(xdiv, ydiv);
            double[] xw = this.__updateExtpat_xw;
            double[] yw = this.__updateExtpat_yw;
            int[] xc = this.__updateExtpat_xc;
            int[] yc = this.__updateExtpat_yc;
            int[] rgb_set = this.__updateExtpat_rgbset;


            for (int iy = this._size.h - 1; iy >= 0; iy--)
            {
                for (int ix = pat_size_w - 1; ix >= 0; ix--)
                {
                    //xw,ywマップを作成
                    reciprocal = 1.0 / i_xdiv2;
                    for (i = xdiv - 1; i >= 0; i--)
                    {
                        xw[i] = LT_POS + SQ_SIZE * (ix * xdiv + i + 0.5) * reciprocal;
                    }
                    reciprocal = 1.0 / i_ydiv2;
                    for (i = ydiv - 1; i >= 0; i--)
                    {
                        yw[i] = LT_POS + SQ_SIZE * (iy * ydiv + i + 0.5) * reciprocal;
                    }
                    //1ピクセルを構成するピクセル座標の集合をxc,yc配列に取得
                    int number_of_pix = 0;
                    for (i = ydiv - 1; i >= 0; i--)
                    {
                        double para01_x_yw_para02 = para01 * yw[i] + para02;
                        double para11_x_yw_para12 = para11 * yw[i] + para12;
                        double para12_x_yw_para22 = para21 * yw[i] + 1.0;
                        for (j = xdiv - 1; j >= 0; j--)
                        {

                            double d = para20 * xw[j] + para12_x_yw_para22;
                            if (d == 0)
                            {
                                throw new NyARException();
                            }
                            int xcw = (int)((para00 * xw[j] + para01_x_yw_para02) / d);
                            int ycw = (int)((para10 * xw[j] + para11_x_yw_para12) / d);
                            if (xcw < 0 || xcw >= img_width || ycw < 0 || ycw >= img_height)
                            {
                                continue;
                            }
                            xc[number_of_pix] = xcw;
                            yc[number_of_pix] = ycw;
                            number_of_pix++;
                        }
                    }
                    //1ピクセル分の配列を取得
                    reader.getPixelSet(xc, yc, number_of_pix, rgb_set);
                    r = g = b = 0;
                    for (i = number_of_pix * 3 - 1; i >= 0; i -= 3)
                    {
                        r += rgb_set[i - 2];// R
                        g += rgb_set[i - 1];// G
                        b += rgb_set[i];// B
                    }
                    //1ピクセル確定
                    this._patdata[iy * pat_size_w + ix] = (((r / xdiv_x_ydiv) & 0xff) << 16) | (((g / xdiv_x_ydiv) & 0xff) << 8) | (((b / xdiv_x_ydiv) & 0xff));
                }
            }
            return;
        }
        private void multiPixel_ANY(int pk_l, int pk_t, int in_w, int in_h, int i_resolution, double[] cpara, byte[] i_in_buf, INyARRgbRaster o_out)
        {
            int res_pix = i_resolution * i_resolution;

            INyARRgbPixelReader out_reader = o_out.getRgbPixelReader();

            //ピクセルリーダーを取得
            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();

            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) * 4;
                            r += (i_in_buf[bp + 2] & 0xff);
                            g += (i_in_buf[bp + 1] & 0xff);
                            b += (i_in_buf[bp + 0] & 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;
        }
        /**
         * @see INyARColorPatt#pickFromRaster
         */
        public bool pickFromRaster(INyARRgbRaster image, NyARIntPoint2d[] i_vertexs)
        {
            //遠近法のパラメータを計算
            double[] cpara = this.__pickFromRaster_cpara;
            if (!this._perspective_gen.getParam(this._pickup_wh, i_vertexs, cpara))
            {
                return(false);
            }

            int resolution = this._resolution;
            int img_x      = image.getWidth();
            int img_y      = image.getHeight();
            int res_pix    = resolution * resolution;

            int[] rgb_tmp = this.__pickFromRaster_rgb_tmp;

            //ピクセルリーダーを取得
            INyARRgbPixelReader reader = image.getRgbPixelReader();
            int p = 0;

            for (int iy = 0; iy < this._size.h * resolution; iy += resolution)
            {
                //解像度分の点を取る。
                for (int ix = 0; ix < this._size.w * resolution; ix += resolution)
                {
                    int r, g, b;
                    r = g = b = 0;
                    for (int i2y = iy; i2y < iy + resolution; i2y++)
                    {
                        int cy = this._pickup_lt.y + i2y;
                        for (int i2x = ix; i2x < ix + resolution; i2x++)
                        {
                            //1ピクセルを作成
                            int    cx = this._pickup_lt.x + i2x;
                            double d  = cpara[6] * cx + cpara[7] * cy + 1.0;
                            int    x  = (int)((cpara[0] * cx + cpara[1] * cy + cpara[2]) / d);
                            int    y  = (int)((cpara[3] * cx + cpara[4] * cy + cpara[5]) / d);
                            if (x < 0)
                            {
                                x = 0;
                            }
                            if (x >= img_x)
                            {
                                x = img_x - 1;
                            }
                            if (y < 0)
                            {
                                y = 0;
                            }
                            if (y >= img_y)
                            {
                                y = img_y - 1;
                            }

                            reader.getPixel(x, y, rgb_tmp);
                            r += rgb_tmp[0];
                            g += rgb_tmp[1];
                            b += rgb_tmp[2];
                        }
                    }
                    r /= res_pix;
                    g /= res_pix;
                    b /= res_pix;
                    this._patdata[p] = ((r & 0xff) << 16) | ((g & 0xff) << 8) | ((b & 0xff));
                    p++;
                }
            }
            //ピクセル問い合わせ
            //ピクセルセット
            return(true);
        }
        private void onePixel_ANY(int pk_l, int pk_t, int in_w, int in_h, double[] cpara, byte[] i_in_buf, INyARRgbRaster o_out)
        {
            INyARRgbPixelReader out_reader = o_out.getRgbPixelReader();

            //ピクセルリーダーを取得
            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;

            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) * 4;
                    r = (i_in_buf[bp + 2] & 0xff);
                    g = (i_in_buf[bp + 1] & 0xff);
                    b = (i_in_buf[bp + 0] & 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;
        }
        private void onePixel_INT1D_X8R8G8B8_32(int pk_l, int pk_t, int in_w, int in_h, double[] cpara, byte[] i_in_buf, INyARRgbRaster o_out)
        {
            Debug.Assert(o_out.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
            int[] pat_data = (int[])o_out.getBuffer();
            //ピクセルリーダーを取得
            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;
            int    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 bp = (x + y * in_w) * 4;
                    r = (i_in_buf[bp + 2] & 0xff);
                    g = (i_in_buf[bp + 1] & 0xff);
                    b = (i_in_buf[bp + 0] & 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;
        }
Exemple #19
0
        public void pickFromRaster(double[] i_cpara, INyARRgbRaster image, int[] o_patt)
        {
            int i2x, i2y;//プライム変数
            int x, y;
            int w;
            int r, g, b;

            int resolution = this._resolution;
            int res_pix    = resolution * resolution;
            int img_x      = image.getWidth();
            int img_y      = image.getHeight();

            int[] rgb_tmp = this._rgb_temp;
            int[] rgb_px  = this._rgb_px;
            int[] rgb_py  = this._rgb_py;

            double[] cp1cy_cp2 = this._cp1cy_cp2;
            double[] cp4cy_cp5 = this._cp4cy_cp5;
            double[] cp7cy_1   = this._cp7cy_1;

            double cp0 = i_cpara[0];
            double cp3 = i_cpara[3];
            double cp6 = i_cpara[6];
            double cp1 = i_cpara[1];
            double cp2 = i_cpara[2];
            double cp4 = i_cpara[4];
            double cp5 = i_cpara[5];
            double cp7 = i_cpara[7];


            int pick_y = this._lt_ref.y;
            int pick_x = this._lt_ref.x;
            //ピクセルリーダーを取得
            INyARRgbPixelReader reader = image.getRgbPixelReader();
            int p = 0;


            for (int iy = 0; iy < this._size_ref.h * resolution; iy += resolution)
            {
                w            = pick_y + iy;
                cp1cy_cp2[0] = cp1 * w + cp2;
                cp4cy_cp5[0] = cp4 * w + cp5;
                cp7cy_1[0]   = cp7 * w + 1.0;
                for (i2y = 1; i2y < resolution; i2y++)
                {
                    cp1cy_cp2[i2y] = cp1cy_cp2[i2y - 1] + cp1;
                    cp4cy_cp5[i2y] = cp4cy_cp5[i2y - 1] + cp4;
                    cp7cy_1[i2y]   = cp7cy_1[i2y - 1] + cp7;
                }
                //解像度分の点を取る。

                for (int ix = 0; ix < this._size_ref.w * resolution; ix += resolution)
                {
                    int n = 0;
                    w = pick_x + ix;
                    for (i2y = resolution - 1; i2y >= 0; i2y--)
                    {
                        double cp0cx = cp0 * w + cp1cy_cp2[i2y];
                        double cp6cx = cp6 * w + cp7cy_1[i2y];
                        double cp3cx = cp3 * w + cp4cy_cp5[i2y];

                        double m = 1 / (cp6cx);
                        double d = -cp6 / (cp6cx * (cp6cx + cp6));

                        double m2 = cp0cx * m;
                        double m3 = cp3cx * m;
                        double d2 = cp0cx * d + cp0 * (m + d);
                        double d3 = cp3cx * d + cp3 * (m + d);
                        for (i2x = resolution - 1; i2x >= 0; i2x--)
                        {
                            //1ピクセルを作成
                            x = rgb_px[n] = (int)(m2);
                            y = rgb_py[n] = (int)(m3);
                            if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                            {
                                if (x < 0)
                                {
                                    rgb_px[n] = 0;
                                }
                                else if (x >= img_x)
                                {
                                    rgb_px[n] = img_x - 1;
                                }
                                if (y < 0)
                                {
                                    rgb_py[n] = 0;
                                }
                                else if (y >= img_y)
                                {
                                    rgb_py[n] = img_y - 1;
                                }
                            }
                            n++;
                            m2 += d2;
                            m3 += d3;
                        }
                    }
                    reader.getPixelSet(rgb_px, rgb_py, res_pix, rgb_tmp);
                    r = g = b = 0;
                    for (int i = res_pix * 3 - 1; i > 0;)
                    {
                        b += rgb_tmp[i--];
                        g += rgb_tmp[i--];
                        r += rgb_tmp[i--];
                    }
                    r        /= res_pix;
                    g        /= res_pix;
                    b        /= res_pix;
                    o_patt[p] = ((r & 0xff) << 16) | ((g & 0xff) << 8) | ((b & 0xff));
                    p++;
                }
            }
            return;
        }
Exemple #20
0
        /**
         * この関数は、ラスタのi_vertexsで定義される四角形からパターンを取得して、インスタンスに格納します。
         */
        public virtual bool pickFromRaster(INyARRgbRaster image, NyARIntPoint2d[] i_vertexs)
        {
            // パターンの切り出しに失敗することもある。
            NyARMat cpara = new NyARMat(8, 1);

            if (!get_cpara(i_vertexs, cpara))
            {
                return(false);
            }
            double[][] para   = cpara.getArray();
            double     para00 = para[0 * 3 + 0][0];
            double     para01 = para[0 * 3 + 1][0];
            double     para02 = para[0 * 3 + 2][0];
            double     para10 = para[1 * 3 + 0][0];
            double     para11 = para[1 * 3 + 1][0];
            double     para12 = para[1 * 3 + 2][0];
            double     para20 = para[2 * 3 + 0][0];
            double     para21 = para[2 * 3 + 1][0];
            double     para22 = 1.0;

            int lx1 = (int)((i_vertexs[0].x - i_vertexs[1].x) * (i_vertexs[0].x - i_vertexs[1].x) + (i_vertexs[0].y - i_vertexs[1].y) * (i_vertexs[0].y - i_vertexs[1].y));
            int lx2 = (int)((i_vertexs[2].x - i_vertexs[3].x) * (i_vertexs[2].x - i_vertexs[3].x) + (i_vertexs[2].y - i_vertexs[3].y) * (i_vertexs[2].y - i_vertexs[3].y));
            int ly1 = (int)((i_vertexs[1].x - i_vertexs[2].x) * (i_vertexs[1].x - i_vertexs[2].x) + (i_vertexs[1].y - i_vertexs[2].y) * (i_vertexs[1].y - i_vertexs[2].y));
            int ly2 = (int)((i_vertexs[3].x - i_vertexs[0].x) * (i_vertexs[3].x - i_vertexs[0].x) + (i_vertexs[3].y - i_vertexs[0].y) * (i_vertexs[3].y - i_vertexs[0].y));

            if (lx2 > lx1)
            {
                lx1 = lx2;
            }
            if (ly2 > ly1)
            {
                ly1 = ly2;
            }

            int sample_pixel_x = this._size.w;
            int sample_pixel_y = this._size.h;

            while (sample_pixel_x * sample_pixel_x < lx1 / 4)
            {
                sample_pixel_x *= 2;
            }
            while (sample_pixel_y * sample_pixel_y < ly1 / 4)
            {
                sample_pixel_y *= 2;
            }

            if (sample_pixel_x > AR_PATT_SAMPLE_NUM)
            {
                sample_pixel_x = AR_PATT_SAMPLE_NUM;
            }
            if (sample_pixel_y > AR_PATT_SAMPLE_NUM)
            {
                sample_pixel_y = AR_PATT_SAMPLE_NUM;
            }

            int xdiv = sample_pixel_x / this._size.w; // xdiv = xdiv2/Config.AR_PATT_SIZE_X;
            int ydiv = sample_pixel_y / this._size.h; // ydiv = ydiv2/Config.AR_PATT_SIZE_Y;


            int img_x = image.getWidth();
            int img_y = image.getHeight();

            double xdiv2_reciprocal = 1.0 / sample_pixel_x;
            double ydiv2_reciprocal = 1.0 / sample_pixel_y;
            int    r, g, b;

            int[] rgb_tmp = new int[3];

            //ピクセルリーダーを取得
            INyARRgbPixelDriver reader = image.getRgbPixelDriver();
            int xdiv_x_ydiv            = xdiv * ydiv;

            for (int iy = 0; iy < this._size.h; iy++)
            {
                for (int ix = 0; ix < this._size.w; ix++)
                {
                    r = g = b = 0;
                    //1ピクセルを作成
                    for (int j = 0; j < ydiv; j++)
                    {
                        double yw = 102.5 + 5.0 * (iy * ydiv + j + 0.5) * ydiv2_reciprocal;
                        for (int i = 0; i < xdiv; i++)
                        {
                            double xw = 102.5 + 5.0 * (ix * xdiv + i + 0.5) * xdiv2_reciprocal;
                            double d  = para20 * xw + para21 * yw + para22;
                            if (d == 0)
                            {
                                throw new NyARException();
                            }
                            int xc = (int)((para00 * xw + para01 * yw + para02) / d);
                            int yc = (int)((para10 * xw + para11 * yw + para12) / d);

                            if (xc >= 0 && xc < img_x && yc >= 0 && yc < img_y)
                            {
                                reader.getPixel(xc, yc, rgb_tmp);
                                r += rgb_tmp[0]; // R
                                g += rgb_tmp[1]; // G
                                b += rgb_tmp[2]; // B
                                // System.out.println(xc+":"+yc+":"+rgb_tmp[0]+":"+rgb_tmp[1]+":"+rgb_tmp[2]);
                            }
                        }
                    }
                    this._patdata[iy * this._size.w + ix] = (((r / xdiv_x_ydiv) & 0xff) << 16) | (((g / xdiv_x_ydiv) & 0xff) << 8) | (((b / xdiv_x_ydiv) & 0xff));
                }
            }
            return(true);
        }
        public void pickFromRaster(double[] i_cpara, INyARRgbRaster image, int[] o_patt)
        {
            double d0, m0;
            int x, y;

            int img_x = image.getWidth();
            int img_y = image.getHeight();
            int patt_w = this._size_ref.w;

            int[] rgb_tmp = this._rgb_temp;
            int[] rgb_px = this._rgb_px;
            int[] rgb_py = this._rgb_py;



            double cp0 = i_cpara[0];
            double cp3 = i_cpara[3];
            double cp6 = i_cpara[6];
            double cp1 = i_cpara[1];
            double cp4 = i_cpara[4];
            double cp7 = i_cpara[7];


            int pick_y = this._lt_ref.y;
            int pick_x = this._lt_ref.x;
            //ピクセルリーダーを取得
            INyARRgbPixelReader reader = image.getRgbPixelReader();
            int p = 0;


            double cp0cx0, cp3cx0;
            double cp1cy_cp20 = cp1 * pick_y + i_cpara[2] + cp0 * pick_x;
            double cp4cy_cp50 = cp4 * pick_y + i_cpara[5] + cp3 * pick_x;
            double cp7cy_10 = cp7 * pick_y + 1.0 + cp6 * pick_x;


            for (int iy = this._size_ref.h - 1; iy >= 0; iy--)
            {
                m0 = 1 / (cp7cy_10);
                d0 = -cp6 / (cp7cy_10 * (cp7cy_10 + cp6));

                cp0cx0 = cp1cy_cp20;
                cp3cx0 = cp4cy_cp50;

                //ピックアップシーケンス

                //0番目のピクセル(検査対象)をピックアップ


                for (int ix = patt_w - 1; ix >= 0; ix--)
                {
                    //1ピクセルを作成
                    x = rgb_px[ix] = (int)(cp0cx0 * m0);
                    y = rgb_py[ix] = (int)(cp3cx0 * m0);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0) { rgb_px[ix] = 0; } else if (x >= img_x) { rgb_px[ix] = img_x - 1; }
                        if (y < 0) { rgb_py[ix] = 0; } else if (y >= img_y) { rgb_py[ix] = img_y - 1; }
                    }
                    cp0cx0 += cp0;
                    cp3cx0 += cp3;
                    m0 += d0;
                }

                cp1cy_cp20 += cp1;
                cp4cy_cp50 += cp4;
                cp7cy_10 += cp7;

                reader.getPixelSet(rgb_px, rgb_py, patt_w, rgb_tmp);
                for (int ix = patt_w - 1; ix >= 0; ix--)
                {
                    int idx = ix * 3;
                    o_patt[p] = (rgb_tmp[idx] << 16) | (rgb_tmp[idx + 1] << 8) | ((rgb_tmp[idx + 2] & 0xff));
                    p++;
                }
            }

            return;
        }
        private void onePixel_INT1D_X8R8G8B8_32(int pk_l, int pk_t, int in_w, int in_h, double[] cpara, INyARRgbPixelReader i_in_reader, INyARRgbRaster o_out)
        {
            Debug.Assert(o_out.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
            int[] rgb_tmp  = this.__pickFromRaster_rgb_tmp;
            int[] pat_data = (int[])o_out.getBuffer();

            //ピクセルリーダーを取得
            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          = 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;
        }
        private void multiPixel_INT1D_X8R8G8B8_32(int pk_l, int pk_t, int in_w, int in_h, int i_resolution, double[] cpara, INyARRgbPixelReader i_in_reader, INyARRgbRaster o_out)
        {
            Debug.Assert(o_out.isEqualBufferType(NyARBufferType.INT1D_X8R8G8B8_32));
            int res_pix = i_resolution * i_resolution;

            int[] rgb_tmp  = this.__pickFromRaster_rgb_tmp;
            int[] pat_data = (int[])o_out.getBuffer();

            //ピクセルリーダーを取得
            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();
            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;
        }
        //分割数16未満になると少し遅くなるかも。
        private void updateExtpat(INyARRgbRaster image, NyARMat i_cpara, int i_xdiv2, int i_ydiv2)
        {
            int i, j;
            int r, g, b;
            //ピクセルリーダーを取得
            int    pat_size_w  = this._size.w;
            int    xdiv        = i_xdiv2 / pat_size_w;   // xdiv = xdiv2/Config.AR_PATT_SIZE_X;
            int    ydiv        = i_ydiv2 / this._size.h; // ydiv = ydiv2/Config.AR_PATT_SIZE_Y;
            int    xdiv_x_ydiv = xdiv * ydiv;
            double reciprocal;

            double[][] para   = i_cpara.getArray();
            double     para00 = para[0 * 3 + 0][0];
            double     para01 = para[0 * 3 + 1][0];
            double     para02 = para[0 * 3 + 2][0];
            double     para10 = para[1 * 3 + 0][0];
            double     para11 = para[1 * 3 + 1][0];
            double     para12 = para[1 * 3 + 2][0];
            double     para20 = para[2 * 3 + 0][0];
            double     para21 = para[2 * 3 + 1][0];

            INyARRgbPixelDriver reader = image.getRgbPixelDriver();
            int img_width  = image.getWidth();
            int img_height = image.getHeight();

            //ワークバッファの準備
            reservWorkBuffers(xdiv, ydiv);
            double[] xw      = this.__updateExtpat_xw;
            double[] yw      = this.__updateExtpat_yw;
            int[]    xc      = this.__updateExtpat_xc;
            int[]    yc      = this.__updateExtpat_yc;
            int[]    rgb_set = this.__updateExtpat_rgbset;


            for (int iy = this._size.h - 1; iy >= 0; iy--)
            {
                for (int ix = pat_size_w - 1; ix >= 0; ix--)
                {
                    //xw,ywマップを作成
                    reciprocal = 1.0 / i_xdiv2;
                    for (i = xdiv - 1; i >= 0; i--)
                    {
                        xw[i] = LT_POS + SQ_SIZE * (ix * xdiv + i + 0.5) * reciprocal;
                    }
                    reciprocal = 1.0 / i_ydiv2;
                    for (i = ydiv - 1; i >= 0; i--)
                    {
                        yw[i] = LT_POS + SQ_SIZE * (iy * ydiv + i + 0.5) * reciprocal;
                    }
                    //1ピクセルを構成するピクセル座標の集合をxc,yc配列に取得
                    int number_of_pix = 0;
                    for (i = ydiv - 1; i >= 0; i--)
                    {
                        double para01_x_yw_para02 = para01 * yw[i] + para02;
                        double para11_x_yw_para12 = para11 * yw[i] + para12;
                        double para12_x_yw_para22 = para21 * yw[i] + 1.0;
                        for (j = xdiv - 1; j >= 0; j--)
                        {
                            double d = para20 * xw[j] + para12_x_yw_para22;
                            if (d == 0)
                            {
                                throw new NyARException();
                            }
                            int xcw = (int)((para00 * xw[j] + para01_x_yw_para02) / d);
                            int ycw = (int)((para10 * xw[j] + para11_x_yw_para12) / d);
                            if (xcw < 0 || xcw >= img_width || ycw < 0 || ycw >= img_height)
                            {
                                continue;
                            }
                            xc[number_of_pix] = xcw;
                            yc[number_of_pix] = ycw;
                            number_of_pix++;
                        }
                    }
                    //1ピクセル分の配列を取得
                    reader.getPixelSet(xc, yc, number_of_pix, rgb_set);
                    r = g = b = 0;
                    for (i = number_of_pix * 3 - 1; i >= 0; i -= 3)
                    {
                        r += rgb_set[i - 2]; // R
                        g += rgb_set[i - 1]; // G
                        b += rgb_set[i];     // B
                    }
                    //1ピクセル確定
                    this._patdata[iy * pat_size_w + ix] = (((r / xdiv_x_ydiv) & 0xff) << 16) | (((g / xdiv_x_ydiv) & 0xff) << 8) | (((b / xdiv_x_ydiv) & 0xff));
                }
            }
            return;
        }
Exemple #25
0
        public void pickFromRaster(double[] i_cpara, INyARRgbRaster image, int[] o_patt)
        {
            double d0, m0;
            int    x, y;

            int img_x  = image.getWidth();
            int img_y  = image.getHeight();
            int patt_w = this._size_ref.w;

            int[] rgb_tmp = this._rgb_temp;
            int[] rgb_px  = this._rgb_px;
            int[] rgb_py  = this._rgb_py;



            double cp0 = i_cpara[0];
            double cp3 = i_cpara[3];
            double cp6 = i_cpara[6];
            double cp1 = i_cpara[1];
            double cp4 = i_cpara[4];
            double cp7 = i_cpara[7];


            int pick_y = this._lt_ref.y;
            int pick_x = this._lt_ref.x;
            //ピクセルリーダーを取得
            INyARRgbPixelReader reader = image.getRgbPixelReader();
            int p = 0;


            double cp0cx0, cp3cx0;
            double cp1cy_cp20 = cp1 * pick_y + i_cpara[2] + cp0 * pick_x;
            double cp4cy_cp50 = cp4 * pick_y + i_cpara[5] + cp3 * pick_x;
            double cp7cy_10   = cp7 * pick_y + 1.0 + cp6 * pick_x;


            for (int iy = this._size_ref.h - 1; iy >= 0; iy--)
            {
                m0 = 1 / (cp7cy_10);
                d0 = -cp6 / (cp7cy_10 * (cp7cy_10 + cp6));

                cp0cx0 = cp1cy_cp20;
                cp3cx0 = cp4cy_cp50;

                //ピックアップシーケンス

                //0番目のピクセル(検査対象)をピックアップ


                for (int ix = patt_w - 1; ix >= 0; ix--)
                {
                    //1ピクセルを作成
                    x = rgb_px[ix] = (int)(cp0cx0 * m0);
                    y = rgb_py[ix] = (int)(cp3cx0 * m0);
                    if (x < 0 || x >= img_x || y < 0 || y >= img_y)
                    {
                        if (x < 0)
                        {
                            rgb_px[ix] = 0;
                        }
                        else if (x >= img_x)
                        {
                            rgb_px[ix] = img_x - 1;
                        }
                        if (y < 0)
                        {
                            rgb_py[ix] = 0;
                        }
                        else if (y >= img_y)
                        {
                            rgb_py[ix] = img_y - 1;
                        }
                    }
                    cp0cx0 += cp0;
                    cp3cx0 += cp3;
                    m0     += d0;
                }

                cp1cy_cp20 += cp1;
                cp4cy_cp50 += cp4;
                cp7cy_10   += cp7;

                reader.getPixelSet(rgb_px, rgb_py, patt_w, rgb_tmp);
                for (int ix = patt_w - 1; ix >= 0; ix--)
                {
                    int idx = ix * 3;
                    o_patt[p] = (rgb_tmp[idx] << 16) | (rgb_tmp[idx + 1] << 8) | ((rgb_tmp[idx + 2] & 0xff));
                    p++;
                }
            }

            return;
        }