PCL
|
Manages transparent allocation and deallocation of shared and local pixel data. More...
#include <PixelAllocator.h>
Public Types | |
using | pixel_traits = P |
using | sample = typename pixel_traits::sample |
Public Member Functions | |
sample ** | AllocateChannelSlots (size_type n) const |
sample * | AllocatePixels (int width, int height) const |
sample * | AllocatePixels (size_type n) const |
template<typename T > | |
void | Deallocate (T *p) const |
bool | operator== (const PixelAllocator< P > &x) const noexcept |
Public Member Functions inherited from pcl::SharedPixelData | |
SharedPixelData ()=default | |
SharedPixelData (const SharedPixelData &x) | |
SharedPixelData (int width, int height, int numberOfChannels, int bitsPerSample, bool floatSample, int colorSpace) | |
SharedPixelData (void *handle, int bitsPerSample, bool floatSample, bool complexSample) | |
virtual | ~SharedPixelData () |
void * | Handle () const noexcept |
bool | IsAliased () const |
bool | IsOwner () const |
bool | IsShared () const noexcept |
SharedPixelData & | operator= (const SharedPixelData &x) |
bool | operator== (const SharedPixelData &x) const noexcept |
Friends | |
class | pcl::GenericImage< P > |
PixelAllocator is responsible for allocation and deallocation of pixel data blocks in PCL. The template argument P corresponds to an instantiation of GenericPixelTraits for a specific pixel sample type.
Unless you are implementing geometrical transformations, or processes that perform direct substitutions of pixel data blocks in images, such as a whole channel, you usually should not have to use the PixelAllocator template class directly in your code. The SharedPixelData and GenericImage classes can perform all the necessary allocations transparently.
When you have to allocate or deallocate pixel data blocks, however, you should never use the new
and delete
operators, or the malloc
, calloc
and free
standard C functions. You must use PixelAllocator for all allocations and deallocations of pixel data exclusively. Among other good reasons for this, pixel data blocks cannot be allocated in your module's local heap if they are being used with shared images, i.e. images living in the PixInsight core application.
The only safe way to allocate and deallocate pixel data in PCL is by using PixelAllocator's member functions. Note that you cannot allocate PixelAllocator directly. For an existing image, you get a reference to a PixelAllocator instance by calling the Allocator() member function of GenericImage. This member function returns a reference to the image's internal allocator, which will perform all pixel allocation tasks that you may need transparently, irrespective of whether the object represents a local or shared image.
Definition at line 106 of file PixelAllocator.h.
using pcl::PixelAllocator< P >::pixel_traits = P |
Represents the pixel traits class used by this instantiation of PixelAllocator.
The pixel_traits
type should be an instantiation of GenericPixelTraits. It identifies a class implementing basic storage and functional primitives optimized for a particular pixel sample type.
Definition at line 118 of file PixelAllocator.h.
using pcl::PixelAllocator< P >::sample = typename pixel_traits::sample |
Represents the data type used to store pixel sample values in this template instantiation of PixelAllocator.
Definition at line 124 of file PixelAllocator.h.
|
inline |
Allocates an array where at least n > 0 channel slots can be optimally stored. A channel slot is a pointer to a contiguous block of pixel samples, where an image can store a single channel.
The allocated array is initialized to zero. Returns the starting address of the allocated array.
This member function throws a std::bad_alloc
exception if there is not enough memory available to allocate the required contiguous block.
Definition at line 181 of file PixelAllocator.h.
|
inline |
Allocates a contiguous block of memory where at least width * height pixel samples can be optimally stored.
Returns the starting address of the allocated block. This is a convenience alias for:
Definition at line 165 of file PixelAllocator.h.
|
inline |
Allocates a contiguous block of memory where at least n > 0 pixel samples can be optimally stored.
Returns the starting address of the allocated block.
This member function throws a std::bad_alloc
exception if there is not enough memory available to allocate the required contiguous block.
Definition at line 148 of file PixelAllocator.h.
|
inline |
Deallocates a previously allocated memory block. The deallocated block becomes available for subsequent allocations.
new
operator, or by other PixelAllocator objects. Failure to follow this rule will lead to severe heap corruption for the calling module. Definition at line 200 of file PixelAllocator.h.
|
inlinenoexcept |
Returns true iff this allocator and another instance are working for the same shared image, or if both of them are working for local images.
All local images share a unique internal allocator, but each shared image has its own, independent allocator object. This responds to the multithreaded nature of the PixInsight core application.
Definition at line 134 of file PixelAllocator.h.
References pcl::SharedPixelData::operator==().