Example #1
0
        /**
         * Readerとbufferを初期化する関数です。コンストラクタから呼び出します。
         * 継承クラスでこの関数を拡張することで、対応するバッファタイプの種類を増やせます。
         * @param i_size
         * ラスタのサイズ
         * @param i_raster_type
         * バッファタイプ
         * @param i_is_alloc
         * 外部参照/内部バッファのフラグ
         * @return
         * 初期化が成功すると、trueです。
         * @
         */
        protected virtual void initInstance(NyARIntSize i_size, int i_raster_type, bool i_is_alloc)
        {
            //バッファの構築
            switch (i_raster_type)
            {
            case NyARBufferType.INT1D_X8R8G8B8_32:
                this._buf = i_is_alloc ? new int[i_size.w * i_size.h] : null;
                break;

            case NyARBufferType.BYTE1D_B8G8R8X8_32:
            case NyARBufferType.BYTE1D_X8R8G8B8_32:
                this._buf = i_is_alloc ? new byte[i_size.w * i_size.h * 4] : null;
                break;

            case NyARBufferType.BYTE1D_R8G8B8_24:
            case NyARBufferType.BYTE1D_B8G8R8_24:
                this._buf = i_is_alloc ? new byte[i_size.w * i_size.h * 3] : null;
                break;

            case NyARBufferType.WORD1D_R5G6B5_16LE:
                this._buf = i_is_alloc ? new short[i_size.w * i_size.h] : null;
                break;

            default:
                throw new NyARException();
            }
            //readerの構築
            this._rgb_pixel_driver   = NyARRgbPixelDriverFactory.createDriver(this);
            this._is_attached_buffer = i_is_alloc;
            return;
        }
Example #2
0
        /**
         * この関数は、ラスタのi_vertexsで定義される四角形からパターンを取得して、インスタンスに格納します。
         */
        public bool pickFromRaster(INyARRgbRaster image, NyARIntPoint2d[] i_vertexs)
        {
            double[] conv_param = this._convparam;
            int      rx2, ry2;

            rx2 = this._size.w;
            ry2 = this._size.h;
            int[] rgb_tmp = new int[3];

            INyARRgbPixelDriver reader = image.getRgbPixelDriver();

            // 変形先領域の頂点を取得

            //変換行列から現在の座標系への変換パラメタを作成
            calcPara(i_vertexs, conv_param);// 変換パラメータを求める
            for (int y = 0; y < ry2; y++)
            {
                for (int x = 0; x < rx2; x++)
                {
                    int ttx = (int)((conv_param[0] * x * y + conv_param[1] * x + conv_param[2] * y + conv_param[3]) + 0.5);
                    int tty = (int)((conv_param[4] * x * y + conv_param[5] * x + conv_param[6] * y + conv_param[7]) + 0.5);
                    reader.getPixel((int)ttx, (int)tty, rgb_tmp);
                    this._patdata[x + y * rx2] = (rgb_tmp[0] << 16) | (rgb_tmp[1] << 8) | rgb_tmp[2];
                }
            }
            return(true);
        }
 /**
  * コンストラクタです。
  * @param i_width
  * このラスタの幅
  * @param i_height
  * このラスタの高さ
  * @
  */
 public NyARColorPatt_PseudoAffine(int i_width, int i_height)
 {
     this._size = new NyARIntSize(i_width, i_height);
     this._patdata = new int[i_height * i_width];
     this._pixelreader = NyARRgbPixelDriverFactory.createDriver(this);
     //疑似アフィン変換のパラメタマトリクスを計算します。
     //長方形から計算すると、有効要素がm00,m01,m02,m03,m10,m11,m20,m23,m30になります。
     NyARDoubleMatrix44 mat = this._invmat;
     mat.m00 = 0;
     mat.m01 = 0;
     mat.m02 = 0;
     mat.m03 = 1.0;
     mat.m10 = 0;
     mat.m11 = i_width - 1;
     mat.m12 = 0;
     mat.m13 = 1.0;
     mat.m20 = (i_width - 1) * (i_height - 1);
     mat.m21 = i_width - 1;
     mat.m22 = i_height - 1;
     mat.m23 = 1.0;
     mat.m30 = 0;
     mat.m31 = 0;
     mat.m32 = i_height - 1;
     mat.m33 = 1.0;
     mat.inverse(mat);
     return;
 }
        public override void doFilter(int i_l, int i_t, int i_w, int i_h, int i_th, INyARGrayscaleRaster i_gsraster)
        {
            Debug.Assert(i_gsraster.isEqualBufferType(NyARBufferType.INT1D_BIN_8));
            INyARRgbPixelDriver input = this._raster.getRgbPixelDriver();

            int[]       output   = (int[])i_gsraster.getBuffer();
            int         th       = i_th * 3;
            NyARIntSize s        = i_gsraster.getSize();
            int         skip_dst = (s.w - i_w);
            int         skip_src = skip_dst;
            //左上から1行づつ走査していく
            int pt_dst = (i_t * s.w + i_l);

            int[] rgb = this.__rgb;
            for (int y = 0; y < i_h; y++)
            {
                int x;
                for (x = 0; x < i_w; x++)
                {
                    input.getPixel(x + i_l, y + i_t, rgb);
                    output[pt_dst++] = (rgb[0] + rgb[1] + rgb[2]) <= th ? 0 : 1;
                }
                //スキップ
                pt_dst += skip_dst;
            }
            return;
        }
