libCZI
Reading and Writing CZI documents made easy
libCZI_Compositor.h
1 // SPDX-FileCopyrightText: 2017-2022 Carl Zeiss Microscopy GmbH
2 //
3 // SPDX-License-Identifier: LGPL-3.0-or-later
4 
5 #pragma once
6 
7 #include "ImportExport.h"
8 #include <cstring>
9 #include <limits>
10 #include <vector>
11 #include <memory>
12 #include "libCZI_Pixels.h"
13 #include "libCZI_Metadata.h"
14 
15 namespace libCZI
16 {
17  class IBitmapData;
18  class IDimCoordinate;
19 
21  enum class AccessorType
22  {
26  };
27 
30  {
31  public:
32  static constexpr std::uint8_t kMemoryUsage = 1;
33  static constexpr std::uint8_t kElementsCount = 2;
34 
37  struct Statistics
38  {
40  std::uint8_t validityMask;
41 
43  std::uint64_t memoryUsage;
44 
46  std::uint32_t elementsCount;
47  };
48 
57  virtual Statistics GetStatistics(std::uint8_t mask) const = 0;
58 
59  virtual ~ISubBlockCacheStatistics() = default;
60 
61  ISubBlockCacheStatistics() = default;
63  ISubBlockCacheStatistics& operator=(const ISubBlockCacheStatistics&) = delete;
65  ISubBlockCacheStatistics& operator=(ISubBlockCacheStatistics&&) noexcept = delete;
66  };
67 
70  {
71  public:
80  struct PruneOptions
81  {
84  std::uint64_t maxMemoryUsage{ (std::numeric_limits<decltype(maxMemoryUsage)>::max)() };
85 
88  std::uint32_t maxSubBlockCount{ (std::numeric_limits<decltype(maxSubBlockCount)>::max)() };
89  };
90 
95  virtual void Prune(const PruneOptions& options) = 0;
96 
97  virtual ~ISubBlockCacheControl() = default;
98 
99  ISubBlockCacheControl() = default;
101  ISubBlockCacheControl& operator=(const ISubBlockCacheControl&) = delete;
102  ISubBlockCacheControl(ISubBlockCacheControl&&) noexcept = delete;
103  ISubBlockCacheControl& operator=(ISubBlockCacheControl&&) noexcept = delete;
104  };
105 
108  {
109  public:
113  virtual std::shared_ptr<IBitmapData> Get(int subblock_index) = 0;
114 
118  virtual void Add(int subblock_index, std::shared_ptr<IBitmapData> pBitmap) = 0;
119 
120  virtual ~ISubBlockCacheOperation() = default;
121 
122  ISubBlockCacheOperation() = default;
124  ISubBlockCacheOperation& operator=(const ISubBlockCacheOperation&) = delete;
126  ISubBlockCacheOperation& operator=(ISubBlockCacheOperation&&) noexcept = delete;
127  };
128 
138  {
139  public:
140  ~ISubBlockCache() override = default;
141 
142  ISubBlockCache() = default;
143  ISubBlockCache(const ISubBlockCache&) = delete;
144  ISubBlockCache& operator=(const ISubBlockCache&) = delete;
145  ISubBlockCache(ISubBlockCache&&) noexcept = delete;
146  ISubBlockCache& operator=(ISubBlockCache&&) noexcept = delete;
147  };
148 
150  class IAccessor
151  {
152  protected:
153  virtual ~IAccessor() = default;
154  };
155 
172  {
173  public:
175  struct Options
176  {
182 
185  bool sortByM;
186 
192 
196 
198  std::shared_ptr<libCZI::IIndexSet> sceneFilter;
199 
203  std::shared_ptr<libCZI::ISubBlockCacheOperation> subBlockCache;
204 
209 
211  void Clear()
212  {
213  this->backGroundColor.r = this->backGroundColor.g = this->backGroundColor.b = std::numeric_limits<float>::quiet_NaN();
214  this->sortByM = true;
215  this->useVisibilityCheckOptimization = false;
216  this->drawTileBorder = false;
217  this->sceneFilter.reset();
218  this->subBlockCache.reset();
219  this->onlyUseSubBlockCacheForCompressedData = true;
220  }
221  };
222 
223  public:
237  virtual std::shared_ptr<libCZI::IBitmapData> Get(const libCZI::IntRect& roi, const IDimCoordinate* planeCoordinate, const Options* pOptions) = 0;
238 
247  virtual std::shared_ptr<libCZI::IBitmapData> Get(libCZI::PixelType pixeltype, const libCZI::IntRect& roi, const IDimCoordinate* planeCoordinate, const Options* pOptions) = 0;
248 
257  virtual void Get(libCZI::IBitmapData* pDest, int xPos, int yPos, const IDimCoordinate* planeCoordinate, const Options* pOptions) = 0;
258 
270  inline std::shared_ptr<libCZI::IBitmapData> Get(int xPos, int yPos, int width, int height, const IDimCoordinate* planeCoordinate, const Options* pOptions) { return this->Get(libCZI::IntRect{ xPos,yPos,width,height }, planeCoordinate, pOptions); }
271 
281  inline std::shared_ptr<libCZI::IBitmapData> Get(libCZI::PixelType pixeltype, int xPos, int yPos, int width, int height, const IDimCoordinate* planeCoordinate, const Options* pOptions) { return this->Get(pixeltype, libCZI::IntRect{ xPos,yPos,width,height }, planeCoordinate, pOptions); }
282  protected:
283  virtual ~ISingleChannelTileAccessor() = default;
284  };
285 
290  {
291  public:
293  struct Options
294  {
300 
303  bool sortByM;
304 
308 
310  std::shared_ptr<libCZI::IIndexSet> sceneFilter;
311 
315  std::shared_ptr<libCZI::ISubBlockCacheOperation> subBlockCache;
316 
319 
321  void Clear()
322  {
323  this->drawTileBorder = false;
324  this->sortByM = true;
325  this->backGroundColor.r = this->backGroundColor.g = this->backGroundColor.b = std::numeric_limits<float>::quiet_NaN();
326  this->sceneFilter.reset();
327  this->subBlockCache.reset();
328  this->onlyUseSubBlockCacheForCompressedData = true;
329  }
330  };
331 
338  {
339  std::uint8_t minificationFactor;
340  std::uint8_t pyramidLayerNo;
341  };
342 
352  virtual std::shared_ptr<libCZI::IBitmapData> Get(const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, const PyramidLayerInfo& pyramidInfo, const libCZI::ISingleChannelPyramidLayerTileAccessor::Options* pOptions) = 0;
353 
361  virtual std::shared_ptr<libCZI::IBitmapData> Get(libCZI::PixelType pixeltype, const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, const PyramidLayerInfo& pyramidInfo, const libCZI::ISingleChannelPyramidLayerTileAccessor::Options* pOptions) = 0;
362 
370  virtual void Get(libCZI::IBitmapData* pDest, int xPos, int yPos, const IDimCoordinate* planeCoordinate, const PyramidLayerInfo& pyramidInfo, const Options* pOptions) = 0;
371  };
372 
379  {
380  public:
382  struct Options
383  {
389 
392  bool sortByM;
393 
397 
400  std::shared_ptr<libCZI::IIndexSet> sceneFilter;
401 
407 
411  std::shared_ptr<libCZI::ISubBlockCacheOperation> subBlockCache;
412 
415 
417  void Clear()
418  {
419  this->drawTileBorder = false;
420  this->sortByM = true;
421  this->backGroundColor.r = this->backGroundColor.g = this->backGroundColor.b = std::numeric_limits<float>::quiet_NaN();
422  this->sceneFilter.reset();
423  this->useVisibilityCheckOptimization = false;
424  this->subBlockCache.reset();
425  this->onlyUseSubBlockCacheForCompressedData = true;
426  }
427  };
428 
435  virtual libCZI::IntSize CalcSize(const libCZI::IntRect& roi, float zoom) const = 0;
436 
446  virtual std::shared_ptr<libCZI::IBitmapData> Get(const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) = 0;
447 
455  virtual std::shared_ptr<libCZI::IBitmapData> Get(libCZI::PixelType pixeltype, const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) = 0;
456 
465  virtual void Get(libCZI::IBitmapData* pDest, const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) = 0;
466  };
467 
469  class LIBCZI_API Compositors
470  {
471  public:
473  struct LIBCZI_API ComposeSingleTileOptions
474  {
478 
480  void Clear() { this->drawTileBorder = false; }
481  };
482 
502  const std::function<bool(int index, std::shared_ptr<libCZI::IBitmapData>& src, int& x, int& y)>& getTiles,
503  libCZI::IBitmapData* dest,
504  int xPos,
505  int yPos,
506  const ComposeSingleTileOptions* pOptions);
507 
510  {
513  };
514 
515 
523  struct ChannelInfo
524  {
526  float weight;
527 
531 
534 
538  float blackPoint;
539 
543  float whitePoint;
544 
552 
555  const std::uint8_t* ptrLookUpTable;
556 
558  void Clear() { std::memset(this, 0, sizeof(*this)); }
559  };
560 
572  libCZI::IBitmapData* dest,
573  int channelCount,
574  libCZI::IBitmapData* const* srcBitmaps,
575  const ChannelInfo* channelInfos);
576 
590  libCZI::IBitmapData* dest,
591  std::uint8_t alphaVal,
592  int channelCount,
593  libCZI::IBitmapData* const* srcBitmaps,
594  const ChannelInfo* channelInfos);
595 
607  static std::shared_ptr<IBitmapData> ComposeMultiChannel_Bgr24(
608  int channelCount,
609  libCZI::IBitmapData* const* srcBitmaps,
610  const ChannelInfo* channelInfos);
611 
624  static std::shared_ptr<IBitmapData> ComposeMultiChannel_Bgra32(
625  std::uint8_t alphaVal,
626  int channelCount,
627  libCZI::IBitmapData* const* srcBitmaps,
628  const ChannelInfo* channelInfos);
629 
640  static std::shared_ptr<IBitmapData> ComposeMultiChannel_Bgr24(
641  int channelCount,
642  std::vector<std::shared_ptr<libCZI::IBitmapData>>::iterator srcBitmapsIterator,
643  const ChannelInfo* channelInfos)
644  {
645  std::vector<IBitmapData*> vecBm; vecBm.reserve(channelCount);
646  for (int i = 0; i < channelCount; ++i)
647  {
648  vecBm.emplace_back((*srcBitmapsIterator).get());
649  ++srcBitmapsIterator;
650  }
651 
652  return ComposeMultiChannel_Bgr24(channelCount, &vecBm[0], channelInfos);
653  }
654 
666  static std::shared_ptr<IBitmapData> ComposeMultiChannel_Bgra32(
667  std::uint8_t alphaVal,
668  int channelCount,
669  std::vector<std::shared_ptr<libCZI::IBitmapData>>::iterator srcBitmapsIterator,
670  const ChannelInfo* channelInfos)
671  {
672  std::vector<IBitmapData*> vecBm; vecBm.reserve(channelCount);
673  for (int i = 0; i < channelCount; ++i)
674  {
675  vecBm.emplace_back((*srcBitmapsIterator).get());
676  ++srcBitmapsIterator;
677  }
678 
679  return ComposeMultiChannel_Bgra32(alphaVal, channelCount, &vecBm[0], channelInfos);
680  }
681  };
682 }
Composition operations are found in this class: multi-tile compositor and multi-channel compositor.
Definition: libCZI_Compositor.h:470
static void ComposeMultiChannel_Bgra32(libCZI::IBitmapData *dest, std::uint8_t alphaVal, int channelCount, libCZI::IBitmapData *const *srcBitmaps, const ChannelInfo *channelInfos)
static std::shared_ptr< IBitmapData > ComposeMultiChannel_Bgra32(std::uint8_t alphaVal, int channelCount, std::vector< std::shared_ptr< libCZI::IBitmapData >>::iterator srcBitmapsIterator, const ChannelInfo *channelInfos)
Definition: libCZI_Compositor.h:666
static std::shared_ptr< IBitmapData > ComposeMultiChannel_Bgr24(int channelCount, std::vector< std::shared_ptr< libCZI::IBitmapData >>::iterator srcBitmapsIterator, const ChannelInfo *channelInfos)
Definition: libCZI_Compositor.h:640
static void ComposeSingleChannelTiles(const std::function< bool(int index, std::shared_ptr< libCZI::IBitmapData > &src, int &x, int &y)> &getTiles, libCZI::IBitmapData *dest, int xPos, int yPos, const ComposeSingleTileOptions *pOptions)
Composes a set of tiles (which are retrieved by calling the getTiles-functor) in the following way: T...
static std::shared_ptr< IBitmapData > ComposeMultiChannel_Bgr24(int channelCount, libCZI::IBitmapData *const *srcBitmaps, const ChannelInfo *channelInfos)
static std::shared_ptr< IBitmapData > ComposeMultiChannel_Bgra32(std::uint8_t alphaVal, int channelCount, libCZI::IBitmapData *const *srcBitmaps, const ChannelInfo *channelInfos)
static void ComposeMultiChannel_Bgr24(libCZI::IBitmapData *dest, int channelCount, libCZI::IBitmapData *const *srcBitmaps, const ChannelInfo *channelInfos)
The base interface (all accessor-interface must derive from this).
Definition: libCZI_Compositor.h:151
Definition: libCZI_Pixels.h:167
Interface used to represent a coordinate (in the space of the dimensions identified by DimensionIndex...
Definition: libCZI_DimCoordinate.h:37
Definition: libCZI_Compositor.h:290
virtual std::shared_ptr< libCZI::IBitmapData > Get(libCZI::PixelType pixeltype, const libCZI::IntRect &roi, const libCZI::IDimCoordinate *planeCoordinate, const PyramidLayerInfo &pyramidInfo, const libCZI::ISingleChannelPyramidLayerTileAccessor::Options *pOptions)=0
virtual void Get(libCZI::IBitmapData *pDest, int xPos, int yPos, const IDimCoordinate *planeCoordinate, const PyramidLayerInfo &pyramidInfo, const Options *pOptions)=0
Copy the composite to the specified bitmap.
virtual std::shared_ptr< libCZI::IBitmapData > Get(const libCZI::IntRect &roi, const libCZI::IDimCoordinate *planeCoordinate, const PyramidLayerInfo &pyramidInfo, const libCZI::ISingleChannelPyramidLayerTileAccessor::Options *pOptions)=0
Definition: libCZI_Compositor.h:379
virtual void Get(libCZI::IBitmapData *pDest, const libCZI::IntRect &roi, const libCZI::IDimCoordinate *planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options *pOptions)=0
Copy the composite to the specified bitmap.
virtual std::shared_ptr< libCZI::IBitmapData > Get(libCZI::PixelType pixeltype, const libCZI::IntRect &roi, const libCZI::IDimCoordinate *planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options *pOptions)=0
virtual std::shared_ptr< libCZI::IBitmapData > Get(const libCZI::IntRect &roi, const libCZI::IDimCoordinate *planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options *pOptions)=0
virtual libCZI::IntSize CalcSize(const libCZI::IntRect &roi, float zoom) const =0
Definition: libCZI_Compositor.h:172
virtual void Get(libCZI::IBitmapData *pDest, int xPos, int yPos, const IDimCoordinate *planeCoordinate, const Options *pOptions)=0
virtual std::shared_ptr< libCZI::IBitmapData > Get(libCZI::PixelType pixeltype, const libCZI::IntRect &roi, const IDimCoordinate *planeCoordinate, const Options *pOptions)=0
virtual std::shared_ptr< libCZI::IBitmapData > Get(const libCZI::IntRect &roi, const IDimCoordinate *planeCoordinate, const Options *pOptions)=0
Gets the tile composite of the specified plane and the specified ROI. The pixeltype is determined by ...
std::shared_ptr< libCZI::IBitmapData > Get(libCZI::PixelType pixeltype, int xPos, int yPos, int width, int height, const IDimCoordinate *planeCoordinate, const Options *pOptions)
Definition: libCZI_Compositor.h:281
std::shared_ptr< libCZI::IBitmapData > Get(int xPos, int yPos, int width, int height, const IDimCoordinate *planeCoordinate, const Options *pOptions)
Definition: libCZI_Compositor.h:270
This interface defines the global operations on the cache. It is used to control the memory usage of ...
Definition: libCZI_Compositor.h:70
virtual void Prune(const PruneOptions &options)=0
Definition: libCZI_Compositor.h:138
This interface defines the operations of adding and querying an element to/from the cache.
Definition: libCZI_Compositor.h:108
virtual void Add(int subblock_index, std::shared_ptr< IBitmapData > pBitmap)=0
virtual std::shared_ptr< IBitmapData > Get(int subblock_index)=0
This interface defines how status information about the cache-state can be queried.
Definition: libCZI_Compositor.h:30
virtual Statistics GetStatistics(std::uint8_t mask) const =0
static constexpr std::uint8_t kElementsCount
Bit-mask identifying the elements-count field in the statistics struct.
Definition: libCZI_Compositor.h:33
static constexpr std::uint8_t kMemoryUsage
Bit-mask identifying the memory-usage field in the statistics struct.
Definition: libCZI_Compositor.h:32
External interfaces, classes, functions and structs are found in the namespace "libCZI".
Definition: libCZI.h:31
AccessorType
Values that represent the accessor types.
Definition: libCZI_Compositor.h:22
@ SingleChannelTileAccessor
The single-channel-tile accessor (associated interface: ISingleChannelTileAccessor).
@ SingleChannelPyramidLayerTileAccessor
The single-channel-pyramidlayer-tile accessor (associated interface: ISingleChannelPyramidLayerTileAc...
@ SingleChannelScalingTileAccessor
The scaling-single-channel-tile accessor (associated interface: ISingleChannelScalingTileAccessor).
PixelType
An enum representing a pixel-type.
Definition: libCZI_Pixels.h:114
Definition: libCZI_Compositor.h:524
float blackPoint
Definition: libCZI_Compositor.h:538
float weight
The weight of the channel.
Definition: libCZI_Compositor.h:526
int lookUpTableElementCount
Definition: libCZI_Compositor.h:551
bool enableTinting
Definition: libCZI_Compositor.h:530
TintingColor tinting
The tinting color (only examined if enableTinting is true).
Definition: libCZI_Compositor.h:533
void Clear()
All members are set to zero.
Definition: libCZI_Compositor.h:558
float whitePoint
Definition: libCZI_Compositor.h:543
const std::uint8_t * ptrLookUpTable
Definition: libCZI_Compositor.h:555
Options for the libCZI::Compositors::ComposeSingleChannelTiles function.
Definition: libCZI_Compositor.h:474
bool drawTileBorder
Definition: libCZI_Compositor.h:477
void Clear()
Clears this object to its blank/initial state.
Definition: libCZI_Compositor.h:480
This structure defines the tinting color.
Definition: libCZI_Compositor.h:510
Rgb8Color color
The tinting color to be used given as RGB24.
Definition: libCZI_Compositor.h:512
Options used for this accessor.
Definition: libCZI_Compositor.h:294
bool drawTileBorder
Definition: libCZI_Compositor.h:307
RgbFloatColor backGroundColor
Definition: libCZI_Compositor.h:299
bool sortByM
Definition: libCZI_Compositor.h:303
bool onlyUseSubBlockCacheForCompressedData
If true, then only bitmaps from sub-blocks with compressed data are added to the cache.
Definition: libCZI_Compositor.h:318
std::shared_ptr< libCZI::IIndexSet > sceneFilter
If specified, only subblocks with a scene-index contained in the set will be considered.
Definition: libCZI_Compositor.h:310
void Clear()
Clears this object to its blank state.
Definition: libCZI_Compositor.h:321
std::shared_ptr< libCZI::ISubBlockCacheOperation > subBlockCache
Definition: libCZI_Compositor.h:315
std::uint8_t minificationFactor
Factor by which adjacent pyramid-layers are shrunk. Commonly used in CZI are 2 or 3.
Definition: libCZI_Compositor.h:339
std::uint8_t pyramidLayerNo
The pyramid layer number.
Definition: libCZI_Compositor.h:340
Options used for this accessor.
Definition: libCZI_Compositor.h:383
RgbFloatColor backGroundColor
Definition: libCZI_Compositor.h:388
std::shared_ptr< libCZI::ISubBlockCacheOperation > subBlockCache
Definition: libCZI_Compositor.h:411
bool onlyUseSubBlockCacheForCompressedData
If true, then only bitmaps from sub-blocks with compressed data are added to the cache.
Definition: libCZI_Compositor.h:414
void Clear()
Clears this object to its blank state.
Definition: libCZI_Compositor.h:417
bool sortByM
Definition: libCZI_Compositor.h:392
bool useVisibilityCheckOptimization
Definition: libCZI_Compositor.h:406
std::shared_ptr< libCZI::IIndexSet > sceneFilter
Definition: libCZI_Compositor.h:400
bool drawTileBorder
Definition: libCZI_Compositor.h:396
Options for controlling the composition operation.
Definition: libCZI_Compositor.h:176
bool useVisibilityCheckOptimization
Definition: libCZI_Compositor.h:191
bool onlyUseSubBlockCacheForCompressedData
Definition: libCZI_Compositor.h:208
RgbFloatColor backGroundColor
Definition: libCZI_Compositor.h:181
bool sortByM
Definition: libCZI_Compositor.h:185
std::shared_ptr< libCZI::IIndexSet > sceneFilter
If specified, only subblocks with a scene-index contained in the set will be considered.
Definition: libCZI_Compositor.h:198
void Clear()
Clears this object to its blank state.
Definition: libCZI_Compositor.h:211
bool drawTileBorder
Definition: libCZI_Compositor.h:195
std::shared_ptr< libCZI::ISubBlockCacheOperation > subBlockCache
Definition: libCZI_Compositor.h:203
Definition: libCZI_Compositor.h:81
Definition: libCZI_Compositor.h:38
std::uint32_t elementsCount
The number of elements in the cache. This field is only valid if the bit kElementsCount is set in the...
Definition: libCZI_Compositor.h:46
std::uint64_t memoryUsage
The memory usage of all elements in the cache. This field is only valid if the bit kMemoryUsage is se...
Definition: libCZI_Compositor.h:43
std::uint8_t validityMask
A bit mask which indicates which members are valid. C.f. the constants kMemoryUsage and kElementsCoun...
Definition: libCZI_Compositor.h:40
A rectangle (with integer coordinates).
Definition: libCZI_Pixels.h:17
A structure representing a size (width and height) in integers.
Definition: libCZI_Pixels.h:91
A structure representing an R-G-B-color triple (as bytes).
Definition: libCZI_Pixels.h:98
A structure representing an R-G-B-color triple (as floats).
Definition: libCZI_Pixels.h:106
float r
The red component.
Definition: libCZI_Pixels.h:107
float b
The blue component.
Definition: libCZI_Pixels.h:109
float g
The green component.
Definition: libCZI_Pixels.h:108