buffer_decoder.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**************************************************************************/
  2. /* buffer_decoder.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #pragma once
  31. #include "core/io/image.h"
  32. #include "core/templates/vector.h"
  33. class CameraFeed;
  34. struct StreamingBuffer {
  35. void *start = nullptr;
  36. size_t length = 0;
  37. };
  38. class BufferDecoder {
  39. protected:
  40. CameraFeed *camera_feed = nullptr;
  41. Ref<Image> image;
  42. int width = 0;
  43. int height = 0;
  44. public:
  45. virtual void decode(StreamingBuffer p_buffer) = 0;
  46. BufferDecoder(CameraFeed *p_camera_feed);
  47. virtual ~BufferDecoder() {}
  48. };
  49. class AbstractYuyvBufferDecoder : public BufferDecoder {
  50. protected:
  51. int *component_indexes = nullptr;
  52. public:
  53. AbstractYuyvBufferDecoder(CameraFeed *p_camera_feed);
  54. ~AbstractYuyvBufferDecoder();
  55. };
  56. class SeparateYuyvBufferDecoder : public AbstractYuyvBufferDecoder {
  57. private:
  58. Vector<uint8_t> y_image_data;
  59. Vector<uint8_t> cbcr_image_data;
  60. Ref<Image> y_image;
  61. Ref<Image> cbcr_image;
  62. public:
  63. SeparateYuyvBufferDecoder(CameraFeed *p_camera_feed);
  64. virtual void decode(StreamingBuffer p_buffer) override;
  65. };
  66. class YuyvToGrayscaleBufferDecoder : public AbstractYuyvBufferDecoder {
  67. private:
  68. Vector<uint8_t> image_data;
  69. public:
  70. YuyvToGrayscaleBufferDecoder(CameraFeed *p_camera_feed);
  71. virtual void decode(StreamingBuffer p_buffer) override;
  72. };
  73. class YuyvToRgbBufferDecoder : public AbstractYuyvBufferDecoder {
  74. private:
  75. Vector<uint8_t> image_data;
  76. public:
  77. YuyvToRgbBufferDecoder(CameraFeed *p_camera_feed);
  78. virtual void decode(StreamingBuffer p_buffer) override;
  79. };
  80. class CopyBufferDecoder : public BufferDecoder {
  81. private:
  82. Vector<uint8_t> image_data;
  83. bool rgba = false;
  84. public:
  85. CopyBufferDecoder(CameraFeed *p_camera_feed, bool p_rgba);
  86. virtual void decode(StreamingBuffer p_buffer) override;
  87. };
  88. class JpegBufferDecoder : public BufferDecoder {
  89. private:
  90. Vector<uint8_t> image_data;
  91. public:
  92. JpegBufferDecoder(CameraFeed *p_camera_feed);
  93. virtual void decode(StreamingBuffer p_buffer) override;
  94. };