Skip to content

Commit

Permalink
Don't require crop width,height be even for 4:2:0
Browse files Browse the repository at this point in the history
These requirements were removed in ISO/IEC 23000-22:2019/Amd. 2:2021
from Section 7.3.6.7. This is one reason most of the clap properties
seen by Chrome were considered invalid.

Bug: b/308458941
  • Loading branch information
wantehchang committed Nov 9, 2023
1 parent 4dd98ef commit adf77ee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* API calls now return AVIF_RESULT_OUT_OF_MEMORY instead of aborting on memory
allocation failure.
* avifenc: Change the default value of the --jobs option from 1 to "all".
* Update avifCropRectConvertCleanApertureBox() to the revised requirements in
ISO/IEC 23000-22:2019/Amd. 2:2021 Section 7.3.6.7.

## [1.0.1] - 2023-08-29

Expand Down
21 changes: 10 additions & 11 deletions src/avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -653,16 +653,15 @@ static avifBool overflowsInt32(int64_t x)
static avifBool avifCropRectIsValid(const avifCropRect * cropRect, uint32_t imageW, uint32_t imageH, avifPixelFormat yuvFormat, avifDiagnostics * diag)

{
// ISO/IEC 23000-22:2019/DAM 2:2021, Section 7.3.6.7:
// 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:
// - when the image is 4:0:0 (monochrome) or 4:4:4, the horizontal and
// vertical cropped offsets and widths shall be integers;
// - when the image is 4:2:2 the horizontal cropped offset and width
// shall be even numbers and the vertical values shall be integers;
// - when the image is 4:2:0 both the horizontal and vertical cropped
// offsets and widths shall be even numbers.
// ...
// - If chroma is subsampled horizontally (i.e., 4:2:2 and 4:2:0), the
// leftmost pixel of the clean aperture shall be even numbers;
// - If chroma is subsampled vertically (i.e., 4:2:0), the topmost line
// of the clean aperture shall be even numbers.

if ((cropRect->width == 0) || (cropRect->height == 0)) {
avifDiagnosticsPrintf(diag, "[Strict] crop rect width and height must be nonzero");
Expand All @@ -675,14 +674,14 @@ static avifBool avifCropRectIsValid(const avifCropRect * cropRect, uint32_t imag
}

if ((yuvFormat == AVIF_PIXEL_FORMAT_YUV420) || (yuvFormat == AVIF_PIXEL_FORMAT_YUV422)) {
if (((cropRect->x % 2) != 0) || ((cropRect->width % 2) != 0)) {
avifDiagnosticsPrintf(diag, "[Strict] crop rect X offset and width must both be even due to this image's YUV subsampling");
if ((cropRect->x % 2) != 0) {
avifDiagnosticsPrintf(diag, "[Strict] crop rect X offset must be even due to this image's YUV subsampling");
return AVIF_FALSE;
}
}
if (yuvFormat == AVIF_PIXEL_FORMAT_YUV420) {
if (((cropRect->y % 2) != 0) || ((cropRect->height % 2) != 0)) {
avifDiagnosticsPrintf(diag, "[Strict] crop rect Y offset and height must both be even due to this image's YUV subsampling");
if ((cropRect->y % 2) != 0) {
avifDiagnosticsPrintf(diag, "[Strict] crop rect Y offset must be even due to this image's YUV subsampling");
return AVIF_FALSE;
}
}
Expand Down

0 comments on commit adf77ee

Please sign in to comment.