Chromium Code Reviews| Index: third_party/openh264/testing/i420_utils.cc |
| diff --git a/third_party/openh264/testing/i420_utils.cc b/third_party/openh264/testing/i420_utils.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d5c9fb5836b7f0c7a08ff98d2b763ac612316901 |
| --- /dev/null |
| +++ b/third_party/openh264/testing/i420_utils.cc |
| @@ -0,0 +1,55 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "third_party/openh264/testing/i420_utils.h" |
| + |
| +#include <limits> |
| + |
| +namespace openh264 { |
| + |
| +static int ClampIntRange(int x, int min, int max) { |
| + return (x >= min && x <= max) ? x : (x > max ? max : min); |
| +} |
| + |
| +void RgbToYuv(uint8_t r, uint8_t g, uint8_t b, |
| + uint8_t* y, uint8_t* u, uint8_t* v) { |
| + int R = r; |
| + int G = g; |
| + int B = b; |
| + *y = ClampIntRange( |
| + (R * 2104 + G * 4130 + B * 802 + 4096 + 131072) >> 13, 16, 235); |
| + *u = ClampIntRange( |
| + (R * -1214 + G * -2384 + B * 3598 + 4096 + 1048576) >> 13, 16, 240); |
| + *v = ClampIntRange( |
| + (R * 3598 + G * -3013 + B * -585 + 4096 + 1048576) >> 13, 16, 240); |
| +} |
| + |
| +void YuvToRgb(uint8_t y, uint8_t u, uint8_t v, |
| + uint8_t* r, uint8_t* g, uint8_t* b) { |
| + int Y = y; |
| + int U = u; |
| + int V = v; |
| + *r = ClampIntRange( |
| + (Y * 9538 + V * 13074 + 4096 - 1826058) >> 13, 0, 255); |
| + *g = ClampIntRange( |
| + (Y * 9538 + U * -3209 + V * -6660 + 4096 + 1110639) >> 13, 0, 255); |
| + *b = ClampIntRange( |
| + (Y * 9538 + U * 16525 + V * -2 + 4096 - 2267650) >> 13, 0, 255); |
| +} |
| + |
| +void CreateRgbFrame(webrtc::VideoFrame* video_frame, int width, int height, |
| + uint8_t r, uint8_t g, uint8_t b) { |
| + uint8_t y, u, v; |
| + RgbToYuv(r, g, b, &y, &u, &v); |
| + video_frame->CreateEmptyFrame(width, height, width, (width + 1) / 2, |
| + (width + 1) / 2); |
| + memset(video_frame->buffer(webrtc::kYPlane), y, |
|
torbjorng
2015/11/18 14:41:09
Slightly ignorant comment: Should we really copy a
hbos_chromium
2015/11/18 15:55:04
I must admit basing this code off of https://code.
|
| + video_frame->allocated_size(webrtc::kYPlane)); |
| + memset(video_frame->buffer(webrtc::kUPlane), u, |
| + video_frame->allocated_size(webrtc::kUPlane)); |
| + memset(video_frame->buffer(webrtc::kVPlane), v, |
| + video_frame->allocated_size(webrtc::kVPlane)); |
| +} |
| + |
| +} // namespace openh264 |