Emircan Uysaler | 901e0ff | 2018-06-26 12:22:38 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 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_I010_BUFFER_H_ |
| 12 | #define API_VIDEO_I010_BUFFER_H_ |
| 13 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 14 | #include <stdint.h> |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 15 | |
Emircan Uysaler | 901e0ff | 2018-06-26 12:22:38 -0700 | [diff] [blame] | 16 | #include <memory> |
| 17 | |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 18 | #include "api/scoped_refptr.h" |
Emircan Uysaler | 901e0ff | 2018-06-26 12:22:38 -0700 | [diff] [blame] | 19 | #include "api/video/video_frame_buffer.h" |
| 20 | #include "api/video/video_rotation.h" |
| 21 | #include "rtc_base/memory/aligned_malloc.h" |
Emircan Uysaler | 901e0ff | 2018-06-26 12:22:38 -0700 | [diff] [blame] | 22 | |
| 23 | namespace webrtc { |
| 24 | |
| 25 | // Plain I010 buffer in standard memory. |
| 26 | class I010Buffer : public I010BufferInterface { |
| 27 | public: |
| 28 | // Create a new buffer. |
| 29 | static rtc::scoped_refptr<I010Buffer> Create(int width, int height); |
| 30 | |
| 31 | // Create a new buffer and copy the pixel data. |
| 32 | static rtc::scoped_refptr<I010Buffer> Copy(const I010BufferInterface& buffer); |
| 33 | |
| 34 | // Convert and put I420 buffer into a new buffer. |
| 35 | static rtc::scoped_refptr<I010Buffer> Copy(const I420BufferInterface& buffer); |
| 36 | |
Artem Titov | 0e61fdd | 2021-07-25 21:50:14 +0200 | [diff] [blame^] | 37 | // Return a rotated copy of `src`. |
Emircan Uysaler | 901e0ff | 2018-06-26 12:22:38 -0700 | [diff] [blame] | 38 | static rtc::scoped_refptr<I010Buffer> Rotate(const I010BufferInterface& src, |
| 39 | VideoRotation rotation); |
| 40 | |
| 41 | // VideoFrameBuffer implementation. |
| 42 | rtc::scoped_refptr<I420BufferInterface> ToI420() override; |
| 43 | |
| 44 | // PlanarYuv16BBuffer implementation. |
| 45 | int width() const override; |
| 46 | int height() const override; |
| 47 | const uint16_t* DataY() const override; |
| 48 | const uint16_t* DataU() const override; |
| 49 | const uint16_t* DataV() const override; |
| 50 | int StrideY() const override; |
| 51 | int StrideU() const override; |
| 52 | int StrideV() const override; |
| 53 | |
| 54 | uint16_t* MutableDataY(); |
| 55 | uint16_t* MutableDataU(); |
| 56 | uint16_t* MutableDataV(); |
| 57 | |
Artem Titov | 0e61fdd | 2021-07-25 21:50:14 +0200 | [diff] [blame^] | 58 | // Scale the cropped area of `src` to the size of `this` buffer, and |
| 59 | // write the result into `this`. |
Emircan Uysaler | 901e0ff | 2018-06-26 12:22:38 -0700 | [diff] [blame] | 60 | void CropAndScaleFrom(const I010BufferInterface& src, |
| 61 | int offset_x, |
| 62 | int offset_y, |
| 63 | int crop_width, |
| 64 | int crop_height); |
| 65 | |
Artem Titov | 0e61fdd | 2021-07-25 21:50:14 +0200 | [diff] [blame^] | 66 | // Scale all of `src` to the size of `this` buffer, with no cropping. |
Emircan Uysaler | 901e0ff | 2018-06-26 12:22:38 -0700 | [diff] [blame] | 67 | void ScaleFrom(const I010BufferInterface& src); |
| 68 | |
Ilya Nikolaevskiy | a921660 | 2018-12-21 14:21:08 +0100 | [diff] [blame] | 69 | // Pastes whole picture to canvas at (offset_row, offset_col). |
| 70 | // Offsets and picture dimensions must be even. |
| 71 | void PasteFrom(const I010BufferInterface& picture, |
| 72 | int offset_col, |
| 73 | int offset_row); |
| 74 | |
Emircan Uysaler | 901e0ff | 2018-06-26 12:22:38 -0700 | [diff] [blame] | 75 | protected: |
| 76 | I010Buffer(int width, int height, int stride_y, int stride_u, int stride_v); |
| 77 | ~I010Buffer() override; |
| 78 | |
| 79 | private: |
| 80 | const int width_; |
| 81 | const int height_; |
| 82 | const int stride_y_; |
| 83 | const int stride_u_; |
| 84 | const int stride_v_; |
| 85 | const std::unique_ptr<uint16_t, AlignedFreeDeleter> data_; |
| 86 | }; |
| 87 | |
| 88 | } // namespace webrtc |
| 89 | |
| 90 | #endif // API_VIDEO_I010_BUFFER_H_ |