w3c / mediacapture-worker

MediaStream with worker
Other
9 stars 12 forks source link

Crop YUV422/YUV420 data? #46

Closed kakukogou closed 8 years ago

kakukogou commented 8 years ago

It is not trivial how to crop YUV422/YUV420 data if the cropping area starts with odd x or y coordinate. For example:

// Give an YUV420P data with the following pixel layout.
.-------------------.-------------------.-------------------.-------------------.
| y(0, 0)           | y(1, 0)           | y(2, 0)           | y(3, 0)           |
| u(0, 0), v(0, 0)  |                   | u(1, 0), v(1, 0)  |                   |
+-------------------+-------------------+-------------------+-------------------+
| y(0, 1)           | y(1, 1)           | y(2, 1)           | y(3, 1)           |
|                   |                   |                   |                   |
+-------------------+-------------------+-------------------+-------------------+
| y(0, 2)           | y(1, 2)           | y(2, 2)           | y(3, 2)           |
| u(0, 1), v(0, 1)  |                   | u(1, 1), v(1, 1)  |                   |
+-------------------+-------------------+-------------------+-------------------+
| y(0, 3)           | y(1, 3)           | y(2, 3)           | y(3, 3)           |
|                   |                   |                   |                   |
+-------------------+-------------------+-------------------+-------------------+

// What if developers call createImageBitmap with the above data 
// and also pass a cropping rectangle starts at a odd x or y coordinate?
var p = createImageBitmap(yuv420PBuffer, ......, 1, 1, 2, 2);

Cropping u/v-channel starts from odd x or y coordinate is not trivial, here are two proposals:

(1) Via re-sampling. We can first up-sample the u/v-channel to the same size of y-channel, do the cropping, and then down-sample aging back to the u/v-channel cropping size. However, by this way, the newly created ImageBitmap's data is not the one passed by the caller. Also, there are plenty of re-sampling methods, should we explicitly define one on the spec?

(2) Avoid it. We can specifically define that only cropping rectangle starts form odd x and y coordinates are allowed for YUV422P/YUV420P/NV12/NV21 format.

I personally prefer the 2nd one, thoughts? @jrmuizel @rocallahan, @ChiahungTai and @anssiko.

kakukogou commented 8 years ago

This is now a non-issue since #57 being merged. Close this issue.