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

Add support for HEIF based images #2633

Open
wants to merge 203 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
203 commits
Select commit Hold shift + click to select a range
0829e86
Scaffolding for HEIC file format
ynse01 Dec 25, 2023
b5ce29d
Fix build
ynse01 Dec 25, 2023
bc97554
Initial Metadata parsing
ynse01 Dec 26, 2023
235aa38
HEIC test images
ynse01 Dec 26, 2023
c0297a3
Adapt code to .NET 8
ynse01 Dec 26, 2023
96b92e8
4CC generated by template
ynse01 Dec 27, 2023
9ad76ce
Rename Heic4CharCode files
ynse01 Dec 27, 2023
c3ce980
Use single buffer per decoder instance
ynse01 Dec 27, 2023
ff9629a
Add another sample image
ynse01 Dec 27, 2023
028e8a5
Initial tests
ynse01 Dec 27, 2023
f892c04
Byte alignment fixes
ynse01 Dec 27, 2023
193fd94
Boundary checking before box allocation
ynse01 Dec 27, 2023
8366d72
Add HIF test image
ynse01 Dec 27, 2023
5f9db61
Add handler parsing
ynse01 Dec 27, 2023
d6dc2b1
Parse HIF metadata
ynse01 Dec 27, 2023
f90d4eb
More HIF support
ynse01 Dec 27, 2023
f234c8b
Decoding of thumbnail with JPEG
ynse01 Dec 27, 2023
e972551
Exposed used compression method in metadata
ynse01 Dec 28, 2023
183b873
Reference image for Heic Decoder Test
ynse01 Dec 28, 2023
0bfa0fe
Initial encoder
ynse01 Dec 28, 2023
b60ce90
Move to Memory namespace
ynse01 Dec 28, 2023
23388b2
Box size predictions
ynse01 Dec 28, 2023
3f4e74b
Fix Heic encoder test
ynse01 Dec 29, 2023
54db9c7
Box size improvements
ynse01 Dec 29, 2023
6372a9a
Add AVIF test image
ynse01 Dec 29, 2023
bb3dc4e
Merge branch 'heic-support' of https://github.com/ynse01/ImageSharp i…
ynse01 Dec 29, 2023
3fae594
Identify AVIF files
ynse01 Dec 29, 2023
046b28f
Tests for AutoExpandingMemory class
ynse01 Dec 29, 2023
9d99b1a
Move to Heif directory
ynse01 Dec 29, 2023
4645e40
Rename namespace and classes to Heif
ynse01 Dec 29, 2023
5ad3d67
Fix configuration test
ynse01 Dec 29, 2023
42ff8f9
Remove reference to x265
ynse01 Jan 5, 2024
934dd61
Include SVT reference
ynse01 Jan 5, 2024
ccbae05
Consistent use of name HEIF
ynse01 Jan 5, 2024
0301aed
Decode ICC profile into metadata
ynse01 Jan 19, 2024
5dedc94
Initial av1 bitstream parsing
ynse01 Jan 7, 2024
f934927
Read parameters
ynse01 Jan 8, 2024
e45a41b
Av1 bitstream tests
ynse01 Jan 12, 2024
7b961ff
Optimized WriteBoolean()
ynse01 Jan 12, 2024
961d55e
Skeleton
ynse01 Jan 19, 2024
790207f
Prepare quantization
ynse01 Jan 20, 2024
03eda75
Merge branch 'main' into heic-support
JimBobSquarePants Feb 7, 2024
43569db
Merge branch 'main' into heic-support
JimBobSquarePants Mar 14, 2024
db44498
Casing in Heif4CharCode
ynse01 Mar 14, 2024
73bdbd8
Make some classes internal
ynse01 Mar 14, 2024
de392d8
Read header from stack allocated buffer
ynse01 Mar 15, 2024
d146069
Check Stream.Read return value
ynse01 Mar 17, 2024
c847f5d
Fix build
ynse01 Mar 17, 2024
a39182d
Merge remote-tracking branch 'upstream/main' into avif-in-heif
ynse01 Apr 5, 2024
b27765f
Merge branch 'heic-support' into avif-in-heif
ynse01 Apr 5, 2024
80140c4
Inverse quantization
ynse01 Apr 6, 2024
2c8dd67
Merge branch 'main' into heic-support
ynse01 Apr 17, 2024
40e9d68
Fix reading of larger literals
ynse01 Apr 17, 2024
66803d0
Merge remote-tracking branch 'upstream/main' into avif-in-heif
ynse01 Apr 17, 2024
894bbf2
Update infra
ynse01 Apr 17, 2024
47dc774
Obu header decoding
ynse01 Apr 21, 2024
6aa74f2
Rename to Av1Decoder
ynse01 Apr 21, 2024
f2bfd5a
Tile decoding interface
ynse01 Apr 23, 2024
73f4dce
Merge branch 'avif-in-heif' into heic-support
ynse01 Apr 23, 2024
a1a1a5a
Fix build
ynse01 Apr 23, 2024
07138c4
Use Tile Decoder interface
ynse01 Apr 23, 2024
6863542
Merge branch 'main' into heic-support
JimBobSquarePants Apr 26, 2024
a1cb2dd
Introduce ObuWriter
ynse01 Apr 28, 2024
74677ed
Fix bitstream writer
ynse01 May 1, 2024
ef572ac
ObuHeader round trips
ynse01 May 3, 2024
95d9f09
Initial symbol parsing
ynse01 May 12, 2024
06b0c04
Fix literal reading and writing
ynse01 May 17, 2024
e34b831
First symbol coding roundtrip
ynse01 May 17, 2024
fec0413
Initial symbol decoding
ynse01 May 28, 2024
b26c0fa
PartitionType symbol round trips
ynse01 Jun 1, 2024
b4f9e31
Merge branch 'main' into heic-support
ynse01 Jun 1, 2024
1184968
Introduce Tile Decoder
ynse01 Jun 1, 2024
881199e
Introduce Av1PartitionInfo and fill it during decoding
ynse01 Jun 2, 2024
98bad4d
Superblock decoding
ynse01 Jun 3, 2024
c0fcb42
Namespace rename
ynse01 Jun 3, 2024
bfed4ee
Add spec reference
ynse01 Jun 3, 2024
a8539f2
Rename Av1Constants class
ynse01 Jun 3, 2024
671c89d
Extend readme
ynse01 Jun 3, 2024
19ca2ea
Introduce Frame buffer class
ynse01 Jun 5, 2024
e64d74d
Simplify IAv1TileDecoder
ynse01 Jun 8, 2024
60869e1
Bug fixes in OBU parsing
ynse01 Jun 9, 2024
d8e7078
Implement reading AV1 Codec Configuration Record
brianpopow Jun 23, 2024
84127fa
Fix mistake in switch case for parsing Heif4CharCode.Av1C
brianpopow Jun 23, 2024
cb4f9ee
Add comments where the methods can be found in the spec
brianpopow Jun 24, 2024
aa44d0c
Add av1 spec file
brianpopow Jun 24, 2024
9ee8d92
Merge branch 'main' into heic-support
ynse01 Jun 24, 2024
c918eca
Merge branch 'heic-support' of https://github.com/ynse01/ImageSharp i…
ynse01 Jun 24, 2024
0ffdf8d
Fix merge errors
ynse01 Jun 24, 2024
a674546
Fix code style violations
ynse01 Jun 24, 2024
215ca66
Fix bug in ObuFrameHeader parsing
ynse01 Jun 25, 2024
5d793a2
Implement ReadSegmentationParameters
brianpopow Jun 25, 2024
dd9f383
Fix escape < sign in XML comment
brianpopow Jun 25, 2024
1d288d3
Implement ReadFilmGrainFilterParameters()
brianpopow Jun 26, 2024
4d79d59
Fix stylecop warnings
brianpopow Jun 26, 2024
6aa609f
Strength test criteria
ynse01 Jun 26, 2024
136110f
Adjustments in ReadSequenceHeader() for case when image is not Reduce…
brianpopow Jun 28, 2024
2accf95
Implement 5.5.4. read Decoder model info
brianpopow Jun 29, 2024
41b980c
Implement missing parts in ReadSequenceHeader for case when ReducedSt…
brianpopow Jun 29, 2024
c4d34c5
Fix issue in ReadSequenceHeader() not reading OrderHintBits
brianpopow Jun 29, 2024
a0fdf02
Implement partition context logic
ynse01 Jun 29, 2024
3556921
Implement ReadTimingInfo, it is needed in ReadUncompressedFrameHeader…
brianpopow Jun 30, 2024
0cf2726
Tiling initialization fixes
ynse01 Jun 30, 2024
5792d05
Annotate Av1TileDecoder methods with spec sections
brianpopow Jul 2, 2024
3382518
Fix build
ynse01 Jul 2, 2024
aaac78a
When TemporalDelimiter header is encountered, seenFrameHeader flag wi…
brianpopow Jul 3, 2024
e60b39f
Implement Transform parsing
ynse01 Jul 3, 2024
9fb5826
Smoke test for tiling
ynse01 Jul 3, 2024
13173a3
Implement GetPlaneResidualSize()
brianpopow Jul 4, 2024
3d84a51
Suppress warning about SA1500: Braces for multi-line statements
brianpopow Jul 4, 2024
6c4e213
Implement Residual
ynse01 Jul 4, 2024
1ff0150
Implement TransformBlock
ynse01 Jul 4, 2024
4e53f7c
Add some code comments
ynse01 Jul 5, 2024
d01cb8e
Merge branch 'main' into heic-support
ynse01 Jul 5, 2024
38c23a5
Disable failing test for in-progress code
ynse01 Jul 5, 2024
30f8884
Implement Coefficient syntax
ynse01 Jul 5, 2024
c8a6203
Implement ScanOrder scan constants
ynse01 Jul 6, 2024
1d83ac3
Implement remaining distributions
ynse01 Jul 6, 2024
23d533a
Some bug fixes
ynse01 Jul 6, 2024
a48e271
Fully implement Heif Item Location
ynse01 Jul 8, 2024
c771350
Prune ITileDecoder interface
ynse01 Jul 9, 2024
be134e8
Various tiling bug fixes
ynse01 Jul 9, 2024
30d7c09
More bug fixes
ynse01 Jul 11, 2024
a1f0f9e
Merge remote-tracking branch 'upstream/main' into heic-support
ynse01 Jul 11, 2024
a4ba77b
Implement mode info indexing in frame buffer
ynse01 Jul 12, 2024
471e3d3
Fix issue in ReadLoopRestorationParameters(): LoopRestorationParamete…
brianpopow Jul 12, 2024
c445729
Fix issue in coefficient parsing
ynse01 Jul 12, 2024
d527d0e
Rename ChannelCount property to PlaneCount
ynse01 Jul 13, 2024
68be923
PlaneCount calculation inside ObuColorConfig
ynse01 Jul 13, 2024
a6a32d4
TransformInfo retrieval changes
ynse01 Jul 13, 2024
d762207
Transform Unit Count variable rename
ynse01 Jul 13, 2024
cb736d7
Continue implement case !IsReducedStillPictureHeader in ReadUncompres…
brianpopow Jul 14, 2024
541ab35
Fix issue in Transform Unit Count
ynse01 Jul 15, 2024
441949f
Simplify code by using constants
ynse01 Jul 15, 2024
5d41465
Renaming Superblock variables
ynse01 Jul 16, 2024
4e1aca9
More Superblock renaming
ynse01 Jul 19, 2024
3976aa2
Merge branch 'main' into heic-support
ynse01 Jul 19, 2024
1812983
Improvements to pretty print routines for OBU headers
ynse01 Jul 19, 2024
62728b6
Add test bitreader test ReadLiteral32BitsWithMsbSet()
brianpopow Jul 20, 2024
38a6f43
Add suggestion howto change ReadLiteral()
brianpopow Jul 20, 2024
72c4263
Add tests for ReadSignedFromUnsigned and ReadLittleEndian
brianpopow Jul 20, 2024
0313bdf
Replace Av1BitStreamReader implementation
ynse01 Jul 20, 2024
cb3f51b
Add tests for ReadUnsignedVariableLength()
brianpopow Jul 20, 2024
64f4241
Additional tests for ReadLittleEndianBytes128()
brianpopow Jul 20, 2024
e8b7682
Also assert bit position
brianpopow Jul 20, 2024
c524346
OBU reader bug fixes
ynse01 Jul 20, 2024
e45bf57
Combine Delta parameters implementation
ynse01 Jul 21, 2024
6e10cc9
Few Obu unit tests taken over from libgav1
ynse01 Jul 21, 2024
4c019f5
Bug fixes in TileDecoder, inspired by libgav1
ynse01 Jul 21, 2024
22b7c72
Implement Read Chroma from Luma syntax
ynse01 Jul 21, 2024
4323205
Misc tile parsing fixes
ynse01 Jul 21, 2024
984d0ac
Additional unit tests for OBU bitstream
ynse01 Jul 23, 2024
e4743ce
Fix build
ynse01 Jul 23, 2024
26d8c22
Scan order unit test and fixes
ynse01 Jul 25, 2024
73718f1
Unit tests for block and transform sizes
ynse01 Jul 25, 2024
08cbc5a
Unit test for Partition Type
ynse01 Jul 26, 2024
5d27f30
Add extremely small AVIF test image
ynse01 Jul 26, 2024
fa2e1b0
Add tests for Orange4x4 image
ynse01 Jul 26, 2024
9409a12
Merge branch 'main' into heic-support
ynse01 Jul 26, 2024
96329f4
Rename TileDecoder into TileReader
ynse01 Jul 27, 2024
056814f
Namespace update
ynse01 Jul 27, 2024
ab2ae29
ObuWriter improvements
ynse01 Aug 4, 2024
8b28187
Merge remote-tracking branch 'upstream/main' into heic-support
ynse01 Aug 4, 2024
b8322fc
Merge in required changes from upstream
ynse01 Aug 4, 2024
23bf5de
Obu reading and writing improvements
ynse01 Aug 4, 2024
729f351
Obu bitstream writer writes to Span iso Stream
ynse01 Aug 4, 2024
2bac577
Fix AutoExpandingMemoryTest
ynse01 Aug 4, 2024
0b1639b
Sync method arguments
ynse01 Aug 5, 2024
1385266
Binary identical OBU read write round trip
ynse01 Aug 5, 2024
1fe733a
Merge remote-tracking branch 'upstream/main' into heic-support
ynse01 Aug 6, 2024
0ff8911
Introduce Av1FrameBuffer class and renaming others
ynse01 Aug 9, 2024
4f4ace4
Skeleton code for pixel pipeline
ynse01 Aug 19, 2024
d93b89c
Merge remote-tracking branch 'upstream/main' into heic-support
ynse01 Aug 19, 2024
2b60337
Rename according to naming scheme
ynse01 Aug 19, 2024
dfff87e
Implement interface in HeifMetadata
ynse01 Aug 19, 2024
d748a0d
Introduce DC predictors
ynse01 Aug 20, 2024
c9baaf0
Prediction decoding
ynse01 Aug 24, 2024
aa1b299
Implement Block Decoder
ynse01 Aug 24, 2024
ad57a99
Skeleton code for Transform
ynse01 Sep 5, 2024
fd76bd8
Disable test which has no implementation yet
ynse01 Sep 5, 2024
97052eb
Implement 4x4 forward DCT transform
ynse01 Sep 30, 2024
242dded
Refactor forward transformers
ynse01 Oct 5, 2024
639186b
Test accuracy of 1d forward transformer
ynse01 Oct 5, 2024
f1908c8
Implement all 1 dimensional forward transforms
ynse01 Oct 6, 2024
c19d687
Bounds check for forward transforms
ynse01 Oct 6, 2024
47c2416
Some more forward transform tests
ynse01 Oct 11, 2024
101e841
Partial accuracy test for forward transform
ynse01 Oct 15, 2024
796ea84
Implementation of some inverse transformers
ynse01 Oct 22, 2024
34e8fc2
2-dimensional inverse transform implementation
ynse01 Oct 23, 2024
2fa5ca1
Tests for inverse transform
ynse01 Nov 2, 2024
8f227bf
Merge branch 'main' into heic-support
ynse01 Nov 2, 2024
0e2679b
Add references to SVT library method names
ynse01 Nov 2, 2024
bf3e50f
Add some SVT references
ynse01 Nov 5, 2024
62a6a23
Bug fixes to partition parsing
ynse01 Nov 5, 2024
6140079
Memory optimization for Frame Info Map
ynse01 Nov 5, 2024
a33bc18
Decode superblock immediately after parsing it
ynse01 Nov 7, 2024
1f2e05f
Superblock info exposes its mode info position
ynse01 Nov 8, 2024
5bea8a2
Merge branch 'main' into heic-support
ynse01 Nov 8, 2024
b4f3fe3
Creator of IAv1TileReader
ynse01 Nov 9, 2024
3abc9a0
Encode partition symbol
ynse01 Nov 15, 2024
0dacc04
Move coefficients reading into Av1SymbolEncoder class
ynse01 Nov 15, 2024
3ea42d0
Make scan order read only
ynse01 Nov 15, 2024
e58a775
Move end-of-block position reading to Av1SymbolDecoder
ynse01 Nov 15, 2024
51d54c6
Bounds checks for Predictors
ynse01 Nov 16, 2024
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
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.

