示例#1
0
        /// <inheritdoc />
        protected override void CopyFromXYZW(PixelRow <Color, uint> row, int targetY, int targetX, int width)
        {
            byte *source      = row.PixelBase;
            byte *destination = this.GetRowPointer(targetY) + targetX;

            Unsafe.CopyBlock(destination, source, (uint)width * 4);
        }
示例#2
0
        protected override void CopyToBGRA(PixelRow <Color, uint> row, int sourceY, int width)
        {
            byte *source      = this.GetRowPointer(sourceY);
            byte *destination = row.DataPointer;

            for (int x = 0; x < width; x++)
            {
                if (BitConverter.IsLittleEndian)
                {
                    *destination = *(source + 1);
                    *(destination + 1) = *(source + 2);
                    *(destination + 2) = *(source + 3);
                    *(destination + 3) = *source;
                }
                else
                {
                    *destination = *source;
                    *(destination + 1) = *(source + 3);
                    *(destination + 2) = *(source + 2);
                    *(destination + 3) = *(source + 1);
                }

                source      += 4;
                destination += 4;
            }
        }
示例#3
0
        /// <inheritdoc />
        protected override void CopyToZYX(PixelRow <Color, uint> row, int sourceY, int width)
        {
            byte *source      = this.GetRowPointer(sourceY);
            byte *destination = row.PixelBase;

            for (int x = 0; x < width; x++)
            {
                // TODO: Do we need this? Only the encoder/decoder cares about the endianess. We should pass it in LittleEndian and let them work it out.
                if (BitConverter.IsLittleEndian)
                {
                    *destination = *(source + 1);
                    *(destination + 1) = *(source + 2);
                    *(destination + 2) = *(source + 3);
                }
                else
                {
                    *destination = *(source + 3);
                    *(destination + 1) = *(source + 2);
                    *(destination + 2) = *(source + 1);
                }

                source      += 4;
                destination += 3;
            }
        }
示例#4
0
        /// <summary>
        /// Copies to a row in <see cref="ComponentOrder.XYZW"/> format.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="sourceY">The target row index.</param>
        /// <param name="width">The width.</param>
        protected virtual void CopyToXYZW(PixelRow <TColor, TPacked> row, int sourceY, int width)
        {
            int offset = 0;

            for (int x = 0; x < width; x++)
            {
                this[x, sourceY].ToBytes(row.Bytes, offset, ComponentOrder.XYZW);
                offset += 4;
            }
        }
示例#5
0
        protected override void CopyFromBGRA(PixelRow <Color, uint> row, int targetY, int width)
        {
            byte *source      = row.DataPointer;
            byte *destination = this.GetRowPointer(targetY);

            for (int x = 0; x < width; x++)
            {
                Unsafe.Write(destination, (uint)(*(source + 2) << 24 | *(source + 1) << 16 | *source << 8 | *(source + 3)));

                source      += 4;
                destination += 4;
            }
        }
示例#6
0
        /// <inheritdoc />
        protected override void CopyFromZYX(PixelRow <Color, uint> row, int targetY, int targetX, int width)
        {
            byte *source      = row.PixelBase;
            byte *destination = this.GetRowPointer(targetY) + targetX;

            for (int x = 0; x < width; x++)
            {
                Unsafe.Write(destination, (uint)(*(source + 2) << 0 | *(source + 1) << 8 | *source << 16 | 255 << 24));

                source      += 3;
                destination += 4;
            }
        }
示例#7
0
        /// <inheritdoc />
        protected override void CopyToZYX(PixelRow <Color, uint> row, int sourceY, int width)
        {
            byte *source      = this.GetRowPointer(sourceY);
            byte *destination = row.PixelBase;

            for (int x = 0; x < width; x++)
            {
                *destination = *(source + 2);
                *(destination + 1) = *(source + 1);
                *(destination + 2) = *(source + 0);

                source      += 4;
                destination += 3;
            }
        }
示例#8
0
        /// <summary>
        /// Copies from a row in <see cref="ComponentOrder.XYZW"/> format.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="targetY">The target row index.</param>
        /// <param name="targetX">The target column index.</param>
        /// <param name="width">The width.</param>
        protected virtual void CopyFromXYZW(PixelRow <TColor, TPacked> row, int targetY, int targetX, int width)
        {
            byte *source      = row.PixelBase;
            byte *destination = this.GetRowPointer(targetY) + targetX;

            TColor packed = default(TColor);
            int    size   = Unsafe.SizeOf <TColor>();

            for (int x = 0; x < width; x++)
            {
                packed.PackFromBytes(*source, *(source + 1), *(source + 2), *(source + 3));
                Unsafe.Write(destination, packed);

                source      += 4;
                destination += size;
            }
        }
示例#9
0
        /// <summary>
        /// Copied a row of pixels to the image.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="sourceY">The source row index.</param>
        /// <exception cref="NotSupportedException">
        /// Thrown when an unsupported component order value is passed.
        /// </exception>
        public void CopyTo(PixelRow <TColor, TPacked> row, int sourceY)
        {
            switch (row.ComponentOrder)
            {
            case ComponentOrder.ZYX:
                this.CopyToZYX(row, sourceY, Math.Min(row.Width, this.Width));
                break;

            case ComponentOrder.ZYXW:
                this.CopyToZYXW(row, sourceY, Math.Min(row.Width, this.Width));
                break;

            case ComponentOrder.XYZ:
                this.CopyToXYZ(row, sourceY, Math.Min(row.Width, this.Width));
                break;

            case ComponentOrder.XYZW:
                this.CopyToXYZW(row, sourceY, Math.Min(row.Width, this.Width));
                break;

            default:
                throw new NotSupportedException();
            }
        }
示例#10
0
        /// <summary>
        /// Copied a row of pixels from the image.
        /// </summary>
        /// <param name="row">The row.</param>
        /// <param name="targetY">The target row index.</param>
        /// <param name="targetX">The target column index.</param>
        /// <exception cref="NotSupportedException">
        /// Thrown when an unsupported component order value is passed.
        /// </exception>
        public void CopyFrom(PixelRow <TColor, TPacked> row, int targetY, int targetX = 0)
        {
            switch (row.ComponentOrder)
            {
            case ComponentOrder.ZYX:
                this.CopyFromZYX(row, targetY, targetX, Math.Min(row.Width, this.Width));
                break;

            case ComponentOrder.ZYXW:
                this.CopyFromZYXW(row, targetY, targetX, Math.Min(row.Width, this.Width));
                break;

            case ComponentOrder.XYZ:
                this.CopyFromXYZ(row, targetY, targetX, Math.Min(row.Width, this.Width));
                break;

            case ComponentOrder.XYZW:
                this.CopyFromXYZW(row, targetY, targetX, Math.Min(row.Width, this.Width));
                break;

            default:
                throw new NotSupportedException();
            }
        }
示例#11
0
        public void CopyTo(PixelRow <TColor, TPacked> row, int sourceY)
        {
            switch (row.ComponentOrder)
            {
            case ComponentOrder.BGR:
                this.CopyToBGR(row, sourceY, Math.Min(row.Width, this.Width));
                break;

            case ComponentOrder.BGRA:
                this.CopyToBGRA(row, sourceY, Math.Min(row.Width, this.Width));
                break;

            case ComponentOrder.RGB:
                this.CopyToRGB(row, sourceY, Math.Min(row.Width, this.Width));
                break;

            case ComponentOrder.RGBA:
                this.CopyToRGBA(row, sourceY, Math.Min(row.Width, this.Width));
                break;

            default:
                throw new NotSupportedException();
            }
        }