Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
034472e
Added base BokehBlurProcessor class, and kernel parameters
Sergio0694 Feb 19, 2019
cdd004d
Added method to calculate the kernel parameters
Sergio0694 Feb 19, 2019
0bcd244
Switched to float, added method to create the 1D kernels
Sergio0694 Feb 19, 2019
3dbf5e5
Added complex kernels normalization
Sergio0694 Feb 19, 2019
c21d35b
Added BokehBlurExtensions class
Sergio0694 Feb 19, 2019
e0c60cc
Added the Complex64 struct type
Sergio0694 Feb 20, 2019
b42b9f7
Switched to Complex64 in the BokehBlurProcessor
Sergio0694 Feb 20, 2019
177a40c
Added caching system for the bokeh processor parameters
Sergio0694 Feb 20, 2019
0716ced
Added WeightedSum method to the Complex64 type
Sergio0694 Feb 20, 2019
47721ce
Added IEquatable<T> interface to the Complex64 type
Sergio0694 Feb 21, 2019
8468a2f
New complex types added
Sergio0694 Feb 21, 2019
2e7fb74
Added method to reshape a DenseMatrix<T> with no copies
Sergio0694 Feb 21, 2019
bd8c2e3
Added bokeh convolution first pass (WIP)
Sergio0694 Feb 21, 2019
ceebb7b
Added second bokeh convolution pass (WIP)
Sergio0694 Feb 21, 2019
732d229
Added image sum pass to the bokeh processor (WIP)
Sergio0694 Feb 21, 2019
5fe13ea
Minor bug fixes (WIP)
Sergio0694 Feb 21, 2019
df8c786
Switched to Vector4 processing in the bokeh computation
Sergio0694 Feb 21, 2019
9bd1c87
Minor tweaks
Sergio0694 Feb 21, 2019
15d0a98
Added Unit test for the bokeh kernel components
Sergio0694 Feb 22, 2019
6fc9c50
Minor performance improvements
Sergio0694 Feb 22, 2019
5985904
Minor code refactoring, added gamma parameter (WIP)
Sergio0694 Feb 22, 2019
3b7ad24
Removed unused temp buffers in the bokeh processing
Sergio0694 Feb 22, 2019
c654965
Gamma highlight processing implemented
Sergio0694 Feb 22, 2019
a261f93
Speed optimizations, fixed partials computations in target rectangle
Sergio0694 Feb 22, 2019
b36a907
Increased epsilon value in the unit tests
Sergio0694 Feb 23, 2019
5b8579b
Fixed for alpha transparency blur
Sergio0694 Feb 23, 2019
bf090ad
Fixed a bug when only blurring a target rectangle
Sergio0694 Feb 23, 2019
34308fe
Added bokeh blur image tests (WIP)
Sergio0694 Feb 23, 2019
c2486eb
Added IXunitSerializable interface to the test info class
Sergio0694 Feb 23, 2019
1fe7a43
culture independent parsing in BokehBlurTest.cs
antonfirsov Feb 23, 2019
fb4efe5
Performance optimizations in the bokeh processor
Sergio0694 Feb 23, 2019
9711d5f
Reduced number of memory allocations, fixed bug with multiple components
Sergio0694 Feb 23, 2019
697766e
Initialization and other speed improvements
Sergio0694 Feb 23, 2019
bd348a3
More initialization speed improvements
Sergio0694 Feb 23, 2019
ee5bbc3
Replaced LINQ with manual loop
Sergio0694 Feb 23, 2019
a64636e
Added BokehBlur overload to just specify the target bounds
Sergio0694 Feb 23, 2019
e18066e
Speed optimizations to the bokeh 1D convolutions
Sergio0694 Feb 23, 2019
1122563
More speed optimizations to the bokeh processor
Sergio0694 Feb 23, 2019
afcf78a
Fixed code style and Complex64.ToString method
Sergio0694 Feb 24, 2019
b56da13
Fixed processing buffer initialization
Sergio0694 Feb 26, 2019
32d062d
Minor performance improvements
Sergio0694 Feb 26, 2019
6e3e541
FIxed issue when applying bokeh blur to specific bounds
Sergio0694 Mar 9, 2019
39ce26c
Minor speed optimizaations
Sergio0694 Mar 9, 2019
4f77a38
Minor code refactoring
Sergio0694 Mar 9, 2019
93b6a82
Fixed convolution upper bound in second 1D pass
Sergio0694 Mar 15, 2019
d0b0b2b
improve BokehBlurTest coverage
antonfirsov Mar 31, 2019
3772e89
use Gray8 instead of Alpha8
antonfirsov Mar 31, 2019
2ed623a
Adjusted guard position in bokeh processor constructor
Sergio0694 Mar 31, 2019
c05d39a
Added BokehBlurParameters struct
Sergio0694 Mar 31, 2019
d511f06
Added BokehBlurKernelData struct
Sergio0694 Mar 31, 2019
73ee135
Minor code refactoring
Sergio0694 Mar 31, 2019
de72bfd
Fixed API change build errors
Sergio0694 Apr 7, 2019
93e8c1a
Bug fixes with the pixel premultiplication steps
Sergio0694 Apr 7, 2019
2e89d3d
Removed unwanted unpremultiplication pass
Sergio0694 Apr 7, 2019
7ec6905
Removed unused using directives
Sergio0694 Apr 7, 2019
2c5c85d
Fixed missing using directives in conditional branches
Sergio0694 Apr 7, 2019
343da66
Update from latest upstream master
JimBobSquarePants Jul 29, 2019
9304db2
Merge branch 'master' into feature_bokeh-blur-impl
JimBobSquarePants Jul 29, 2019
32d9077
Update Block8x8F.Generated.cs
JimBobSquarePants Jul 29, 2019
512586e
Update GenericBlock8x8.Generated.cs
JimBobSquarePants Jul 29, 2019
0e6259d
Manual checking for files with LF (see gitter)
Sergio0694 Jul 29, 2019
f36564c
Removed unused using directive
Sergio0694 Jul 29, 2019
9491262
Added IEquatable<ComplexVector4> interface
Sergio0694 Jul 29, 2019
9edf46b
Added IEquatable<BokehBlurParameters> interface
Sergio0694 Jul 29, 2019
db58163
Moved bokeh blur parameters types
Sergio0694 Jul 29, 2019
24cc75a
Added reference to original source code
Sergio0694 Jul 29, 2019
0a77f69
Complex convolution methods moved to another class
Sergio0694 Jul 29, 2019
04984cd
Switched to MathF in the bokeh blur processor
Sergio0694 Jul 29, 2019
a70518b
Switched to Vector4.Clamp
Sergio0694 Jul 29, 2019
8aec5e0
Added Buffer2D<T>.Slice API
Sergio0694 Aug 1, 2019
3f24cee
Added BokehBlurExecutionMode enum
Sergio0694 Aug 1, 2019
06dfb02
Added new bokeh blur processor constructors
Sergio0694 Aug 1, 2019
f1a0c37
Added new bokeh blur extension overloads with execution mode
Sergio0694 Aug 1, 2019
ebd64f6
Code refactoring in preparation for the execution mode switch
Sergio0694 Aug 1, 2019
5fc559a
Implemented execution mode switch in the bokeh processor
Sergio0694 Aug 1, 2019
7e7f163
Merge pull request #7 from Sergio0694/feature_bokeh-blur-impl-switch
Sergio0694 Aug 4, 2019
9aa75cc
Moved BokehBlurExecutionMode struct
Sergio0694 Aug 5, 2019
0869492
Removed unused using directives
Sergio0694 Aug 5, 2019
f663adf
Minor code refactoring
Sergio0694 Aug 5, 2019
8e9986e
More minor code refactoring
Sergio0694 Aug 5, 2019
5d28f6e
Update External
JimBobSquarePants Aug 6, 2019
c94948c
Fix undisposed buffers
JimBobSquarePants Aug 6, 2019
11fadaf
Bokeh blur processor cache switched to concurrent dictionary
Sergio0694 Aug 6, 2019
871ae09
Minor code refactoring
Sergio0694 Aug 6, 2019
efe5322
Merge branch 'master' into feature_bokeh-blur-impl
antonfirsov Aug 6, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions src/ImageSharp/Color/Color.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Licensed under the Apache License, Version 2.0.

