OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "third_party/openh264/testing/i420_utils.h" | |
6 | |
7 #include <limits> | |
8 | |
9 namespace openh264 { | |
10 | |
11 static int ClampIntRange(int x, int min, int max) { | |
12 return (x >= min && x <= max) ? x : (x > max ? max : min); | |
13 } | |
14 | |
15 void RgbToYuv(uint8_t r, uint8_t g, uint8_t b, | |
16 uint8_t* y, uint8_t* u, uint8_t* v) { | |
17 int R = r; | |
18 int G = g; | |
19 int B = b; | |
20 *y = ClampIntRange( | |
21 (R * 2104 + G * 4130 + B * 802 + 4096 + 131072) >> 13, 16, 235); | |
22 *u = ClampIntRange( | |
23 (R * -1214 + G * -2384 + B * 3598 + 4096 + 1048576) >> 13, 16, 240); | |
24 *v = ClampIntRange( | |
25 (R * 3598 + G * -3013 + B * -585 + 4096 + 1048576) >> 13, 16, 240); | |
26 } | |
27 | |
28 void YuvToRgb(uint8_t y, uint8_t u, uint8_t v, | |
29 uint8_t* r, uint8_t* g, uint8_t* b) { | |
30 int Y = y; | |
31 int U = u; | |
32 int V = v; | |
33 *r = ClampIntRange( | |
34 (Y * 9538 + V * 13074 + 4096 - 1826058) >> 13, 0, 255); | |
35 *g = ClampIntRange( | |
36 (Y * 9538 + U * -3209 + V * -6660 + 4096 + 1110639) >> 13, 0, 255); | |
37 *b = ClampIntRange( | |
38 (Y * 9538 + U * 16525 + V * -2 + 4096 - 2267650) >> 13, 0, 255); | |
39 } | |
40 | |
41 void CreateRgbFrame(webrtc::VideoFrame* video_frame, int width, int height, | |
42 uint8_t r, uint8_t g, uint8_t b) { | |
43 uint8_t y, u, v; | |
44 RgbToYuv(r, g, b, &y, &u, &v); | |
45 video_frame->CreateEmptyFrame(width, height, width, (width + 1) / 2, | |
46 (width + 1) / 2); | |
47 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.
| |
48 video_frame->allocated_size(webrtc::kYPlane)); | |
49 memset(video_frame->buffer(webrtc::kUPlane), u, | |
50 video_frame->allocated_size(webrtc::kUPlane)); | |
51 memset(video_frame->buffer(webrtc::kVPlane), v, | |
52 video_frame->allocated_size(webrtc::kVPlane)); | |
53 } | |
54 | |
55 } // namespace openh264 | |
OLD | NEW |