예제 #1
0
        public void Equals_RelativeTolerance_IsImplemented()
        {
            var v = Luminance.FromCandelaPerSquareMeters(1);

            Assert.True(v.Equals(Luminance.FromCandelaPerSquareMeters(1), CandelaPerSquareMetersTolerance, ComparisonType.Relative));
            Assert.False(v.Equals(Luminance.Zero, CandelaPerSquareMetersTolerance, ComparisonType.Relative));
        }
예제 #2
0
        public void ConversionRoundTrip()
        {
            Luminance candelapersquaremeter = Luminance.FromCandelaPerSquareMeters(1);

            AssertEx.EqualTolerance(1, Luminance.FromCandelaPerSquareMeters(candelapersquaremeter.CandelaPerSquareMeters).CandelaPerSquareMeters, CandelaPerSquareMetersTolerance);
            AssertEx.EqualTolerance(1, Luminance.FromFootLamberts(candelapersquaremeter.FootLamberts).CandelaPerSquareMeters, FootLambertsTolerance);
        }
예제 #3
0
        public void CandelaPerSquareMeterToLuminanceUnits()
        {
            Luminance candelapersquaremeter = Luminance.FromCandelaPerSquareMeters(1);

            AssertEx.EqualTolerance(CandelaPerSquareMetersInOneCandelaPerSquareMeter, candelapersquaremeter.CandelaPerSquareMeters, CandelaPerSquareMetersTolerance);
            AssertEx.EqualTolerance(FootLambertsInOneCandelaPerSquareMeter, candelapersquaremeter.FootLamberts, FootLambertsTolerance);
        }
예제 #4
0
        public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit()
        {
            var quantity = new Luminance();

            Assert.Equal(0, quantity.Value);
            Assert.Equal(LuminanceUnit.CandelaPerSquareMeter, quantity.Unit);
        }
예제 #5
0
        public void As()
        {
            var candelapersquaremeter = Luminance.FromCandelaPerSquareMeters(1);

            AssertEx.EqualTolerance(CandelaPerSquareMetersInOneCandelaPerSquareMeter, candelapersquaremeter.As(LuminanceUnit.CandelaPerSquareMeter), CandelaPerSquareMetersTolerance);
            AssertEx.EqualTolerance(FootLambertsInOneCandelaPerSquareMeter, candelapersquaremeter.As(LuminanceUnit.FootLambert), FootLambertsTolerance);
        }
예제 #6
0
        public void CompareToIsImplemented()
        {
            Luminance candelapersquaremeter = Luminance.FromCandelaPerSquareMeters(1);

            Assert.Equal(0, candelapersquaremeter.CompareTo(candelapersquaremeter));
            Assert.True(candelapersquaremeter.CompareTo(Luminance.Zero) > 0);
            Assert.True(Luminance.Zero.CompareTo(candelapersquaremeter) < 0);
        }
예제 #7
0
 public bool Equals(xyYColor other)
 {
     if (other == null)
     {
         throw new ArgumentNullException("other");
     }
     return(x.Equals(other.x) && y.Equals(other.y) && Luminance.Equals(other.Luminance));
 }
