-
Notifications
You must be signed in to change notification settings - Fork 0
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 #4
base: main
Are you sure you want to change the base?
Conversation
…nto heic-support
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
30 file(s) reviewed, 62 comment(s)
Edit PR Review Bot Settings | Greptile
// Copyright (c) Six Labors. | ||
// Licensed under the Six Labors Split License. | ||
|
||
using SixLabors.ImageSharp.Formats.Heif.Av1.Transform; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Transform namespace is imported but not used
|
||
public void Reset() => this.BitPosition = 0; | ||
|
||
public void Skip(int bitCount) => this.BitPosition += bitCount; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: no bounds checking on Skip() - could advance beyond buffer end
int byteOffset = Av1Math.DivideBy8Floor(this.BitPosition); | ||
byte shift = (byte)(7 - Av1Math.Modulus8(this.BitPosition)); | ||
this.BitPosition++; | ||
return (uint)((this.data[byteOffset] >> shift) & 0x01); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: ReadBit() needs bounds check on byteOffset against data.Length
|
||
ulong value = 0; | ||
length = 0; | ||
for (int i = 0; i < 56; i += 7) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: magic number 56 should be defined as constant with descriptive name
DebugGuard.IsTrue(Av1Math.Modulus8(this.BitPosition) == 0, "Reading of Little Endian value only allowed on byte alignment"); | ||
|
||
uint t = 0; | ||
for (int i = 0; i < 8 * n; i += 8) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: potential integer overflow if n > int.MaxValue/8
|
||
namespace SixLabors.ImageSharp.Formats.Heif.Av1.OpenBitstreamUnit; | ||
|
||
internal class ObuFrameHeader |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: class should be sealed since it's not designed for inheritance
|
||
namespace SixLabors.ImageSharp.Formats.Heif.Av1.OpenBitstreamUnit; | ||
|
||
internal class ObuFrameSize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider making this class sealed since it's not designed for inheritance and is internal
internal int FrameWidth { get; set; } | ||
|
||
internal int FrameHeight { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Consider adding validation to ensure width/height are non-negative
|
||
internal int FrameHeight { get; set; } | ||
|
||
internal int SuperResolutionDenominator { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: SuperResolutionDenominator should be greater than or equal to 9 per AV1 spec
internal class ObuFrameSize | ||
{ | ||
internal int FrameWidth { get; set; } | ||
|
||
internal int FrameHeight { get; set; } | ||
|
||
internal int SuperResolutionDenominator { get; set; } | ||
|
||
internal int SuperResolutionUpscaledWidth { get; set; } | ||
|
||
internal int RenderWidth { get; set; } | ||
|
||
internal int RenderHeight { get; set; } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: XML documentation missing for class and properties to explain their purpose and constraints
Prerequisites
Description
This PR is an attempt to start with SixLabors#1320
Implemented decoding and encoding of images based on a HEIF (ISO/IEC 23008-12:2022) container. These include (amongst others): HEIC, HIF and AVIF.
Please note this PR does NOT add any new compression algorithm to ImageSharp. For now it will take a JPEG thumbnail as its pixel source.
Needless to say, much more work is needed after this PR to reach the goal. I'm try to help there also.
Please do let me know any comments, also on whether to support the HEIF file format in the first place.
Greptile Summary
This PR adds initial support for HEIF-based image formats (HEIC, HIF, AVIF) by implementing AV1 codec components and HEIF container handling.
src/ImageSharp/Formats/Heif/Av1/
including bitstream handling, frame buffers, and color format support.heic
,.hif
, and.avif
file formats in.gitattributes
Configuration.cs
viaHeifConfigurationModule