| 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/system_wrappers/include/tick_util.h" | 18 #include "webrtc/system_wrappers/include/tick_util.h" |
| 19 #include "webrtc/test/testsupport/fileutils.h" | 19 #include "webrtc/test/testsupport/fileutils.h" |
| 20 #include "webrtc/video_frame.h" | 20 #include "webrtc/video_frame.h" |
| 21 | 21 |
| 22 namespace webrtc { | 22 namespace webrtc { |
| 23 | 23 |
| 24 int PrintBuffer(const uint8_t* buffer, int width, int height, int stride) { |
| 25 if (buffer == NULL) |
| 26 return -1; |
| 27 int k; |
| 28 const uint8_t* tmp_buffer = buffer; |
| 29 for (int i = 0; i < height; i++) { |
| 30 k = 0; |
| 31 for (int j = 0; j < width; j++) { |
| 32 printf("%d ", tmp_buffer[k++]); |
| 33 } |
| 34 tmp_buffer += stride; |
| 35 printf(" \n"); |
| 36 } |
| 37 printf(" \n"); |
| 38 return 0; |
| 39 } |
| 40 |
| 41 int PrintFrame(const VideoFrame* frame, const char* str) { |
| 42 if (frame == NULL) |
| 43 return -1; |
| 44 printf("%s %dx%d \n", str, frame->width(), frame->height()); |
| 45 |
| 46 int ret = 0; |
| 47 for (int plane_num = 0; plane_num < kNumOfPlanes; ++plane_num) { |
| 48 PlaneType plane_type = static_cast<PlaneType>(plane_num); |
| 49 int width = (plane_num ? (frame->width() + 1) / 2 : frame->width()); |
| 50 int height = (plane_num ? (frame->height() + 1) / 2 : frame->height()); |
| 51 ret += PrintBuffer(frame->buffer(plane_type), width, height, |
| 52 frame->stride(plane_type)); |
| 53 } |
| 54 return ret; |
| 55 } |
| 56 |
| 57 |
| 58 // Create an image from on a YUV frame. Every plane value starts with a start |
| 59 // value, and will be set to increasing values. |
| 60 void CreateImage(VideoFrame* frame, int plane_offset[kNumOfPlanes]) { |
| 61 if (frame == NULL) |
| 62 return; |
| 63 for (int plane_num = 0; plane_num < kNumOfPlanes; ++plane_num) { |
| 64 int width = (plane_num != kYPlane ? (frame->width() + 1) / 2 : |
| 65 frame->width()); |
| 66 int height = (plane_num != kYPlane ? (frame->height() + 1) / 2 : |
| 67 frame->height()); |
| 68 PlaneType plane_type = static_cast<PlaneType>(plane_num); |
| 69 uint8_t *data = frame->buffer(plane_type); |
| 70 for (int i = 0; i < height; i++) { |
| 71 for (int j = 0; j < width; j++) { |
| 72 data[j] = static_cast<uint8_t>(i + plane_offset[plane_num] + j); |
| 73 } |
| 74 data += frame->stride(plane_type); |
| 75 } |
| 76 } |
| 77 } |
| 78 |
| 24 class TestLibYuv : public ::testing::Test { | 79 class TestLibYuv : public ::testing::Test { |
| 25 protected: | 80 protected: |
| 26 TestLibYuv(); | 81 TestLibYuv(); |
| 27 virtual void SetUp(); | 82 virtual void SetUp(); |
| 28 virtual void TearDown(); | 83 virtual void TearDown(); |
| 29 | 84 |
| 30 FILE* source_file_; | 85 FILE* source_file_; |
| 31 VideoFrame orig_frame_; | 86 VideoFrame orig_frame_; |
| 32 std::unique_ptr<uint8_t[]> orig_buffer_; | 87 std::unique_ptr<uint8_t[]> orig_buffer_; |
| 33 const int width_; | 88 const int width_; |
| (...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 288 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); | 343 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); |
| 289 EXPECT_EQ(128, stride_y); | 344 EXPECT_EQ(128, stride_y); |
| 290 EXPECT_EQ(64, stride_uv); | 345 EXPECT_EQ(64, stride_uv); |
| 291 width = 127; | 346 width = 127; |
| 292 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); | 347 Calc16ByteAlignedStride(width, &stride_y, &stride_uv); |
| 293 EXPECT_EQ(128, stride_y); | 348 EXPECT_EQ(128, stride_y); |
| 294 EXPECT_EQ(64, stride_uv); | 349 EXPECT_EQ(64, stride_uv); |
| 295 } | 350 } |
| 296 | 351 |
| 297 } // namespace webrtc | 352 } // namespace webrtc |
| OLD | NEW |