예제 #8
0
        public void Equals_SameType_IsImplemented()
        {
            var a = Luminance.FromCandelaPerSquareMeters(1);
            var b = Luminance.FromCandelaPerSquareMeters(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
        }
예제 #9
0
 public Chunk(ChunkPosition pos)
 {
     position   = pos;
     neighbours = new Chunk[6];
     densities  = new float[Point.CUBE_SIZE];
     luminance  = new Luminance(this);
     triangles  = new List <Triangle>();
 }
예제 #10
0
        public void Equals_QuantityAsObject_IsImplemented()
        {
            object a = Luminance.FromCandelaPerSquareMeters(1);
            object b = Luminance.FromCandelaPerSquareMeters(2);

            Assert.True(a.Equals(a));
            Assert.False(a.Equals(b));
            Assert.False(a.Equals((object)null));
        }
예제 #11
0
 public override int GetHashCode()
 {
     unchecked
     {
         int hashCode = x.GetHashCode();
         hashCode = (hashCode * 397) ^ y.GetHashCode();
         hashCode = (hashCode * 397) ^ Luminance.GetHashCode();
         return(hashCode);
     }
 }
예제 #12
0
        public void ArithmeticOperators()
        {
            Luminance v = Luminance.FromCandelaPerSquareMeters(1);

            AssertEx.EqualTolerance(-1, -v.CandelaPerSquareMeters, CandelaPerSquareMetersTolerance);
            AssertEx.EqualTolerance(2, (Luminance.FromCandelaPerSquareMeters(3) - v).CandelaPerSquareMeters, CandelaPerSquareMetersTolerance);
            AssertEx.EqualTolerance(2, (v + v).CandelaPerSquareMeters, CandelaPerSquareMetersTolerance);
            AssertEx.EqualTolerance(10, (v * 10).CandelaPerSquareMeters, CandelaPerSquareMetersTolerance);
            AssertEx.EqualTolerance(10, (10 * v).CandelaPerSquareMeters, CandelaPerSquareMetersTolerance);
            AssertEx.EqualTolerance(2, (Luminance.FromCandelaPerSquareMeters(10) / 5).CandelaPerSquareMeters, CandelaPerSquareMetersTolerance);
            AssertEx.EqualTolerance(2, Luminance.FromCandelaPerSquareMeters(10) / Luminance.FromCandelaPerSquareMeters(5), CandelaPerSquareMetersTolerance);
        }
예제 #13
0
        public void From_ValueAndUnit_ReturnsQuantityWithSameValueAndUnit()
        {
            var quantity00 = Luminance.From(1, LuminanceUnit.CandelaPerSquareMeter);

            AssertEx.EqualTolerance(1, quantity00.CandelaPerSquareMeters, CandelaPerSquareMetersTolerance);
            Assert.Equal(LuminanceUnit.CandelaPerSquareMeter, quantity00.Unit);

            var quantity01 = Luminance.From(1, LuminanceUnit.FootLambert);

            AssertEx.EqualTolerance(1, quantity01.FootLamberts, FootLambertsTolerance);
            Assert.Equal(LuminanceUnit.FootLambert, quantity01.Unit);
        }
예제 #14
0
        public void ToUnit()
        {
            var candelapersquaremeter = Luminance.FromCandelaPerSquareMeters(1);

            var candelapersquaremeterQuantity = candelapersquaremeter.ToUnit(LuminanceUnit.CandelaPerSquareMeter);

            AssertEx.EqualTolerance(CandelaPerSquareMetersInOneCandelaPerSquareMeter, (double)candelapersquaremeterQuantity.Value, CandelaPerSquareMetersTolerance);
            Assert.Equal(LuminanceUnit.CandelaPerSquareMeter, candelapersquaremeterQuantity.Unit);

            var footlambertQuantity = candelapersquaremeter.ToUnit(LuminanceUnit.FootLambert);

            AssertEx.EqualTolerance(FootLambertsInOneCandelaPerSquareMeter, (double)footlambertQuantity.Value, FootLambertsTolerance);
            Assert.Equal(LuminanceUnit.FootLambert, footlambertQuantity.Unit);
        }
예제 #15
0
        public void ComparisonOperators()
        {
            Luminance oneCandelaPerSquareMeter  = Luminance.FromCandelaPerSquareMeters(1);
            Luminance twoCandelaPerSquareMeters = Luminance.FromCandelaPerSquareMeters(2);

            Assert.True(oneCandelaPerSquareMeter < twoCandelaPerSquareMeters);
            Assert.True(oneCandelaPerSquareMeter <= twoCandelaPerSquareMeters);
            Assert.True(twoCandelaPerSquareMeters > oneCandelaPerSquareMeter);
            Assert.True(twoCandelaPerSquareMeters >= oneCandelaPerSquareMeter);

            Assert.False(oneCandelaPerSquareMeter > twoCandelaPerSquareMeters);
            Assert.False(oneCandelaPerSquareMeter >= twoCandelaPerSquareMeters);
            Assert.False(twoCandelaPerSquareMeters < oneCandelaPerSquareMeter);
            Assert.False(twoCandelaPerSquareMeters <= oneCandelaPerSquareMeter);
        }
예제 #16
0
        public void EqualityOperators()
        {
            var a = Luminance.FromCandelaPerSquareMeters(1);
            var b = Luminance.FromCandelaPerSquareMeters(2);

            // ReSharper disable EqualExpressionComparison

            Assert.True(a == a);
            Assert.False(a != a);

            Assert.True(a != b);
            Assert.False(a == b);

            Assert.False(a == null);
            Assert.False(null == a);

// ReSharper restore EqualExpressionComparison
        }
예제 #17
0
        public void Luminance_QuantityInfo_ReturnsQuantityInfoDescribingQuantity()
        {
            var quantity = new Luminance(1, LuminanceUnit.CandelaPerSquareMeter);

            QuantityInfo <LuminanceUnit> quantityInfo = quantity.QuantityInfo;

            Assert.Equal(Luminance.Zero, quantityInfo.Zero);
            Assert.Equal("Luminance", quantityInfo.Name);
            Assert.Equal(QuantityType.Luminance, quantityInfo.QuantityType);

            var units     = EnumUtils.GetEnumValues <LuminanceUnit>().Except(new[] { LuminanceUnit.Undefined }).ToArray();
            var unitNames = units.Select(x => x.ToString());

            // Obsolete members
#pragma warning disable 618
            Assert.Equal(units, quantityInfo.Units);
            Assert.Equal(unitNames, quantityInfo.UnitNames);
#pragma warning restore 618
        }
예제 #18
0
 void Awake()
 {
     ins = this;
 }
예제 #19
0
        public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value)
        {
            var quantity = Luminance.FromCandelaPerSquareMeters(value);

            Assert.Equal(Luminance.FromCandelaPerSquareMeters(-value), -quantity);
        }
