private string GenerateText(Image <Rgba32> masterImage, int ratio = 5) { _progressService.Reset(); StringBuilder sb = new StringBuilder(); int hRatio = ratio * 2; var totalProgress = masterImage.Height / hRatio; for (int h = 0; h < masterImage.Height; h += hRatio) { Span <Rgba32> rowSpan = masterImage.GetPixelRowSpan(h); for (var w = 0; w < masterImage.Width; w += ratio) { var grayColor = new L8(); grayColor.FromRgba32(rowSpan[w]); int index = grayColor.PackedValue * 10 / 255; sb.Append(asciiChars[index]); } sb.AppendLine(); _progressService.IncrementProgress(totalProgress); } return(sb.ToString()); }
public void L8_FromRgba32(byte rgb) { // Arrange L8 gray = default; byte expected = ColorNumerics.Get8BitBT709Luminance(rgb, rgb, rgb); // Act gray.FromRgba32(new Rgba32(rgb, rgb, rgb)); byte actual = gray.PackedValue; // Assert Assert.Equal(expected, actual); }
public void Rgba32_ToL8_IsInverseOf_L8_ToRgba32(byte luminance) { var original = new L8(luminance); Rgba32 rgba = default; original.ToRgba32(ref rgba); L8 mirror = default; mirror.FromRgba32(rgba); Assert.Equal(original, mirror); }
public void CalculateIntegralImage_Rgba32Works(TestImageProvider <Rgba32> provider) { using Image <Rgba32> image = provider.GetImage(); // Act: Buffer2D <ulong> integralBuffer = image.CalculateIntegralImage(); // Assert: VerifySumValues(provider, integralBuffer, (Rgba32 pixel) => { L8 outputPixel = default; outputPixel.FromRgba32(pixel); return(outputPixel.PackedValue); }); }