Skip to content
Draft
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
32 changes: 23 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions dom/media/MediaData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -422,11 +422,11 @@ already_AddRefed<VideoData> VideoData::CreateAndCopyData(

// The naming convention for libyuv and associated utils is word-order.
// The naming convention in the gfx stack is byte-order.
ConvertYCbCrAToARGB(aBuffer.mPlanes[0].mData, aBuffer.mPlanes[1].mData,
aBuffer.mPlanes[2].mData, aAlphaPlane.mData,
aBuffer.mPlanes[0].mStride, aBuffer.mPlanes[1].mStride,
buffer.data, buffer.stride, buffer.size.width,
buffer.size.height);
ConvertI420AlphaToARGB(aBuffer.mPlanes[0].mData, aBuffer.mPlanes[1].mData,
aBuffer.mPlanes[2].mData, aAlphaPlane.mData,
aBuffer.mPlanes[0].mStride, aBuffer.mPlanes[1].mStride,
buffer.data, buffer.stride, buffer.size.width,
buffer.size.height);

return v.forget();
}
Expand Down
141 changes: 139 additions & 2 deletions gfx/2d/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,149 @@ inline bool IsOpaque(SurfaceFormat aFormat) {
}
}

// These are standardized Coding-independent Code Points
// See [Rec. ITU-T H.273
// (12/2016)](https://www.itu.int/rec/T-REC-H.273-201612-I/en)
//
// We deliberately use an unscoped enum with fixed uint8_t representation since
// all possible values [0, 255] are legal, but it's unwieldy to declare 200+
// "RESERVED" enumeration values. Having a fixed underlying type avoids any
// potential UB and avoids the need for a cast when passing these values across
// FFI to functions like qcms_profile_create_cicp.
namespace CICP {
enum ColourPrimaries : uint8_t {
CP_RESERVED_MIN = 0, // 0, 3, [13, 21], [23, 255] are all reserved
CP_BT709 = 1,
CP_UNSPECIFIED = 2,
CP_BT470M = 4,
CP_BT470BG = 5,
CP_BT601 = 6,
CP_SMPTE240 = 7,
CP_GENERIC_FILM = 8,
CP_BT2020 = 9,
CP_XYZ = 10,
CP_SMPTE431 = 11,
CP_SMPTE432 = 12,
CP_EBU3213 = 22,
};

inline bool IsReserved(ColourPrimaries aIn) {
switch (aIn) {
case CP_BT709:
case CP_UNSPECIFIED:
case CP_BT470M:
case CP_BT470BG:
case CP_BT601:
case CP_SMPTE240:
case CP_GENERIC_FILM:
case CP_BT2020:
case CP_XYZ:
case CP_SMPTE431:
case CP_SMPTE432:
case CP_EBU3213:
return false;
default:
return true;
}
}

enum TransferCharacteristics : uint8_t {
TC_RESERVED_MIN = 0, // 0, 3, [19, 255] are all reserved
TC_BT709 = 1,
TC_UNSPECIFIED = 2,
TC_BT470M = 4,
TC_BT470BG = 5,
TC_BT601 = 6,
TC_SMPTE240 = 7,
TC_LINEAR = 8,
TC_LOG_100 = 9,
TC_LOG_100_SQRT10 = 10,
TC_IEC61966 = 11,
TC_BT_1361 = 12,
TC_SRGB = 13,
TC_BT2020_10BIT = 14,
TC_BT2020_12BIT = 15,
TC_SMPTE2084 = 16,
TC_SMPTE428 = 17,
TC_HLG = 18,
};

inline bool IsReserved(TransferCharacteristics aIn) {
switch (aIn) {
case TC_BT709:
case TC_UNSPECIFIED:
case TC_BT470M:
case TC_BT470BG:
case TC_BT601:
case TC_SMPTE240:
case TC_LINEAR:
case TC_LOG_100:
case TC_LOG_100_SQRT10:
case TC_IEC61966:
case TC_BT_1361:
case TC_SRGB:
case TC_BT2020_10BIT:
case TC_BT2020_12BIT:
case TC_SMPTE2084:
case TC_SMPTE428:
case TC_HLG:
return false;
default:
return true;
}
}

enum MatrixCoefficients : uint8_t {
MC_IDENTITY = 0,
MC_BT709 = 1,
MC_UNSPECIFIED = 2,
MC_RESERVED_MIN = 3, // 3, [15, 255] are all reserved
MC_FCC = 4,
MC_BT470BG = 5,
MC_BT601 = 6,
MC_SMPTE240 = 7,
MC_YCGCO = 8,
MC_BT2020_NCL = 9,
MC_BT2020_CL = 10,
MC_SMPTE2085 = 11,
MC_CHROMAT_NCL = 12,
MC_CHROMAT_CL = 13,
MC_ICTCP = 14,
};

inline bool IsReserved(MatrixCoefficients aIn) {
switch (aIn) {
case MC_IDENTITY:
case MC_BT709:
case MC_UNSPECIFIED:
case MC_RESERVED_MIN:
case MC_FCC:
case MC_BT470BG:
case MC_BT601:
case MC_SMPTE240:
case MC_YCGCO:
case MC_BT2020_NCL:
case MC_BT2020_CL:
case MC_SMPTE2085:
case MC_CHROMAT_NCL:
case MC_CHROMAT_CL:
case MC_ICTCP:
return false;
default:
return true;
}
}
} // namespace CICP

