예제 #1
0
            private void LimitBufferCapacity(int bufferCapacityInBytes)
            {
                var allocator = new TestMemoryAllocator();

                allocator.BufferCapacityInBytes    = bufferCapacityInBytes;
                this.configuration.MemoryAllocator = allocator;
            }
예제 #2
0
        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>()));
        }
예제 #3
0
        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));
                }
            }
        }
예제 #4
0
        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>(
예제 #5
0
        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);
        }