buffer_decoder.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. #ifndef BUFFER_DECODER_H
  31. #define BUFFER_DECODER_H
  32. #include "core/io/image.h"
  33. #include "core/templates/vector.h"
  34. class CameraFeed;
  35. struct StreamingBuffer {
  36. void *start = nullptr;
  37. size_t length = 0;
  38. };
  39. class BufferDecoder {
  40. protected:
  41. CameraFeed *camera_feed = nullptr;
  42. Ref<Image> image;
  43. int width = 0;
  44. int height = 0;
  45. public:
  46. virtual void decode(StreamingBuffer p_buffer) = 0;
  47. BufferDecoder(CameraFeed *p_camera_feed);
  48. virtual ~BufferDecoder() {}
  49. };
  50. class AbstractYuyvBufferDecoder : public BufferDecoder {
  51. protected:
  52. int *component_indexes = nullptr;
  53. public:
  54. AbstractYuyvBufferDecoder(CameraFeed *p_camera_feed);
  55. ~AbstractYuyvBufferDecoder();
  56. };
  57. class SeparateYuyvBufferDecoder : public AbstractYuyvBufferDecoder {
  58. private:
  59. Vector<uint8_t> y_image_data;
  60. Vector<uint8_t> cbcr_image_data;
  61. Ref<Image> y_image;
  62. Ref<Image> cbcr_image;
  63. public:
  64. SeparateYuyvBufferDecoder(CameraFeed *p_camera_feed);
  65. virtual void decode(StreamingBuffer p_buffer) override;
  66. };
  67. class YuyvToGrayscaleBufferDecoder : public AbstractYuyvBufferDecoder {
  68. private:
  69. Vector<uint8_t> image_data;
  70. public:
  71. YuyvToGrayscaleBufferDecoder(CameraFeed *p_camera_feed);
  72. virtual void decode(StreamingBuffer p_buffer) override;
  73. };
  74. class YuyvToRgbBufferDecoder : public AbstractYuyvBufferDecoder {
  75. private:
  76. Vector<uint8_t> image_data;
  77. public:
  78. YuyvToRgbBufferDecoder(CameraFeed *p_camera_feed);
  79. virtual void decode(StreamingBuffer p_buffer) override;
  80. };
  81. class CopyBufferDecoder : public BufferDecoder {
  82. private:
  83. Vector<uint8_t> image_data;
  84. bool rgba = false;
  85. public:
  86. CopyBufferDecoder(CameraFeed *p_camera_feed, bool p_rgba);
  87. virtual void decode(StreamingBuffer p_buffer) override;
  88. };
  89. class JpegBufferDecoder : public BufferDecoder {
  90. private:
  91. Vector<uint8_t> image_data;
  92. public:
  93. JpegBufferDecoder(CameraFeed *p_camera_feed);
  94. virtual void decode(StreamingBuffer p_buffer) override;
  95. };
  96. #endif // BUFFER_DECODER_H