ImageLayer Structure#

Equivalent of Photoshops Image Layer

template<typename T>
struct ImageLayer : public Layer<T>#

Public Types

using storage_type = std::unordered_map<Enum::ChannelIDInfo, std::unique_ptr<ImageChannel>, Enum::ChannelIDInfoHasher>#

Alias for our storage data type.

using data_type = std::unordered_map<Enum::ChannelIDInfo, std::vector<T>, Enum::ChannelIDInfoHasher>#

Public Functions

template<typename ExecutionPolicy = std::execution::parallel_policy, std::enable_if_t<std::is_execution_policy_v<ExecutionPolicy>, int> = 0>
inline ImageLayer(std::unordered_map<Enum::ChannelID, std::vector<T>> &&data, Layer<T>::Params &parameters, const ExecutionPolicy policy = std::execution::par)#

Generate an ImageLayer instance ready to be used in a LayeredFile document.

Template Parameters:

ExecutionPolicy – the execution policy to generate the image layer with, at most parallelizes to data.size()

Parameters:
  • data – the ImageData to associate with the layer

  • parameters – The parameters dictating layer name, width, height, mask etc.

  • policy – The execution policy for the image data compression

template<typename ExecutionPolicy = std::execution::parallel_policy, std::enable_if_t<std::is_execution_policy_v<ExecutionPolicy>, int> = 0>
inline ImageLayer(std::unordered_map<int16_t, std::vector<T>> &&data, Layer<T>::Params &parameters, const ExecutionPolicy policy = std::execution::par)#

Generate an ImageLayer instance ready to be used in a LayeredFile document.

Template Parameters:

ExecutionPolicy – the execution policy to generate the image layer with, at most parallelizes to imageData.size()

Parameters:
  • imageData – the ImageData to associate with the channel

  • layerParameters – The parameters dictating layer name, width, height, mask etc.

  • policy – The execution policy for the image data compression

inline ImageLayer(const LayerRecord &layerRecord, ChannelImageData &channelImageData, const FileHeader &header)#

Initialize our imageLayer by first parsing the base Layer instance and then moving the additional channels into our representation. This constructor is primarily for internal usage and it is encouraged to use the other constructors taking image data directly instead.

inline std::vector<T> getChannel(const Enum::ChannelID channelID, bool doCopy = true)#

Extract a specified channel from the layer given its channel ID. This also works for masks

Parameters:
  • channelID – the channel ID to extract

  • doCopy – whether to extract the channel by copying the data. If this is false the channel will no longer hold any image data!

inline std::vector<T> getChannel(const int16_t channelIndex, bool doCopy = true)#

Extract a specified channel from the layer given its channel ID. This also works for masks

Parameters:
  • channelIndex – the channel index to extract

  • doCopy – whether to extract the channel by copying the data. If this is false the channel will no longer hold any image data!

template<typename ExecutionPolicy = std::execution::parallel_policy, std::enable_if_t<std::is_execution_policy_v<ExecutionPolicy>, int> = 0>
inline data_type getImageData(bool doCopy = true, const ExecutionPolicy policy = std::execution::par)#

Extract all the channels of the ImageLayer into an unordered_map. Includes the mask channel

Template Parameters:

ExecutionPolicy – the execution policy to get the image data with

Parameters:
  • doCopy – whether to extract the image data by copying the data. If this is false the channel will no longer hold any image data!

  • policy – The execution policy for the image data decompression

inline void setChannel(const Enum::ChannelID channelID, const std::span<const T> data, const Enum::Compression compression = Enum::Compression::ZipPrediction)#

Set or replace the data for a certain channel without rebuilding the whole ImageLayer. If the channel provided exists in m_ImageData we replace it, if it doesn’t we insert it. The channel must be both be valid for the given colormode as well as having the same size as m_Width * m_Height

Parameters:
  • channelID – The channel to insert or replace, must be valid for the given colormode. I.e. cannot be Enum::ChannelID::Cyan for an RGB layer/file

  • data – The data to write to the channel, must have the same size as m_Width * m_Height

  • compression – The compression codec to use for writing to file, this does not have to be the same as the other channels! Defaults to ZipPrediction