Example #5
0
        /**
         * コンストラクタです。
         * @param i_width
         * このラスタの幅
         * @param i_height
         * このラスタの高さ
         * @
         */
        public NyARColorPatt_PseudoAffine(int i_width, int i_height)
        {
            this._size        = new NyARIntSize(i_width, i_height);
            this._patdata     = new int[i_height * i_width];
            this._pixelreader = NyARRgbPixelDriverFactory.createDriver(this);
            //疑似アフィン変換のパラメタマトリクスを計算します。
            //長方形から計算すると、有効要素がm00,m01,m02,m03,m10,m11,m20,m23,m30になります。
            NyARDoubleMatrix44 mat = this._invmat;

            mat.m00 = 0;
            mat.m01 = 0;
            mat.m02 = 0;
            mat.m03 = 1.0;
            mat.m10 = 0;
            mat.m11 = i_width - 1;
            mat.m12 = 0;
            mat.m13 = 1.0;
            mat.m20 = (i_width - 1) * (i_height - 1);
            mat.m21 = i_width - 1;
            mat.m22 = i_height - 1;
            mat.m23 = 1.0;
            mat.m30 = 0;
            mat.m31 = 0;
            mat.m32 = i_height - 1;
            mat.m33 = 1.0;
            mat.inverse(mat);
            return;
        }
Example #6
0
 public void switchRaster(INyARRaster i_ref_raster)
 {
     if (!(i_ref_raster is INyARRgbRaster))
     {
         throw new NyARException();
     }
     this._rgbd = ((INyARRgbRaster)i_ref_raster).getRgbPixelDriver();
 }
Example #7
0
 /**
  * コンストラクタです。
  * 解像度を指定して、インスタンスを生成します。
  * @param i_width
  * ラスタのサイズ
  * @param i_height
  * ラスタのサイズ
  * @
  */
 public NyARColorPatt_Base(int i_width, int i_height)
 {
     //入力制限
     Debug.Assert(i_width <= 64 && i_height <= 64);
     this._size        = new NyARIntSize(i_width, i_height);
     this._patdata     = new int[i_height * i_width];
     this._pixelreader = NyARRgbPixelDriverFactory.createDriver(this);
     return;
 }
 private void initInstance(int i_width, int i_height, int i_point_per_pix)
 {
     Debug.Assert(i_width > 2 && i_height > 2);
     this._sample_per_pixel = i_point_per_pix;
     this._size             = new NyARIntSize(i_width, i_height);
     this._patdata          = new int[i_height * i_width];
     this._pixelreader      = NyARRgbPixelDriverFactory.createDriver(this);
     return;
 }
 private void initInstance(int i_width, int i_height, int i_point_per_pix)
 {
     Debug.Assert(i_width > 2 && i_height > 2);
     this._sample_per_pixel = i_point_per_pix;
     this._size = new NyARIntSize(i_width, i_height);
     this._patdata = new int[i_height * i_width];
     this._pixelreader = NyARRgbPixelDriverFactory.createDriver(this);
     return;
 }
 /**
  * コンストラクタです。
  * 解像度を指定して、インスタンスを生成します。
  * @param i_width
  * ラスタのサイズ
  * @param i_height
  * ラスタのサイズ
  * @ 
  */
 public NyARColorPatt_Base(int i_width, int i_height)
 {
     //入力制限
     Debug.Assert(i_width <= 64 && i_height <= 64);
     this._size = new NyARIntSize(i_width, i_height);
     this._patdata = new int[i_height * i_width];
     this._pixelreader = NyARRgbPixelDriverFactory.createDriver(this);
     return;
 }
