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

Allow YCgCoRe and YCgCoRo decoding. #2078

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/ci-fuzztest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
-DAVIF_LIBYUV=${{ matrix.libyuv }}
-DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON
-DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_GTEST=LOCAL
-DAVIF_ENABLE_EXPERIMENTAL_YCGCO_R=ON
-DAVIF_ENABLE_YCGCO_R_ENCODING=ON
-DAVIF_ENABLE_EXPERIMENTAL_GAIN_MAP=ON
-DAVIF_ENABLE_EXPERIMENTAL_MINI=ON
-DAVIF_ENABLE_EXPERIMENTAL_SAMPLE_TRANSFORM=ON
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-linux-static-old-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
-DAVIF_LOCAL_LIBSHARPYUV=ON -DAVIF_LOCAL_LIBXML2=ON -DAVIF_LOCAL_LIBYUV=ON
-DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON
-DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_LOCAL_GTEST=ON
-DAVIF_ENABLE_EXPERIMENTAL_YCGCO_R=ON
-DAVIF_ENABLE_YCGCO_R_ENCODING=ON
-DAVIF_ENABLE_EXPERIMENTAL_GAIN_MAP=ON
-DAVIF_ENABLE_EXPERIMENTAL_MINI=ON
-DAVIF_ENABLE_WERROR=ON
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-unix-shared-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
-DAVIF_LIBYUV=${{ matrix.libyuv }}
-DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON
-DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_GTEST=LOCAL
-DAVIF_ENABLE_EXPERIMENTAL_YCGCO_R=ON
-DAVIF_ENABLE_YCGCO_R_ENCODING=ON
-DAVIF_ENABLE_EXPERIMENTAL_GAIN_MAP=ON
-DAVIF_ENABLE_EXPERIMENTAL_MINI=ON
-DAVIF_ENABLE_EXPERIMENTAL_SAMPLE_TRANSFORM=ON
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-unix-static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
-DAVIF_LIBSHARPYUV=LOCAL -DAVIF_LIBXML2=LOCAL -DAVIF_LIBYUV=LOCAL
-DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON
-DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_GTEST=LOCAL
-DAVIF_ENABLE_EXPERIMENTAL_YCGCO_R=ON
-DAVIF_ENABLE_YCGCO_R_ENCODING=ON
-DAVIF_ENABLE_EXPERIMENTAL_GAIN_MAP=ON
-DAVIF_ENABLE_EXPERIMENTAL_MINI=ON
-DAVIF_ENABLE_EXPERIMENTAL_SAMPLE_TRANSFORM=ON
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-windows-installed.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jobs:
-DAVIF_LIBYUV=SYSTEM -DAVIF_ZLIBPNG=SYSTEM
-DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON
-DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_GTEST=LOCAL
-DAVIF_ENABLE_EXPERIMENTAL_YCGCO_R=ON
-DAVIF_ENABLE_YCGCO_R_ENCODING=ON
-DAVIF_ENABLE_EXPERIMENTAL_GAIN_MAP=ON
-DAVIF_ENABLE_EXPERIMENTAL_MINI=ON
-DAVIF_ENABLE_EXPERIMENTAL_SAMPLE_TRANSFORM=ON
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-windows-shared-local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
-DAVIF_LIBYUV=LOCAL -DAVIF_ZLIBPNG=LOCAL
-DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON
-DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_GTEST=LOCAL
-DAVIF_ENABLE_EXPERIMENTAL_YCGCO_R=ON
-DAVIF_ENABLE_YCGCO_R_ENCODING=ON
-DAVIF_ENABLE_EXPERIMENTAL_GAIN_MAP=ON
-DAVIF_ENABLE_EXPERIMENTAL_MINI=ON
-DAVIF_ENABLE_EXPERIMENTAL_SAMPLE_TRANSFORM=ON
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
-DAVIF_LIBYUV=LOCAL -DAVIF_ZLIBPNG=LOCAL
-DAVIF_BUILD_EXAMPLES=ON -DAVIF_BUILD_APPS=ON
-DAVIF_BUILD_TESTS=ON -DAVIF_ENABLE_GTEST=ON -DAVIF_GTEST=LOCAL
-DAVIF_ENABLE_EXPERIMENTAL_YCGCO_R=ON
-DAVIF_ENABLE_YCGCO_R_ENCODING=ON
-DAVIF_ENABLE_EXPERIMENTAL_GAIN_MAP=ON
-DAVIF_ENABLE_EXPERIMENTAL_MINI=ON
-DAVIF_ENABLE_EXPERIMENTAL_SAMPLE_TRANSFORM=ON
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ The changes are relative to the previous release, unless the baseline is specifi
avifGainMapMetadataDouble structs.
* Add avif(Un)SignedFraction structs and avifDoubleTo(Un)SignedFraction
utility functions.
* Allow YCgCo_Re and YCgCo_Ro decoding by default. Encoding is still conditioned
to the AVIF_ENABLE_YCGCO_R_ENCODING CMake flag.