inline void setChannel(const int16_t index, const std::span<const T> data, const Enum::Compression compression = Enum::Compression::ZipPrediction)#

Set or replace the data for a certain channel without rebuilding the whole ImageLayer. If the channel provided exists in m_ImageData we replace it, if it doesn’t we insert it. The channel must be both be valid for the given colormode as well as having the same size as m_Width * m_Height

Parameters:
  • index – The index to insert or replace, must be valid for the given colormode. I.e. cannot be 4 for an RGB layer/file

  • data – The data to write to the channel, must have the same size as m_Width * m_Height

  • compression – The compression codec to use for writing to file, this does not have to be the same as the other channels! Defaults to ZipPrediction

template<typename ExecutionPolicy = std::execution::parallel_policy, std::enable_if_t<std::is_execution_policy_v<ExecutionPolicy>, int> = 0>
inline void setImageData(std::unordered_map<int16_t, std::vector<T>> &&data, const Enum::Compression compression = Enum::Compression::ZipPrediction, const ExecutionPolicy policy = std::execution::par)#

Set the image data for the whole file without rebuilding the layer. This function is useful if e.g. you modified the data and want to insert it back in-place. The same constraints apply as for the constructor. I.e. all indices must be valid for the colormode of the layer and the size of each channel must be exactly width * height. If you wish to rescale the layer please first modify the layers width and height, after which the data can be set.

Parameters:
  • data – The data to write to the layer, must have the same size as m_Width * m_Height

  • compression – The compression codec to use for writing to file, this does not have to be the same as other layers! Defaults to ZipPrediction

  • policy – The execution policy for the channel creation

template<typename ExecutionPolicy = std::execution::parallel_policy, std::enable_if_t<std::is_execution_policy_v<ExecutionPolicy>, int> = 0>
inline void setImageData(std::unordered_map<Enum::ChannelID, std::vector<T>> &&data, const Enum::Compression compression = Enum::Compression::ZipPrediction, const ExecutionPolicy policy = std::execution::par)#

Set the image data for the whole file without rebuilding the layer. This function is useful if e.g. you modified the data and want to insert it back in-place. The same constraints apply as for the constructor. I.e. all indices must be valid for the colormode of the layer and the size of each channel must be exactly width * height. If you wish to rescale the layer please first modify the layers width and height, after which the data can be set.

Parameters:
  • data – The data to write to the layer, must have the same size as m_Width * m_Height

  • compression – The compression codec to use for writing to file, this does not have to be the same as other layers! Defaults to ZipPrediction

  • policy – The execution policy for the channel creation

template<typename ExecutionPolicy = std::execution::parallel_policy, std::enable_if_t<std::is_execution_policy_v<ExecutionPolicy>, int> = 0>
inline void setImageData(data_type data, const Enum::Compression compression = Enum::Compression::ZipPrediction, const ExecutionPolicy policy = std::execution::par)#

Set the image data for the whole file without rebuilding the layer. This function is useful if e.g. you modified the data and want to insert it back in-place. The same constraints apply as for the constructor. I.e. all indices must be valid for the colormode of the layer and the size of each channel must be exactly width * height. If you wish to rescale the layer please first modify the layers width and height, after which the data can be set.

Parameters:
  • data – The data to write to the layer, must have the same size as m_Width * m_Height

  • compression – The compression codec to use for writing to file, this does not have to be the same as other layers! Defaults to ZipPrediction

  • policy – The execution policy for the channel creation

inline virtual void setCompression(const Enum::Compression compCode) override#

Change the compression codec of all the image channels.

inline std::tuple<LayerRecord, ChannelImageData> toPhotoshop(const Enum::ColorMode colorMode, const FileHeader &header) override#

Generate a photoshop layerRecord and imageData based on the current layer. Mostly for internal use.

Public Members

storage_type m_ImageData#

Store the image data as a per-channel map to be used later using a custom hash function.