using System;

namespace SixLabors.ImageSharp.Formats.Heif.Av1.Transform;

internal static class Av1SinusConstants
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public Av1Transform2dFlipConfiguration(Av1TransformType transformType, Av1Transf
this.TransformFunctionTypeRow = TransformFunctionTypeMap[txw_idx][(int)tx_type_1d_row];
this.StageNumberColumn = StageNumberList[(int)this.TransformFunctionTypeColumn];
this.StageNumberRow = StageNumberList[(int)this.TransformFunctionTypeRow];
this.StageRangeColumn = new int[12];
this.StageRangeRow = new int[12];
this.StageRangeColumn = new byte[12];
this.StageRangeRow = new byte[12];
this.NonScaleRange();
}

Expand All @@ -169,9 +169,9 @@ public Av1Transform2dFlipConfiguration(Av1TransformType transformType, Av1Transf

public Span<int> Shift => this.shift;

public int[] StageRangeColumn { get; }
public byte[] StageRangeColumn { get; }

public int[] StageRangeRow { get; }
public byte[] StageRangeRow { get; }

/// <summary>
/// SVT: svt_av1_gen_fwd_stage_range
Expand All @@ -184,13 +184,13 @@ public void GenerateStageRange(int bitDepth)
// i < MAX_TXFM_STAGE_NUM will mute above array bounds warning
for (int i = 0; i < this.StageNumberColumn && i < MaxStageNumber; ++i)
{
this.StageRangeColumn[i] = this.StageRangeColumn[i] + shift[0] + bitDepth + 1;
this.StageRangeColumn[i] = (byte)(this.StageRangeColumn[i] + shift[0] + bitDepth + 1);
}

// i < MAX_TXFM_STAGE_NUM will mute above array bounds warning
for (int i = 0; i < this.StageNumberRow && i < MaxStageNumber; ++i)
{
this.StageRangeRow[i] = this.StageRangeRow[i] + shift[0] + shift[1] + bitDepth + 1;
this.StageRangeRow[i] = (byte)(this.StageRangeRow[i] + shift[0] + shift[1] + bitDepth + 1);
}
}

