chromium/third_party/libavif/src/src/colr.c

// Copyright 2019 Joe Drago. All rights reserved.
// SPDX-License-Identifier: BSD-2-Clause

#include "avif/internal.h"

#include <float.h>
#include <math.h>
#include <string.h>

struct avifColorPrimariesTable
{};
static const struct avifColorPrimariesTable avifColorPrimariesTables[] =;
static const int avifColorPrimariesTableSize =;

void avifColorPrimariesGetValues(avifColorPrimaries acp, float outPrimaries[8])
{}

static avifBool matchesTo3RoundedPlaces(float a, float b)
{}

static avifBool primariesMatch(const float p1[8], const float p2[8])
{}

avifColorPrimaries avifColorPrimariesFind(const float inPrimaries[8], const char ** outName)
{}

avifResult avifTransferCharacteristicsGetGamma(avifTransferCharacteristics atc, float * gamma)
{}

avifTransferCharacteristics avifTransferCharacteristicsFindByGamma(float gamma)
{}

struct avifMatrixCoefficientsTable
{};

// https://www.itu.int/rec/T-REC-H.273-201612-I/en
static const struct avifMatrixCoefficientsTable matrixCoefficientsTables[] =;

static const int avifMatrixCoefficientsTableSize =;

static avifBool calcYUVInfoFromCICP(const avifImage * image, float coeffs[3])
{}

void avifCalcYUVCoefficients(const avifImage * image, float * outR, float * outG, float * outB)
{}

// ---------------------------------------------------------------------------
// Transfer characteristics
//
// Transfer characteristics are defined in ITU-T H.273 https://www.itu.int/rec/T-REC-H.273-201612-S/en
// with formulas for linear to gamma conversion in Table 3.
// This is based on tongyuantongyu's implementation in https://github.com/AOMediaCodec/libavif/pull/444
// with some fixes/changes in the first commit:
// - Fixed 5 transfer curves where toLinear and toGamma functions were swapped (470M, 470BG, Log100,
//   Log100Sqrt10 and SMPTE428)
// - 'avifToLinearLog100' and 'avifToLinearLog100Sqrt10' were modified to return the middle of the
//   range of linear values that are gamma-encoded to 0.0 in order to reduce the max round trip error,
//   based on vrabaud's change in
//   https://chromium.googlesource.com/webm/libwebp/+/25d94f473b10882b8bee9288d00539001b692042
// - In this file, PQ and HLG return "extended SDR" linear values in [0.0, 10000/203] and
//   [0.0, 1000/203] respectively, where a value of 1.0 means SDR white brightness (203 nits), and any
//   value above 1.0 is brigther.
// See git history for further changes.

struct avifTransferCharacteristicsTable
{};

static float avifToLinear709(float gamma)
{}

static float avifToGamma709(float linear)
{}

static float avifToLinear470M(float gamma)
{}

static float avifToGamma470M(float linear)
{}

static float avifToLinear470BG(float gamma)
{}

static float avifToGamma470BG(float linear)
{}

static float avifToLinearSMPTE240(float gamma)
{}

static float avifToGammaSMPTE240(float linear)
{}

static float avifToGammaLinear(float gamma)
{}

static float avifToLinearLog100(float gamma)
{}

static float avifToGammaLog100(float linear)
{}

static float avifToLinearLog100Sqrt10(float gamma)
{}

static float avifToGammaLog100Sqrt10(float linear)
{}

static float avifToLinearIEC61966(float gamma)
{}

static float avifToGammaIEC61966(float linear)
{}

static float avifToLinearBT1361(float gamma)
{}

static float avifToGammaBT1361(float linear)
{}

static float avifToLinearSRGB(float gamma)
{}

static float avifToGammaSRGB(float linear)
{}

#define PQ_MAX_NITS
#define HLG_PEAK_LUMINANCE_NITS
#define SDR_WHITE_NITS

static float avifToLinearPQ(float gamma)
{}

static float avifToGammaPQ(float linear)
{}

static float avifToLinearSMPTE428(float gamma)
{}

static float avifToGammaSMPTE428(float linear)
{}

// Formula from ITU-R BT.2100-2
// Assumes Lw=1000 (max display luminance in nits).
// For simplicity, approximates Ys (which should be 0.2627*r+0.6780*g+0.0593*b)
// to the input value (r, g, or b depending on the current channel).
static float avifToLinearHLG(float gamma)
{}

static float avifToGammaHLG(float linear)
{}

static const struct avifTransferCharacteristicsTable transferCharacteristicsTables[] =;

static const int avifTransferCharacteristicsTableSize =;

avifTransferFunction avifTransferCharacteristicsGetGammaToLinearFunction(avifTransferCharacteristics atc)
{}

avifTransferFunction avifTransferCharacteristicsGetLinearToGammaFunction(avifTransferCharacteristics atc)
{}

void avifColorPrimariesComputeYCoeffs(avifColorPrimaries colorPrimaries, float coeffs[3])
{}