w3c / webcodecs

WebCodecs is a flexible web API for encoding and decoding audio and video.

Home Page:https://w3c.github.io/webcodecs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sourceWidthBytes from sampleWidth, not sampleHeight

Yahweasel opened this issue · comments

In Compute Layout and Allocation Size, step 7.9, we compute sourceWidthBytes from sampleHeight. Obviously, it should be sampleWidth

EDIT: I had misunderstood the 10- and 12-bit formats, so I previously reported a different error which is not actually an error. Previous text left below for posterity.

In Compute Layout and Allocation Size, step 7.9, we compute sourceWidthBytes for the data layout. I see one bug and one potential bug with this calculation:

  1. This is computed from sampleHeight, but is obviously supposed to be sampleWidth
  2. With the addition of 10-bit and 12-bit formats, sampleBytes is no longer necessarily an integer. As a consequence, the result of this multiplication is itself no longer necessarily an integer. My reading of this has the result truncated implicitly by assignment to the unsigned long target type, but that's not made explicit by the text. More to the point, that's wrong; we would presumably want to ceil the value, not truncate/floor it. e.g., 3 pixels at 10bpp is 30 bits, but would actually be stored as 3 bytes by my reading, but should obviously be 4 bytes.

There's a similar potential issue to (2) with sourceLeftBytes, but nothing actually makes sense with sourceLeftBytes. We can't crop in the middle of a byte :)