Blender V4.3
allocimbuf.cc File Reference
#include <cstddef>
#include "IMB_imbuf.hh"
#include "IMB_imbuf_types.hh"
#include "IMB_allocimbuf.hh"
#include "IMB_colormanagement_intern.hh"
#include "IMB_filetype.hh"
#include "IMB_metadata.hh"
#include "imbuf.hh"
#include "MEM_guardedalloc.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
#include "GPU_texture.hh"

Go to the source code of this file.

Functions

void imb_refcounter_lock_init ()
 
void imb_refcounter_lock_exit ()
 
void imb_mmap_lock_init ()
 
void imb_mmap_lock_exit ()
 
void imb_mmap_lock ()
 
void imb_mmap_unlock ()
 
template<class BufferType >
static void imb_free_buffer (BufferType &buffer)
 
static void imb_free_dds_buffer (DDSData &dds_data)
 
template<class BufferType >
bool imb_alloc_buffer (BufferType &buffer, const uint x, const uint y, const uint channels, const size_t type_size, bool initialize_pixels)
 
template<class BufferType >
void imb_make_writeable_buffer (BufferType &buffer)
 
template<class BufferType >
auto imb_steal_buffer_data (BufferType &buffer) -> decltype(BufferType::data)
 
void imb_freemipmapImBuf (ImBuf *ibuf)
 
void imb_freerectfloatImBuf (ImBuf *ibuf)
 
void imb_freerectImBuf (ImBuf *ibuf)
 
static void freeencodedbufferImBuf (ImBuf *ibuf)
 
void imb_freerectImbuf_all (ImBuf *ibuf)
 
void IMB_free_gpu_textures (ImBuf *ibuf)
 
void IMB_freeImBuf (ImBuf *ibuf)
 
void IMB_refImBuf (ImBuf *ibuf)
 
ImBufIMB_makeSingleUser (ImBuf *ibuf)
 
bool imb_addencodedbufferImBuf (ImBuf *ibuf)
 
bool imb_enlargeencodedbufferImBuf (ImBuf *ibuf)
 
void * imb_alloc_pixels (uint x, uint y, uint channels, size_t typesize, bool initialize_pixels, const char *alloc_name)
 
bool imb_addrectfloatImBuf (ImBuf *ibuf, const uint channels, bool initialize_pixels)
 
bool imb_addrectImBuf (ImBuf *ibuf, bool initialize_pixels)
 
uint8_tIMB_steal_byte_buffer (ImBuf *ibuf)
 
floatIMB_steal_float_buffer (ImBuf *ibuf)
 
uint8_tIMB_steal_encoded_buffer (ImBuf *ibuf)
 
void IMB_make_writable_byte_buffer (ImBuf *ibuf)
 
void IMB_make_writable_float_buffer (ImBuf *ibuf)
 
void IMB_assign_byte_buffer (ImBuf *ibuf, uint8_t *buffer_data, const ImBufOwnership ownership)
 
void IMB_assign_float_buffer (ImBuf *ibuf, float *buffer_data, const ImBufOwnership ownership)
 
void IMB_assign_byte_buffer (ImBuf *ibuf, const ImBufByteBuffer &buffer, const ImBufOwnership ownership)
 
void IMB_assign_float_buffer (ImBuf *ibuf, const ImBufFloatBuffer &buffer, const ImBufOwnership ownership)
 
void IMB_assign_dds_data (ImBuf *ibuf, const DDSData &data, const ImBufOwnership ownership)
 
ImBufIMB_allocFromBufferOwn (uint8_t *byte_buffer, float *float_buffer, uint w, uint h, uint channels)
 
ImBufIMB_allocFromBuffer (const uint8_t *byte_buffer, const float *float_buffer, uint w, uint h, uint channels)
 
ImBufIMB_allocImBuf (uint x, uint y, uchar planes, uint flags)
 
bool IMB_initImBuf (ImBuf *ibuf, uint x, uint y, uchar planes, uint flags)
 
ImBufIMB_dupImBuf (const ImBuf *ibuf1)
 
size_t IMB_get_rect_len (const ImBuf *ibuf)
 Get the length of the rect of the given image buffer in terms of pixels.
 
size_t IMB_get_size_in_memory (ImBuf *ibuf)
 

Variables

static SpinLock refcounter_spin
 
static SpinLock mmap_spin
 

Function Documentation

◆ freeencodedbufferImBuf()

static void freeencodedbufferImBuf ( ImBuf * ibuf)
static

◆ imb_addencodedbufferImBuf()

◆ imb_addrectfloatImBuf()

◆ imb_addrectImBuf()

◆ imb_alloc_buffer()