Example #11
0
        public void setPixels(int[] i_x, int[] i_y, int i_num, int[] i_intgs)
        {
            INyARRgbPixelDriver r = this._rgbd;

            for (int i = i_num - 1; i >= 0; i--)
            {
                int gs = i_intgs[i];
                r.setPixel(i_x[i], i_y[i], gs, gs, gs);
            }
        }
Example #12
0
        public void getPixelSet(int[] i_x, int[] i_y, int i_n, int[] o_buf, int i_st_buf)
        {
            INyARRgbPixelDriver r = this._rgbd;

            int[] tmp = this._tmp;
            for (int i = i_n - 1; i >= 0; i--)
            {
                r.getPixel(i_x[i], i_y[i], tmp);
                o_buf[i_st_buf + i] = (tmp[0] + tmp[1] + tmp[2]) / 3;
            }
            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);
                }
            }
        }
Example #14
0
        public double makeColorData(int[] o_out)
        {
            NyARIntSize         size   = this._ref_raster.getSize();
            INyARRgbPixelDriver pixdev = this._ref_raster.getRgbPixelDriver();

            int[] rgb   = this.__rgb;
            int   width = size.w;
            //<平均値計算>
            int ave = 0;//<PV/>

            for (int y = size.h - 1; y >= 0; y--)
            {
                for (int x = width - 1; x >= 0; x--)
                {
                    pixdev.getPixel(x, y, rgb);
                    ave += rgb[0] + rgb[1] + rgb[2];
                }
            }
            //<平均値計算>
            int number_of_pix = size.w * size.h;

            ave = number_of_pix * 255 * 3 - ave;
            ave = 255 - (ave / (number_of_pix * 3));//(255-R)-ave を分解するための事前計算

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

            //<差分値計算>
            for (int y = size.h - 1; y >= 0; y--)
            {
                for (int x = width - 1; x >= 0; x--)
                {
                    pixdev.getPixel(x, y, rgb);
                    w_sum = (ave - rgb[2]); o_out[input_ptr--] = w_sum; sum += w_sum * w_sum; //B
                    w_sum = (ave - rgb[1]); o_out[input_ptr--] = w_sum; sum += w_sum * w_sum; //G
                    w_sum = (ave - rgb[0]); o_out[input_ptr--] = w_sum; sum += w_sum * w_sum; //R
                }
            }
            //<差分値計算(FORの1/8展開)/>
            double p = Math.Sqrt((double)sum);

            return(p != 0.0 ? p : 0.0000001);
        }
        public void createHistogram(int i_l, int i_t, int i_w, int i_h, int i_skip, NyARHistogram o_histogram)
        {
            o_histogram.reset();
            int[] data_ptr          = o_histogram.data;
            INyARRgbPixelDriver drv = this._gsr.getRgbPixelDriver();
            int pix_count           = i_w;
            int pix_mod_part        = pix_count - (pix_count % 8);

            //左上から1行づつ走査していく
            for (int y = i_h - 1; y >= 0; y -= i_skip)
            {
                for (int x = pix_count - 1; x >= pix_mod_part; x--)
                {
                    drv.getPixel(x, y, tmp);
                    data_ptr[(tmp[0] + tmp[1] + tmp[2]) / 3]++;
                }
            }
            o_histogram.total_of_data = i_w * i_h / i_skip;
            return;
        }
        public void convertRect(int l, int t, int w, int h, INyARGrayscaleRaster o_raster)
        {
            int[] wk        = this._wk;
            int   b         = t + h;
            int   pix_count = w;

            switch (o_raster.getBufferType())
            {
            default:
                INyARGsPixelDriver  out_drv = o_raster.getGsPixelDriver();
                INyARRgbPixelDriver in_drv  = this._ref_raster.getRgbPixelDriver();
                for (int y = t; y < b; y++)
                {
                    for (int x = pix_count - 1; x >= 0; x--)
                    {
                        in_drv.getPixel(x, y, wk);
                        out_drv.setPixel(x, y, (306 * (wk[2] & 0xff) + 601 * (wk[1] & 0xff) + 117 * (wk[0] & 0xff)) >> 10);
                    }
                }
                return;
            }
        }
