OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <math.h> | 11 #include <math.h> |
12 #include <string.h> | 12 #include <string.h> |
13 | 13 |
14 #include <memory> | 14 #include <memory> |
15 | 15 |
16 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 17 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
18 #include "webrtc/test/testsupport/fileutils.h" | 18 #include "webrtc/test/testsupport/fileutils.h" |
19 #include "webrtc/video_frame.h" | 19 #include "webrtc/video_frame.h" |
20 | 20 |
21 namespace webrtc { | 21 namespace webrtc { |
22 | 22 |
| 23 int PrintBuffer(const uint8_t* buffer, int width, int height, int stride) { |
| 24 if (buffer == NULL) |
| 25 return -1; |
| 26 int k; |
| 27 const uint8_t* tmp_buffer = buffer; |
| 28 for (int i = 0; i < height; i++) { |
| 29 k = 0; |
| 30 for (int j = 0; j < width; j++) { |
| 31 printf("%d ", tmp_buffer[k++]); |
| 32 } |
| 33 tmp_buffer += stride; |
| 34 printf(" \n"); |
| 35 } |
| 36 printf(" \n"); |
| 37 return 0; |
| 38 } |
| 39 |
| 40 int PrintFrame(const VideoFrame* frame, const char* str) { |
| 41 if (frame == NULL) |
| 42 return -1; |
| 43 printf("%s %dx%d \n", str, frame->width(), frame->height()); |
| 44 |
| 45 int ret = 0; |
| 46 for (int plane_num = 0; plane_num < kNumOfPlanes; ++plane_num) { |
| 47 PlaneType plane_type = static_cast<PlaneType>(plane_num); |
| 48 int width = (plane_num ? (frame->width() + 1) / 2 : frame->width()); |
| 49 int height = (plane_num ? (frame->height() + 1) / 2 : frame->height()); |
| 50 ret += PrintBuffer(frame->buffer(plane_type), width, height, |
| 51 frame->stride(plane_type)); |
| 52 } |
| 53 return ret; |
| 54 } |
| 55 |
| 56 |
| 57 // Create an image from on a YUV frame. Every plane value starts with a start |
| 58 // value, and will be set to increasing values. |
| 59 void CreateImage(VideoFrame* frame, int plane_offset[kNumOfPlanes]) { |
| 60 if (frame == NULL) |
| 61 return; |
| 62 for (int plane_num = 0; plane_num < kNumOfPlanes; ++plane_num) { |
| 63 int width = (plane_num != kYPlane ? (frame->width() + 1) / 2 : |
| 64 frame->width()); |
| 65 int height = (plane_num != kYPlane ? (frame->height() + 1) / 2 : |
| 66 frame->height()); |
| 67 PlaneType plane_type = static_cast<PlaneType>(plane_num); |
| 68 uint8_t *data = frame->buffer(plane_type); |
| 69 for (int i = 0; i < height; i++) { |
| 70 for (int j = 0; j < width; j++) { |
| 71 data[j] = static_cast<uint8_t>(i + plane_offset[plane_num] + j); |
| 72 } |
| 73 data += frame->stride(plane_type); |
| 74 } |
| 75 } |
| 76 } |
| 77 |
23 class TestLibYuv : public ::testing::Test { | 78 class TestLibYuv : public ::testing::Test { |
24 protected: | 79 protected: |
25 TestLibYuv(); | 80 TestLibYuv(); |
26 virtual void SetUp(); | 81 virtual void SetUp(); |
27 virtual void TearDown(); | 82 virtual void TearDown(); |
28 | 83 |
29 FILE* source_file_; | 84 FILE* source_file_; |
30 VideoFrame orig_frame_; | 85 VideoFrame orig_frame_; |
31 std::unique_ptr<uint8_t[]> orig_buffer_; | 86 std::unique_ptr<uint8_t[]> orig_buffer_; |
32 const int width_; | 87 const int width_; |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); | 342 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); |
288 EXPECT_EQ(128, stride_y); | 343 EXPECT_EQ(128, stride_y); |
289 EXPECT_EQ(64, stride_uv); | 344 EXPECT_EQ(64, stride_uv); |
290 width = 127; | 345 width = 127; |
291 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); | 346 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); |
292 EXPECT_EQ(128, stride_y); | 347 EXPECT_EQ(128, stride_y); |
293 EXPECT_EQ(64, stride_uv); | 348 EXPECT_EQ(64, stride_uv); |
294 } | 349 } |
295 | 350 |
296 } // namespace webrtc | 351 } // namespace webrtc |
OLD | NEW |