Bug 1832350 - Make VideoColorSpaceInit's members to null by default r=padenot,emilio

Per https://github.com/w3c/webcodecs/pull/591, the VideoColorSpaceInit's
members now shoule be null.

Differential Revision: https://phabricator.services.mozilla.com/D177669
This commit is contained in:
Chun-Min Chang 2023-05-11 17:19:39 +00:00
Родитель 79659c7736
Коммит e561622ae6
3 изменённых файлов: 30 добавлений и 40 удалений

Просмотреть файл

@ -30,15 +30,6 @@ class VideoColorSpace final : public nsISupports, public nsWrapperCache {
protected:
~VideoColorSpace() = default;
private:
template <class T>
static Nullable<T> ToNullable(const Optional<T>& aInput) {
if (aInput.WasPassed()) {
return Nullable<T>(aInput.Value());
}
return Nullable<T>();
}
public:
// This should return something that eventually allows finding a
// path to the global this object is associated with. Most simply,
@ -52,19 +43,19 @@ class VideoColorSpace final : public nsISupports, public nsWrapperCache {
const GlobalObject& aGlobal, const VideoColorSpaceInit& aInit,
ErrorResult& aRv);
Nullable<VideoColorPrimaries> GetPrimaries() const {
return ToNullable(mInit.mPrimaries);
const Nullable<VideoColorPrimaries>& GetPrimaries() const {
return mInit.mPrimaries;
}
Nullable<VideoTransferCharacteristics> GetTransfer() const {
return ToNullable(mInit.mTransfer);
const Nullable<VideoTransferCharacteristics>& GetTransfer() const {
return mInit.mTransfer;
}
Nullable<VideoMatrixCoefficients> GetMatrix() const {
return ToNullable(mInit.mMatrix);
const Nullable<VideoMatrixCoefficients>& GetMatrix() const {
return mInit.mMatrix;
}
Nullable<bool> GetFullRange() const { return ToNullable(mInit.mFullRange); }
const Nullable<bool>& GetFullRange() const { return mInit.mFullRange; }
private:
nsCOMPtr<nsIGlobalObject> mParent;

Просмотреть файл

@ -691,8 +691,8 @@ static VideoColorSpaceInit PickColorSpace(
colorSpace = *aInitColorSpace;
// By spec, we MAY replace null members of aInitColorSpace with guessed
// values so we can always use these in CreateYUVImageFromBuffer.
if (IsYUVFormat(aFormat) && !colorSpace.mMatrix.WasPassed()) {
colorSpace.mMatrix.Construct(VideoMatrixCoefficients::Bt709);
if (IsYUVFormat(aFormat) && colorSpace.mMatrix.IsNull()) {
colorSpace.mMatrix.SetValue(VideoMatrixCoefficients::Bt709);
}
return colorSpace;
}
@ -704,21 +704,20 @@ static VideoColorSpaceInit PickColorSpace(
case VideoPixelFormat::I444:
case VideoPixelFormat::NV12:
// https://w3c.github.io/webcodecs/#rec709-color-space
colorSpace.mFullRange.Construct(false);
colorSpace.mMatrix.Construct(VideoMatrixCoefficients::Bt709);
colorSpace.mPrimaries.Construct(VideoColorPrimaries::Bt709);
colorSpace.mTransfer.Construct(VideoTransferCharacteristics::Bt709);
colorSpace.mFullRange.SetValue(false);
colorSpace.mMatrix.SetValue(VideoMatrixCoefficients::Bt709);
colorSpace.mPrimaries.SetValue(VideoColorPrimaries::Bt709);
colorSpace.mTransfer.SetValue(VideoTransferCharacteristics::Bt709);
break;
case VideoPixelFormat::RGBA:
case VideoPixelFormat::RGBX:
case VideoPixelFormat::BGRA:
case VideoPixelFormat::BGRX:
// https://w3c.github.io/webcodecs/#srgb-color-space
colorSpace.mFullRange.Construct(true);
colorSpace.mMatrix.Construct(VideoMatrixCoefficients::Rgb);
colorSpace.mPrimaries.Construct(VideoColorPrimaries::Bt709);
colorSpace.mTransfer.Construct(
VideoTransferCharacteristics::Iec61966_2_1);
colorSpace.mFullRange.SetValue(true);
colorSpace.mMatrix.SetValue(VideoMatrixCoefficients::Rgb);
colorSpace.mPrimaries.SetValue(VideoColorPrimaries::Bt709);
colorSpace.mTransfer.SetValue(VideoTransferCharacteristics::Iec61966_2_1);
break;
case VideoPixelFormat::EndGuard_:
MOZ_ASSERT_UNREACHABLE("unsupported format");
@ -875,16 +874,16 @@ static Result<RefPtr<layers::Image>, nsCString> CreateYUVImageFromBuffer(
data.mCbCrStride = reader->mStrideU;
data.mChromaSubsampling = gfx::ChromaSubsampling::HALF_WIDTH_AND_HEIGHT;
// Color settings.
if (aColorSpace.mFullRange.WasPassed() && aColorSpace.mFullRange.Value()) {
if (!aColorSpace.mFullRange.IsNull() && aColorSpace.mFullRange.Value()) {
data.mColorRange = gfx::ColorRange::FULL;
}
MOZ_RELEASE_ASSERT(aColorSpace.mMatrix.WasPassed());
MOZ_RELEASE_ASSERT(!aColorSpace.mMatrix.IsNull());
data.mYUVColorSpace = ToColorSpace(aColorSpace.mMatrix.Value());
if (aColorSpace.mTransfer.WasPassed()) {
if (!aColorSpace.mTransfer.IsNull()) {
data.mTransferFunction =
ToTransferFunction(aColorSpace.mTransfer.Value());
}
if (aColorSpace.mPrimaries.WasPassed()) {
if (!aColorSpace.mPrimaries.IsNull()) {
data.mColorPrimaries = ToPrimaries(aColorSpace.mPrimaries.Value());
}
@ -919,16 +918,16 @@ static Result<RefPtr<layers::Image>, nsCString> CreateYUVImageFromBuffer(
data.mCbCrStride = reader.mStrideUV;
data.mChromaSubsampling = gfx::ChromaSubsampling::HALF_WIDTH_AND_HEIGHT;
// Color settings.
if (aColorSpace.mFullRange.WasPassed() && aColorSpace.mFullRange.Value()) {
if (!aColorSpace.mFullRange.IsNull() && aColorSpace.mFullRange.Value()) {
data.mColorRange = gfx::ColorRange::FULL;
}
MOZ_RELEASE_ASSERT(aColorSpace.mMatrix.WasPassed());
MOZ_RELEASE_ASSERT(!aColorSpace.mMatrix.IsNull());
data.mYUVColorSpace = ToColorSpace(aColorSpace.mMatrix.Value());
if (aColorSpace.mTransfer.WasPassed()) {
if (!aColorSpace.mTransfer.IsNull()) {
data.mTransferFunction =
ToTransferFunction(aColorSpace.mTransfer.Value());
}
if (aColorSpace.mPrimaries.WasPassed()) {
if (!aColorSpace.mPrimaries.IsNull()) {
data.mColorPrimaries = ToPrimaries(aColorSpace.mPrimaries.Value());
}
@ -972,7 +971,7 @@ static Result<RefPtr<VideoFrame>, nsCString> CreateVideoFrameFromBuffer(
nsIGlobalObject* aGlobal, const T& aBuffer,
const VideoFrameBufferInit& aInit) {
if (aInit.mColorSpace.WasPassed() &&
aInit.mColorSpace.Value().mTransfer.WasPassed() &&
!aInit.mColorSpace.Value().mTransfer.IsNull() &&
aInit.mColorSpace.Value().mTransfer.Value() ==
VideoTransferCharacteristics::Linear) {
return Err(nsCString("linear RGB is not supported"));

Просмотреть файл

@ -22,10 +22,10 @@ interface VideoColorSpace {
};
dictionary VideoColorSpaceInit {
VideoColorPrimaries primaries;
VideoTransferCharacteristics transfer;
VideoMatrixCoefficients matrix;
boolean fullRange;
VideoColorPrimaries? primaries = null;
VideoTransferCharacteristics? transfer = null;
VideoMatrixCoefficients? matrix = null;
boolean? fullRange = null;
};
enum VideoColorPrimaries {