Example #17
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);
        }
        //分割数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;
        }
Example #19
0
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            BitmapData in_bmp = this._ref_raster.lockBitmap();
            int        in_w   = this._ref_raster.getWidth();
            int        in_h   = this._ref_raster.getHeight();

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

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

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

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

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

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

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

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

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

                            int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                            r = (px >> 16) & 0xff;  // R
                            g = (px >> 8) & 0xff;   // G
                            b = (px) & 0xff;        // B
                            cp7_cy_1_cp6_cx   += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;
                            out_reader.setPixel(ix, iy, r, g, b);
                        }
                        cp7_cy_1   += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    this._ref_raster.unlockBitmap();
                    return(true);
                }
                break;
            }
            this._ref_raster.unlockBitmap();
            return(false);
        }
 /**
  * Readerとbufferを初期化する関数です。コンストラクタから呼び出します。
  * 継承クラスでこの関数を拡張することで、対応するバッファタイプの種類を増やせます。
  * @param i_size
  * ラスタのサイズ
  * @param i_raster_type
  * バッファタイプ
  * @param i_is_alloc
  * 外部参照/内部バッファのフラグ
  * @return
  * 初期化が成功すると、trueです。
  * @
  */
 protected virtual void initInstance(NyARIntSize i_size, int i_raster_type, bool i_is_alloc)
 {
     //バッファの構築
     switch (i_raster_type)
     {
         case NyARBufferType.INT1D_X8R8G8B8_32:
             this._buf = i_is_alloc ? new int[i_size.w * i_size.h] : null;
             break;
         case NyARBufferType.BYTE1D_B8G8R8X8_32:
         case NyARBufferType.BYTE1D_X8R8G8B8_32:
             this._buf = i_is_alloc ? new byte[i_size.w * i_size.h * 4] : null;
             break;
         case NyARBufferType.BYTE1D_R8G8B8_24:
         case NyARBufferType.BYTE1D_B8G8R8_24:
             this._buf = i_is_alloc ? new byte[i_size.w * i_size.h * 3] : null;
             break;
         case NyARBufferType.WORD1D_R5G6B5_16LE:
             this._buf = i_is_alloc ? new short[i_size.w * i_size.h] : null;
             break;
         default:
             throw new NyARException();
     }
     //readerの構築
     this._rgb_pixel_driver = NyARRgbPixelDriverFactory.createDriver(this);
     this._is_attached_buffer = i_is_alloc;
     return;
 }
