mikhal@webrtc.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include <math.h> |
| 12 | #include <string.h> |
| 13 | |
Henrik Kjellander | a80c16a | 2017-07-01 16:48:15 +0200 | [diff] [blame] | 14 | #include "webrtc/api/video/i420_buffer.h" |
Edward Lemur | c20978e | 2017-07-06 19:44:34 +0200 | [diff] [blame] | 15 | #include "webrtc/api/video/video_frame.h" |
| 16 | #include "webrtc/rtc_base/bind.h" |
| 17 | #include "webrtc/rtc_base/timeutils.h" |
Peter Boström | eb66e80 | 2015-06-05 11:08:03 +0200 | [diff] [blame] | 18 | #include "webrtc/test/fake_texture_frame.h" |
Niels Möller | 739fcb9 | 2016-02-29 13:11:45 +0100 | [diff] [blame] | 19 | #include "webrtc/test/frame_utils.h" |
kwiberg | ac9f876 | 2016-09-30 22:29:43 -0700 | [diff] [blame] | 20 | #include "webrtc/test/gtest.h" |
mikhal@webrtc.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 24 | namespace { |
| 25 | |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 26 | rtc::scoped_refptr<I420Buffer> CreateGradient(int width, int height) { |
| 27 | rtc::scoped_refptr<I420Buffer> buffer( |
nisse | ac62bd4 | 2016-06-20 03:38:52 -0700 | [diff] [blame] | 28 | I420Buffer::Create(width, height)); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 29 | // Initialize with gradient, Y = 128(x/w + y/h), U = 256 x/w, V = 256 y/h |
| 30 | for (int x = 0; x < width; x++) { |
| 31 | for (int y = 0; y < height; y++) { |
| 32 | buffer->MutableDataY()[x + y * width] = |
| 33 | 128 * (x * height + y * width) / (width * height); |
| 34 | } |
| 35 | } |
magjed | 3f07549 | 2017-06-01 10:02:26 -0700 | [diff] [blame] | 36 | int chroma_width = buffer->ChromaWidth(); |
| 37 | int chroma_height = buffer->ChromaHeight(); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 38 | for (int x = 0; x < chroma_width; x++) { |
| 39 | for (int y = 0; y < chroma_height; y++) { |
| 40 | buffer->MutableDataU()[x + y * chroma_width] = |
| 41 | 255 * x / (chroma_width - 1); |
| 42 | buffer->MutableDataV()[x + y * chroma_width] = |
| 43 | 255 * y / (chroma_height - 1); |
| 44 | } |
| 45 | } |
| 46 | return buffer; |
| 47 | } |
| 48 | |
| 49 | // The offsets and sizes describe the rectangle extracted from the |
| 50 | // original (gradient) frame, in relative coordinates where the |
| 51 | // original frame correspond to the unit square, 0.0 <= x, y < 1.0. |
magjed | 3f07549 | 2017-06-01 10:02:26 -0700 | [diff] [blame] | 52 | void CheckCrop(const webrtc::I420BufferInterface& frame, |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 53 | double offset_x, |
| 54 | double offset_y, |
| 55 | double rel_width, |
| 56 | double rel_height) { |
nisse | f33970b | 2016-10-18 06:01:34 -0700 | [diff] [blame] | 57 | int width = frame.width(); |
| 58 | int height = frame.height(); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 59 | // Check that pixel values in the corners match the gradient used |
| 60 | // for initialization. |
| 61 | for (int i = 0; i < 2; i++) { |
| 62 | for (int j = 0; j < 2; j++) { |
| 63 | // Pixel coordinates of the corner. |
| 64 | int x = i * (width - 1); |
| 65 | int y = j * (height - 1); |
| 66 | // Relative coordinates, range 0.0 - 1.0 correspond to the |
| 67 | // size of the uncropped input frame. |
| 68 | double orig_x = offset_x + i * rel_width; |
| 69 | double orig_y = offset_y + j * rel_height; |
| 70 | |
nisse | f33970b | 2016-10-18 06:01:34 -0700 | [diff] [blame] | 71 | EXPECT_NEAR(frame.DataY()[x + y * frame.StrideY()] / 256.0, |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 72 | (orig_x + orig_y) / 2, 0.02); |
nisse | f33970b | 2016-10-18 06:01:34 -0700 | [diff] [blame] | 73 | EXPECT_NEAR(frame.DataU()[x / 2 + (y / 2) * frame.StrideU()] / 256.0, |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 74 | orig_x, 0.02); |
nisse | f33970b | 2016-10-18 06:01:34 -0700 | [diff] [blame] | 75 | EXPECT_NEAR(frame.DataV()[x / 2 + (y / 2) * frame.StrideV()] / 256.0, |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 76 | orig_y, 0.02); |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
magjed | 3f07549 | 2017-06-01 10:02:26 -0700 | [diff] [blame] | 81 | void CheckRotate(int width, |
| 82 | int height, |
| 83 | webrtc::VideoRotation rotation, |
| 84 | const webrtc::I420BufferInterface& rotated) { |
nisse | f33970b | 2016-10-18 06:01:34 -0700 | [diff] [blame] | 85 | int rotated_width = width; |
| 86 | int rotated_height = height; |
| 87 | |
| 88 | if (rotation == kVideoRotation_90 || rotation == kVideoRotation_270) { |
| 89 | std::swap(rotated_width, rotated_height); |
| 90 | } |
| 91 | EXPECT_EQ(rotated_width, rotated.width()); |
| 92 | EXPECT_EQ(rotated_height, rotated.height()); |
| 93 | |
| 94 | // Clock-wise order (with 0,0 at top-left) |
| 95 | const struct { int x; int y; } corners[] = { |
| 96 | { 0, 0 }, { 1, 0 }, { 1, 1 }, { 0, 1 } |
| 97 | }; |
| 98 | // Corresponding corner colors of the frame produced by CreateGradient. |
| 99 | const struct { int y; int u; int v; } colors[] = { |
| 100 | {0, 0, 0}, { 127, 255, 0}, { 255, 255, 255 }, {127, 0, 255} |
| 101 | }; |
| 102 | int corner_offset = static_cast<int>(rotation) / 90; |
| 103 | |
| 104 | for (int i = 0; i < 4; i++) { |
| 105 | int j = (i + corner_offset) % 4; |
| 106 | int x = corners[j].x * (rotated_width - 1); |
| 107 | int y = corners[j].y * (rotated_height - 1); |
| 108 | EXPECT_EQ(colors[i].y, rotated.DataY()[x + y * rotated.StrideY()]); |
| 109 | EXPECT_EQ(colors[i].u, |
| 110 | rotated.DataU()[(x / 2) + (y / 2) * rotated.StrideU()]); |
| 111 | EXPECT_EQ(colors[i].v, |
| 112 | rotated.DataV()[(x / 2) + (y / 2) * rotated.StrideV()]); |
| 113 | } |
| 114 | } |
| 115 | |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 116 | } // namespace |
mikhal@webrtc.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 117 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 118 | TEST(TestVideoFrame, WidthHeightValues) { |
nisse | f122a85 | 2016-10-04 23:27:30 -0700 | [diff] [blame] | 119 | VideoFrame frame(I420Buffer::Create(10, 10, 10, 14, 90), |
| 120 | webrtc::kVideoRotation_0, |
| 121 | 789 * rtc::kNumMicrosecsPerMillisec); |
mikhal@webrtc.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 122 | const int valid_value = 10; |
mikhal@webrtc.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 123 | EXPECT_EQ(valid_value, frame.width()); |
mikhal@webrtc.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 124 | EXPECT_EQ(valid_value, frame.height()); |
wu@webrtc.org | 6c75c98 | 2014-04-15 17:46:33 +0000 | [diff] [blame] | 125 | frame.set_timestamp(123u); |
| 126 | EXPECT_EQ(123u, frame.timestamp()); |
| 127 | frame.set_ntp_time_ms(456); |
| 128 | EXPECT_EQ(456, frame.ntp_time_ms()); |
wu@webrtc.org | 6c75c98 | 2014-04-15 17:46:33 +0000 | [diff] [blame] | 129 | EXPECT_EQ(789, frame.render_time_ms()); |
mikhal@webrtc.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 130 | } |
| 131 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 132 | TEST(TestVideoFrame, ShallowCopy) { |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 133 | uint32_t timestamp = 1; |
| 134 | int64_t ntp_time_ms = 2; |
nisse | 1c0dea8 | 2017-01-30 02:43:18 -0800 | [diff] [blame] | 135 | int64_t timestamp_us = 3; |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 136 | int stride_y = 15; |
| 137 | int stride_u = 10; |
| 138 | int stride_v = 10; |
| 139 | int width = 15; |
| 140 | int height = 15; |
| 141 | |
| 142 | const int kSizeY = 400; |
| 143 | const int kSizeU = 100; |
| 144 | const int kSizeV = 100; |
| 145 | const VideoRotation kRotation = kVideoRotation_270; |
| 146 | uint8_t buffer_y[kSizeY]; |
| 147 | uint8_t buffer_u[kSizeU]; |
| 148 | uint8_t buffer_v[kSizeV]; |
| 149 | memset(buffer_y, 16, kSizeY); |
| 150 | memset(buffer_u, 8, kSizeU); |
| 151 | memset(buffer_v, 4, kSizeV); |
nisse | 2f58ec8 | 2016-11-28 03:47:52 -0800 | [diff] [blame] | 152 | |
nisse | f0a7c5a | 2016-10-31 05:48:07 -0700 | [diff] [blame] | 153 | VideoFrame frame1( |
nisse | 2f58ec8 | 2016-11-28 03:47:52 -0800 | [diff] [blame] | 154 | I420Buffer::Copy(width, height, |
| 155 | buffer_y, stride_y, |
| 156 | buffer_u, stride_u, |
| 157 | buffer_v, stride_v), |
nisse | f0a7c5a | 2016-10-31 05:48:07 -0700 | [diff] [blame] | 158 | kRotation, 0); |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 159 | frame1.set_timestamp(timestamp); |
| 160 | frame1.set_ntp_time_ms(ntp_time_ms); |
nisse | 1c0dea8 | 2017-01-30 02:43:18 -0800 | [diff] [blame] | 161 | frame1.set_timestamp_us(timestamp_us); |
nisse | f0a7c5a | 2016-10-31 05:48:07 -0700 | [diff] [blame] | 162 | VideoFrame frame2(frame1); |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 163 | |
nisse | f0a7c5a | 2016-10-31 05:48:07 -0700 | [diff] [blame] | 164 | EXPECT_EQ(frame1.video_frame_buffer(), frame2.video_frame_buffer()); |
magjed | 3f07549 | 2017-06-01 10:02:26 -0700 | [diff] [blame] | 165 | rtc::scoped_refptr<I420BufferInterface> yuv1 = |
| 166 | frame1.video_frame_buffer()->GetI420(); |
| 167 | rtc::scoped_refptr<I420BufferInterface> yuv2 = |
| 168 | frame2.video_frame_buffer()->GetI420(); |
| 169 | EXPECT_EQ(yuv1->DataY(), yuv2->DataY()); |
| 170 | EXPECT_EQ(yuv1->DataU(), yuv2->DataU()); |
| 171 | EXPECT_EQ(yuv1->DataV(), yuv2->DataV()); |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 172 | |
| 173 | EXPECT_EQ(frame2.timestamp(), frame1.timestamp()); |
| 174 | EXPECT_EQ(frame2.ntp_time_ms(), frame1.ntp_time_ms()); |
nisse | 1c0dea8 | 2017-01-30 02:43:18 -0800 | [diff] [blame] | 175 | EXPECT_EQ(frame2.timestamp_us(), frame1.timestamp_us()); |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 176 | EXPECT_EQ(frame2.rotation(), frame1.rotation()); |
| 177 | |
| 178 | frame2.set_timestamp(timestamp + 1); |
| 179 | frame2.set_ntp_time_ms(ntp_time_ms + 1); |
nisse | 1c0dea8 | 2017-01-30 02:43:18 -0800 | [diff] [blame] | 180 | frame2.set_timestamp_us(timestamp_us + 1); |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 181 | frame2.set_rotation(kVideoRotation_90); |
| 182 | |
| 183 | EXPECT_NE(frame2.timestamp(), frame1.timestamp()); |
| 184 | EXPECT_NE(frame2.ntp_time_ms(), frame1.ntp_time_ms()); |
nisse | 1c0dea8 | 2017-01-30 02:43:18 -0800 | [diff] [blame] | 185 | EXPECT_NE(frame2.timestamp_us(), frame1.timestamp_us()); |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 186 | EXPECT_NE(frame2.rotation(), frame1.rotation()); |
| 187 | } |
| 188 | |
Miguel Casas-Sanchez | 4765070 | 2015-05-29 17:21:40 -0700 | [diff] [blame] | 189 | TEST(TestVideoFrame, TextureInitialValues) { |
Magnus Jedvert | 90e3190 | 2017-06-07 11:32:50 +0200 | [diff] [blame] | 190 | VideoFrame frame = test::FakeNativeBuffer::CreateFrame( |
| 191 | 640, 480, 100, 10, webrtc::kVideoRotation_0); |
magjed@webrtc.org | 45cdcce | 2015-03-06 10:41:00 +0000 | [diff] [blame] | 192 | EXPECT_EQ(640, frame.width()); |
| 193 | EXPECT_EQ(480, frame.height()); |
| 194 | EXPECT_EQ(100u, frame.timestamp()); |
| 195 | EXPECT_EQ(10, frame.render_time_ms()); |
nisse | 26acec4 | 2016-04-15 03:43:39 -0700 | [diff] [blame] | 196 | ASSERT_TRUE(frame.video_frame_buffer() != nullptr); |
Magnus Jedvert | 90e3190 | 2017-06-07 11:32:50 +0200 | [diff] [blame] | 197 | EXPECT_TRUE(frame.video_frame_buffer()->type() == |
| 198 | VideoFrameBuffer::Type::kNative); |
magjed@webrtc.org | 45cdcce | 2015-03-06 10:41:00 +0000 | [diff] [blame] | 199 | |
| 200 | frame.set_timestamp(200); |
| 201 | EXPECT_EQ(200u, frame.timestamp()); |
nisse | 1c0dea8 | 2017-01-30 02:43:18 -0800 | [diff] [blame] | 202 | frame.set_timestamp_us(20); |
| 203 | EXPECT_EQ(20, frame.timestamp_us()); |
magjed@webrtc.org | 45cdcce | 2015-03-06 10:41:00 +0000 | [diff] [blame] | 204 | } |
| 205 | |
nisse | 7cc9cc0 | 2016-03-29 23:44:19 -0700 | [diff] [blame] | 206 | TEST(TestI420FrameBuffer, Copy) { |
| 207 | rtc::scoped_refptr<I420Buffer> buf1( |
nisse | ac62bd4 | 2016-06-20 03:38:52 -0700 | [diff] [blame] | 208 | I420Buffer::Create(20, 10)); |
nisse | 06176e4 | 2016-04-18 05:34:40 -0700 | [diff] [blame] | 209 | memset(buf1->MutableDataY(), 1, 200); |
| 210 | memset(buf1->MutableDataU(), 2, 50); |
| 211 | memset(buf1->MutableDataV(), 3, 50); |
nisse | e3fe4a7 | 2016-11-10 08:44:38 -0800 | [diff] [blame] | 212 | rtc::scoped_refptr<I420Buffer> buf2 = I420Buffer::Copy(*buf1); |
nisse | 7cc9cc0 | 2016-03-29 23:44:19 -0700 | [diff] [blame] | 213 | EXPECT_TRUE(test::FrameBufsEqual(buf1, buf2)); |
| 214 | } |
| 215 | |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 216 | TEST(TestI420FrameBuffer, Scale) { |
| 217 | rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100); |
| 218 | |
| 219 | // Pure scaling, no cropping. |
| 220 | rtc::scoped_refptr<I420Buffer> scaled_buffer( |
nisse | ac62bd4 | 2016-06-20 03:38:52 -0700 | [diff] [blame] | 221 | I420Buffer::Create(150, 75)); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 222 | |
nisse | e3fe4a7 | 2016-11-10 08:44:38 -0800 | [diff] [blame] | 223 | scaled_buffer->ScaleFrom(*buf); |
nisse | f33970b | 2016-10-18 06:01:34 -0700 | [diff] [blame] | 224 | CheckCrop(*scaled_buffer, 0.0, 0.0, 1.0, 1.0); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | TEST(TestI420FrameBuffer, CropXCenter) { |
| 228 | rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100); |
| 229 | |
| 230 | // Pure center cropping, no scaling. |
| 231 | rtc::scoped_refptr<I420Buffer> scaled_buffer( |
nisse | ac62bd4 | 2016-06-20 03:38:52 -0700 | [diff] [blame] | 232 | I420Buffer::Create(100, 100)); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 233 | |
nisse | e3fe4a7 | 2016-11-10 08:44:38 -0800 | [diff] [blame] | 234 | scaled_buffer->CropAndScaleFrom(*buf, 50, 0, 100, 100); |
nisse | f33970b | 2016-10-18 06:01:34 -0700 | [diff] [blame] | 235 | CheckCrop(*scaled_buffer, 0.25, 0.0, 0.5, 1.0); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | TEST(TestI420FrameBuffer, CropXNotCenter) { |
| 239 | rtc::scoped_refptr<I420Buffer> buf = CreateGradient(200, 100); |
| 240 | |
| 241 | // Non-center cropping, no scaling. |
| 242 | rtc::scoped_refptr<I420Buffer> scaled_buffer( |
nisse | ac62bd4 | 2016-06-20 03:38:52 -0700 | [diff] [blame] | 243 | I420Buffer::Create(100, 100)); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 244 | |
nisse | e3fe4a7 | 2016-11-10 08:44:38 -0800 | [diff] [blame] | 245 | scaled_buffer->CropAndScaleFrom(*buf, 25, 0, 100, 100); |
nisse | f33970b | 2016-10-18 06:01:34 -0700 | [diff] [blame] | 246 | CheckCrop(*scaled_buffer, 0.125, 0.0, 0.5, 1.0); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | TEST(TestI420FrameBuffer, CropYCenter) { |
| 250 | rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200); |
| 251 | |
| 252 | // Pure center cropping, no scaling. |
| 253 | rtc::scoped_refptr<I420Buffer> scaled_buffer( |
nisse | ac62bd4 | 2016-06-20 03:38:52 -0700 | [diff] [blame] | 254 | I420Buffer::Create(100, 100)); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 255 | |
nisse | e3fe4a7 | 2016-11-10 08:44:38 -0800 | [diff] [blame] | 256 | scaled_buffer->CropAndScaleFrom(*buf, 0, 50, 100, 100); |
nisse | f33970b | 2016-10-18 06:01:34 -0700 | [diff] [blame] | 257 | CheckCrop(*scaled_buffer, 0.0, 0.25, 1.0, 0.5); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | TEST(TestI420FrameBuffer, CropYNotCenter) { |
| 261 | rtc::scoped_refptr<I420Buffer> buf = CreateGradient(100, 200); |
| 262 | |
| 263 | // Non-center cropping, no scaling. |
| 264 | rtc::scoped_refptr<I420Buffer> scaled_buffer( |
nisse | ac62bd4 | 2016-06-20 03:38:52 -0700 | [diff] [blame] | 265 | I420Buffer::Create(100, 100)); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 266 | |
nisse | e3fe4a7 | 2016-11-10 08:44:38 -0800 | [diff] [blame] | 267 | scaled_buffer->CropAndScaleFrom(*buf, 0, 25, 100, 100); |
nisse | f33970b | 2016-10-18 06:01:34 -0700 | [diff] [blame] | 268 | CheckCrop(*scaled_buffer, 0.0, 0.125, 1.0, 0.5); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | TEST(TestI420FrameBuffer, CropAndScale16x9) { |
| 272 | rtc::scoped_refptr<I420Buffer> buf = CreateGradient(640, 480); |
| 273 | |
| 274 | // Center crop to 640 x 360 (16/9 aspect), then scale down by 2. |
| 275 | rtc::scoped_refptr<I420Buffer> scaled_buffer( |
nisse | ac62bd4 | 2016-06-20 03:38:52 -0700 | [diff] [blame] | 276 | I420Buffer::Create(320, 180)); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 277 | |
nisse | e3fe4a7 | 2016-11-10 08:44:38 -0800 | [diff] [blame] | 278 | scaled_buffer->CropAndScaleFrom(*buf); |
nisse | f33970b | 2016-10-18 06:01:34 -0700 | [diff] [blame] | 279 | CheckCrop(*scaled_buffer, 0.0, 0.125, 1.0, 0.75); |
Niels Möller | 718a763 | 2016-06-13 13:06:01 +0200 | [diff] [blame] | 280 | } |
| 281 | |
nisse | f33970b | 2016-10-18 06:01:34 -0700 | [diff] [blame] | 282 | class TestI420BufferRotate |
| 283 | : public ::testing::TestWithParam<webrtc::VideoRotation> {}; |
| 284 | |
| 285 | TEST_P(TestI420BufferRotate, Rotates) { |
magjed | 3f07549 | 2017-06-01 10:02:26 -0700 | [diff] [blame] | 286 | rtc::scoped_refptr<I420BufferInterface> buffer = CreateGradient(640, 480); |
| 287 | rtc::scoped_refptr<I420BufferInterface> rotated_buffer = |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 288 | I420Buffer::Rotate(*buffer, GetParam()); |
nisse | f33970b | 2016-10-18 06:01:34 -0700 | [diff] [blame] | 289 | CheckRotate(640, 480, GetParam(), *rotated_buffer); |
| 290 | } |
| 291 | |
| 292 | INSTANTIATE_TEST_CASE_P(Rotate, TestI420BufferRotate, |
| 293 | ::testing::Values(kVideoRotation_0, |
| 294 | kVideoRotation_90, |
| 295 | kVideoRotation_180, |
| 296 | kVideoRotation_270)); |
| 297 | |
mikhal@webrtc.org | 043ed9e | 2012-09-18 16:14:26 +0000 | [diff] [blame] | 298 | } // namespace webrtc |