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.
It is not trivial how to crop YUV422/YUV420 data if the cropping area starts with odd x or y coordinate. For example:
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.