Chromium Code Reviews| Index: client/site_tests/audiovideo_V4L2/src/media_v4l2_test.cc |
| diff --git a/client/site_tests/audiovideo_V4L2/src/media_v4l2_test.cc b/client/site_tests/audiovideo_V4L2/src/media_v4l2_test.cc |
| index a398e05a3e33bab8e256e92bead3b72c3cff401b..86cf54dec5d86df870faf98890dcb1aaa1e9b8ba 100644 |
| --- a/client/site_tests/audiovideo_V4L2/src/media_v4l2_test.cc |
| +++ b/client/site_tests/audiovideo_V4L2/src/media_v4l2_test.cc |
| @@ -122,32 +122,94 @@ class V4L2DeviceX11 : public V4L2Device { |
| void ConvertYUVToRGB32(uint8_t* in, uint8_t* out, int32_t ifmt, |
| int32_t width, int32_t height, |
| int32_t istride, int32_t ostride) { |
| - if (ifmt == v4l2_fourcc('Y', 'U', 'Y', 'V')) { |
| + if ((ifmt == v4l2_fourcc('Y', 'U', 'Y', 'V')) || |
| + (ifmt == v4l2_fourcc('Y', 'V', 'Y', 'U')) || |
| + (ifmt == v4l2_fourcc('U', 'Y', 'V', 'Y')) || |
| + (ifmt == v4l2_fourcc('V', 'Y', 'U', 'Y'))) { |
| for (int32_t i = 0; i < height; ++i) { |
| for (int32_t j = 0; j < width * 2; j += 4) { |
| - int32_t y0 = in[j]; |
| - int32_t y1 = in[j + 2]; |
| - int32_t u = in[j + 1] - 128; |
| - int32_t v = in[j + 3] - 128; |
| - |
| - int32_t r = (298 * y0 + 409 * v + 128) >> 8; |
| - int32_t g = (298 * y0 - 100 * u - 208 * v + 128) >> 8; |
| - int32_t b = (298 * y0 + 516 * u + 128) >> 8; |
| - out[j * 2 + 0] = clip(b, 0, 255); |
| - out[j * 2 + 1] = clip(g, 0, 255); |
| - out[j * 2 + 2] = clip(r, 0, 255); |
| - out[j * 2 + 3] = 255; |
| - r = (298 * y1 + 409 * v + 128) >> 8; |
| - g = (298 * y1 - 100 * u - 208 * v + 128) >> 8; |
| - b = (298 * y1 + 516 * u + 128) >> 8; |
| - out[j * 2 + 4] = clip(b, 0, 255); |
| - out[j * 2 + 5] = clip(g, 0, 255); |
| - out[j * 2 + 6] = clip(r, 0, 255); |
| - out[j * 2 + 7] = 255; |
| + int32_t y0; |
| + int32_t y1; |
| + int32_t u; |
| + int32_t v; |
| + |
| + if (ifmt == v4l2_fourcc('Y', 'U', 'Y', 'V')) { |
| + y0 = in[j]; |
| + y1 = in[j + 2]; |
| + u = in[j + 1] - 128; |
| + v = in[j + 3] - 128; |
| + } else if (ifmt == v4l2_fourcc('Y', 'V', 'Y', 'U')) { |
| + y0 = in[j]; |
| + y1 = in[j + 2]; |
| + u = in[j + 3] - 128; |
| + v = in[j + 1] - 128; |
| + } else if (ifmt == v4l2_fourcc('U', 'Y', 'V', 'Y')) { |
| + y0 = in[j + 1]; |
| + y1 = in[j + 3]; |
| + u = in[j] - 128; |
| + v = in[j + 2] - 128; |
| + } else if (ifmt == v4l2_fourcc('V', 'Y', 'U', 'Y')) { |
| + y0 = in[j + 1]; |
| + y1 = in[j + 3]; |
| + u = in[j + 2] - 128; |
| + v = in[j] - 128; |
| + } else { |
| + CHECK(0); |
| + } |
|
jiesun
2011/04/28 17:28:27
I actually prefer to do the branching outside the
|
| + |
| + int32_t r = (298 * y0 + 409 * v + 128) >> 8; |
| + int32_t g = (298 * y0 - 100 * u - 208 * v + 128) >> 8; |
| + int32_t b = (298 * y0 + 516 * u + 128) >> 8; |
| + |
| + out[j * 2 + 0] = clip(b, 0, 255); |
| + out[j * 2 + 1] = clip(g, 0, 255); |
| + out[j * 2 + 2] = clip(r, 0, 255); |
| + out[j * 2 + 3] = 255; |
| + |
| + r = (298 * y1 + 409 * v + 128) >> 8; |
| + g = (298 * y1 - 100 * u - 208 * v + 128) >> 8; |
| + b = (298 * y1 + 516 * u + 128) >> 8; |
| + |
| + out[j * 2 + 4] = clip(b, 0, 255); |
| + out[j * 2 + 5] = clip(g, 0, 255); |
| + out[j * 2 + 6] = clip(r, 0, 255); |
| + out[j * 2 + 7] = 255; |
| } |
| in += istride; |
| out += ostride; |
| } |
| + } else if (ifmt == v4l2_fourcc('Y', 'U', '1', '2')) { |
|
jiesun
2011/04/28 17:32:31
|| ifmt == v4l2_fourcc('Y', 'V', '1', '2')
since i
|
| + // Can't use pixels_per_line for this. While pixels per line is 12, |
| + // the rest of this part of code is using line stride as the |
| + // y-plane's line stride, which should just be the width of the image. |
| + istride = width; |
| + |
| + uint8_t* y_plane = in; |
| + uint8_t* u_plane = in + height * istride; |
| + // assumption. stride for uv is half of the y stride. |
| + uint8_t* v_plane = u_plane + height * istride / 4; |
|
jiesun
2011/04/28 17:32:31
if (ifmt == v4l2_fourcc('Y', 'V', '1', '2')) swap
|
| + for (int32_t i = 0; i < height; ++i) { |
| + for (int32_t j = 0; j < width; ++j) { |
| + int32_t y = y_plane[j]; |
| + int32_t u = u_plane[j>>1]; |
|
jiesun
2011/04/28 17:28:27
apparently that I had forgetten to -128 here and t
|
| + int32_t v = v_plane[j>>1]; |
|
jiesun
2011/04/28 17:28:27
please also add space around binary operator >>.
|
| + |
| + int32_t r = (298 * y + 409 * v + 128) >> 8; |
| + int32_t g = (298 * y - 100 * u - 208 * v + 128) >> 8; |
| + int32_t b = (298 * y + 516 * u + 128) >> 8; |
| + |
| + out[j * 4 + 0] = clip(b, 0, 255); |
| + out[j * 4 + 1] = clip(g, 0, 255); |
| + out[j * 4 + 2] = clip(r, 0, 255); |
| + out[j * 4 + 3] = 255; |
| + } |
| + y_plane += istride; |
| + if (i&1) { |
| + u_plane += istride >> 1; |
| + v_plane += istride >> 1; |
| + } |
| + out += ostride; |
| + } |
| } else { |
| CHECK(0); |
| } |