private void LimitBufferCapacity(int bufferCapacityInBytes) { var allocator = new TestMemoryAllocator(); allocator.BufferCapacityInBytes = bufferCapacityInBytes; this.configuration.MemoryAllocator = allocator; }
internal static AllocatorBufferCapacityConfigurator LimitAllocatorBufferCapacity <TPixel>( this TestImageProvider <TPixel> provider) where TPixel : unmanaged, IPixel <TPixel> { var allocator = new TestMemoryAllocator(); provider.Configuration.MemoryAllocator = allocator; return(new AllocatorBufferCapacityConfigurator(allocator, Unsafe.SizeOf <TPixel>())); }
public void WorkingBufferSizeHintInBytes_IsAppliedCorrectly <TPixel>( TestImageProvider <TPixel> provider, int workingBufferLimitInRows) where TPixel : struct, IPixel <TPixel> { using (Image <TPixel> image0 = provider.GetImage()) { Size destSize = image0.Size() / 4; var configuration = Configuration.CreateDefaultInstance(); int workingBufferSizeHintInBytes = workingBufferLimitInRows * destSize.Width * SizeOfVector4; var allocator = new TestMemoryAllocator(); configuration.MemoryAllocator = allocator; configuration.WorkingBufferSizeHintInBytes = workingBufferSizeHintInBytes; var verticalKernelMap = ResizeKernelMap.Calculate( KnownResamplers.Bicubic, destSize.Height, image0.Height, Configuration.Default.MemoryAllocator); int minimumWorkerAllocationInBytes = verticalKernelMap.MaxDiameter * 2 * destSize.Width * SizeOfVector4; verticalKernelMap.Dispose(); using (Image <TPixel> image = image0.Clone(configuration)) { image.Mutate(x => x.Resize(destSize, KnownResamplers.Bicubic, false)); image.DebugSave( provider, testOutputDetails: workingBufferLimitInRows, appendPixelTypeToFileName: false); image.CompareToReferenceOutput( ImageComparer.TolerantPercentage(0.001f), provider, testOutputDetails: workingBufferLimitInRows, appendPixelTypeToFileName: false); Assert.NotEmpty(allocator.AllocationLog); int maxAllocationSize = allocator.AllocationLog.Where( e => e.ElementType == typeof(Vector4)).Max(e => e.LengthInBytes); Assert.True(maxAllocationSize <= Math.Max(workingBufferSizeHintInBytes, minimumWorkerAllocationInBytes)); } } }
public void WorkingBufferSizeHintInBytes_IsAppliedCorrectly <TPixel>( TestImageProvider <TPixel> provider, int workingBufferLimitInRows) where TPixel : unmanaged, IPixel <TPixel> { using (Image <TPixel> image0 = provider.GetImage()) { Size destSize = image0.Size() / 4; var configuration = Configuration.CreateDefaultInstance(); int workingBufferSizeHintInBytes = workingBufferLimitInRows * destSize.Width * SizeOfVector4; var allocator = new TestMemoryAllocator(); configuration.MemoryAllocator = allocator; configuration.WorkingBufferSizeHintInBytes = workingBufferSizeHintInBytes; var verticalKernelMap = ResizeKernelMap.Calculate <BicubicResampler>(
internal static void RunBufferCapacityLimitProcessorTest <TPixel>( this TestImageProvider <TPixel> provider, int bufferCapacityInPixelRows, Action <IImageProcessingContext> process, object testOutputDetails = null, ImageComparer comparer = null) where TPixel : unmanaged, IPixel <TPixel> { comparer ??= ImageComparer.Exact; using Image <TPixel> expected = provider.GetImage(); int width = expected.Width; expected.Mutate(process); var allocator = new TestMemoryAllocator(); provider.Configuration.MemoryAllocator = allocator; allocator.BufferCapacityInBytes = bufferCapacityInPixelRows * width * Unsafe.SizeOf <TPixel>(); using Image <TPixel> actual = provider.GetImage(); actual.Mutate(process); comparer.VerifySimilarity(expected, actual); }