Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Settings"/> struct.
 /// </summary>
 /// <param name="range">The range.</param>
 /// <param name="average">if set to <c>true</c> [average].</param>
 /// <param name="invert">if set to <c>true</c> [invert].</param>
 /// <param name="useAlpha">if set to <c>true</c> [use alpha].</param>
 public Settings(GorgonRangeF range, bool average, bool invert, bool useAlpha)
 {
     WhiteRange  = range;
     _useAverage = Convert.ToInt32(average);
     _invert     = Convert.ToInt32(invert);
     _useAlpha   = Convert.ToInt32(useAlpha);
 }
Esempio n. 2
0
        /// <summary>
        /// Function to set the alpha channel for a specific buffer in the image.
        /// </summary>
        /// <param name="buffer">The buffer to set the alpha channel on.</param>
        /// <param name="alphaValue">The value to set.</param>
        /// <param name="updateAlphaRange">[Optional] The range of alpha values in the buffer that will be updated.</param>
        /// <param name="region">[Optional] The region in the buffer to update.</param>
        /// <returns>The fluent interface for the buffer that was updated.</returns>
        /// <exception cref="ArgumentNullException">Thrown when the <paramref name="buffer"/> parameter is <b>null</b>.</exception>
        /// <exception cref="ArgumentException">Thrown if the buffer format is compressed.</exception>
        /// <remarks>
        /// <para>
        /// This will set the alpha channel for the image data in the <paramref name="buffer"/> to a discrete value specified by <paramref name="alphaValue"/>.
        /// </para>
        /// <para>
        /// If the <paramref name="updateAlphaRange"/> parameter is set, then the alpha values in the <paramref name="buffer"/> will be examined and if the alpha value is less than the minimum range or
        /// greater than the maximum range, then the <paramref name="alphaValue"/> will <b>not</b> be set on the alpha channel.
        /// </para>
        /// <para>
        /// If the <paramref name="region"/> is not specified, then the entire buffer is updated, otherwise only the values within the <paramref name="region"/> are updated.
        /// </para>
        /// </remarks>
        public static IGorgonImageBuffer SetAlpha(this IGorgonImageBuffer buffer, float alphaValue, GorgonRangeF?updateAlphaRange = null, DX.Rectangle?region = null)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer));
            }

            // If we don't have an alpha channel, then don't do anything.
            if (!buffer.FormatInformation.HasAlpha)
            {
                return(buffer);
            }

            // We don't support compressed formats.
            if (buffer.FormatInformation.IsCompressed)
            {
                throw new ArgumentException(string.Format(Resources.GORIMG_ERR_FORMAT_NOT_SUPPORTED, buffer.Format), nameof(buffer));
            }

            if (updateAlphaRange == null)
            {
                updateAlphaRange = new GorgonRangeF(0, 1);
            }

            var fullRect = new DX.Rectangle(0, 0, buffer.Width - 1, buffer.Height - 1);

            if (region == null)
            {
                region = fullRect;
            }
            else
            {
                region = DX.Rectangle.Intersect(region.Value, fullRect);
            }

            unsafe
            {
                byte *src   = (byte *)buffer.Data;
                uint  alpha = (uint)(alphaValue * 255.0f);
                uint  min   = (uint)(updateAlphaRange.Value.Minimum * 255.0f);
                uint  max   = (uint)(updateAlphaRange.Value.Maximum * 255.0f);
                int   pitch = buffer.PitchInformation.RowPitch / buffer.Width;

                for (int y = region.Value.Top; y <= region.Value.Bottom; ++y)
                {
                    byte *horzPtr = src + region.Value.Left * buffer.FormatInformation.SizeInBytes;
                    ImageUtilities.SetAlphaScanline(horzPtr, region.Value.Width * pitch, horzPtr, region.Value.Width * pitch, buffer.Format, alpha, min, max);
                    src += buffer.PitchInformation.RowPitch;
                }
            }

            return(buffer);
        }
        /// <summary>
        /// Function to convert a <see cref="GorgonRangeF"/> of texel coordinates to pixel space.
        /// </summary>
        /// <param name="texelCoordinates">The texel coordinates to convert.</param>
        /// <param name="mipLevel">[Optional] The mip level to use.</param>
        /// <returns>A <see cref="GorgonRange"/> containing the pixel space coordinates.</returns>
        /// <remarks>
        /// <para>
        /// If specified, the <paramref name="mipLevel"/> only applies to the <see cref="MipSlice"/> and <see cref="MipCount"/> for this view, it will be constrained if it falls outside of that range.
        /// Because of this, the coordinates returned may not be the exact size of the texture bound to the view at mip level 0. If the <paramref name="mipLevel"/> is omitted, then the first mip level
        /// for the underlying <see cref="Texture"/> is used.
        /// </para>
        /// </remarks>
        public GorgonRange ToPixel(GorgonRangeF texelCoordinates, int?mipLevel = null)
        {
            float width = Texture.Width;

            if (mipLevel == null)
            {
                return(new GorgonRange((int)(texelCoordinates.Minimum * width), (int)(texelCoordinates.Maximum * width)));
            }

            width = GetMipWidth(mipLevel.Value);

            return(new GorgonRange((int)(texelCoordinates.Minimum * width), (int)(texelCoordinates.Maximum * width)));
        }
Esempio n. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Gorgon2DAlphaTest"/> struct.
 /// </summary>
 /// <param name="isEnabled">TRUE to enable alpha testing, FALSE to disable.</param>
 /// <param name="alphaRange">The alpha range to clip.</param>
 public Gorgon2DAlphaTest(bool isEnabled, GorgonRangeF alphaRange)
 {
     IsEnabled  = isEnabled ? 1 : 0;
     LowerAlpha = alphaRange.Minimum;
     UpperAlpha = alphaRange.Maximum;
 }