Example #21
0
        protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out)
        {
            BitmapData in_bmp  = this._ref_raster.lockBitmap();
            int        in_w    = this._ref_raster.getWidth();
            int        in_h    = this._ref_raster.getHeight();
            int        res_pix = i_resolution * i_resolution;

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

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();

            if (o_out is NyARBitmapRaster)
            {
                NyARBitmapRaster bmr = ((NyARBitmapRaster)o_out);
                BitmapData       bm  = bmr.lockBitmap();
                for (int iy = out_h - 1; iy >= 0; iy--)
                {
                    //解像度分の点を取る。
                    for (int ix = out_w - 1; ix >= 0; ix--)
                    {
                        int r, g, b;
                        r = g = b = 0;
                        int    cy = pk_t + iy * i_resolution;
                        int    cx = pk_l + ix * i_resolution;
                        double cp7_cy_1_cp6_cx_b   = cp7 * cy + 1.0 + cp6 * cx;
                        double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                        double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                        for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                        {
                            double cp7_cy_1_cp6_cx   = cp7_cy_1_cp6_cx_b;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                            for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0)
                                {
                                    x = 0;
                                }
                                else if (x >= in_w)
                                {
                                    x = in_w - 1;
                                }
                                if (y < 0)
                                {
                                    y = 0;
                                }
                                else if (y >= in_h)
                                {
                                    y = in_h - 1;
                                }

                                int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                                r += (px >> 16) & 0xff; // R
                                g += (px >> 8) & 0xff;  // G
                                b += (px) & 0xff;       // B
                                cp7_cy_1_cp6_cx   += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                            }
                            cp7_cy_1_cp6_cx_b   += cp7;
                            cp1_cy_cp2_cp0_cx_b += cp1;
                            cp4_cy_cp5_cp3_cx_b += cp4;
                        }
                        Marshal.WriteInt32(bm.Scan0, ix * 4 + iy * bm.Stride,
                                           (0x00ff0000 & ((r / res_pix) << 16)) | (0x0000ff00 & ((g / res_pix) << 8)) | (0x0000ff & (b / res_pix)));
                    }
                }
                bmr.unlockBitmap();
                this._ref_raster.unlockBitmap();
                return(true);
            }
            else if (o_out is INyARRgbRaster)
            {
                INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                for (int iy = out_h - 1; iy >= 0; iy--)
                {
                    //解像度分の点を取る。
                    for (int ix = out_w - 1; ix >= 0; ix--)
                    {
                        int r, g, b;
                        r = g = b = 0;
                        int    cy = pk_t + iy * i_resolution;
                        int    cx = pk_l + ix * i_resolution;
                        double cp7_cy_1_cp6_cx_b   = cp7 * cy + 1.0 + cp6 * cx;
                        double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                        double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                        for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                        {
                            double cp7_cy_1_cp6_cx   = cp7_cy_1_cp6_cx_b;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                            for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0)
                                {
                                    x = 0;
                                }
                                else if (x >= in_w)
                                {
                                    x = in_w - 1;
                                }
                                if (y < 0)
                                {
                                    y = 0;
                                }
                                else if (y >= in_h)
                                {
                                    y = in_h - 1;
                                }

                                int px = Marshal.ReadInt32(in_bmp.Scan0, (x * 4 + y * in_bmp.Stride));
                                r += (px >> 16) & 0xff; // R
                                g += (px >> 8) & 0xff;  // G
                                b += (px) & 0xff;       // B
                                cp7_cy_1_cp6_cx   += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                            }
                            cp7_cy_1_cp6_cx_b   += cp7;
                            cp1_cy_cp2_cp0_cx_b += cp1;
                            cp4_cy_cp5_cp3_cx_b += cp4;
                        }
                        out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix);
                    }
                }
                this._ref_raster.unlockBitmap();
                return(true);
            }
            else
            {
                throw new NyARException();
            }
        }
        protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out)
        {
            int res_pix = i_resolution * i_resolution;

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

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

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();

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

                                i_in_reader.getPixel(x, y, rgb_tmp);
                                r += rgb_tmp[0];
                                g += rgb_tmp[1];
                                b += rgb_tmp[2];
                                cp7_cy_1_cp6_cx   += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                            }
                            cp7_cy_1_cp6_cx_b   += cp7;
                            cp1_cy_cp2_cp0_cx_b += cp1;
                            cp4_cy_cp5_cp3_cx_b += cp4;
                        }
                        r          /= res_pix;
                        g          /= res_pix;
                        b          /= res_pix;
                        pat_data[p] = ((r & 0xff) << 16) | ((g & 0xff) << 8) | ((b & 0xff));
                        p--;
                    }
                }
                return(true);

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

                                    i_in_reader.getPixel(x, y, rgb_tmp);
                                    r += rgb_tmp[0];
                                    g += rgb_tmp[1];
                                    b += rgb_tmp[2];
                                    cp7_cy_1_cp6_cx   += cp6;
                                    cp1_cy_cp2_cp0_cx += cp0;
                                    cp4_cy_cp5_cp3_cx += cp3;
                                }
                                cp7_cy_1_cp6_cx_b   += cp7;
                                cp1_cy_cp2_cp0_cx_b += cp1;
                                cp4_cy_cp5_cp3_cx_b += cp4;
                            }
                            out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix);
                        }
                    }
                    return(true);
                }
                break;
            }
            return(false);
        }
 public void switchRaster(INyARRaster i_ref_raster)
 {
     if (!(i_ref_raster is INyARRgbRaster))
     {
         throw new NyARException();
     }
     this._rgbd = ((INyARRgbRaster)i_ref_raster).getRgbPixelDriver();
 }
 public NyARGsPixelDriver_RGBX(INyARRgbRaster i_raster)
 {
     this._rgbd = i_raster.getRgbPixelDriver();
 }
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            byte[] i_in_buf = (byte[])this._ref_raster.getBuffer();
            int    in_w     = this._ref_raster.getWidth();
            int    in_h     = this._ref_raster.getHeight();
            //ピクセルリーダーを取得
            double cp0 = cpara[0];
            double cp3 = cpara[3];
            double cp6 = cpara[6];
            double cp1 = cpara[1];
            double cp4 = cpara[4];
            double cp7 = cpara[7];

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

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

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

                        int bp = (x + y * in_w) * 3;
                        r = (i_in_buf[bp + 0] & 0xff);
                        g = (i_in_buf[bp + 1] & 0xff);
                        b = (i_in_buf[bp + 2] & 0xff);
                        cp7_cy_1_cp6_cx   += cp6;
                        cp1_cy_cp2_cp0_cx += cp0;
                        cp4_cy_cp5_cp3_cx += cp3;
                        pat_data[p]        = (r << 16) | (g << 8) | ((b & 0xff));
                        p++;
                    }
                    cp7_cy_1   += cp7;
                    cp1_cy_cp2 += cp1;
                    cp4_cy_cp5 += cp4;
                }
                return(true);

            default:
                if (o_out is INyARRgbRaster)
                {
                    INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx   = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;

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

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

                            out_reader.setPixel(ix, iy, r, g, b);
                        }
                        cp7_cy_1   += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    return(true);
                }
                break;
            }
            return(false);
        }
