Ejemplo n.º 1
0
        /* DsXRGB32Rasterの内容を保持しているテクスチャにコピーします。
         * i_rasterのサイズは、このインスタンスに指定したテクスチャサイズ(コンストラクタ等に指定したサイズ)と同じである必要です。
         * ラスタデータはテクスチャの左上を基点にwidth x heightだけコピーされ、残りの部分は更新されません。
         */
        public void setRaster(INyARRgbRaster i_raster)
        {
            Debug.Assert(!this._is_dispose);
            int pitch;

            using (GraphicsStream texture_rect = this.m_texture.LockRectangle(0, LockFlags.None, out pitch))
            {
                try{
                    int dst = (int)texture_rect.InternalData;
                    switch (i_raster.getBufferType())
                    {
                    case NyARBufferType.BYTE1D_B8G8R8X8_32:
                    {
                        byte[] buf = (byte[])i_raster.getBuffer();
                        //テクスチャのピッチって何?
                        int src_w = this.m_width * 4;
                        int src   = 0;
                        for (int r = this.m_height - 1; r >= 0; r--)
                        {
                            Marshal.Copy(buf, src, (IntPtr)dst, pitch);
                            dst += pitch;
                            src += src_w;
                        }
                    }
                    break;

                    case NyARBufferType.OBJECT_CS_Bitmap:
                        NyARBitmapRaster ra = (NyARBitmapRaster)(i_raster);
                        BitmapData       bm = ra.lockBitmap();
                        try
                        {
                            int src = (int)bm.Scan0;
                            for (int r = this.m_height - 1; r >= 0; r--)
                            {
                                NyARD3dUtil.RtlCopyMemory((IntPtr)dst, (IntPtr)src, pitch);
                                dst += pitch;
                                src += bm.Stride;
                            }
                        }
                        finally
                        {
                            ra.unlockBitmap();
                        }
                        break;

                    default:
                        throw new NyARException();
                    }
                }
                finally
                {
                    //テクスチャをアンロックする
                    this.m_texture.UnlockRectangle(0);
                }
            }
            return;
        }
Ejemplo n.º 2
0
        /* DsXRGB32Rasterの内容を保持しているサーフェイスにコピーします。
         */
        public void setRaster(INyARRgbRaster i_sample)
        {
            Debug.Assert(!this._is_dispose);
            int pitch;
            int s_stride = this.m_width * 4;

            using (GraphicsStream gs = this._surface.LockRectangle(LockFlags.None, out pitch))
            {
                try{
                    switch (i_sample.getBufferType())
                    {
                    case NyARBufferType.BYTE1D_B8G8R8X8_32:
                        if (pitch % s_stride == 0)
                        {
                            Marshal.Copy((byte[])i_sample.getBuffer(), 0, (IntPtr)((int)gs.InternalData), this.m_width * 4 * this.m_height);
                        }
                        else
                        {
                            int s_idx = 0;
                            int d_idx = (int)gs.InternalData;
                            for (int i = this.m_height - 1; i >= 0; i--)
                            {
                                //どう考えてもポインタです。
                                Marshal.Copy((byte[])i_sample.getBuffer(), s_idx, (IntPtr)(d_idx), s_stride);
                                s_idx += s_stride;
                                d_idx += pitch;
                            }
                        }
                        break;

                    case NyARBufferType.OBJECT_CS_Bitmap:
                        NyARBitmapRaster ra = (NyARBitmapRaster)(i_sample);
                        BitmapData       bm = ra.lockBitmap();
                        try{
                            //コピー
                            int src = (int)bm.Scan0;
                            int dst = (int)gs.InternalData;
                            for (int r = this.m_height - 1; r >= 0; r--)
                            {
                                NyARD3dUtil.RtlCopyMemory((IntPtr)dst, (IntPtr)src, s_stride);
                                dst += pitch;
                                src += bm.Stride;
                            }
                        }finally{
                            ra.unlockBitmap();
                        }
                        break;

                    default:
                        throw new NyARException();
                    }
                }finally{
                    this._surface.UnlockRectangle();
                }
                return;
            }
        }