Beispiel #1
0
        public void Short4_FromRgb48_ToRgb48()
        {
            // arrange
            var input    = default(Short4);
            var actual   = default(Rgb48);
            var expected = new Rgb48(65535, 0, 65535);

            // act
            input.FromRgb48(expected);
            actual.FromScaledVector4(input.ToScaledVector4());

            // assert
            Assert.Equal(expected, actual);
        }
Beispiel #2
0
        public void Rgb48_PackFromRgb48_ToRgb48()
        {
            // arrange
            var input    = default(Rgba64);
            var actual   = default(Rgb48);
            var expected = new Rgb48(65535, 0, 65535);

            // act
            input.PackFromRgb48(expected);
            input.ToRgb48(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
Beispiel #3
0
        public void Rgb48_ToScaledVector4()
        {
            // arrange
            var short2 = new Rgb48(Vector3.One);

            // act
            Vector4 actual = short2.ToScaledVector4();

            // assert
            Assert.Equal(1, actual.X);
            Assert.Equal(1, actual.Y);
            Assert.Equal(1, actual.Z);
            Assert.Equal(1, actual.W);
        }
Beispiel #4
0
        public void Rgb48_ToRgba32()
        {
            // arrange
            var rgba48   = new Rgb48(5140, 9766, 19532);
            var expected = new Rgba32(20, 38, 76, 255);

            // act
            Rgba32 actual = default;

            rgba48.ToRgba32(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
Beispiel #5
0
        public void Alpha8_PackFromRgb48_ToRgb48()
        {
            // arrange
            var alpha    = default(Alpha8);
            var actual   = default(Rgb48);
            var expected = new Rgb48(0, 0, 0);

            // act
            alpha.PackFromRgb48(expected);
            alpha.ToRgb48(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
Beispiel #6
0
        public void Argb32_PackFromRgb48_ToRgb48()
        {
            // arrange
            var argb     = default(Argb32);
            var actual   = default(Rgb48);
            var expected = new Rgb48(65535, 0, 65535);

            // act
            argb.PackFromRgb48(expected);
            argb.ToRgb48(ref actual);

            // assert
            Assert.Equal(expected, actual);
        }
Beispiel #7
0
        public void Rgb48_FromScaledVector4()
        {
            // arrange
            var pixel    = default(Rgb48);
            var short3   = new Rgb48(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue);
            var expected = new Rgb48(ushort.MaxValue, ushort.MaxValue, ushort.MaxValue);

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

            pixel.FromScaledVector4(scaled);

            // assert
            Assert.Equal(expected, pixel);
        }
Beispiel #8
0
        public void Rgb48_PackFromScaledVector4()
        {
            // arrange
            var pixel    = default(Rgb48);
            var short3   = new Rgb48(Vector3.One);
            var expected = new Rgb48(Vector3.One);

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

            pixel.PackFromScaledVector4(scaled);

            // assert
            Assert.Equal(expected, pixel);
        }
Beispiel #9
0
        public static void SetWhiteAndBlackpoint(this Image <Rgb48> image, bool bwNegative)
        {
            // Note that for what is dark/bright depends on if the image is positive or negative
            // Naming here is based on a negative image which means low value is bright after inversion
            Rgb48 darkest   = FindLargestValue(image, bwNegative);
            Rgb48 brightest = FindSmallestValue(image, bwNegative);

            image.ProcessPixelRows(accessor => {
                for (int y = 0; y < image.Height; y++)
                {
                    Span <Rgb48> pixelRowSpan = accessor.GetRowSpan(y);
                    for (int x = 0; x < image.Width; x++)
                    {
                        var pixel = pixelRowSpan[x];

                        /* Set levels
                         * ChannelValue = 65 535 * ( ( ChannelValue - BrightestValue ) /  ( DarkestValue - BrightestValue ) )
                         * Again, please note that Dark/Bright is depending on if the image is a positive or negative
                         * and here I am assuming we are looking at a negative image pre-inversion
                         */

                        double r = (double)(pixel.R - brightest.R) / (darkest.R - brightest.R);
                        double g = (double)(pixel.G - brightest.G) / (darkest.G - brightest.G);
                        double b = (double)(pixel.B - brightest.B) / (darkest.B - brightest.B);
                        r        = Math.Clamp(r, 0, 1);
                        g        = Math.Clamp(g, 0, 1);
                        b        = Math.Clamp(b, 0, 1);
                        pixel    = new Rgb48((ushort)(65_534 * r),
                                             (ushort)(65_534 * g),
                                             (ushort)(65_534 * b));

                        pixelRowSpan[x] = pixel;
                    }
                }
            });
        }
Beispiel #10
0
 public void FromRgb48(Rgb48 source) => this.FromScaledVector4(source.ToScaledVector4());
Beispiel #11
0
        /// <summary>
        /// Collects a row of grayscale pixels.
        /// </summary>
        /// <typeparam name="TPixel">The pixel format.</typeparam>
        /// <param name="rowSpan">The image row span.</param>
        private void CollectGrayscaleBytes <TPixel>(ReadOnlySpan <TPixel> rowSpan)
            where TPixel : struct, IPixel <TPixel>
        {
            // Use ITU-R recommendation 709 to match libpng.
            const float RX = .2126F;
            const float GX = .7152F;
            const float BX = .0722F;
            Span <byte> rawScanlineSpan = this.rawScanline.GetSpan();

            if (this.pngColorType.Equals(PngColorType.Grayscale))
            {
                // TODO: Realistically we should support 1, 2, 4, 8, and 16 bit grayscale images.
                // we currently do the other types via palette. Maybe RC as I don't understand how the data is packed yet
                // for 1, 2, and 4 bit grayscale images.
                if (this.use16Bit)
                {
                    // 16 bit grayscale
                    Rgb48 rgb = default;
                    for (int x = 0, o = 0; x < rowSpan.Length; x++, o += 2)
                    {
                        rowSpan[x].ToRgb48(ref rgb);
                        ushort luminance = (ushort)((RX * rgb.R) + (GX * rgb.G) + (BX * rgb.B));
                        BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), luminance);
                    }
                }
                else
                {
                    // 8 bit grayscale
                    Rgb24 rgb = default;
                    for (int x = 0; x < rowSpan.Length; x++)
                    {
                        rowSpan[x].ToRgb24(ref rgb);
                        rawScanlineSpan[x] = (byte)((RX * rgb.R) + (GX * rgb.G) + (BX * rgb.B));
                    }
                }
            }
            else
            {
                if (this.use16Bit)
                {
                    // 16 bit grayscale + alpha
                    Rgba64 rgba = default;
                    for (int x = 0, o = 0; x < rowSpan.Length; x++, o += 4)
                    {
                        rowSpan[x].ToRgba64(ref rgba);
                        ushort luminance = (ushort)((RX * rgba.R) + (GX * rgba.G) + (BX * rgba.B));
                        BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o, 2), luminance);
                        BinaryPrimitives.WriteUInt16BigEndian(rawScanlineSpan.Slice(o + 2, 2), rgba.A);
                    }
                }
                else
                {
                    // 8 bit grayscale + alpha
                    Rgba32 rgba = default;
                    for (int x = 0, o = 0; x < rowSpan.Length; x++, o += 2)
                    {
                        rowSpan[x].ToRgba32(ref rgba);
                        rawScanlineSpan[o]     = (byte)((RX * rgba.R) + (GX * rgba.G) + (BX * rgba.B));
                        rawScanlineSpan[o + 1] = rgba.A;
                    }
                }
            }
        }
Beispiel #12
0
 public void FromRgb48(Rgb48 source)
 {
 }
Beispiel #13
0
 public Color(Rgb48 pixel)
 {
     this.data = new Rgba64(pixel.R, pixel.G, pixel.B, ushort.MaxValue);
     this.boxedHighPrecisionPixel = null;
 }
 /// <inheritdoc />
 public void FromRgb48(Rgb48 source)
 {
     throw new NotImplementedException();
 }