예제 #20
0
        public void GetHashCode_Equals()
        {
            var quantity = Luminance.FromCandelaPerSquareMeters(1.0);

            Assert.Equal(new { Luminance.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode());
        }
예제 #21
0
        public void Convert_ChangeType_QuantityType_EqualsQuantityType()
        {
            var quantity = Luminance.FromCandelaPerSquareMeters(1.0);

            Assert.Equal(QuantityType.Luminance, Convert.ChangeType(quantity, typeof(QuantityType)));
        }
예제 #22
0
        public void Convert_ChangeType_UnitType_EqualsUnit()
        {
            var quantity = Luminance.FromCandelaPerSquareMeters(1.0);

            Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(LuminanceUnit)));
        }
예제 #23
0
        public void Convert_ChangeType_SelfType_EqualsSelf()
        {
            var quantity = Luminance.FromCandelaPerSquareMeters(1.0);

            Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(Luminance)));
        }
예제 #24
0
        public void Convert_ToString_EqualsToString()
        {
            var quantity = Luminance.FromCandelaPerSquareMeters(1.0);

            Assert.Equal(quantity.ToString(), Convert.ToString(quantity));
        }
예제 #25
0
        public void Convert_ToSingle_EqualsValueAsSameType()
        {
            var quantity = Luminance.FromCandelaPerSquareMeters(1.0);

            Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity));
        }
