Changeset View
Changeset View
Standalone View
Standalone View
source/blender/compositor/intern/COM_MemoryBuffer.h
| Show All 38 Lines | |||||
| }; | }; | ||||
| enum class MemoryBufferExtend { | enum class MemoryBufferExtend { | ||||
| Clip, | Clip, | ||||
| Extend, | Extend, | ||||
| Repeat, | Repeat, | ||||
| }; | }; | ||||
| struct BaseBuffer { | |||||
| /** | |||||
| * Memory bytes available for use. | |||||
| * | |||||
| * It may be less than total_bytes when recycling buffers. | |||||
| */ | |||||
| size_t used_bytes; | |||||
| /** | |||||
| * Total memory bytes. | |||||
| */ | |||||
| size_t total_bytes; | |||||
| /** | |||||
| * Bytes size of a channel (sizeof(type)). | |||||
| */ | |||||
| size_t channel_bytes; | |||||
| /** | |||||
| * Number of channels used in an element (or pixel). | |||||
| */ | |||||
| int elem_channels; | |||||
| /** | |||||
| * Number of channels in an element (or pixel). Includes unused channels. | |||||
| * | |||||
| * e.g: RGBA image format but only R channel is used. | |||||
| */ | |||||
| size_t elem_stride; | |||||
| /** | |||||
| * Offset between elements. | |||||
| * | |||||
| * Should always be used for the x dimension when calculating buffer offsets. | |||||
| * It will be 0 when is_single_elem=true. | |||||
| * e.g: offset = y * buffer.row_jump + x * buffer.elem_jump | |||||
| */ | |||||
| int elem_jump; | |||||
| /** | |||||
| * Buffer resolution width. | |||||
| * | |||||
| * Shouldn't be used for calculating buffer memory size. Single element buffers may have any | |||||
| * resolution but it still is one element in memory. | |||||
| */ | |||||
| int width; | |||||
| /** | |||||
| * Buffer resolution height. | |||||
| * | |||||
| * Shouldn't be used for calculating buffer memory size. Single elem buffers may have any | |||||
| * resolution but it still is one element in memory. | |||||
| */ | |||||
| int height; | |||||
| /** | |||||
| * Offset between rows. | |||||
| * | |||||
| * Should always be used for the y dimension when calculating buffer offsets. | |||||
| * It will be 0 when is_single_elem=true. | |||||
| * e.g: offset = y * buffer.row_jump + x * buffer.elem_jump | |||||
| */ | |||||
| int row_jump; | |||||
| /** | |||||
| * Whether buffer is a single element in memory independently of its resolution (repeated for all | |||||
| * elements in the resolution). Used for set operations. | |||||
| */ | |||||
| bool is_single_elem; | |||||
| /** | |||||
| * Get the number of elements in memory for a row. For single element buffers it will always | |||||
| * be 1. | |||||
| */ | |||||
| int get_memory_width() const | |||||
| { | |||||
| return is_single_elem ? 1 : width; | |||||
| } | |||||
| /** | |||||
| * Get number of elements in memory for a column. For single element buffers it will | |||||
| * always be 1. | |||||
| */ | |||||
| int get_memory_height() const | |||||
| { | |||||
| return is_single_elem ? 1 : height; | |||||
| } | |||||
| virtual ~BaseBuffer(){}; | |||||
| protected: | |||||
| BaseBuffer() | |||||
| { | |||||
| } | |||||
| #ifdef WITH_CXX_GUARDEDALLOC | |||||
| MEM_CXX_CLASS_ALLOC_FUNCS("COM:BaseBuffer") | |||||
| #endif | |||||
| }; | |||||
| class MemoryProxy; | class MemoryProxy; | ||||
| /** | /** | ||||
| * \brief a MemoryBuffer contains access to the data of a chunk | * \brief a MemoryBuffer contains access to the data of a chunk | ||||
| */ | */ | ||||
| class MemoryBuffer { | class MemoryBuffer : public BaseBuffer { | ||||
| private: | private: | ||||
| /** | /** | ||||
| * \brief proxy of the memory (same for all chunks in the same buffer) | * \brief proxy of the memory (same for all chunks in the same buffer) | ||||
| */ | */ | ||||
| MemoryProxy *m_memoryProxy; | MemoryProxy *m_memoryProxy; | ||||
| /** | /** | ||||
| * \brief the type of buffer DataType::Value, DataType::Vector, DataType::Color | * \brief the type of buffer DataType::Value, DataType::Vector, DataType::Color | ||||
| Show All 37 Lines | public: | ||||
| */ | */ | ||||
| MemoryBuffer(const MemoryBuffer &src); | MemoryBuffer(const MemoryBuffer &src); | ||||
| /** | /** | ||||
| * \brief destructor | * \brief destructor | ||||
| */ | */ | ||||
| ~MemoryBuffer(); | ~MemoryBuffer(); | ||||
| float &operator[](int index) | |||||
| { | |||||
| return m_buffer[index]; | |||||
| } | |||||
| const float &operator[](int index) const | |||||
| { | |||||
| return m_buffer[index]; | |||||
| } | |||||
| /** | |||||
| * Get offset needed to jump from buffer start to given coordinates. | |||||
| */ | |||||
| int get_offset(int x, int y) const | |||||
| { | |||||
| return (y - m_rect.ymin) * row_jump + (x - m_rect.xmin) * elem_jump; | |||||
| } | |||||
| /** | |||||
| * Get buffer element at given coordinates. | |||||
| */ | |||||
| float *get_elem(int x, int y) | |||||
| { | |||||
| return m_buffer + get_offset(x, y); | |||||
| } | |||||
| /** | |||||
| * Get buffer element at given coordinates. | |||||
| */ | |||||
| const float *get_elem(int x, int y) const | |||||
| { | |||||
| return m_buffer + get_offset(x, y); | |||||
| } | |||||
| /** | |||||
| * Get channel value at given coordinates. | |||||
| */ | |||||
| float &get_value(int x, int y, int channel) | |||||
| { | |||||
| return m_buffer[get_offset(x, y) + channel]; | |||||
| } | |||||
| /** | |||||
| * Get channel value at given coordinates. | |||||
| */ | |||||
| const float &get_value(int x, int y, int channel) const | |||||
| { | |||||
| return m_buffer[get_offset(x, y) + channel]; | |||||
| } | |||||
| /** | |||||
| * Get the buffer row end. | |||||
| */ | |||||
| const float *get_row_end(int y) const | |||||
| { | |||||
| return m_buffer + get_offset(width, y); | |||||
| } | |||||
| uint8_t get_num_channels() | uint8_t get_num_channels() | ||||
| { | { | ||||
| return this->m_num_channels; | return this->m_num_channels; | ||||
| } | } | ||||
| /** | /** | ||||
| * \brief get the data of this MemoryBuffer | * \brief get the data of this MemoryBuffer | ||||
| * \note buffer should already be available in memory | * \note buffer should already be available in memory | ||||
| ▲ Show 20 Lines • Show All 221 Lines • Show Last 20 Lines | |||||