Compositor: Add MemoryBuffer constructor from size

This patch adds a new MemoryBuffer constructor from width and heights.
Useful for temporary allocations where we don't care about the area.
This commit is contained in:
Omar Emara
2024-03-21 17:35:19 +02:00
parent f6657db713
commit d8a89aa972
2 changed files with 18 additions and 0 deletions

View File

@@ -28,6 +28,19 @@ static rcti create_rect(const int width, const int height)
return rect;
}
MemoryBuffer::MemoryBuffer(DataType data_type, int width, int height)
{
BLI_rcti_init(&rect_, 0, width, 0, height);
is_a_single_elem_ = false;
num_channels_ = COM_data_type_num_channels(data_type);
buffer_ = (float *)MEM_mallocN_aligned(
sizeof(float) * buffer_len() * num_channels_, 16, "COM_MemoryBuffer");
owns_data_ = true;
datatype_ = data_type;
set_strides();
}
MemoryBuffer::MemoryBuffer(DataType data_type, const rcti &rect, bool is_a_single_elem)
{
rect_ = rect;

View File

@@ -90,6 +90,11 @@ class MemoryBuffer {
int to_positive_y_stride_;
public:
/**
* \brief construct new temporarily MemoryBuffer for a width and height.
*/
MemoryBuffer(DataType data_type, int width, int height);
/**
* \brief construct new temporarily MemoryBuffer for an area
*/