예제 #1
0
        /// <summary>
        /// Overlays pixel data from another <see cref="BitmapBuffer"/>, with alpha blending.
        /// </summary>
        /// <param name="x">
        /// The x-coordinate where to begin writing in this <see cref="BitmapBuffer"/>.</param>
        /// <param name="y">
        /// The y-coordinate where to begin writing in this <see cref="BitmapBuffer"/>.</param>
        /// <param name="source">
        /// Another <see cref="BitmapBuffer"/> containing the rectangle to overlay.</param>
        /// <param name="bounds">
        /// The pixel rectangle within the specified <paramref name="source"/> to overlay.</param>
        /// <param name="color">
        /// The <see cref="Color"/> to substitute for all <paramref name="source"/> pixels.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="source"/> is a null reference.</exception>
        /// <remarks><para>
        /// <b>Overlay</b> blends all <see cref="Pixels"/> elements within the specified <paramref
        /// name="bounds"/> of the specified <paramref name="source"/> buffer with the corresponding
        /// <see cref="Pixels"/> elements in this <see cref="BitmapBuffer"/>, starting with the
        /// specified <paramref name="x"/> and <paramref name="y"/> coordinates.
        /// </para><para>
        /// <b>Overlay</b> calls <see cref="BitmapUtility.BlendPbgra32"/> to perform alpha blending
        /// between the specified <paramref name="source"/> buffer (acting as the overlay) and this
        /// <see cref="BitmapBuffer"/> (acting as the blending target). No coordinate checking is
        /// performed.
        /// </para><para>
        /// <b>Overlay</b> substitutes the specified <paramref name="color"/> for the actual color
        /// channels of each <paramref name="source"/> pixel, while using its alpha channel to
        /// govern alpha blending with the corresponding <see cref="Pixels"/> element. The alpha
        /// channel of the specified <paramref name="color"/> is ignored.</para></remarks>

        public void Overlay(int x, int y, BitmapBuffer source, RectI bounds, Color color)
        {
            if (source == null)
            {
                ThrowHelper.ThrowArgumentNullException("source");
            }

            int sourceOffset = bounds.X + source._size.Width * bounds.Y;
            int targetOffset = x + _size.Width * y;

            for (int dy = 0; dy < bounds.Height; dy++)
            {
                for (int dx = 0; dx < bounds.Width; dx++)
                {
                    uint p0 = source._pixels[sourceOffset + dx];
                    uint p1 = _pixels[targetOffset + dx];

                    // multiply color channels with source alpha
                    color.A = (byte)(p0 >> 24);
                    p0      = BitmapUtility.ColorToPbgra32(color);

                    _pixels[targetOffset + dx] = BitmapUtility.BlendPbgra32(p0, p1);
                }

                sourceOffset += source._size.Width;
                targetOffset += _size.Width;
            }
        }
예제 #2
0
        /// <summary>
        /// Blends the specified pixel in the <see cref="BitmapBuffer"/> with the specified <see
        /// cref="Color"/>.</summary>
        /// <param name="x">
        /// The x-coordinate of the pixel to blend with <paramref name="color"/>.</param>
        /// <param name="y">
        /// The y-coordinate of the pixel to blend with <paramref name="color"/>.</param>
        /// <param name="color">
        /// The <see cref="Color"/> to blend with the pixel at the specified location in the <see
        /// cref="BitmapBuffer"/>.</param>
        /// <remarks><para>
        /// <b>BlendPixel</b> blends the <see cref="Pixels"/> element at the specified <paramref
        /// name="x"/> and <paramref name="y"/> coordinates with the <see
        /// cref="PixelFormats.Pbgra32"/> representation of the specified <paramref name="color"/>.
        /// </para><para>
        /// <b>BlendPixel</b> calls <see cref="BitmapUtility.BlendPbgra32"/> to perform alpha
        /// blending between the specified <paramref name="color"/> (acting as the overlay) and this
        /// <see cref="BitmapBuffer"/> (acting as the blending target). No coordinate checking is
        /// performed.</para></remarks>

        public void BlendPixel(int x, int y, Color color)
        {
            uint value = BitmapUtility.ColorToPbgra32(color);
            int  i     = x + _size.Width * y;

            _pixels[i] = BitmapUtility.BlendPbgra32(value, _pixels[i]);
        }
