Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Unified Diff: third_party/openh264/testing/i420_utils.cc

Issue 1403893007: Adding third_party/openh264/src, build files and unittests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rename var to 'use_openh264', add OpenH264 to 'all' target of GN Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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,
+ 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

Powered by Google App Engine
This is Rietveld 408576698