示例#1
0
        public void ConstructFrom_Vector4()
        {
            var    source   = new Vector4(0f, 0.2f, 0.5f, 1f);
            Rgba64 expected = default;

            expected.FromScaledVector4(source);

            var actual = new Rgba64(source);

            Assert.Equal(expected, actual);
        }
示例#2
0
        public void Rgba64_FromScaledVector4(ushort r, ushort g, ushort b, ushort a)
        {
            // arrange
            var source = new Rgba64(r, g, b, a);

            // act
            Vector4 scaled = source.ToScaledVector4();

            Rgba64 actual = default;

            actual.FromScaledVector4(scaled);

            // assert
            Assert.Equal(source, actual);
        }
        public static void ModifyPixel <TPixel>(ImageFrame <TPixel> img, int x, int y, byte perChannelChange)
            where TPixel : unmanaged, IPixel <TPixel>
        {
            TPixel pixel     = img[x, y];
            Rgba64 rgbaPixel = default;

            rgbaPixel.FromScaledVector4(pixel.ToScaledVector4());
            ushort change = (ushort)Math.Round((perChannelChange / 255F) * 65535F);

            if (rgbaPixel.R + perChannelChange <= 255)
            {
                rgbaPixel.R += change;
            }
            else
            {
                rgbaPixel.R -= change;
            }

            if (rgbaPixel.G + perChannelChange <= 255)
            {
                rgbaPixel.G += change;
            }
            else
            {
                rgbaPixel.G -= change;
            }

            if (rgbaPixel.B + perChannelChange <= 255)
            {
                rgbaPixel.B += perChannelChange;
            }
            else
            {
                rgbaPixel.B -= perChannelChange;
            }

            if (rgbaPixel.A + perChannelChange <= 255)
            {
                rgbaPixel.A += perChannelChange;
            }
            else
            {
                rgbaPixel.A -= perChannelChange;
            }

            pixel.FromRgba64(rgbaPixel);
            img[x, y] = pixel;
        }