Example #26
0
        /**
         * この関数は、元画像を回転してから、差分画像を生成して、格納します。
         * 制限として、この関数はあまり高速ではありません。連続使用するときは、最適化を検討してください。
         * @param i_raster
         * 差分画像の元画像。サイズは、このインスタンスと同じである必要があります。
         * @param i_direction
         * 右上の位置です。0=1象限、1=2象限、、2=3象限、、3=4象限の位置に対応します。
         * @
         */
        public void setRaster(INyARRgbRaster i_raster, int i_direction)
        {
            int width                  = this._size.w;
            int height                 = this._size.h;
            int i_number_of_pix        = width * height;
            INyARRgbPixelDriver reader = i_raster.getRgbPixelDriver();

            int[] rgb  = new int[3];
            int[] dout = this._data;
            int   ave;//<PV/>

            //<平均値計算>
            ave = 0;
            for (int y = height - 1; y >= 0; y--)
            {
                for (int x = width - 1; x >= 0; x--)
                {
                    reader.getPixel(x, y, rgb);
                    ave += rgb[0] + rgb[1] + rgb[2];
                }
            }
            //<平均値計算>
            ave = i_number_of_pix * 255 * 3 - ave;
            ave = 255 - (ave / (i_number_of_pix * 3));//(255-R)-ave を分解するための事前計算

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

            switch (i_direction)
            {
            case 0:
                for (int y = height - 1; y >= 0; y--)
                {
                    for (int x = width - 1; x >= 0; x--)
                    {
                        reader.getPixel(x, y, rgb);
                        w_sum = (ave - rgb[2]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //B
                        w_sum = (ave - rgb[1]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //G
                        w_sum = (ave - rgb[0]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //R
                    }
                }
                break;

            case 1:
                for (int x = 0; x < width; x++)
                {
                    for (int y = height - 1; y >= 0; y--)
                    {
                        reader.getPixel(x, y, rgb);
                        w_sum = (ave - rgb[2]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //B
                        w_sum = (ave - rgb[1]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //G
                        w_sum = (ave - rgb[0]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //R
                    }
                }
                break;

            case 2:
                for (int y = 0; y < height; y++)
                {
                    for (int x = 0; x < width; x++)
                    {
                        reader.getPixel(x, y, rgb);
                        w_sum = (ave - rgb[2]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //B
                        w_sum = (ave - rgb[1]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //G
                        w_sum = (ave - rgb[0]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //R
                    }
                }
                break;

            case 3:
                for (int x = width - 1; x >= 0; x--)
                {
                    for (int y = 0; y < height; y++)
                    {
                        reader.getPixel(x, y, rgb);
                        w_sum = (ave - rgb[2]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //B
                        w_sum = (ave - rgb[1]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //G
                        w_sum = (ave - rgb[0]); dout[input_ptr--] = w_sum; sum += w_sum * w_sum;    //R
                    }
                }
                break;
            }
            //<差分値計算>
            //<差分値計算(FORの1/8展開)/>
            double p = Math.Sqrt((double)sum);

            this._pow = (p != 0.0 ? p : 0.0000001);
        }
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            int[] rgb_tmp = this.__pickFromRaster_rgb_tmp;
            int   in_w    = this._ref_raster.getWidth();
            int   in_h    = this._ref_raster.getHeight();

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

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

            INyARRgbPixelDriver i_in_reader = this._ref_raster.getRgbPixelDriver();

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

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

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

                        pat_data[p] = (rgb_tmp[0] << 16) | (rgb_tmp[1] << 8) | ((rgb_tmp[2] & 0xff));
                        p++;
                    }
                    cp7_cy_1   += cp7;
                    cp1_cy_cp2 += cp1;
                    cp4_cy_cp5 += cp4;
                }
                return(true);

            default:
                //ANY to RGBx
                if (o_out is INyARRgbRaster)
                {
                    INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                    for (int iy = 0; iy < out_h; iy++)
                    {
                        //解像度分の点を取る。
                        double cp7_cy_1_cp6_cx   = cp7_cy_1;
                        double cp1_cy_cp2_cp0_cx = cp1_cy_cp2;
                        double cp4_cy_cp5_cp3_cx = cp4_cy_cp5;
                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0)
                            {
                                x = 0;
                            }
                            else if (x >= in_w)
                            {
                                x = in_w - 1;
                            }
                            if (y < 0)
                            {
                                y = 0;
                            }
                            else if (y >= in_h)
                            {
                                y = in_h - 1;
                            }

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

                            out_reader.setPixel(ix, iy, rgb_tmp);
                        }
                        cp7_cy_1   += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    return(true);
                }
                break;
            }
            return(false);
        }
        protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out)
        {
            int res_pix = i_resolution * i_resolution;

            byte[] i_in_buf = (byte[])this._ref_raster.getBuffer();
            int    in_w     = this._ref_raster.getWidth();
            int    in_h     = this._ref_raster.getHeight();

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

            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();

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

                                int bp = (x + y * in_w) * 3;
                                r += (i_in_buf[bp + 0] & 0xff);
                                g += (i_in_buf[bp + 1] & 0xff);
                                b += (i_in_buf[bp + 2] & 0xff);
                                cp7_cy_1_cp6_cx   += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                            }
                            cp7_cy_1_cp6_cx_b   += cp7;
                            cp1_cy_cp2_cp0_cx_b += cp1;
                            cp4_cy_cp5_cp3_cx_b += cp4;
                        }
                        out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix);
                    }
                }
                return(true);
            }
            return(false);
        }