template<class BufferType >
bool imb_alloc_buffer ( BufferType & buffer,
const uint x,
const uint y,
const uint channels,
const size_t type_size,
bool initialize_pixels )

◆ imb_alloc_pixels()

void * imb_alloc_pixels ( unsigned int x,
unsigned int y,
unsigned int channels,
size_t typesize,
bool initialize_pixels,
const char * alloc_name )

Exported for image tools in blender, to quickly allocate 32 bits rect.

Definition at line 369 of file allocimbuf.cc.

References MEM_callocN, MEM_mallocN, and SIZE_MAX.

Referenced by convertRGBAToLogElement(), imb_alloc_buffer(), logImageGetDataRGBA(), and logImageSetDataRGBA().

◆ IMB_allocFromBuffer()

ImBuf * IMB_allocFromBuffer ( const uint8_t * byte_buffer,
const float * float_buffer,
unsigned int w,
unsigned int h,
unsigned int channels )

Create a copy of a pixel buffer and wrap it to a new ImBuf

Definition at line 544 of file allocimbuf.cc.

References ImBuf::byte_buffer, channels(), ImBuf::channels, ImBufByteBuffer::data, ImBufFloatBuffer::data, ImBuf::float_buffer, imb_alloc_buffer(), IMB_allocImBuf(), and w().

◆ IMB_allocFromBufferOwn()

ImBuf * IMB_allocFromBufferOwn ( uint8_t * byte_buffer,
float * float_buffer,
unsigned int w,
unsigned int h,
unsigned int channels )

Create a copy of a pixel buffer and wrap it to a new ImBuf (transferring ownership to the in imbuf).

Definition at line 518 of file allocimbuf.cc.

References BLI_assert, channels(), ImBuf::channels, IB_TAKE_OWNERSHIP, IMB_allocImBuf(), IMB_assign_byte_buffer(), IMB_assign_float_buffer(), MEM_allocN_len, and w().

Referenced by blend_file_thumb_from_screenshot(), and studiolight_load_equirect_image().

◆ IMB_allocImBuf()

ImBuf * IMB_allocImBuf ( uint x,
uint y,
uchar planes,
uint flags )

Definition at line 576 of file allocimbuf.cc.

References IMB_freeImBuf(), and IMB_initImBuf().

Referenced by IMB_allocFromBuffer(), IMB_allocFromBufferOwn(), and IMB_dupImBuf().

◆ IMB_assign_byte_buffer() [1/2]

void IMB_assign_byte_buffer ( ImBuf * ibuf,
const ImBufByteBuffer & buffer,
ImBufOwnership ownership )

Assign the content and the color space of the corresponding buffer the data from the given buffer.

Note
Does not modify the topology (width, height, number of channels) or the mipmaps in any way.
The ownership of the data in the source buffer is ignored.

Definition at line 492 of file allocimbuf.cc.

References ImBuf::byte_buffer, ImBufByteBuffer::colorspace, ImBufByteBuffer::data, and IMB_assign_byte_buffer().

◆ IMB_assign_byte_buffer() [2/2]

void IMB_assign_byte_buffer ( ImBuf * ibuf,
uint8_t * buffer_data,
ImBufOwnership ownership )

Assign the content of the corresponding buffer with the given data and ownership. The current content of the buffer is released corresponding to its ownership configuration.

Note
Does not modify the topology (width, height, number of channels) or the mipmaps in any way.

Definition at line 466 of file allocimbuf.cc.

References ImBuf::byte_buffer, ImBufByteBuffer::data, ImBuf::flags, IB_rect, imb_free_buffer(), and ImBufByteBuffer::ownership.

Referenced by colormanage_cache_put(), blender::realtime_compositor::compute_linear_buffer(), image_undo_steal_and_assign_byte_buffer(), IMB_allocFromBufferOwn(), IMB_assign_byte_buffer(), paint_2d_do_making_brush(), RE_render_result_rect_from_ibuf(), RE_render_result_rect_to_ibuf(), render_result_rect_fill_zero(), scale_with_function(), and screenshot_exec().

◆ IMB_assign_dds_data()

void IMB_assign_dds_data ( ImBuf * ibuf,
const DDSData & data,
const ImBufOwnership ownership )

◆ IMB_assign_float_buffer() [1/2]

void IMB_assign_float_buffer ( ImBuf * ibuf,
const ImBufFloatBuffer & buffer,
const ImBufOwnership ownership )

◆ IMB_assign_float_buffer() [2/2]

◆ IMB_dupImBuf()

◆ imb_enlargeencodedbufferImBuf()

◆ imb_free_buffer()

template<class BufferType >
static void imb_free_buffer ( BufferType & buffer)
static

