public void WorksWithDiscoBuffers <TPixel>( TestImageProvider <TPixel> provider, int workingBufferLimitInRows, int bufferCapacityInRows) where TPixel : struct, IPixel <TPixel> { using Image <TPixel> expected = provider.GetImage(); int width = expected.Width; Size destSize = expected.Size() / 4; expected.Mutate(c => c.Resize(destSize, KnownResamplers.Bicubic, false)); // Replace configuration: provider.Configuration = Configuration.CreateDefaultInstance(); // Note: when AllocatorCapacityInBytes < WorkingBufferSizeHintInBytes, // ResizeProcessor is expected to use the minimum of the two values, when establishing the working buffer. provider.LimitAllocatorBufferCapacity().InBytes(width * bufferCapacityInRows * SizeOfVector4); provider.Configuration.WorkingBufferSizeHintInBytes = width * workingBufferLimitInRows * SizeOfVector4; using Image <TPixel> actual = provider.GetImage(); actual.Mutate(c => c.Resize(destSize, KnownResamplers.Bicubic, false)); actual.DebugSave(provider, $"{workingBufferLimitInRows}-{bufferCapacityInRows}"); ImageComparer.Exact.VerifySimilarity(expected, actual); }
public void EncodeGeneratedPatterns <TPixel>(TestImageProvider <TPixel> provider, bool limitAllocationBuffer) where TPixel : struct, IPixel <TPixel> { if (limitAllocationBuffer) { provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100); } using (Image <TPixel> image = provider.GetImage()) { var encoder = new GifEncoder { // Use the palette quantizer without dithering to ensure results // are consistent Quantizer = new WebSafePaletteQuantizer(new QuantizerOptions { Dither = null }) }; // Always save as we need to compare the encoded output. provider.Utility.SaveTestOutputFile(image, "gif", encoder); } // Compare encoded result string path = provider.Utility.GetTestOutputFileName("gif", null, true); using (var encoded = Image.Load <Rgba32>(path)) { encoded.CompareToReferenceOutput(ValidatorComparer, provider, null, "gif"); } }
public void GifDecoder_DegenerateMemoryRequest_ShouldTranslateTo_ImageFormatException<TPixel>(TestImageProvider<TPixel> provider) where TPixel : unmanaged, IPixel<TPixel> { provider.LimitAllocatorBufferCapacity().InPixelsSqrt(10); InvalidImageContentException ex = Assert.Throws<InvalidImageContentException>(() => provider.GetImage(GifDecoder)); Assert.IsType<InvalidMemoryOperationException>(ex.InnerException); }
public void DangerousGetPixelRowMemory_PixelDataIsCorrect <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { provider.LimitAllocatorBufferCapacity().InPixelsSqrt(200); using Image <TPixel> image = provider.GetImage(); for (int y = 0; y < image.Height; y++) { // Act: Memory <TPixel> rowMemoryFromImage = image.DangerousGetPixelRowMemory(y); Memory <TPixel> rowMemoryFromFrame = image.Frames.RootFrame.DangerousGetPixelRowMemory(y); Span <TPixel> spanFromImage = rowMemoryFromImage.Span; Span <TPixel> spanFromFrame = rowMemoryFromFrame.Span; Assert.Equal(spanFromFrame.Length, spanFromImage.Length); Assert.True(Unsafe.AreSame(ref spanFromFrame[0], ref spanFromImage[0])); // Assert: for (int x = 0; x < image.Width; x++) { Assert.Equal(provider.GetExpectedBasicTestPatternPixelAt(x, y), spanFromImage[x]); } } }
public async Task DecodeAsnc_DegenerateMemoryRequest_ShouldTranslateTo_ImageFormatException <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { provider.LimitAllocatorBufferCapacity().InBytesSqrt(10); InvalidImageContentException ex = await Assert.ThrowsAsync <InvalidImageContentException>(() => provider.GetImageAsync(JpegDecoder)); this.Output.WriteLine(ex.Message); Assert.IsType <InvalidMemoryOperationException>(ex.InnerException); }
public void DegenerateMemoryRequest_ShouldTranslateTo_ImageFormatException <TPixel>(TestImageProvider <TPixel> provider) where TPixel : struct, IPixel <TPixel> { provider.LimitAllocatorBufferCapacity().InBytesSqrt(10); ImageFormatException ex = Assert.Throws <ImageFormatException>(() => provider.GetImage(JpegDecoder)); this.Output.WriteLine(ex.Message); Assert.IsType <InvalidMemoryOperationException>(ex.InnerException); }
static void RunTest(string providerDump, string nonContiguousBuffersStr) { TestImageProvider <Rgba32> provider = BasicSerializer.Deserialize <TestImageProvider <Rgba32> >(providerDump); provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100); using Image <Rgba32> image = provider.GetImage(PngDecoder); image.DebugSave(provider, testOutputDetails: nonContiguousBuffersStr); image.CompareToOriginal(provider); }
public void EncodeBaseline_WorksWithDiscontiguousBuffers <TPixel>(TestImageProvider <TPixel> provider, JpegSubsample subsample) where TPixel : unmanaged, IPixel <TPixel> { ImageComparer comparer = subsample == JpegSubsample.Ratio444 ? ImageComparer.TolerantPercentage(0.1f) : ImageComparer.TolerantPercentage(5f); provider.LimitAllocatorBufferCapacity().InBytesSqrt(200); TestJpegEncoderCore(provider, subsample, 100, JpegColorType.YCbCr, comparer); }
public void GetPixelRowSpan_ShouldReferenceSpanOfMemory <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { provider.LimitAllocatorBufferCapacity().InPixelsSqrt(200); using Image <TPixel> image = provider.GetImage(); Memory <TPixel> memory = image.GetPixelRowMemory(image.Height - 1); Span <TPixel> span = image.GetPixelRowSpan(image.Height - 1); Assert.True(span == memory.Span); }
public void TiffEncode_WorksWithDiscontiguousBuffers <TPixel>(TestImageProvider <TPixel> provider, TiffPhotometricInterpretation photometricInterpretation) where TPixel : unmanaged, IPixel <TPixel> { provider.LimitAllocatorBufferCapacity().InPixelsSqrt(200); using Image <TPixel> image = provider.GetImage(); var encoder = new TiffEncoder { PhotometricInterpretation = photometricInterpretation }; image.DebugSave(provider, encoder); }
public void OwnedMemory_PixelDataIsCorrect <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { provider.LimitAllocatorBufferCapacity().InPixelsSqrt(200); using Image <TPixel> image = provider.GetImage(); // Act: IMemoryGroup <TPixel> memoryGroup = image.GetPixelMemoryGroup(); // Assert: VerifyMemoryGroupDataMatchesTestPattern(provider, memoryGroup, image.Size()); }
static void RunTest(string providerDump, string nonContiguousBuffersStr) { TestImageProvider <Rgba32> provider = BasicSerializer.Deserialize <TestImageProvider <Rgba32> >(providerDump); provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100); using Image <Rgba32> image = provider.GetImage(BmpDecoder); image.DebugSave(provider, nonContiguousBuffersStr); if (TestEnvironment.IsWindows) { image.CompareToOriginal(provider); } }
static void RunTest(string providerDump, string nonContiguousBuffersStr) { TestImageProvider <Rgb24> provider = BasicSerializer.Deserialize <TestImageProvider <Rgb24> >(providerDump); provider.LimitAllocatorBufferCapacity().InBytesSqrt(200); using Image <Rgb24> image = provider.GetImage(JpegDecoder); image.DebugSave(provider, nonContiguousBuffersStr); provider.Utility.TestName = DecodeProgressiveJpegOutputName; image.CompareToReferenceOutput( GetImageComparer(provider), provider, appendPixelTypeToFileName: false); }
public void Encode_WorksWithDiscontiguousBuffers <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { provider.LimitAllocatorBufferCapacity().InPixelsSqrt(200); foreach (PngInterlaceMode interlaceMode in InterlaceMode) { TestPngEncoderCore( provider, PngColorType.Rgb, PngFilterMethod.Adaptive, PngBitDepth.Bit8, interlaceMode, appendPixelType: true, appendPngColorType: true); } }
static void RunTest(string providerDump, string nonContiguousBuffersStr) { TestImageProvider <TPixel> provider = BasicSerializer.Deserialize <TestImageProvider <TPixel> >(providerDump); if (!string.IsNullOrEmpty(nonContiguousBuffersStr)) { provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100); } using Image <TPixel> image = provider.GetImage(BmpDecoder); image.DebugSave(provider, testOutputDetails: nonContiguousBuffersStr); if (TestEnvironment.IsWindows) { image.CompareToOriginal(provider); } }
static void RunTest(string providerDump, string nonContiguousBuffersStr) { TestImageProvider <TPixel> provider = BasicSerializer.Deserialize <TestImageProvider <TPixel> >(providerDump); if (!string.IsNullOrEmpty(nonContiguousBuffersStr)) { provider.LimitAllocatorBufferCapacity().InPixels(1000 * 8); } using Image <TPixel> image = provider.GetImage(JpegDecoder); image.DebugSave(provider, testOutputDetails: nonContiguousBuffersStr); provider.Utility.TestName = DecodeBaselineJpegOutputName; image.CompareToReferenceOutput( GetImageComparer(provider), provider, appendPixelTypeToFileName: false); }
public void GetPixelRowMemory_PixelDataIsCorrect <TPixel>(TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { provider.LimitAllocatorBufferCapacity().InPixelsSqrt(200); using Image <TPixel> image = provider.GetImage(); for (int y = 0; y < image.Height; y++) { // Act: Memory <TPixel> rowMemory = image.GetPixelRowMemory(y); Span <TPixel> span = rowMemory.Span; // Assert: for (int x = 0; x < image.Width; x++) { Assert.Equal(provider.GetExpectedBasicTestPatternPixelAt(x, y), span[x]); } } }
public void TgaEncoder_WorksWithDiscontiguousBuffers <TPixel>(TestImageProvider <TPixel> provider, TgaBitsPerPixel bitsPerPixel) where TPixel : unmanaged, IPixel <TPixel> { provider.LimitAllocatorBufferCapacity().InPixelsSqrt(100); TestTgaEncoderCore(provider, bitsPerPixel, TgaCompression.RunLength); }
public void Encode_WorksWithDiscontiguousBuffers <TPixel>(TestImageProvider <TPixel> provider, BmpBitsPerPixel bitsPerPixel) where TPixel : unmanaged, IPixel <TPixel> { provider.LimitAllocatorBufferCapacity().InBytesSqrt(100); TestBmpEncoderCore(provider, bitsPerPixel); }