Example #29
0
        protected override bool multiPixel(int pk_l, int pk_t, double[] cpara, int i_resolution, INyARRaster o_out)
        {
            Color32[] in_pixs = (Color32[])this._ref_raster.getBuffer();
            int       in_w    = this._ref_raster.getWidth();
            int       in_h    = this._ref_raster.getHeight();
            int       res_pix = i_resolution * i_resolution;

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

            int step, offset;
            int out_w = o_out.getWidth();
            int out_h = o_out.getHeight();

            if (o_out is INyARRgbRaster)
            {
                INyARRgbPixelDriver out_reader = ((INyARRgbRaster)o_out).getRgbPixelDriver();
                if (this._is_inv_v)
                {
                    offset = in_w * (in_h - 1);
                    step   = -in_w;
                }
                else
                {
                    offset = 0;
                    step   = in_w;
                }
                for (int iy = out_h - 1; iy >= 0; iy--)
                {
                    //解像度分の点を取る。
                    for (int ix = out_w - 1; ix >= 0; ix--)
                    {
                        int r, g, b;
                        r = g = b = 0;
                        int    cy = pk_t + iy * i_resolution;
                        int    cx = pk_l + ix * i_resolution;
                        double cp7_cy_1_cp6_cx_b   = cp7 * cy + 1.0 + cp6 * cx;
                        double cp1_cy_cp2_cp0_cx_b = cp1 * cy + cp2 + cp0 * cx;
                        double cp4_cy_cp5_cp3_cx_b = cp4 * cy + cp5 + cp3 * cx;
                        for (int i2y = i_resolution - 1; i2y >= 0; i2y--)
                        {
                            double cp7_cy_1_cp6_cx   = cp7_cy_1_cp6_cx_b;
                            double cp1_cy_cp2_cp0_cx = cp1_cy_cp2_cp0_cx_b;
                            double cp4_cy_cp5_cp3_cx = cp4_cy_cp5_cp3_cx_b;
                            for (int i2x = i_resolution - 1; i2x >= 0; i2x--)
                            {
                                //1ピクセルを作成
                                double d = 1 / (cp7_cy_1_cp6_cx);
                                int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                                int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                                if (x < 0)
                                {
                                    x = 0;
                                }
                                else if (x >= in_w)
                                {
                                    x = in_w - 1;
                                }
                                if (y < 0)
                                {
                                    y = 0;
                                }
                                else if (y >= in_h)
                                {
                                    y = in_h - 1;
                                }
                                Color32 px = in_pixs[x + offset + step * y];
                                r += px.r; // R
                                g += px.g; // G
                                b += px.b; // B
                                cp7_cy_1_cp6_cx   += cp6;
                                cp1_cy_cp2_cp0_cx += cp0;
                                cp4_cy_cp5_cp3_cx += cp3;
                            }
                            cp7_cy_1_cp6_cx_b   += cp7;
                            cp1_cy_cp2_cp0_cx_b += cp1;
                            cp4_cy_cp5_cp3_cx_b += cp4;
                        }
                        out_reader.setPixel(ix, iy, r / res_pix, g / res_pix, b / res_pix);
                    }
                }
                return(true);
            }
            return(false);
        }
