Beispiel #1
0
        public override void BlitToMemory(Media.BasicBox srcBox, Media.PixelBox dst)
        {
            if (!this.Buffer.Contains(srcBox))
            {
                throw new ArgumentOutOfRangeException("srcBox", "source box out of range.");
            }

            if (srcBox.Left == 0 && srcBox.Right == width && srcBox.Top == 0 && srcBox.Bottom == height && srcBox.Front == 0 && srcBox.Back == depth && dst.Width == width && dst.Height == height && dst.Depth == depth && GLES2PixelUtil.GetGLOriginFormat(dst.Format) != 0)
            {
                //The direct case: the user wants the entire texture in a format supported by GL
                //so we don't need an intermediate buffer
                this.Download(dst);
            }
            else
            {
                //Use buffer for intermediate copy
                this.AllocateBuffer();
                //Download entire buffer
                this.Download(this.Buffer);
                if (srcBox.Width != dst.Width || srcBox.Height != dst.Height || srcBox.Depth != dst.Depth)
                {
                    //We need scaling
                    Image.Scale(this.Buffer.GetSubVolume(srcBox), dst, ImageFilter.Bilinear);
                }
                else
                {
                    //Just copy the bit that we need
                    PixelConverter.BulkPixelConversion(this.Buffer.GetSubVolume(srcBox), dst);
                }

                this.FreeBuffer();
            }
        }
Beispiel #2
0
        public override void BlitFromMemory(Media.PixelBox src, Media.BasicBox dstBox)
        {
            if (this.Buffer.Contains(dstBox) == false)
            {
                throw new ArgumentOutOfRangeException("dstBox", "Destination box out of range");
            }

            PixelBox scaled;

            if (src.Width != dstBox.Width || src.Height != dstBox.Height || src.Depth != dstBox.Depth)
            {
                //Scale to destination size
                //This also does pixel format conversion if needed
                this.AllocateBuffer();
                scaled = this.Buffer.GetSubVolume(dstBox);
                Image.Scale(src, scaled, ImageFilter.Bilinear);
            }
            else if ((src.Format != format) || ((GLES2PixelUtil.GetGLOriginFormat(src.Format) == 0) && (src.Format != PixelFormat.R8G8B8)))
            {
                //Extents match, but format is not accepted as valid source format for GL
                //do conversion in temporary buffer
                this.AllocateBuffer();
                scaled = this.Buffer.GetSubVolume(dstBox);
                PixelConverter.BulkPixelConversion(src, scaled);
                if (src.Format == PixelFormat.A4R4G4B4)
                {
                    // ARGB->BGRA
                    GLES2PixelUtil.ConvertToGLFormat(ref scaled, ref scaled);
                }
            }
            else
            {
                this.AllocateBuffer();
                scaled = src.Clone();

                if (src.Format == PixelFormat.R8G8B8)
                {
                    scaled.Format = PixelFormat.B8G8R8;
                    PixelConverter.BulkPixelConversion(src, scaled);
                }
            }

            this.Upload(scaled, dstBox);
            this.FreeBuffer();
        }