using System;
using System.Buffers.Binary;
using System.Globalization;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down
105 changes: 105 additions & 0 deletions src/ImageSharp/Common/Helpers/Buffer2DUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Primitives;

namespace SixLabors.ImageSharp
{
/// <summary>
/// Extension methods for <see cref="Buffer2D{T}"/>.
/// TODO: One day rewrite all this to use SIMD intrinsics. There's a lot of scope for improvement.
/// </summary>
internal static class Buffer2DUtils
{
/// <summary>
/// Computes the sum of vectors in <paramref name="targetRow"/> weighted by the kernel weight values.
/// </summary>
/// <typeparam name="TPixel">The pixel format.</typeparam>
/// <param name="kernel">The 1D convolution kernel.</param>
/// <param name="sourcePixels">The source frame.</param>
/// <param name="targetRow">The target row.</param>
/// <param name="row">The current row.</param>
/// <param name="column">The current column.</param>
/// <param name="minRow">The minimum working area row.</param>
/// <param name="maxRow">The maximum working area row.</param>
/// <param name="minColumn">The minimum working area column.</param>
/// <param name="maxColumn">The maximum working area column.</param>
public static void Convolve4<TPixel>(
Span<Complex64> kernel,
Buffer2D<TPixel> sourcePixels,
Span<ComplexVector4> targetRow,
int row,
int column,
int minRow,
int maxRow,
int minColumn,
int maxColumn)
where TPixel : struct, IPixel<TPixel>
{
ComplexVector4 vector = default;
int kernelLength = kernel.Length;
int radiusY = kernelLength >> 1;
int sourceOffsetColumnBase = column + minColumn;
ref Complex64 baseRef = ref MemoryMarshal.GetReference(kernel);

for (int i = 0; i < kernelLength; i++)
{
int offsetY = (row + i - radiusY).Clamp(minRow, maxRow);
int offsetX = sourceOffsetColumnBase.Clamp(minColumn, maxColumn);
Span<TPixel> sourceRowSpan = sourcePixels.GetRowSpan(offsetY);
var currentColor = sourceRowSpan[offsetX].ToVector4();

vector.Sum(Unsafe.Add(ref baseRef, i) * currentColor);
}

targetRow[column] = vector;
}

/// <summary>
/// Computes the sum of vectors in <paramref name="targetRow"/> weighted by the kernel weight values.
/// </summary>
/// <param name="kernel">The 1D convolution kernel.</param>
/// <param name="sourceValues">The source frame.</param>
/// <param name="targetRow">The target row.</param>
/// <param name="row">The current row.</param>
/// <param name="column">The current column.</param>
/// <param name="minRow">The minimum working area row.</param>
/// <param name="maxRow">The maximum working area row.</param>
/// <param name="minColumn">The minimum working area column.</param>
/// <param name="maxColumn">The maximum working area column.</param>
public static void Convolve4(
Span<Complex64> kernel,
Buffer2D<ComplexVector4> sourceValues,
Span<ComplexVector4> targetRow,
int row,
int column,
int minRow,
int maxRow,
int minColumn,
int maxColumn)
{
ComplexVector4 vector = default;
int kernelLength = kernel.Length;
int radiusX = kernelLength >> 1;
int sourceOffsetColumnBase = column + minColumn;

int offsetY = row.Clamp(minRow, maxRow);
ref ComplexVector4 sourceRef = ref MemoryMarshal.GetReference(sourceValues.GetRowSpan(offsetY));
ref Complex64 baseRef = ref MemoryMarshal.GetReference(kernel);

for (int x = 0; x < kernelLength; x++)
{
int offsetX = (sourceOffsetColumnBase + x - radiusX).Clamp(minColumn, maxColumn);
vector.Sum(Unsafe.Add(ref baseRef, x) * Unsafe.Add(ref sourceRef, offsetX));
}

targetRow[column] = vector;
}
}
}
14 changes: 5 additions & 9 deletions src/ImageSharp/Common/Helpers/DenseMatrixUtils.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Six Labors and contributors.
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
Expand Down Expand Up @@ -45,8 +45,6 @@ public static void Convolve2D3<TPixel>(
int maxColumn)
where TPixel : struct, IPixel<TPixel>
{
Vector4 vector = default;

Convolve2DImpl(
in matrixY,
in matrixX,
Expand All @@ -57,7 +55,7 @@ public static void Convolve2D3<TPixel>(
maxRow,
minColumn,
maxColumn,
ref vector);
out Vector4 vector);

ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column);
vector.W = target.W;
Expand Down Expand Up @@ -95,8 +93,6 @@ public static void Convolve2D4<TPixel>(
int maxColumn)
where TPixel : struct, IPixel<TPixel>
{
Vector4 vector = default;

Convolve2DImpl(
in matrixY,
in matrixX,
Expand All @@ -107,7 +103,7 @@ public static void Convolve2D4<TPixel>(
maxRow,
minColumn,
maxColumn,
ref vector);
out Vector4 vector);

ref Vector4 target = ref Unsafe.Add(ref targetRowRef, column);
Vector4Utils.UnPremultiply(ref vector);
Expand All @@ -125,7 +121,7 @@ public static void Convolve2DImpl<TPixel>(
int maxRow,
int minColumn,
int maxColumn,
ref Vector4 vector)
out Vector4 vector)
where TPixel : struct, IPixel<TPixel>
{
Vector4 vectorY = default;
Expand Down Expand Up @@ -281,4 +277,4 @@ private static void ConvolveImpl<TPixel>(
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.

using System;
using System.Diagnostics;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down
3 changes: 0 additions & 3 deletions src/ImageSharp/Common/Helpers/SimdUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Tuples;

namespace SixLabors.ImageSharp
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.

using System;
using System.Collections.Generic;

using SixLabors.Primitives;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System;
using System.Runtime.CompilerServices;

using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.PixelFormats;

namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
Expand Down
1 change: 0 additions & 1 deletion src/ImageSharp/Formats/Jpeg/Components/GenericBlock8x8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using SixLabors.ImageSharp.Advanced;
using SixLabors.ImageSharp.Memory;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Memory;

// ReSharper disable InconsistentNaming
namespace SixLabors.ImageSharp.Formats.Jpeg.Components
Expand Down
1 change: 0 additions & 1 deletion src/ImageSharp/Memory/Buffer2DExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.

using System;
using System.Buffers;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
Expand Down
24 changes: 21 additions & 3 deletions src/ImageSharp/Memory/Buffer2D{T}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,31 @@ public Buffer2D(MemorySource<T> memorySource, int width, int height)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get
{
ImageSharp.DebugGuard.MustBeLessThan(x, this.Width, nameof(x));
ImageSharp.DebugGuard.MustBeLessThan(y, this.Height, nameof(y));
DebugGuard.MustBeLessThan(x, this.Width, nameof(x));
DebugGuard.MustBeLessThan(y, this.Height, nameof(y));

Span<T> span = this.Span;
return ref span[(this.Width * y) + x];
}
}

/// <summary>
/// Creates a new <see cref="Buffer2D{T}"/> instance that maps to a target rows interval from the current instance.
/// </summary>
/// <param name="y">The target vertical offset for the rows interval to retrieve.</param>
/// <param name="h">The desired number of rows to extract.</param>
/// <returns>The new <see cref="Buffer2D{T}"/> instance with the requested rows interval.</returns>
public Buffer2D<T> Slice(int y, int h)
{
DebugGuard.MustBeGreaterThanOrEqualTo(y, 0, nameof(y));
DebugGuard.MustBeGreaterThan(h, 0, nameof(h));
DebugGuard.MustBeLessThanOrEqualTo(y + h, this.Height, nameof(h));

Memory<T> slice = this.Memory.Slice(y * this.Width, h * this.Width);
var memory = new MemorySource<T>(slice);
return new Buffer2D<T>(memory, this.Width, h);
}

/// <summary>
/// Disposes the <see cref="Buffer2D{T}"/> instance
/// </summary>
Expand Down Expand Up @@ -98,4 +116,4 @@ private static void SwapDimensionData(Buffer2D<T> a, Buffer2D<T> b)
a.Height = bSize.Height;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0.

using System;
using System.Text;

namespace SixLabors.ImageSharp.Metadata.Profiles.Icc
{
Expand Down
1 change: 0 additions & 1 deletion src/ImageSharp/PixelFormats/PixelImplementations/Gray16.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Six Labors and contributors.
// Licensed under the Apache License, Version 2.0.

using System;
using System.Numerics;
using System.Runtime.CompilerServices;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Runtime.InteropServices;

using SixLabors.ImageSharp.PixelFormats.Utils;
using SixLabors.Memory;

namespace SixLabors.ImageSharp.PixelFormats
{
Expand Down
2 changes: 0 additions & 2 deletions src/ImageSharp/PixelFormats/PixelOperations{TPixel}.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System;
using System.Buffers;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

using SixLabors.ImageSharp.Memory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

using SixLabors.ImageSharp.ColorSpaces.Companding;

namespace SixLabors.ImageSharp.PixelFormats.Utils
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

using SixLabors.ImageSharp.ColorSpaces.Companding;

namespace SixLabors.ImageSharp.PixelFormats.Utils
{
/// <content>
Expand Down
Loading