PCL
pcl::PixelAllocator< P > Class Template Reference

Manages transparent allocation and deallocation of shared and local pixel data. More...

#include <PixelAllocator.h>

+ Inheritance diagram for pcl::PixelAllocator< P >:

Public Types

using pixel_traits = P
 
using sample = typename pixel_traits::sample
 

Public Member Functions

sample ** AllocateChannelSlots (size_type n) const
 
sampleAllocatePixels (int width, int height) const
 
sampleAllocatePixels (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
 
SharedPixelDataoperator= (const SharedPixelData &x)
 
bool operator== (const SharedPixelData &x) const noexcept
 

Friends

class pcl::GenericImage< P >
 

Detailed Description

template<class P>
class pcl::PixelAllocator< 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.

See also
GenericPixelTraits, GenericImage, SharedPixelData

Definition at line 106 of file PixelAllocator.h.

Member Typedef Documentation

◆ pixel_traits

template<class P >
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.

◆ sample

template<class P >
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.

Member Function Documentation

◆ AllocateChannelSlots()

template<class P >
sample** pcl::PixelAllocator< P >::AllocateChannelSlots ( size_type  n) const
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.

◆ AllocatePixels() [1/2]

template<class P >
sample* pcl::PixelAllocator< P >::AllocatePixels ( int  width,
int  height 
) const
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:

AllocatePixels( size_type( width )*size_type( height ) );
sample * AllocatePixels(size_type n) const
size_t size_type
Definition: Defs.h:609

Definition at line 165 of file PixelAllocator.h.

◆ AllocatePixels() [2/2]

template<class P >
sample* pcl::PixelAllocator< P >::AllocatePixels ( size_type  n) const
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.

◆ Deallocate()

template<class P >
template<typename T >
void pcl::PixelAllocator< P >::Deallocate ( T *  p) const
inline

Deallocates a previously allocated memory block. The deallocated block becomes available for subsequent allocations.

Warning
Do not use this function to deallocate memory that has not been allocated by this PixelAllocator object. This includes memory blocks allocated by the global 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.

◆ operator==()

template<class P >
bool pcl::PixelAllocator< P >::operator== ( const PixelAllocator< P > &  x) const
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==().


The documentation for this class was generated from the following file: