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/update comments about avifCleanApertureBox #1749

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 13 additions & 7 deletions include/avif/avif.h
Original file line number Diff line number Diff line change
Expand Up @@ -428,30 +428,36 @@ typedef uint32_t avifTransformFlags;

typedef struct avifPixelAspectRatioBox
{
// 'pasp' from ISO/IEC 14496-12:2015 12.1.4.3
// 'pasp' from ISO/IEC 14496-12:2022 12.1.4.3

// define the relative width and height of a pixel
uint32_t hSpacing;
uint32_t vSpacing;
} avifPixelAspectRatioBox;

// NOTE: The members of the avifCleanApertureBox struct are declared as uint32_t to match the
// unsigned int(32) type used in ISO/IEC 14496-12:2022 faithfully. However, ISO/IEC 14496-12:2022
// 12.1.4.1 clearly interprets these values as signed int(32) and talk about them being strictly
wantehchang marked this conversation as resolved.
Show resolved Hide resolved
wantehchang marked this conversation as resolved.
Show resolved Hide resolved
// positive, positive, or negative. Cast these struct members to int32_t before use.
wantehchang marked this conversation as resolved.
Show resolved Hide resolved
typedef struct avifCleanApertureBox
{
// 'clap' from ISO/IEC 14496-12:2015 12.1.4.3
// 'clap' from ISO/IEC 14496-12:2022 12.1.4.3

// a fractional number which defines the exact clean aperture width, in counted pixels, of the video image
// a fractional number which defines the width of the clean aperture image
uint32_t widthN;
uint32_t widthD;

// a fractional number which defines the exact clean aperture height, in counted pixels, of the video image
// a fractional number which defines the height of the clean aperture image
uint32_t heightN;
uint32_t heightD;

// a fractional number which defines the horizontal offset of clean aperture centre minus (width-1)/2. Typically 0.
// a fractional number which defines the horizontal offset between the clean aperture image
// centre and the full aperture image centre. Typically 0.
uint32_t horizOffN;
uint32_t horizOffD;

// a fractional number which defines the vertical offset of clean aperture centre minus (height-1)/2. Typically 0.
// a fractional number which defines the vertical offset between clean aperture image centre
// and the full aperture image centre. Typically 0.
uint32_t vertOffN;
uint32_t vertOffD;
} avifCleanApertureBox;
Expand Down Expand Up @@ -711,7 +717,7 @@ typedef struct avifImage
// appropriately, but do not impact/adjust the actual pixel buffers used (images won't be
// pre-cropped or mirrored upon decode). Basic explanations from the standards are offered in
// comments above, but for detailed explanations, please refer to the HEIF standard (ISO/IEC
// 23008-12:2017) and the BMFF standard (ISO/IEC 14496-12:2015).
// 23008-12:2017) and the BMFF standard (ISO/IEC 14496-12:2022).
//
// To encode any of these boxes, set the values in the associated box, then enable the flag in
// transformFlags. On decode, only honor the values in boxes with the associated transform flag set.
Expand Down
11 changes: 10 additions & 1 deletion src/avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ avifBool avifCropRectConvertCleanApertureBox(avifCropRect * cropRect,
{
avifDiagnosticsClearError(diag);

// ISO/IEC 14496-12:2020, Section 12.1.4.1:
// ISO/IEC 14496-12:2022, Section 12.1.4.1:
// For horizOff and vertOff, D shall be strictly positive and N may be
// positive or negative. For cleanApertureWidth and cleanApertureHeight,
// N shall be positive and D shall be strictly positive.
Expand All @@ -719,6 +719,15 @@ avifBool avifCropRectConvertCleanApertureBox(avifCropRect * cropRect,
return AVIF_FALSE;
}

// ISO/IEC 23000-22:2019/Amd. 2:2021, Section 7.3.6.7:
// The clean aperture property is restricted according to the chroma
// sampling format of the input image (4:4:4, 4:2:2:, 4:2:0, or 4:0:0) as
// follows:
// - cleanApertureWidth and cleanApertureHeight shall be integers;
// - The leftmost pixel and the topmost line of the clean aperture as
// defined in ISO/IEC 14496-12:2020, Section 12.1.4.1 shall be integers;
// ...

if ((widthN % widthD) != 0) {
avifDiagnosticsPrintf(diag, "[Strict] clap width %d/%d is not an integer", widthN, widthD);
return AVIF_FALSE;
Expand Down