1 /* 2 * Copyright (c) 2021 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 #ifndef API_VIDEO_I444_BUFFER_H_ 12 #define API_VIDEO_I444_BUFFER_H_ 13 14 #include <stdint.h> 15 16 #include <memory> 17 18 #include "api/scoped_refptr.h" 19 #include "api/video/video_frame_buffer.h" 20 #include "api/video/video_rotation.h" 21 #include "rtc_base/memory/aligned_malloc.h" 22 #include "rtc_base/system/rtc_export.h" 23 24 namespace webrtc { 25 26 // Plain I444 buffer in standard memory. 27 // I444 represents an image with in YUV format withouth any chroma subsampling. 28 // https://en.wikipedia.org/wiki/Chroma_subsampling#4:4:4 29 class RTC_EXPORT I444Buffer : public I444BufferInterface { 30 public: 31 static rtc::scoped_refptr<I444Buffer> Create(int width, int height); 32 static rtc::scoped_refptr<I444Buffer> Create(int width, 33 int height, 34 int stride_y, 35 int stride_u, 36 int stride_v); 37 38 // Create a new buffer and copy the pixel data. 39 static rtc::scoped_refptr<I444Buffer> Copy(const I444BufferInterface& buffer); 40 41 static rtc::scoped_refptr<I444Buffer> Copy(int width, 42 int height, 43 const uint8_t* data_y, 44 int stride_y, 45 const uint8_t* data_u, 46 int stride_u, 47 const uint8_t* data_v, 48 int stride_v); 49 50 // Returns a rotated copy of |src|. 51 static rtc::scoped_refptr<I444Buffer> Rotate(const I444BufferInterface& src, 52 VideoRotation rotation); 53 54 rtc::scoped_refptr<I420BufferInterface> ToI420() final; GetI420()55 const I420BufferInterface* GetI420() const final { return nullptr; } 56 57 // Sets all three planes to all zeros. Used to work around for 58 // quirks in memory checkers 59 // (https://bugs.chromium.org/p/libyuv/issues/detail?id=377) and 60 // ffmpeg (http://crbug.com/390941). 61 // TODO(https://crbug.com/390941): Deprecated. Should be deleted if/when those 62 // issues are resolved in a better way. Or in the mean time, use SetBlack. 63 void InitializeData(); 64 65 int width() const override; 66 int height() const override; 67 const uint8_t* DataY() const override; 68 const uint8_t* DataU() const override; 69 const uint8_t* DataV() const override; 70 71 int StrideY() const override; 72 int StrideU() const override; 73 int StrideV() const override; 74 75 uint8_t* MutableDataY(); 76 uint8_t* MutableDataU(); 77 uint8_t* MutableDataV(); 78 79 // Scale the cropped area of |src| to the size of |this| buffer, and 80 // write the result into |this|. 81 void CropAndScaleFrom(const I444BufferInterface& src, 82 int offset_x, 83 int offset_y, 84 int crop_width, 85 int crop_height); 86 87 protected: 88 I444Buffer(int width, int height); 89 I444Buffer(int width, int height, int stride_y, int stride_u, int stride_v); 90 91 ~I444Buffer() override; 92 93 private: 94 const int width_; 95 const int height_; 96 const int stride_y_; 97 const int stride_u_; 98 const int stride_v_; 99 const std::unique_ptr<uint8_t, AlignedFreeDeleter> data_; 100 }; 101 102 } // namespace webrtc 103 104 #endif // API_VIDEO_I444_BUFFER_H_ 105