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)); }
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); }
public void CandelaPerSquareMeterToLuminanceUnits() { Luminance candelapersquaremeter = Luminance.FromCandelaPerSquareMeters(1); AssertEx.EqualTolerance(CandelaPerSquareMetersInOneCandelaPerSquareMeter, candelapersquaremeter.CandelaPerSquareMeters, CandelaPerSquareMetersTolerance); AssertEx.EqualTolerance(FootLambertsInOneCandelaPerSquareMeter, candelapersquaremeter.FootLamberts, FootLambertsTolerance); }
public void DefaultCtor_ReturnsQuantityWithZeroValueAndBaseUnit() { var quantity = new Luminance(); Assert.Equal(0, quantity.Value); Assert.Equal(LuminanceUnit.CandelaPerSquareMeter, quantity.Unit); }
public void As() { var candelapersquaremeter = Luminance.FromCandelaPerSquareMeters(1); AssertEx.EqualTolerance(CandelaPerSquareMetersInOneCandelaPerSquareMeter, candelapersquaremeter.As(LuminanceUnit.CandelaPerSquareMeter), CandelaPerSquareMetersTolerance); AssertEx.EqualTolerance(FootLambertsInOneCandelaPerSquareMeter, candelapersquaremeter.As(LuminanceUnit.FootLambert), FootLambertsTolerance); }
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); }
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)); }
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)); }
public Chunk(ChunkPosition pos) { position = pos; neighbours = new Chunk[6]; densities = new float[Point.CUBE_SIZE]; luminance = new Luminance(this); triangles = new List <Triangle>(); }
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)); }
public override int GetHashCode() { unchecked { int hashCode = x.GetHashCode(); hashCode = (hashCode * 397) ^ y.GetHashCode(); hashCode = (hashCode * 397) ^ Luminance.GetHashCode(); return(hashCode); } }
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); }
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); }
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); }
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); }
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 }
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 }
void Awake() { ins = this; }
public void NegationOperator_ReturnsQuantity_WithNegatedValue(double value) { var quantity = Luminance.FromCandelaPerSquareMeters(value); Assert.Equal(Luminance.FromCandelaPerSquareMeters(-value), -quantity); }
public void GetHashCode_Equals() { var quantity = Luminance.FromCandelaPerSquareMeters(1.0); Assert.Equal(new { Luminance.QuantityType, quantity.Value, quantity.Unit }.GetHashCode(), quantity.GetHashCode()); }
public void Convert_ChangeType_QuantityType_EqualsQuantityType() { var quantity = Luminance.FromCandelaPerSquareMeters(1.0); Assert.Equal(QuantityType.Luminance, Convert.ChangeType(quantity, typeof(QuantityType))); }
public void Convert_ChangeType_UnitType_EqualsUnit() { var quantity = Luminance.FromCandelaPerSquareMeters(1.0); Assert.Equal(quantity.Unit, Convert.ChangeType(quantity, typeof(LuminanceUnit))); }
public void Convert_ChangeType_SelfType_EqualsSelf() { var quantity = Luminance.FromCandelaPerSquareMeters(1.0); Assert.Equal(quantity, Convert.ChangeType(quantity, typeof(Luminance))); }
public void Convert_ToString_EqualsToString() { var quantity = Luminance.FromCandelaPerSquareMeters(1.0); Assert.Equal(quantity.ToString(), Convert.ToString(quantity)); }
public void Convert_ToSingle_EqualsValueAsSameType() { var quantity = Luminance.FromCandelaPerSquareMeters(1.0); Assert.Equal((float)quantity.Value, Convert.ToSingle(quantity)); }
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); }
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];*/ } }); }
public void Convert_ChangeType_BaseDimensions_EqualsBaseDimensions() { var quantity = Luminance.FromCandelaPerSquareMeters(1.0); Assert.Equal(Luminance.BaseDimensions, Convert.ChangeType(quantity, typeof(BaseDimensions))); }
public void Convert_ToUInt64_EqualsValueAsSameType() { var quantity = Luminance.FromCandelaPerSquareMeters(1.0); Assert.Equal((ulong)quantity.Value, Convert.ToUInt64(quantity)); }
public void Convert_ChangeType_InvalidType_ThrowsInvalidCastException() { var quantity = Luminance.FromCandelaPerSquareMeters(1.0); Assert.Throws <InvalidCastException>(() => Convert.ChangeType(quantity, typeof(QuantityFormatter))); }