예제 #3
0
        /// <summary>
        /// Clears the <see cref="BitmapBuffer"/> with the specified <see cref="Color"/>.</summary>
        /// <param name="color">
        /// The new <see cref="Color"/> for all pixels in the <see cref="BitmapBuffer"/>.</param>
        /// <remarks>
        /// <b>Clear</b> sets all elements of the <see cref="Pixels"/> array to the <see
        /// cref="PixelFormats.Pbgra32"/> representation of the specified <paramref name="color"/>.
        /// </remarks>

        public void Clear(Color color)
        {
            uint value = BitmapUtility.ColorToPbgra32(color);

            for (int i = 0; i < _pixels.Length; i++)
            {
                _pixels[i] = value;
            }
        }
예제 #4
0
        public void ColorToPbgra32()
        {
            Assert.AreEqual(0xFF203040, BitmapUtility.ColorToPbgra32(
                                Color.FromArgb(0xFF, 0x20, 0x30, 0x40)));

            Assert.AreEqual(0x7F0F171F, BitmapUtility.ColorToPbgra32(
                                Color.FromArgb(0x7F, 0x20, 0x30, 0x40)));

            Assert.AreEqual(0x00000000, BitmapUtility.ColorToPbgra32(
                                Color.FromArgb(0x00, 0x20, 0x30, 0x40)));
        }
예제 #5
0
        /// <summary>
        /// Clears the specified rectangle in the <see cref="BitmapBuffer"/> with the specified <see
        /// cref="Color"/>.</summary>
        /// <param name="bounds">
        /// The pixel rectangle in the <see cref="BitmapBuffer"/> to fill with the specified
        /// <paramref name="color"/>.</param>
        /// <param name="color">
        /// The new <see cref="Color"/> for all pixels within the specified <paramref
        /// name="bounds"/> of the <see cref="BitmapBuffer"/>.</param>
        /// <remarks>
        /// <b>Clear</b> sets all <see cref="Pixels"/> elements within the specified <paramref
        /// name="bounds"/> to the <see cref="PixelFormats.Pbgra32"/> representation of the
        /// specified <paramref name="color"/>. No coordinate checking is performed.</remarks>

        public void Clear(RectI bounds, Color color)
        {
            uint value  = BitmapUtility.ColorToPbgra32(color);
            int  offset = bounds.X + _size.Width * bounds.Y;

            for (int y = 0; y < bounds.Height; y++)
            {
                for (int x = 0; x < bounds.Width; x++)
                {
                    _pixels[offset + x] = value;
                }

                offset += _size.Width;
            }
        }
예제 #6
0
        /// <summary>
        /// Sets the specified pixel in the <see cref="BitmapBuffer"/> to the specified <see
        /// cref="Color"/>.</summary>
        /// <param name="x">
        /// The x-coordinate of the pixel to change to <paramref name="color"/>.</param>
        /// <param name="y">
        /// The y-coordinate of the pixel to change to <paramref name="color"/>.</param>
        /// <param name="color">
        /// The new <see cref="Color"/> for the pixel at the specified location in the <see
        /// cref="BitmapBuffer"/>.</param>
        /// <remarks>
        /// <b>SetPixel</b> sets the <see cref="Pixels"/> element at the specified <paramref
        /// name="x"/> and <paramref name="y"/> coordinates to the <see
        /// cref="PixelFormats.Pbgra32"/> representation of the specified <paramref name="color"/>.
        /// No alpha blending or coordinate checking is performed.</remarks>

        public void SetPixel(int x, int y, Color color)
        {
            uint value = BitmapUtility.ColorToPbgra32(color);

            _pixels[x + _size.Width * y] = value;
        }