## [1.1.1] - 2024-07-30

Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ option(BUILD_SHARED_LIBS "Build shared avif library" ON)

option(AVIF_ENABLE_WERROR "Treat all compiler warnings as errors" OFF)

option(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R "Enable experimental YCgCo-R matrix code" OFF)
option(AVIF_ENABLE_YCGCO_R_ENCODING "Enable YCgCo-R matrix codes for encoding" OFF)
option(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP
"Enable experimental gain map code (for HDR images that look good both on HDR and SDR displays)" OFF
)
Expand Down Expand Up @@ -360,8 +360,8 @@ if(AVIF_ENABLE_COVERAGE)
endif()
endif()

if(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
add_compile_definitions(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
if(AVIF_ENABLE_YCGCO_R_ENCODING)
add_compile_definitions(AVIF_ENABLE_YCGCO_R_ENCODING)
endif()

if(AVIF_ENABLE_EXPERIMENTAL_GAIN_MAP)
Expand Down
8 changes: 4 additions & 4 deletions apps/avifenc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1936,12 +1936,12 @@ int main(int argc, char * argv[])
// Matrix coefficients.
if (settings.cicpExplicitlySet) {
avifBool incompatibleMC = (settings.matrixCoefficients != AVIF_MATRIX_COEFFICIENTS_IDENTITY);
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
#if defined(AVIF_ENABLE_YCGCO_R_ENCODING)
incompatibleMC &= (settings.matrixCoefficients != AVIF_MATRIX_COEFFICIENTS_YCGCO_RE &&
settings.matrixCoefficients != AVIF_MATRIX_COEFFICIENTS_YCGCO_RO);
#endif
if (incompatibleMC) {
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
#if defined(AVIF_ENABLE_YCGCO_R_ENCODING)
fprintf(stderr, "Matrix coefficients have to be identity, YCgCo-Re, or YCgCo-Ro in lossless mode.\n");
#else
fprintf(stderr, "Matrix coefficients have to be identity in lossless mode.\n");
Expand Down Expand Up @@ -2374,12 +2374,12 @@ int main(int argc, char * argv[])
}

avifBool matrixCoefficientsAreLosslessCompatible = usingIdentityMatrix;
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
#if defined(AVIF_ENABLE_YCGCO_R_ENCODING)
matrixCoefficientsAreLosslessCompatible |= (image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RE ||
image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RO);
#endif
if (!matrixCoefficientsAreLosslessCompatible && !using400) {
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
#if defined(AVIF_ENABLE_YCGCO_R_ENCODING)
fprintf(stderr, "WARNING: [--lossless] Input data was RGB and matrixCoefficients isn't set to identity (--cicp x/x/0) or YCgCo-Re/Ro (--cicp x/x/16 or x/x/17); Output might not be lossless.\n");
#else
fprintf(stderr, "WARNING: [--lossless] Input data was RGB and matrixCoefficients isn't set to identity (--cicp x/x/0); Output might not be lossless.\n");
Expand Down
10 changes: 1 addition & 9 deletions apps/shared/avifjpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -938,22 +938,15 @@ static avifBool avifJPEGReadInternal(FILE * f,

avif->width = cinfo.output_width;
avif->height = cinfo.output_height;
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
const avifBool useYCgCoR = (avif->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RE ||
avif->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RO);
#endif
if (avif->yuvFormat == AVIF_PIXEL_FORMAT_NONE) {
// Identity and YCgCo-R are only valid with YUV444.
avif->yuvFormat = (avif->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_IDENTITY
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
|| useYCgCoR
#endif
)
avif->yuvFormat = (avif->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_IDENTITY || useYCgCoR)
? AVIF_PIXEL_FORMAT_YUV444
: AVIF_APP_DEFAULT_PIXEL_FORMAT;
}
avif->depth = requestedDepth ? requestedDepth : 8;
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
if (useYCgCoR) {
if (avif->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RO) {
fprintf(stderr, "AVIF_MATRIX_COEFFICIENTS_YCGCO_RO cannot be used with JPEG because it has an even bit depth.\n");
Expand All @@ -965,7 +958,6 @@ static avifBool avifJPEGReadInternal(FILE * f,
}
avif->depth = 10;
}
#endif
avifRGBImageSetDefaults(&rgb, avif);
rgb.format = AVIF_RGB_FORMAT_RGB;
rgb.chromaDownsampling = chromaDownsampling;
Expand Down
16 changes: 3 additions & 13 deletions apps/shared/avifpng.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,21 +317,15 @@ avifBool avifPNGRead(const char * inputFilename,
avif->width = rawWidth;
avif->height = rawHeight;
avif->yuvFormat = requestedFormat;
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
if (avif->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RO) {
fprintf(stderr, "AVIF_MATRIX_COEFFICIENTS_YCGCO_RO cannot be used with PNG because it has an even bit depth.\n");
goto cleanup;
}
const avifBool useYCgCoR = (avif->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RE);
#endif
if (avif->yuvFormat == AVIF_PIXEL_FORMAT_NONE) {
if ((rawColorType == PNG_COLOR_TYPE_GRAY) || (rawColorType == PNG_COLOR_TYPE_GRAY_ALPHA)) {
avif->yuvFormat = AVIF_PIXEL_FORMAT_YUV400;
} else if (avif->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_IDENTITY
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
|| useYCgCoR
#endif
) {
} else if (avif->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_IDENTITY ||
avif->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RE) {
// Identity and YCgCo-R are only valid with YUV444.
avif->yuvFormat = AVIF_PIXEL_FORMAT_YUV444;
} else {
Expand All @@ -346,8 +340,7 @@ avifBool avifPNGRead(const char * inputFilename,
avif->depth = 12;
}
}
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
if (useYCgCoR) {
if (avif->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RE) {
if (imgBitDepth != 8) {
fprintf(stderr, "AVIF_MATRIX_COEFFICIENTS_YCGCO_RE cannot be used on 16 bit input because it adds two bits.\n");
goto cleanup;
Expand All @@ -358,7 +351,6 @@ avifBool avifPNGRead(const char * inputFilename,
}
avif->depth = 10;
}
#endif

if (!ignoreColorProfile) {
char * iccpProfileName = NULL;
Expand Down Expand Up @@ -541,7 +533,6 @@ avifBool avifPNGWrite(const char * outputFilename, const avifImage * avif, uint3
if (rgbDepth == 0) {
rgbDepth = (avif->depth > 8) ? 16 : 8;
}
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
if (avif->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RO) {
fprintf(stderr, "AVIF_MATRIX_COEFFICIENTS_YCGCO_RO cannot be used with PNG because it has an even bit depth.\n");
goto cleanup;
Expand All @@ -558,7 +549,6 @@ avifBool avifPNGWrite(const char * outputFilename, const avifImage * avif, uint3

rgbDepth = 8;
}
#endif

volatile avifBool monochrome8bit = (avif->yuvFormat == AVIF_PIXEL_FORMAT_YUV400) && !avif->alphaPlane && (avif->depth == 8) &&
(rgbDepth == 8);
Expand Down
2 changes: 0 additions & 2 deletions include/avif/avif.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,10 +399,8 @@ enum
AVIF_MATRIX_COEFFICIENTS_CHROMA_DERIVED_NCL = 12,
AVIF_MATRIX_COEFFICIENTS_CHROMA_DERIVED_CL = 13,
AVIF_MATRIX_COEFFICIENTS_ICTCP = 14,
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
AVIF_MATRIX_COEFFICIENTS_YCGCO_RE = 16,
AVIF_MATRIX_COEFFICIENTS_YCGCO_RO = 17,
#endif
AVIF_MATRIX_COEFFICIENTS_LAST
};
typedef uint16_t avifMatrixCoefficients; // AVIF_MATRIX_COEFFICIENTS_*
Expand Down
6 changes: 2 additions & 4 deletions include/avif/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,8 @@ typedef enum avifReformatMode
AVIF_REFORMAT_MODE_YUV_COEFFICIENTS = 0, // Normal YUV conversion using coefficients
AVIF_REFORMAT_MODE_IDENTITY, // Pack GBR directly into YUV planes (AVIF_MATRIX_COEFFICIENTS_IDENTITY)
AVIF_REFORMAT_MODE_YCGCO, // YUV conversion using AVIF_MATRIX_COEFFICIENTS_YCGCO
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
AVIF_REFORMAT_MODE_YCGCO_RE, // YUV conversion using AVIF_MATRIX_COEFFICIENTS_YCGCO_RE
AVIF_REFORMAT_MODE_YCGCO_RO, // YUV conversion using AVIF_MATRIX_COEFFICIENTS_YCGCO_RO
#endif
AVIF_REFORMAT_MODE_YCGCO_RE, // YUV conversion using AVIF_MATRIX_COEFFICIENTS_YCGCO_RE
AVIF_REFORMAT_MODE_YCGCO_RO, // YUV conversion using AVIF_MATRIX_COEFFICIENTS_YCGCO_RO
} avifReformatMode;

typedef enum avifAlphaMultiplyMode
Expand Down
24 changes: 2 additions & 22 deletions src/reformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,6 @@ avifBool avifGetRGBColorSpaceInfo(const avifRGBImage * rgb, avifRGBColorSpaceInf

avifBool avifGetYUVColorSpaceInfo(const avifImage * image, avifYUVColorSpaceInfo * info)
{
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
const avifBool useYCgCo = (image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RE) ||
(image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RO);
#endif

AVIF_CHECK(image->depth == 8 || image->depth == 10 || image->depth == 12 || image->depth == 16);
AVIF_CHECK(image->yuvFormat >= AVIF_PIXEL_FORMAT_YUV444 && image->yuvFormat < AVIF_PIXEL_FORMAT_COUNT);
AVIF_CHECK(image->yuvRange == AVIF_RANGE_LIMITED || image->yuvRange == AVIF_RANGE_FULL);
Expand All @@ -110,11 +105,8 @@ avifBool avifGetYUVColorSpaceInfo(const avifImage * image, avifYUVColorSpaceInfo
// YCgCo performs limited-full range adjustment on R,G,B but the current implementation performs range adjustment
// on Y,U,V. So YCgCo with limited range is unsupported.
if ((image->matrixCoefficients == 3 /* CICP reserved */) ||
((image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
|| useYCgCo
#endif
) &&
((image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO || image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RE ||
image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RO) &&
(image->yuvRange == AVIF_RANGE_LIMITED)) ||
(image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_BT2020_CL) ||
(image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_SMPTE2085) ||
Expand Down Expand Up @@ -146,7 +138,6 @@ avifBool avifGetYUVColorSpaceInfo(const avifImage * image, avifYUVColorSpaceInfo

static avifBool avifPrepareReformatState(const avifImage * image, const avifRGBImage * rgb, avifReformatState * state)
{
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
const avifBool useYCgCoRe = (image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RE);
const avifBool useYCgCoRo = (image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RO);
if (useYCgCoRe || useYCgCoRo) {
Expand All @@ -155,7 +146,6 @@ static avifBool avifPrepareReformatState(const avifImage * image, const avifRGBI
return AVIF_FALSE;
}
}
#endif

AVIF_CHECK(avifGetRGBColorSpaceInfo(rgb, &state->rgb));
AVIF_CHECK(avifGetYUVColorSpaceInfo(image, &state->yuv));
Expand All @@ -166,12 +156,10 @@ static avifBool avifPrepareReformatState(const avifImage * image, const avifRGBI
state->yuv.mode = AVIF_REFORMAT_MODE_IDENTITY;
} else if (image->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO) {
state->yuv.mode = AVIF_REFORMAT_MODE_YCGCO;
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
} else if (useYCgCoRe) {
state->yuv.mode = AVIF_REFORMAT_MODE_YCGCO_RE;
} else if (useYCgCoRo) {
state->yuv.mode = AVIF_REFORMAT_MODE_YCGCO_RO;
#endif
}

if (state->yuv.mode != AVIF_REFORMAT_MODE_YUV_COEFFICIENTS) {
Expand All @@ -196,12 +184,8 @@ static int avifYUVColorSpaceInfoUVToUNorm(avifYUVColorSpaceInfo * info, float v)

// YCgCo performs limited-full range adjustment on R,G,B but the current implementation performs range adjustment
// on Y,U,V. So YCgCo with limited range is unsupported.
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
assert((info->mode != AVIF_REFORMAT_MODE_YCGCO && info->mode != AVIF_REFORMAT_MODE_YCGCO_RE && info->mode != AVIF_REFORMAT_MODE_YCGCO_RO) ||
(info->range == AVIF_RANGE_FULL));
#else
assert((info->mode != AVIF_REFORMAT_MODE_YCGCO) || (info->range == AVIF_RANGE_FULL));
#endif

if (info->mode == AVIF_REFORMAT_MODE_IDENTITY) {
unorm = (int)avifRoundf(v * info->rangeY + info->biasY);
Expand Down Expand Up @@ -359,7 +343,6 @@ avifResult avifImageRGBToYUV(avifImage * image, const avifRGBImage * rgb)
yuvBlock[bI][bJ].y = 0.5f * rgbPixel[1] + 0.25f * (rgbPixel[0] + rgbPixel[2]);
yuvBlock[bI][bJ].u = 0.5f * rgbPixel[1] - 0.25f * (rgbPixel[0] + rgbPixel[2]);
yuvBlock[bI][bJ].v = 0.5f * (rgbPixel[0] - rgbPixel[2]);
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
} else if (state.yuv.mode == AVIF_REFORMAT_MODE_YCGCO_RE || state.yuv.mode == AVIF_REFORMAT_MODE_YCGCO_RO) {
// Formulas 58,59,60,61 from https://www.itu.int/rec/T-REC-H.273-202407-P
const int R = (int)avifRoundf(AVIF_CLAMP(rgbPixel[0] * rgbMaxChannelF, 0.0f, rgbMaxChannelF));
Expand All @@ -371,7 +354,6 @@ avifResult avifImageRGBToYUV(avifImage * image, const avifRGBImage * rgb)
yuvBlock[bI][bJ].y = (t + (Cg >> 1)) / state.yuv.rangeY;
yuvBlock[bI][bJ].u = Cg / state.yuv.rangeUV;
yuvBlock[bI][bJ].v = Co / state.yuv.rangeUV;
#endif
} else {
float Y = (kr * rgbPixel[0]) + (kg * rgbPixel[1]) + (kb * rgbPixel[2]);
yuvBlock[bI][bJ].y = Y;
Expand Down Expand Up @@ -769,7 +751,6 @@ static avifResult avifImageYUVAnyToRGBAnySlow(const avifImage * image,
G = Y + Cb;
B = t - Cr;
R = t + Cr;
#if defined(AVIF_ENABLE_EXPERIMENTAL_YCGCO_R)
} else if (state->yuv.mode == AVIF_REFORMAT_MODE_YCGCO_RE || state->yuv.mode == AVIF_REFORMAT_MODE_YCGCO_RO) {
// YCgCoRe/YCgCoRo: Formulas 62,63,64,65 from https://www.itu.int/rec/T-REC-H.273-202407-P
const int YY = unormY;
Expand All @@ -782,7 +763,6 @@ static avifResult avifImageYUVAnyToRGBAnySlow(const avifImage * image,
G /= rgbMaxChannelF;
B /= rgbMaxChannelF;
R /= rgbMaxChannelF;
#endif
} else {
// Normal YUV
R = Y + (2 * (1 - kr)) * Cr;
Expand Down
10 changes: 10 additions & 0 deletions src/write.c
Original file line number Diff line number Diff line change
Expand Up @@ -1615,6 +1615,16 @@ static avifResult avifValidateGrid(uint32_t gridCols,
AVIF_ASSERT_OR_RETURN(cellImage->gainMap && cellImage->gainMap->image);
cellImage = cellImage->gainMap->image;
}
#endif
#if !defined(AVIF_ENABLE_YCGCO_R_ENCODING)
if (cellImage->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RE ||
cellImage->matrixCoefficients == AVIF_MATRIX_COEFFICIENTS_YCGCO_RO) {
avifDiagnosticsPrintf(diag,
"YCGCO_R is not enabled for encoding. "
"Please set AVIF_ENABLE_YCGCO_R_ENCODING in CMake. "
"cf https://github.com/AOMediaCodec/libavif/issues/2077.");
return AVIF_RESULT_INVALID_IMAGE_GRID;
}
#endif
const uint32_t expectedCellWidth = ((cellIndex + 1) % gridCols) ? tileWidth : bottomRightCell->width;
const uint32_t expectedCellHeight = (cellIndex < (cellCount - gridCols)) ? tileHeight : bottomRightCell->height;
Expand Down
Loading
Loading