Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jpeg downscaling decoding #2076

Merged
merged 34 commits into from
Jul 17, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
36180c6
playground
Mar 19, 2022
11220a3
Replaced absurdly complicated math from JpegComponentPostProcessor
Mar 19, 2022
afbf44b
Infrastructure
Mar 21, 2022
017919a
First working prototype, not optimized
Mar 22, 2022
5cca314
Added playground benchmarks
Mar 22, 2022
a10be09
Resizing converter no longer depends on avx converter only
Mar 23, 2022
1ce994a
Unified spectral conversion for direct and downscaled routines
Mar 25, 2022
4e17b69
Added second stage to the resizing decoding
Mar 26, 2022
f4d5f1a
Chroma subsampling for downscaling decoder
Mar 26, 2022
282e593
Update playground
Mar 26, 2022
8192ff2
Initial processor implementation, code base for tests
Mar 29, 2022
52f507d
Separated scaled IDCT methods
Apr 1, 2022
6eceb6c
Moved quantization table initialization to component post processors
Apr 1, 2022
03407f1
4x4 implementation, tests
Apr 2, 2022
1050cf2
Fixed bug leading to gray images after decoding
Apr 12, 2022
9575a24
Fix compilation error
Apr 12, 2022
c57ca1b
Merge branch 'main' into dp/jpeg-downscaling-decode
Apr 12, 2022
12776f0
IDCT resizing modes
Apr 23, 2022
7057245
Code cleanup, removed invalid second pass logic, marked scaled decodi…
Apr 26, 2022
bfbfdfa
Added tests for out jpeg image size getter method
Apr 30, 2022
b943f80
Restored Program.cs
Apr 30, 2022
bb82e27
Merge branch 'main' into dp/jpeg-downscaling-decode
May 1, 2022
6747339
Docs & review fixes
May 1, 2022
1aff245
Merge branch 'dp/jpeg-downscaling-decode' of https://github.com/br3ak…
May 1, 2022
f011dcc
Unsafe.Add fix
May 1, 2022
3feb7f6
Merge branch 'main' of https://github.com/SixLabors/ImageSharp into d…
May 1, 2022
95c56b0
Small bug fixes, ready for merging
May 1, 2022
ed86426
Updated load-resize-save benchmark, deleted obsolete benchmarks
May 1, 2022
9f35b78
Merge branch 'main' into dp/jpeg-downscaling-decode
May 2, 2022
2896faf
Merge branch 'main' into dp/jpeg-downscaling-decode
brianpopow May 17, 2022
3f16a68
Merge branch 'main' into dp/jpeg-downscaling-decode
Jun 26, 2022
9851315
Added resizing benchmark results
Jun 26, 2022
d0de191
Merge remote-tracking branch 'upstream/main' into dp/jpeg-downscaling…
JimBobSquarePants Jul 16, 2022
7a9cf87
Fix headers
JimBobSquarePants Jul 16, 2022
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
Prev Previous commit
Next Next commit
Resizing converter no longer depends on avx converter only
  • Loading branch information
Dmitry Pentin committed Mar 26, 2022
commit a10be094f0f257988d747d49f075735371d01754
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
#if SUPPORTS_RUNTIME_INTRINSICS
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;

namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Decoder.ColorConverters
Expand All @@ -25,7 +26,9 @@ protected JpegColorConverterAvx(JpegColorSpace colorSpace, int precision)
{
}

public override bool IsAvailable => Avx.IsSupported;
public sealed override bool IsAvailable => Avx.IsSupported;

public sealed override int ElementsPerBatch => Vector256<float>.Count;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ protected JpegColorConverterBase(JpegColorSpace colorSpace, int precision)
/// </summary>
public abstract bool IsAvailable { get; }

/// <summary>
/// Gets a value indicating how many pixels are processed in a single batch.
/// </summary>
/// <remarks>
/// This generaly should be equal to register size,
br3aker marked this conversation as resolved.
Show resolved Hide resolved
/// e.g. 1 for scalar implementation, 8 for AVX implementation and so on.
/// </remarks>
public abstract int ElementsPerBatch { get; }

/// <summary>
/// Gets the <see cref="JpegColorSpace"/> of this converter.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ protected JpegColorConverterScalar(JpegColorSpace colorSpace, int precision)
{
}

public override bool IsAvailable => true;
public sealed override bool IsAvailable => true;

public sealed override int ElementsPerBatch => 1;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal abstract partial class JpegColorConverterBase
/// Even though real life data is guaranteed to be of size
/// divisible by 8 newer SIMD instructions like AVX512 won't work with
/// such data out of the box. These converters have fallback code
/// for 'remainder' data.
/// for remainder data.
/// </remarks>
internal abstract class JpegColorConverterVector : JpegColorConverterBase
{
Expand All @@ -28,7 +28,9 @@ protected JpegColorConverterVector(JpegColorSpace colorSpace, int precision)

public sealed override bool IsAvailable => Vector.IsHardwareAccelerated && Vector<float>.Count % 4 == 0;

public override void ConvertToRgbInplace(in ComponentValues values)
public sealed override int ElementsPerBatch => Vector<float>.Count;

public sealed override void ConvertToRgbInplace(in ComponentValues values)
{
DebugGuard.IsTrue(this.IsAvailable, $"{this.GetType().Name} converter is not supported on current hardware.");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,20 @@ public override void InjectFrameData(JpegFrame frame, IRawJpegData jpegData)
int blockPixelSize = 8 / scaleDenominator;
this.pixelRowsPerStep = majorVerticalSamplingFactor * blockPixelSize;

// BUFFER SIZE MUST BE DIVISIBLE BY 8 ATM
// TODO: fix this mess
// color converter
JpegColorConverterBase converter = this.GetColorConverter(frame, jpegData);
this.colorConverter = converter;

int bufferWidth = majorBlockWidth * blockPixelSize;
int correctedBufferWidth = bufferWidth + (8 - (bufferWidth % 8));
int batchSize = converter.ElementsPerBatch;
int correctedBufferWidth = bufferWidth + (batchSize - (bufferWidth % batchSize));
var postProcessorBufferSize = new Size(correctedBufferWidth, this.pixelRowsPerStep);

this.componentProcessors = new JpegComponentPostProcessor8[frame.Components.Length];
for (int i = 0; i < this.componentProcessors.Length; i++)
{
this.componentProcessors[i] = new JpegComponentPostProcessor8(allocator, frame, jpegData, postProcessorBufferSize, frame.Components[i]);
}

// color converter
this.colorConverter = this.GetColorConverter(frame, jpegData);
}

public override void ConvertStrideBaseline()
Expand Down