blob: 1208b3185254aff267d4978e4242a2000d80e997 [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
14#include <memory>
15
16#include "api/video/video_frame_buffer.h"
17#include "api/video/video_rotation.h"
18#include "rtc_base/memory/aligned_malloc.h"
19
20namespace webrtc {
21
22// Plain I010 buffer in standard memory.
23class I010Buffer : public I010BufferInterface {
24 public:
25 // Create a new buffer.
26 static rtc::scoped_refptr<I010Buffer> Create(int width, int height);
27
28 // Create a new buffer and copy the pixel data.
29 static rtc::scoped_refptr<I010Buffer> Copy(const I010BufferInterface& buffer);
30
31 // Convert and put I420 buffer into a new buffer.
32 static rtc::scoped_refptr<I010Buffer> Copy(const I420BufferInterface& buffer);
33
34 // Return a rotated copy of |src|.
35 static rtc::scoped_refptr<I010Buffer> Rotate(const I010BufferInterface& src,
36 VideoRotation rotation);
37
38 // VideoFrameBuffer implementation.
39 rtc::scoped_refptr<I420BufferInterface> ToI420() override;
40
41 // PlanarYuv16BBuffer implementation.
42 int width() const override;
43 int height() const override;
44 const uint16_t* DataY() const override;
45 const uint16_t* DataU() const override;
46 const uint16_t* DataV() const override;
47 int StrideY() const override;
48 int StrideU() const override;
49 int StrideV() const override;
50
51 uint16_t* MutableDataY();
52 uint16_t* MutableDataU();
53 uint16_t* MutableDataV();
54
55 // Scale the cropped area of |src| to the size of |this| buffer, and
56 // write the result into |this|.
57 void CropAndScaleFrom(const I010BufferInterface& src,
58 int offset_x,
59 int offset_y,
60 int crop_width,
61 int crop_height);
62
63 // Scale all of |src| to the size of |this| buffer, with no cropping.
64 void ScaleFrom(const I010BufferInterface& src);
65
66 protected:
67 I010Buffer(int width, int height, int stride_y, int stride_u, int stride_v);
68 ~I010Buffer() override;
69
70 private:
71 const int width_;
72 const int height_;
73 const int stride_y_;
74 const int stride_u_;
75 const int stride_v_;
76 const std::unique_ptr<uint16_t, AlignedFreeDeleter> data_;
77};
78
79} // namespace webrtc
80
81#endif // API_VIDEO_I010_BUFFER_H_