◆ imb_free_dds_buffer()

static void imb_free_dds_buffer ( DDSData & dds_data)
static

◆ IMB_free_gpu_textures()

void IMB_free_gpu_textures ( ImBuf * ibuf)

◆ IMB_freeImBuf()

◆ imb_freemipmapImBuf()

◆ imb_freerectfloatImBuf()

◆ imb_freerectImBuf()

◆ imb_freerectImbuf_all()

void imb_freerectImbuf_all ( ImBuf * ibuf)

Free all CPU pixel data (associated with image size).

Definition at line 230 of file allocimbuf.cc.

References freeencodedbufferImBuf(), imb_freerectfloatImBuf(), and imb_freerectImBuf().

Referenced by IMB_freeImBuf(), and ubuf_ensure_compat_ibuf().

◆ IMB_get_rect_len()

size_t IMB_get_rect_len ( const ImBuf * ibuf)

Get the length of the rect of the given image buffer in terms of pixels.

This is the width * the height of the image buffer. This function is preferred over ibuf->x * ibuf->y due to overflow issues when working with large resolution images (30kx30k).

Definition at line 708 of file allocimbuf.cc.

References ImBuf::x, and ImBuf::y.

Referenced by IMB_color_to_bw(), IMB_float_from_rect(), IMB_saturation(), and multiply_ibuf().

◆ IMB_get_size_in_memory()

◆ IMB_initImBuf()

bool IMB_initImBuf ( ImBuf * ibuf,
unsigned int x,
unsigned int y,
unsigned char planes,
unsigned int flags )

◆ IMB_make_writable_byte_buffer()

void IMB_make_writable_byte_buffer ( ImBuf * ibuf)

Make corresponding buffers available for modification. Is achieved by ensuring that the given ImBuf is the only owner of the underlying buffer data.

Definition at line 456 of file allocimbuf.cc.

References ImBuf::byte_buffer, and imb_make_writeable_buffer().

Referenced by imbuf_ensure_editable().

◆ IMB_make_writable_float_buffer()

void IMB_make_writable_float_buffer ( ImBuf * ibuf)

Definition at line 461 of file allocimbuf.cc.

References ImBuf::float_buffer, and imb_make_writeable_buffer().

Referenced by imbuf_ensure_editable().

◆ imb_make_writeable_buffer()

template<class BufferType >
void imb_make_writeable_buffer ( BufferType & buffer)

◆ IMB_makeSingleUser()

◆ imb_mmap_lock()

void imb_mmap_lock ( )

◆ imb_mmap_lock_exit()

void imb_mmap_lock_exit ( )

Definition at line 51 of file allocimbuf.cc.

References BLI_spin_end(), and mmap_spin.

Referenced by IMB_exit().

◆ imb_mmap_lock_init()

void imb_mmap_lock_init ( )

Definition at line 46 of file allocimbuf.cc.

References BLI_spin_init(), and mmap_spin.

Referenced by IMB_init().

◆ imb_mmap_unlock()

void imb_mmap_unlock ( )

◆ imb_refcounter_lock_exit()

void imb_refcounter_lock_exit ( )

Definition at line 38 of file allocimbuf.cc.

References BLI_spin_end(), and refcounter_spin.

Referenced by IMB_exit().

◆ imb_refcounter_lock_init()

void imb_refcounter_lock_init ( )

Definition at line 33 of file allocimbuf.cc.

References BLI_spin_init(), and refcounter_spin.

Referenced by IMB_init().

◆ IMB_refImBuf()

◆ imb_steal_buffer_data()

template<class BufferType >
auto imb_steal_buffer_data ( BufferType & buffer) -> decltype(BufferType::data)

◆ IMB_steal_byte_buffer()

uint8_t * IMB_steal_byte_buffer ( ImBuf * ibuf)

Steal the buffer data pointer: the ImBuf is no longer an owner of this data.

Note
If the ImBuf does not own the data the behavior is undefined.
Stealing encoded buffer resets the encoded size.

Definition at line 430 of file allocimbuf.cc.

References ImBuf::byte_buffer, data, ImBuf::flags, and imb_steal_buffer_data().

Referenced by icon_verify_datatoc(), image_undo_steal_and_assign_byte_buffer(), imb_gpu_get_data(), and UI_icon_to_preview().

◆ IMB_steal_encoded_buffer()

uint8_t * IMB_steal_encoded_buffer ( ImBuf * ibuf)

◆ IMB_steal_float_buffer()

Variable Documentation

◆ mmap_spin

SpinLock mmap_spin
static

◆ refcounter_spin

SpinLock refcounter_spin
static