예제 #26
0
        public unsafe int[] applyModification(ushort[] image, iPoint2D dim, iPoint2D offset, int colorDepth, ref SoftwareBitmap bitmap)
        {
            int[] value = new int[256];
            using (BitmapBuffer buffer = bitmap.LockBuffer(BitmapBufferAccessMode.Write))
            {
                using (var reference = buffer.CreateReference())
                {
                    BitmapPlaneDescription bufferLayout = buffer.GetPlaneDescription(0);
                    ((IMemoryBufferByteAccess)reference).GetBuffer(out var temp, out uint capacity);
                    maxValue = (uint)(1 << colorDepth);
                    int shift = colorDepth - 8;
                    if (!cameraWB)
                    {
                        mul = new float[4];
                        //Balance.calculateRGB((int)temperature, out mul[0], out mul[1], out mul[2]);
                        mul[2] = (float)(255 / temperature);
                        mul[0] = (float)(255.0 / tint);
                        mul[1] = 1;
                    }

                    //generate the curve
                    double[] xCurve = new double[5], yCurve = new double[5];
                    //mid point
                    xCurve[2] = maxValue / 2;
                    yCurve[2] = maxValue / 2;
                    //shadow
                    xCurve[0] = 0;
                    yCurve[0] = shadow * (maxValue / (400));
                    //hightlight
                    xCurve[4] = maxValue;
                    yCurve[4] = maxValue - (hightlight * (maxValue / 400));
                    //contrast
                    xCurve[1] = maxValue / 4;
                    yCurve[1] = ((yCurve[0] + yCurve[2]) / 2) - (maxValue / 200);
                    xCurve[3] = maxValue * 3 / 4;
                    yCurve[3] = ((yCurve[2] + yCurve[4]) / 2) + (maxValue / 200);
                    maxValue--;

                    //interpolate with spline
                    //double[] contrastCurve = Balance.contrast_curve(shadow, hightlight, 1 << colorDepth);
                    double[] contrastCurve = Curve.cubicSpline(xCurve, yCurve);

                    //Change the gamma/No more gammaneeded here, the raw should be transformed to neutral gamma before demos
                    //double[] gammaCurve = Balance.gamma_curve(0.45, 4.5, 2, 8192 << 3);

                    //gammacurve from camera
                    //double[] gammaCurve = Balance.gamma_curve(camCurve[0] / 100, camCurve[1] / 10, 2, 8192 << 3);

                    Parallel.For(offset.y, dim.y + offset.y, y =>
                    {
                        int realY   = y * dim.x * 3;
                        int bufferY = y * dim.x * 4 + +bufferLayout.StartIndex;
                        for (int x = offset.x; x < dim.x + offset.x; x++)
                        {
                            int realPix   = realY + (3 * x);
                            int bufferPix = bufferY + (4 * x);
                            //get the RGB value
                            double red = image[realPix],
                            green      = image[realPix + 1],
                            blue       = image[realPix + 2];

                            //convert to linear rgb (not needed, the raw should be in linear already)

                            /*Balance.sRGBToRGB(ref red, maxValue - 1);
                             * Balance.sRGBToRGB(ref green, maxValue - 1);
                             * Balance.sRGBToRGB(ref blue, maxValue - 1);*/

                            //scale according to the white balance
                            red   *= mul[0];
                            green *= mul[1];
                            blue  *= mul[2];
                            //clip
                            Luminance.Clip(ref red, ref green, ref blue, maxValue);
                            double h = 0, s = 0, l = 0;
                            //transform to HSL value
                            Color.rgbToHsl(red, green, blue, maxValue, ref h, ref s, ref l);
                            //change brightness from curve
                            //add saturation
                            l  = contrastCurve[(uint)(l * maxValue)] / maxValue;
                            s *= saturation;
                            s += vibrance;
                            l *= exposure;
                            l += brightness / 100;
                            //change back to RGB
                            Color.hslToRgb(h, s, l, maxValue, ref red, ref green, ref blue);

                            //Luminance.Exposure(ref red, ref green, ref blue, exposure);
                            //Luminance.Brightness(ref red, ref green, ref blue, brightness);
                            //Balance.scaleGamma(ref red, ref green, ref blue, gamma, maxValue);
                            Luminance.Contraste(ref red, ref green, ref blue, maxValue, contrast);

                            //clip
                            Luminance.Clip(ref red, ref green, ref blue, maxValue);

                            temp[bufferPix]     = (byte)((int)blue >> shift);
                            temp[bufferPix + 1] = (byte)((int)green >> shift);
                            temp[bufferPix + 2] = (byte)((int)red >> shift);

                            Interlocked.Increment(ref value[(((int)red >> shift) + ((int)green >> shift) + ((int)blue >> shift)) / 3]);
                            //set transparency to 255 else image will be blank
                            temp[bufferPix + 3] = 255;
                            //change gamma from curve

                            /*
                             * image[i * 3] = (ushort)gammaCurve[(int)red];
                             * image[(i * 3) + 1] = (ushort)gammaCurve[(int)green];
                             * image[(i * 3) + 2] = (ushort)gammaCurve[(int)blue];*/
                        }
                    });
                }
            }
            return(value);
        }
