i010_buffer.h 2.8 KB

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