Example #30
0
        protected override bool onePixel(int pk_l, int pk_t, double[] cpara, INyARRaster o_out)
        {
            Color32[] in_pixs = (Color32[])this._ref_raster.getBuffer();
            int       in_w    = this._ref_raster.getWidth();
            int       in_h    = this._ref_raster.getHeight();

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

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

            int step, offset;

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

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

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

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

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

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

                        for (int ix = 0; ix < out_w; ix++)
                        {
                            //1ピクセルを作成
                            double d = 1 / (cp7_cy_1_cp6_cx);
                            int    x = (int)((cp1_cy_cp2_cp0_cx) * d);
                            int    y = (int)((cp4_cy_cp5_cp3_cx) * d);
                            if (x < 0)
                            {
                                x = 0;
                            }
                            else if (x >= in_w)
                            {
                                x = in_w - 1;
                            }
                            if (y < 0)
                            {
                                y = 0;
                            }
                            else if (y >= in_h)
                            {
                                y = in_h - 1;
                            }
                            Color32 px = in_pixs[x + offset + step * y];
                            cp7_cy_1_cp6_cx   += cp6;
                            cp1_cy_cp2_cp0_cx += cp0;
                            cp4_cy_cp5_cp3_cx += cp3;
                            out_reader.setPixel(ix, iy, px.r, px.g, px.b);
                        }
                        cp7_cy_1   += cp7;
                        cp1_cy_cp2 += cp1;
                        cp4_cy_cp5 += cp4;
                    }
                    return(true);
                }
                break;
            }
            return(false);
        }
Example #31
0
 public NyARGsPixelDriver_RGBX(INyARRgbRaster i_raster)
 {
     this._rgbd = i_raster.getRgbPixelDriver();
 }