OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/cast/test/utility/video_utility.h" | 5 #include "media/cast/test/utility/video_utility.h" |
6 | 6 |
7 #include <math.h> | 7 #include <math.h> |
8 #include <cstdio> | 8 #include <cstdio> |
9 | 9 |
10 #include "base/rand_util.h" | 10 #include "base/rand_util.h" |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
56 frame2->stride(VideoFrame::kVPlane), | 56 frame2->stride(VideoFrame::kVPlane), |
57 frame1->coded_size().width(), | 57 frame1->coded_size().width(), |
58 frame1->coded_size().height()); | 58 frame1->coded_size().height()); |
59 } | 59 } |
60 | 60 |
61 void PopulateVideoFrame(VideoFrame* frame, int start_value) { | 61 void PopulateVideoFrame(VideoFrame* frame, int start_value) { |
62 const gfx::Size frame_size = frame->coded_size(); | 62 const gfx::Size frame_size = frame->coded_size(); |
63 const int stripe_size = | 63 const int stripe_size = |
64 std::max(32, std::min(frame_size.width(), frame_size.height()) / 8) & -2; | 64 std::max(32, std::min(frame_size.width(), frame_size.height()) / 8) & -2; |
65 | 65 |
66 int height = frame_size.height(); | 66 // Set Y. |
67 int stride_y = frame->stride(VideoFrame::kYPlane); | 67 const int height = frame_size.height(); |
68 int stride_u = frame->stride(VideoFrame::kUPlane); | 68 const int stride_y = frame->stride(VideoFrame::kYPlane); |
69 int stride_v = frame->stride(VideoFrame::kVPlane); | |
70 int half_height = (height + 1) / 2; | |
71 uint8* y_plane = frame->data(VideoFrame::kYPlane); | 69 uint8* y_plane = frame->data(VideoFrame::kYPlane); |
72 uint8* u_plane = frame->data(VideoFrame::kUPlane); | |
73 uint8* v_plane = frame->data(VideoFrame::kVPlane); | |
74 | |
75 // Set Y. | |
76 for (int j = 0; j < height; ++j) { | 70 for (int j = 0; j < height; ++j) { |
77 const int stripe_j = (j / stripe_size) * stripe_size; | 71 const int stripe_j = (j / stripe_size) * stripe_size; |
78 for (int i = 0; i < stride_y; ++i) { | 72 for (int i = 0; i < stride_y; ++i) { |
79 const int stripe_i = (i / stripe_size) * stripe_size; | 73 const int stripe_i = (i / stripe_size) * stripe_size; |
80 *y_plane = static_cast<uint8>(start_value + stripe_i + stripe_j); | 74 *y_plane = static_cast<uint8>(start_value + stripe_i + stripe_j); |
81 ++y_plane; | 75 ++y_plane; |
82 } | 76 } |
83 } | 77 } |
84 | 78 |
85 // Set U. | 79 const int half_height = (height + 1) / 2; |
86 for (int j = 0; j < half_height; ++j) { | 80 if (frame->format() == VideoFrame::NV12) { |
87 const int stripe_j = (j / stripe_size) * stripe_size; | 81 const int stride_uv = frame->stride(VideoFrame::kUVPlane); |
88 for (int i = 0; i < stride_u; ++i) { | 82 uint8* uv_plane = frame->data(VideoFrame::kUVPlane); |
89 const int stripe_i = (i / stripe_size) * stripe_size; | 83 |
90 *u_plane = static_cast<uint8>(start_value + stripe_i + stripe_j); | 84 // Set U and V. |
91 ++u_plane; | 85 for (int j = 0; j < half_height; ++j) { |
| 86 const int stripe_j = (j / stripe_size) * stripe_size; |
| 87 for (int i = 0; i < stride_uv; i += 2) { |
| 88 const int stripe_i = (i / stripe_size) * stripe_size; |
| 89 *uv_plane = *(uv_plane + 1) = |
| 90 static_cast<uint8>(start_value + stripe_i + stripe_j); |
| 91 uv_plane += 2; |
| 92 } |
92 } | 93 } |
93 } | 94 } else { // I420, YV12, etc. |
| 95 const int stride_u = frame->stride(VideoFrame::kUPlane); |
| 96 const int stride_v = frame->stride(VideoFrame::kVPlane); |
| 97 uint8* u_plane = frame->data(VideoFrame::kUPlane); |
| 98 uint8* v_plane = frame->data(VideoFrame::kVPlane); |
94 | 99 |
95 // Set V. | 100 // Set U. |
96 for (int j = 0; j < half_height; ++j) { | 101 for (int j = 0; j < half_height; ++j) { |
97 const int stripe_j = (j / stripe_size) * stripe_size; | 102 const int stripe_j = (j / stripe_size) * stripe_size; |
98 for (int i = 0; i < stride_v; ++i) { | 103 for (int i = 0; i < stride_u; ++i) { |
99 const int stripe_i = (i / stripe_size) * stripe_size; | 104 const int stripe_i = (i / stripe_size) * stripe_size; |
100 *u_plane = static_cast<uint8>(start_value + stripe_i + stripe_j); | 105 *u_plane = static_cast<uint8>(start_value + stripe_i + stripe_j); |
101 ++v_plane; | 106 ++u_plane; |
| 107 } |
| 108 } |
| 109 |
| 110 // Set V. |
| 111 for (int j = 0; j < half_height; ++j) { |
| 112 const int stripe_j = (j / stripe_size) * stripe_size; |
| 113 for (int i = 0; i < stride_v; ++i) { |
| 114 const int stripe_i = (i / stripe_size) * stripe_size; |
| 115 *u_plane = static_cast<uint8>(start_value + stripe_i + stripe_j); |
| 116 ++v_plane; |
| 117 } |
102 } | 118 } |
103 } | 119 } |
104 } | 120 } |
105 | 121 |
106 void PopulateVideoFrameWithNoise(VideoFrame* frame) { | 122 void PopulateVideoFrameWithNoise(VideoFrame* frame) { |
107 int height = frame->coded_size().height(); | 123 int height = frame->coded_size().height(); |
108 int stride_y = frame->stride(VideoFrame::kYPlane); | 124 int stride_y = frame->stride(VideoFrame::kYPlane); |
109 int stride_u = frame->stride(VideoFrame::kUPlane); | 125 int stride_u = frame->stride(VideoFrame::kUPlane); |
110 int stride_v = frame->stride(VideoFrame::kVPlane); | 126 int stride_v = frame->stride(VideoFrame::kVPlane); |
111 int half_height = (height + 1) / 2; | 127 int half_height = (height + 1) / 2; |
(...skipping 25 matching lines...) Expand all Loading... |
137 memcpy(u_plane, raw_data + width * height, half_width * half_height); | 153 memcpy(u_plane, raw_data + width * height, half_width * half_height); |
138 memcpy(v_plane, | 154 memcpy(v_plane, |
139 raw_data + width * height + half_width * half_height, | 155 raw_data + width * height + half_width * half_height, |
140 half_width * half_height); | 156 half_width * half_height); |
141 delete[] raw_data; | 157 delete[] raw_data; |
142 return true; | 158 return true; |
143 } | 159 } |
144 | 160 |
145 } // namespace cast | 161 } // namespace cast |
146 } // namespace media | 162 } // namespace media |
OLD | NEW |