w3c / webcodecs

WebCodecs is a flexible web API for encoding and decoding audio and video.
https://w3c.github.io/webcodecs/
Other
975 stars 137 forks source link

VideoColorSpace: enum to replace nullable boolean? #592

Closed tidoust closed 1 year ago

tidoust commented 1 year ago

The VideoColorSpace interface has a nullable boolean attribute fullRange. That means the attribute actually captures 3 states: null, false, true. Using a boolean to capture 3 states does not seem like good practice, as developers will collate the first two cases if they write code such as:

if (!colorSpace.fullRange) {
  // ...
}

Wouldn't an enum be preferrable?

For what it's worth, there are 3 other occurrences of nullable booleans in web specs: ProximitySensor.near, RTCPeerConnection.canTrickleIceCandidates, XRCompositionLayer.chromaticAberrationCorrection. They could also benefit from using an enum.

sandersdan commented 1 year ago

I don't think so; the states are true, false, and unspecified, with unspecified being rare or even aberrant. It's actually probably for the best if null and false are collated since non-full-range is the most common interpretation.

There are ways of specifying the range that include more categories; internally Chrome splits unspecified into invalid vs derived. There is always a correct value to use that is either true or false, though.

dalecurtis commented 1 year ago

Dan's points are correct, so closing this.