예제 #27
0
        public void applyModification(ushort[] image, iPoint2D dim, iPoint2D offset, int colorDepth)
        {
            maxValue = (uint)(1 << colorDepth);
            if (!cameraWB)
            {
                mul = new float[4];
                //Balance.calculateRGB((int)temperature, out mul[0], out mul[1], out mul[2]);
                mul[0] = (float)(255 / temperature);
                mul[1] = (float)(255 / tint);
                mul[2] = 1;
            }

            //generate the curve
            double[] xCurve = new double[5], yCurve = new double[5];
            //mid point
            xCurve[2] = maxValue / 2;
            yCurve[2] = maxValue / 2;
            //shadow
            xCurve[0] = 0;
            yCurve[0] = shadow * (maxValue / (400));
            //hightlight
            xCurve[4] = maxValue;
            yCurve[4] = maxValue - (hightlight * (maxValue / 400));
            //contrast
            xCurve[1] = maxValue / 4;
            yCurve[1] = ((yCurve[0] + yCurve[2]) / 2) - (maxValue / 200);
            xCurve[3] = maxValue * 3 / 4;
            yCurve[3] = ((yCurve[2] + yCurve[4]) / 2) + (maxValue / 200);
            maxValue--;

            //interpolate with spline
            //double[] contrastCurve = Balance.contrast_curve(shadow, hightlight, 1 << colorDepth);
            double[] contrastCurve = Curve.cubicSpline(xCurve, yCurve);

            //Change the gamma/No more gammaneeded here, the raw should be transformed to neutral gamma before demos
            //double[] gammaCurve = Balance.gamma_curve(0.45, 4.5, 2, 8192 << 3);

            //gammacurve from camera
            //double[] gammaCurve = Balance.gamma_curve(camCurve[0] / 100, camCurve[1] / 10, 2, 8192 << 3);

            Parallel.For(offset.y, dim.y, y =>
            {
                int realY = y * dim.x * 3;
                for (int x = offset.x; x < dim.x; x++)
                {
                    int realPix = realY + (3 * x);
                    //get the RGB value
                    double red = image[realPix],
                    green      = image[realPix + 1],
                    blue       = image[realPix + 2];

                    //convert to linear rgb (not needed, the raw should be in linear already)

                    /*Balance.sRGBToRGB(ref red, maxValue - 1);
                     * Balance.sRGBToRGB(ref green, maxValue - 1);
                     * Balance.sRGBToRGB(ref blue, maxValue - 1);*/

                    //scale according to the white balance
                    //Balance.scaleColor(ref red, ref green, ref blue, mul);
                    red   *= mul[0];
                    green *= mul[1];
                    blue  *= mul[2];
                    //clip
                    Luminance.Clip(ref red, ref green, ref blue, maxValue);
                    double h = 0, s = 0, l = 0;
                    //transform to HSL value
                    Color.rgbToHsl(red, green, blue, maxValue, ref h, ref s, ref l);
                    //change brightness from curve
                    //add saturation
                    l  = contrastCurve[(uint)(l * maxValue)] / maxValue;
                    s *= saturation;
                    s += vibrance;
                    l *= exposure;
                    l += brightness / 100;
                    //change back to RGB
                    Color.hslToRgb(h, s, l, maxValue, ref red, ref green, ref blue);

                    //Luminance.Exposure(ref red, ref green, ref blue, exposure);
                    //Luminance.Brightness(ref red, ref green, ref blue, brightness);
                    //Balance.scaleGamma(ref red, ref green, ref blue, gamma, maxValue);
                    Luminance.Contraste(ref red, ref green, ref blue, maxValue, contrast);

                    //clip
                    Luminance.Clip(ref red, ref green, ref blue, maxValue);
                    image[realPix]     = (byte)red;
                    image[realPix + 1] = (byte)green;
                    image[realPix + 2] = (byte)blue;
                    //change gamma from curve

                    /*
                     * image[i * 3] = (ushort)gammaCurve[(int)red];
                     * image[(i * 3) + 1] = (ushort)gammaCurve[(int)green];
                     * image[(i * 3) + 2] = (ushort)gammaCurve[(int)blue];*/
                }
            });
        }
예제 #28
0
        public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions()
        {
            var quantity = Luminance.FromCandelaPerSquareMeters(1.0);

            Assert.Equal(Luminance.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions)));
        }
예제 #29
0
        public void Convert_ToUInt64_EqualsValueAsSameType()
        {
            var quantity = Luminance.FromCandelaPerSquareMeters(1.0);

            Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity));
        }
예제 #30
0
        public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException()
        {
            var quantity = Luminance.FromCandelaPerSquareMeters(1.0);

            Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter)));
        }