blob: 4b35ca31e5edd8b95e4f2707a2b5351cb712ca18 [file] [log] [blame]
Emircan Uysaler901e0ff2018-06-26 12:22:38 -07001/*
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 Gerey3e707812018-11-28 16:47:49 +010014#include <stdint.h>
Emircan Uysaler901e0ff2018-06-26 12:22:38 -070015#include <memory>
16
Mirko Bonadeid9708072019-01-25 20:26:48 +010017#include "api/scoped_refptr.h"
Emircan Uysaler901e0ff2018-06-26 12:22:38 -070018#include "api/video/video_frame_buffer.h"
19#include "api/video/video_rotation.h"
20#include "rtc_base/memory/aligned_malloc.h"
Emircan Uysaler901e0ff2018-06-26 12:22:38 -070021
22namespace webrtc {
23
24// Plain I010 buffer in standard memory.
25class I010Buffer : public I010BufferInterface {
26 public:
27 // Create a new buffer.
28 static rtc::scoped_refptr<I010Buffer> Create(int width, int height);
29
30 // Create a new buffer and copy the pixel data.
31 static rtc::scoped_refptr<I010Buffer> Copy(const I010BufferInterface& buffer);
32
33 // Convert and put I420 buffer into a new buffer.
34 static rtc::scoped_refptr<I010Buffer> Copy(const I420BufferInterface& buffer);
35
36 // Return a rotated copy of |src|.
37 static rtc::scoped_refptr<I010Buffer> Rotate(const I010BufferInterface& src,
38 VideoRotation rotation);
39
40 // VideoFrameBuffer implementation.
41 rtc::scoped_refptr<I420BufferInterface> ToI420() override;
42
43 // PlanarYuv16BBuffer implementation.
44 int width() const override;
45 int height() const override;
46 const uint16_t* DataY() const override;
47 const uint16_t* DataU() const override;
48 const uint16_t* DataV() const override;
49 int StrideY() const override;
50 int StrideU() const override;
51 int StrideV() const override;
52
53 uint16_t* MutableDataY();
54 uint16_t* MutableDataU();
55 uint16_t* MutableDataV();
56
57 // Scale the cropped area of |src| to the size of |this| buffer, and
58 // write the result into |this|.
59 void CropAndScaleFrom(const I010BufferInterface& src,
60 int offset_x,
61 int offset_y,
62 int crop_width,
63 int crop_height);
64
65 // Scale all of |src| to the size of |this| buffer, with no cropping.
66 void ScaleFrom(const I010BufferInterface& src);
67
Ilya Nikolaevskiya9216602018-12-21 14:21:08 +010068 // Pastes whole picture to canvas at (offset_row, offset_col).
69 // Offsets and picture dimensions must be even.
70 void PasteFrom(const I010BufferInterface& picture,
71 int offset_col,
72 int offset_row);
73
Emircan Uysaler901e0ff2018-06-26 12:22:38 -070074 protected:
75 I010Buffer(int width, int height, int stride_y, int stride_u, int stride_v);
76 ~I010Buffer() override;
77
78 private:
79 const int width_;
80 const int height_;
81 const int stride_y_;
82 const int stride_u_;
83 const int stride_v_;
84 const std::unique_ptr<uint16_t, AlignedFreeDeleter> data_;
85};
86
87} // namespace webrtc
88
89#endif // API_VIDEO_I010_BUFFER_H_