-
-
Notifications
You must be signed in to change notification settings - Fork 852
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
1,310 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
using SixLabors.ImageSharp.Formats.Heif.Av1.Transform; | ||
|
||
namespace SixLabors.ImageSharp.Formats.Heif.Av1; | ||
|
||
internal static class Av1BitDepthExtensions | ||
{ | ||
public static int GetBitCount(this Av1BitDepth bitDepth) => 8 + ((int)bitDepth << 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
src/ImageSharp/Formats/Heif/Av1/OpenBitstreamUnit/ObuPartitionInfo.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
155 changes: 155 additions & 0 deletions
155
src/ImageSharp/Formats/Heif/Av1/Pipeline/Av1FrameDecoder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
using SixLabors.ImageSharp.Formats.Heif.Av1.OpenBitstreamUnit; | ||
using SixLabors.ImageSharp.Formats.Heif.Av1.Pipeline.Quantification; | ||
using SixLabors.ImageSharp.Formats.Heif.Av1.Tiling; | ||
using SixLabors.ImageSharp.Formats.Heif.Av1.Transform; | ||
|
||
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Pipeline; | ||
|
||
internal class Av1FrameDecoder | ||
{ | ||
private readonly ObuSequenceHeader sequenceHeader; | ||
private readonly ObuFrameHeader frameHeader; | ||
private readonly Av1FrameInfo frameInfo; | ||
private readonly Av1InverseQuantizer inverseQuantizer; | ||
private readonly DeQuant deQuants; | ||
|
||
public Av1FrameDecoder(ObuSequenceHeader sequenceHeader, ObuFrameHeader frameHeader, Av1FrameInfo frameInfo) | ||
{ | ||
this.sequenceHeader = sequenceHeader; | ||
this.frameHeader = frameHeader; | ||
this.frameInfo = frameInfo; | ||
this.inverseQuantizer = new(sequenceHeader, frameHeader); | ||
this.deQuants = new(); | ||
} | ||
|
||
public void DecodeFrame() | ||
{ | ||
for (int column = 0; column < this.frameHeader.TilesInfo.TileColumnCount; column++) | ||
{ | ||
this.DecodeFrameTiles(column); | ||
} | ||
|
||
bool doLoopFilterFlag = false; | ||
bool doLoopRestoration = false; | ||
bool doUpscale = false; | ||
this.DecodeLoopFilterForFrame(doLoopFilterFlag); | ||
if (doLoopRestoration) | ||
{ | ||
// LoopRestorationSaveBoundaryLines(false); | ||
} | ||
|
||
// DecodeCdef(); | ||
// SuperResolutionUpscaling(doUpscale); | ||
if (doLoopRestoration && doUpscale) | ||
{ | ||
// LoopRestorationSaveBoundaryLines(true); | ||
} | ||
|
||
// DecodeLoopRestoration(doLoopRestoration); | ||
// PadPicture(); | ||
} | ||
|
||
private void DecodeFrameTiles(int tileColumn) | ||
{ | ||
int tileRowCount = this.frameHeader.TilesInfo.TileRowCount; | ||
int tileCount = tileRowCount * this.frameHeader.TilesInfo.TileColumnCount; | ||
for (int row = 0; row < tileRowCount; row++) | ||
{ | ||
int superblockRowTileStart = this.frameHeader.TilesInfo.TileRowStartModeInfo[row] << Av1Constants.ModeInfoSizeLog2 >> | ||
this.sequenceHeader.SuperblockSizeLog2; | ||
int superblockRow = row + superblockRowTileStart; | ||
|
||
int modeInfoRow = superblockRow << this.sequenceHeader.SuperblockSizeLog2 >> Av1Constants.ModeInfoSizeLog2; | ||
|
||
// EbColorConfig* color_config = &dec_mod_ctxt->seq_header->color_config; | ||
// svt_cfl_init(&dec_mod_ctxt->cfl_ctx, color_config); | ||
this.DecodeTileRow(row, tileColumn, modeInfoRow, superblockRow); | ||
} | ||
} | ||
|
||
private void DecodeTileRow(int tileRow, int tileColumn, int modeInfoRow, int superblockRow) | ||
{ | ||
int superblockModeInfoSizeLog2 = this.sequenceHeader.SuperblockSizeLog2 - Av1Constants.ModeInfoSizeLog2; | ||
int superblockRowTileStart = this.frameHeader.TilesInfo.TileRowStartModeInfo[tileRow] << Av1Constants.ModeInfoSizeLog2 >> | ||
this.sequenceHeader.SuperblockSizeLog2; | ||
|
||
int superblockRowInTile = superblockRow - superblockRowTileStart; | ||
|
||
ObuTileGroupHeader tileInfo = this.frameHeader.TilesInfo; | ||
for (int modeInfoColumn = tileInfo.TileColumnStartModeInfo[tileColumn]; modeInfoColumn < tileInfo.TileColumnStartModeInfo[tileColumn + 1]; | ||
modeInfoColumn += this.sequenceHeader.SuperblockModeInfoSize) | ||
{ | ||
int superblockColumn = modeInfoColumn << Av1Constants.ModeInfoSizeLog2 >> this.sequenceHeader.SuperblockSizeLog2; | ||
|
||
Av1SuperblockInfo superblockInfo = this.frameInfo.GetSuperblock(new Point(superblockColumn, superblockRow)); | ||
|
||
Point modeInfoPosition = new Point(modeInfoColumn, modeInfoRow); | ||
this.DecodeSuperblock(modeInfoPosition, superblockInfo); | ||
} | ||
} | ||
|
||
private void DecodeSuperblock(Point modeInfoPosition, Av1SuperblockInfo superblockInfo) | ||
{ | ||
this.inverseQuantizer.UpdateDequant(this.deQuants, superblockInfo); | ||
DecodePartition(modeInfoPosition, superblockInfo); | ||
} | ||
|
||
private static void DecodePartition(Point modeInfoPosition, Av1SuperblockInfo superblockInfo) | ||
{ | ||
Av1BlockModeInfo modeInfo = superblockInfo.GetModeInfo(modeInfoPosition); | ||
|
||
for (int i = 0; i < superblockInfo.BlockCount; i++) | ||
{ | ||
Point subPosition = modeInfo.PositionInSuperblock; | ||
Av1BlockSize subSize = modeInfo.BlockSize; | ||
Point globalPosition = new(modeInfoPosition.X, modeInfoPosition.Y); | ||
globalPosition.Offset(subPosition); | ||
Av1BlockDecoder.DecodeBlock(modeInfo, globalPosition, subSize, superblockInfo); | ||
} | ||
} | ||
|
||
private void DecodeLoopFilterForFrame(bool doLoopFilterFlag) | ||
{ | ||
if (!doLoopFilterFlag) | ||
{ | ||
return; | ||
} | ||
|
||
int superblockSizeLog2 = this.sequenceHeader.SuperblockSizeLog2; | ||
int pictureWidthInSuperblocks = Av1Math.DivideLog2Ceiling(this.frameHeader.FrameSize.FrameWidth, this.sequenceHeader.SuperblockSizeLog2); | ||
int pictureHeightInSuperblocks = Av1Math.DivideLog2Ceiling(this.frameHeader.FrameSize.FrameHeight, this.sequenceHeader.SuperblockSizeLog2); | ||
|
||
// Loop over a frame : tregger dec_loop_filter_sb for each SB | ||
for (int superblockIndexY = 0; superblockIndexY < pictureHeightInSuperblocks; ++superblockIndexY) | ||
{ | ||
for (int superblockIndexX = 0; superblockIndexX < pictureWidthInSuperblocks; ++superblockIndexX) | ||
{ | ||
int superblockOriginX = superblockIndexX << superblockSizeLog2; | ||
int superblockOriginY = superblockIndexY << superblockSizeLog2; | ||
bool endOfRowFlag = superblockIndexX == pictureWidthInSuperblocks - 1; | ||
|
||
Point superblockPoint = new(superblockOriginX, superblockOriginY); | ||
Av1SuperblockInfo superblockInfo = this.frameInfo.GetSuperblock(superblockPoint); | ||
|
||
// LF function for a SB | ||
/* | ||
DecodeLoopFilterForSuperblock( | ||
superblockInfo, | ||
this.frameHeader, | ||
this.sequenceHeader, | ||
reconstructionFrameBuffer, | ||
loopFilterContext, | ||
superblockOriginY >> 2, | ||
superblockOriginX >> 2, | ||
Av1Plane.Y, | ||
3, | ||
endOfRowFlag, | ||
superblockInfo.SuperblockDeltaLoopFilter); | ||
*/ | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/ImageSharp/Formats/Heif/Av1/Pipeline/LoopFilter/Av1LoopFilterContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
namespace SixLabors.ImageSharp.Formats.Heif.Av1.Pipeline.LoopFilter; | ||
|
||
internal class Av1LoopFilterContext | ||
{ | ||
} |
Oops, something went wrong.