Expand Down Expand Up @@ -296,7 +296,7 @@ private void NonScaleRange()
int stage_num_col = this.StageNumberColumn;
for (int i = 0; i < stage_num_col; ++i)
{
this.StageRangeColumn[i] = (range_mult2_col[i] + 1) >> 1;
this.StageRangeColumn[i] = (byte)((range_mult2_col[i] + 1) >> 1);
}
}

Expand All @@ -306,7 +306,7 @@ private void NonScaleRange()
Span<int> range_mult2_row = RangeMulti2List[(int)this.TransformFunctionTypeRow];
for (int i = 0; i < stage_num_row; ++i)
{
this.StageRangeRow[i] = (range_mult2_col[this.StageNumberColumn - 1] + range_mult2_row[i] + 1) >> 1;
this.StageRangeRow[i] = (byte)((range_mult2_col[this.StageNumberColumn - 1] + range_mult2_row[i] + 1) >> 1);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,39 @@ namespace SixLabors.ImageSharp.Formats.Heif.Av1.Transform.Forward;
internal class Av1Dct4ForwardTransformer : IAv1ForwardTransformer
{
public void Transform(ref int input, ref int output, int cosBit, Span<byte> stageRange)
=> throw new NotImplementedException();
{
Span<int> cospi = Av1SinusConstants.CosinusPi(cosBit);
ref int bf0 = ref output;
ref int bf1 = ref output;
Span<int> stepSpan = new int[4];
ref int step0 = ref stepSpan[0];
ref int step1 = ref Unsafe.Add(ref step0, 1);
ref int step2 = ref Unsafe.Add(ref step0, 2);
ref int step3 = ref Unsafe.Add(ref step0, 3);
ref int output1 = ref Unsafe.Add(ref output, 1);
ref int output2 = ref Unsafe.Add(ref output, 2);
ref int output3 = ref Unsafe.Add(ref output, 3);

// stage 0;

// stage 1;
output = input + Unsafe.Add(ref input, 3);
output1 = Unsafe.Add(ref input, 1) + Unsafe.Add(ref input, 2);
output2 = -Unsafe.Add(ref input, 2) + Unsafe.Add(ref input, 1);
output3 = -Unsafe.Add(ref input, 3) + Unsafe.Add(ref input, 0);

// stage 2
step0 = HalfBtf(cospi[32], output, cospi[32], output1, cosBit);
step1 = HalfBtf(-cospi[32], output1, cospi[32], output, cosBit);
step2 = HalfBtf(cospi[48], output2, cospi[16], output3, cosBit);
step3 = HalfBtf(cospi[48], output3, -cospi[16], output2, cosBit);

// stage 3
output = step0;
output1 = step2;
output2 = step1;
output3 = step3;
}

public void TransformAvx2(ref Vector256<int> input, ref Vector256<int> output, int cosBit, int columnNumber)
ynse01 marked this conversation as resolved.
Show resolved Hide resolved
=> throw new NotImplementedException("Too small block for Vector implementation, use TransformSse() method instead.");
Expand All @@ -20,7 +52,8 @@ public void TransformAvx2(ref Vector256<int> input, ref Vector256<int> output, i
/// </summary>
public static void TransformSse(ref Vector128<int> input, ref Vector128<int> output, byte cosBit, int columnNumber)
{
/*
#pragma warning disable CA1857 // A constant is expected for the parameter

// We only use stage-2 bit;
// shift[0] is used in load_buffer_4x4()
// shift[1] is used in txfm_func_col()
Expand All @@ -35,51 +68,71 @@ public static void TransformSse(ref Vector128<int> input, ref Vector128<int> out
Vector128<int> v0, v1, v2, v3;

int endidx = 3 * columnNumber;
s0 = Sse41.Add(input, Unsafe.Add(ref input, endidx));
s3 = Sse41.Subtract(input, Unsafe.Add(ref input, endidx));
s0 = Sse2.Add(input, Unsafe.Add(ref input, endidx));
ynse01 marked this conversation as resolved.
Show resolved Hide resolved
s3 = Sse2.Subtract(input, Unsafe.Add(ref input, endidx));
endidx -= columnNumber;
s1 = Sse41.Add(Unsafe.Add(ref input, columnNumber), Unsafe.Add(ref input, endidx));
s2 = Sse41.Subtract(Unsafe.Add(ref input, columnNumber), Unsafe.Add(ref input, endidx));
s1 = Sse2.Add(Unsafe.Add(ref input, columnNumber), Unsafe.Add(ref input, endidx));
s2 = Sse2.Subtract(Unsafe.Add(ref input, columnNumber), Unsafe.Add(ref input, endidx));

// btf_32_sse4_1_type0(cospi32, cospi32, s[01], u[02], bit);
u0 = Sse41.MultiplyLow(s0, cospi32);
u1 = Sse41.MultiplyLow(s1, cospi32);
u2 = Sse41.Add(u0, u1);
v0 = Sse41.Subtract(u0, u1);
u2 = Sse2.Add(u0, u1);
v0 = Sse2.Subtract(u0, u1);

u3 = Sse41.Add(u2, rnding);
v1 = Sse41.Add(v0, rnding);
u3 = Sse2.Add(u2, rnding);
v1 = Sse2.Add(v0, rnding);

u0 = Sse41.ShiftRightArithmetic(u3, cosBit);
u2 = Sse41.ShiftRightArithmetic(v1, cosBit);
u0 = Sse2.ShiftRightArithmetic(u3, cosBit);
u2 = Sse2.ShiftRightArithmetic(v1, cosBit);

// btf_32_sse4_1_type1(cospi48, cospi16, s[23], u[13], bit);
v0 = Sse41.MultiplyLow(s2, cospi48);
v1 = Sse41.MultiplyLow(s3, cospi16);
v2 = Sse41.Add(v0, v1);
v2 = Sse2.Add(v0, v1);

v3 = Sse41.Add(v2, rnding);
u1 = Sse41.ShiftRightArithmetic(v3, cosBit);
v3 = Sse2.Add(v2, rnding);
u1 = Sse2.ShiftRightArithmetic(v3, cosBit);

v0 = Sse41.MultiplyLow(s2, cospi16);
v1 = Sse41.MultiplyLow(s3, cospi48);
v2 = Sse41.Subtract(v1, v0);
v2 = Sse2.Subtract(v1, v0);

v3 = Sse41.Add(v2, rnding);
u3 = Sse41.ShiftRightArithmetic(v3, cosBit);
v3 = Sse2.Add(v2, rnding);
u3 = Sse2.ShiftRightArithmetic(v3, cosBit);

// Note: shift[1] and shift[2] are zeros

// Transpose 4x4 32-bit
v0 = Sse41.UnpackLow(u0, u1);
v1 = Sse41.UnpackHigh(u0, u1);
v2 = Sse41.UnpackLow(u2, u3);
v3 = Sse41.UnpackHigh(u2, u3);

output = Sse41.UnpackLow(v0.AsInt64(), v2.AsInt64()).AsInt32();
Unsafe.Add(ref output, 1) = Sse41.UnpackHigh(v0.AsInt64(), v2.AsInt64()).AsInt32();
Unsafe.Add(ref output, 2) = Sse41.UnpackLow(v1.AsInt64(), v3.AsInt64()).AsInt32();
Unsafe.Add(ref output, 3) = Sse41.UnpackHigh(v1.AsInt64(), v3.AsInt64()).AsInt32();
*/
v0 = Sse2.UnpackLow(u0, u1);
v1 = Sse2.UnpackHigh(u0, u1);
v2 = Sse2.UnpackLow(u2, u3);
v3 = Sse2.UnpackHigh(u2, u3);

output = Sse2.UnpackLow(v0.AsInt64(), v2.AsInt64()).AsInt32();
Unsafe.Add(ref output, 1) = Sse2.UnpackHigh(v0.AsInt64(), v2.AsInt64()).AsInt32();
Unsafe.Add(ref output, 2) = Sse2.UnpackLow(v1.AsInt64(), v3.AsInt64()).AsInt32();
Unsafe.Add(ref output, 3) = Sse2.UnpackHigh(v1.AsInt64(), v3.AsInt64()).AsInt32();
#pragma warning restore CA1857 // A constant is expected for the parameter
}

private static int HalfBtf(int w0, int in0, int w1, int in1, int bit)
{
long result64 = (long)(w0 * in0) + (w1 * in1);
long intermediate = result64 + (1L << (bit - 1));

// NOTE(david.barker): The value 'result_64' may not necessarily fit
// into 32 bits. However, the result of this function is nominally
// ROUND_POWER_OF_TWO_64(result_64, bit)
// and that is required to fit into stage_range[stage] many bits
// (checked by range_check_buf()).
//
// Here we've unpacked that rounding operation, and it can be shown
// that the value of 'intermediate' here *does* fit into 32 bits
// for any conformant bitstream.
// The upshot is that, if you do all this calculation using
// wrapping 32-bit arithmetic instead of (non-wrapping) 64-bit arithmetic,
// then you'll still get the correct result.
return (int)(intermediate >> bit);
}
}
Loading
Loading