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