enum class YUVColorSpace : uint8_t {
BT601,
BT709,
BT2020,
// This represents the unknown format and is a valid value.
UNKNOWN,
Identity, // Todo: s/YUVColorSpace/ColorSpace/, s/Identity/SRGB/
Default = BT709,
_First = BT601,
_Last = Identity,
UNKNOWN = Identity,
_NUM_COLORSPACE
};

Expand Down
9 changes: 9 additions & 0 deletions gfx/layers/ImageContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,15 @@ struct PlanarYCbCrData {
}
};

// This type is currently only used for AVIF and therefore makes some
// AVIF-specific assumptions (e.g., Alpha's bpc and stride is equal to Y's one)
struct PlanarAlphaData {
uint8_t* mChannel = nullptr;
gfx::IntSize mSize = gfx::IntSize(0, 0);
gfx::ColorDepth mDepth = gfx::ColorDepth::COLOR_8;
bool mPremultiplied = false;
};

/****** Image subtypes for the different formats ******/

/**
Expand Down
41 changes: 41 additions & 0 deletions gfx/thebes/gfxUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,47 @@ const float kBT2020NarrowYCbCrToRGB_RowMajor[16] = {
}
}

// Translate from CICP values to the color spaces we support, or return
// Nothing() if there is no appropriate match to let the caller choose
// a default or generate an error.
//
// See Rec. ITU-T H.273 (12/2016) for details on CICP
/* static */ Maybe<gfx::YUVColorSpace> gfxUtils::CicpToColorSpace(
const CICP::MatrixCoefficients aMatrixCoefficients,
const CICP::ColourPrimaries aColourPrimaries, LazyLogModule& aLogger) {
switch (aMatrixCoefficients) {
case CICP::MatrixCoefficients::MC_BT2020_NCL:
case CICP::MatrixCoefficients::MC_BT2020_CL:
return Some(gfx::YUVColorSpace::BT2020);
case CICP::MatrixCoefficients::MC_BT601:
return Some(gfx::YUVColorSpace::BT601);
case CICP::MatrixCoefficients::MC_BT709:
return Some(gfx::YUVColorSpace::BT709);
case CICP::MatrixCoefficients::MC_IDENTITY:
return Some(gfx::YUVColorSpace::Identity);
case CICP::MatrixCoefficients::MC_CHROMAT_NCL:
case CICP::MatrixCoefficients::MC_CHROMAT_CL:
case CICP::MatrixCoefficients::MC_UNSPECIFIED:
switch (aColourPrimaries) {
case CICP::ColourPrimaries::CP_BT601:
return Some(gfx::YUVColorSpace::BT601);
case CICP::ColourPrimaries::CP_BT709:
return Some(gfx::YUVColorSpace::BT709);
case CICP::ColourPrimaries::CP_BT2020:
return Some(gfx::YUVColorSpace::BT2020);
default:
MOZ_LOG(aLogger, LogLevel::Debug,
("Couldn't infer color matrix from primaries: %hhu",
aColourPrimaries));
return {};
}
default:
MOZ_LOG(aLogger, LogLevel::Debug,
("Unsupported color matrix value: %hhu", aMatrixCoefficients));
return {};
}
}

/* static */
void gfxUtils::WriteAsPNG(SourceSurface* aSurface, const nsAString& aFile) {
WriteAsPNG(aSurface, NS_ConvertUTF16toUTF8(aFile).get());
Expand Down
5 changes: 5 additions & 0 deletions gfx/thebes/gfxUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ class gfxUtils {
static const float* YuvToRgbMatrix4x4ColumnMajor(
mozilla::gfx::YUVColorSpace aYUVColorSpace);

static mozilla::Maybe<mozilla::gfx::YUVColorSpace> CicpToColorSpace(
const mozilla::gfx::CICP::MatrixCoefficients,
const mozilla::gfx::CICP::ColourPrimaries,
mozilla::LazyLogModule& aLogger);

/**
* Creates a copy of aSurface, but having the SurfaceFormat aFormat.
*
Expand Down
Loading