libCZI
Reading CZI documents made easy
libCZI_Compositor.h
1 //******************************************************************************
2 //
3 // libCZI is a reader for the CZI fileformat written in C++
4 // Copyright (C) 2017 Zeiss Microscopy GmbH
5 //
6 // This program is free software: you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation, either version 3 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 //
19 // To obtain a commercial version please contact Zeiss Microscopy GmbH.
20 //
21 //******************************************************************************
22 
23 #pragma once
24 
25 #include "ImportExport.h"
26 #include <cstring>
27 #include <limits>
28 #include "libCZI_Pixels.h"
29 #include "libCZI_Metadata.h"
30 
31 namespace libCZI
32 {
33  class IBitmapData;
34  class IDimCoordinate;
35 
37  enum class AccessorType
38  {
42  };
43 
45  class IAccessor
46  {
47  protected:
48  virtual ~IAccessor(){}
49  };
50 
67  {
68  public:
70  struct Options
71  {
77 
80  bool sortByM;
81 
85 
87  std::shared_ptr<libCZI::IIndexSet> sceneFilter;
88 
90  void Clear()
91  {
92  this->backGroundColor.r = this->backGroundColor.g = this->backGroundColor.b = std::numeric_limits<float>::quiet_NaN();
93  this->sortByM = true;
94  this->drawTileBorder = false;
95  this->sceneFilter.reset();
96  }
97  };
98 
99  public:
113  virtual std::shared_ptr<libCZI::IBitmapData> Get(const libCZI::IntRect& roi, const IDimCoordinate* planeCoordinate, const Options* pOptions) = 0;
114 
123  virtual std::shared_ptr<libCZI::IBitmapData> Get(libCZI::PixelType pixeltype, const libCZI::IntRect& roi, const IDimCoordinate* planeCoordinate, const Options* pOptions) = 0;
124 
133  virtual void Get(libCZI::IBitmapData* pDest, int xPos, int yPos, const IDimCoordinate* planeCoordinate, const Options* pOptions) = 0;
134 
146  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); }
147 
157  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); }
158  protected:
159  virtual ~ISingleChannelTileAccessor() {}
160  };
161 
166  {
167  public:
169  struct Options
170  {
176 
180 
182  std::shared_ptr<libCZI::IIndexSet> sceneFilter;
183 
185  void Clear()
186  {
187  this->drawTileBorder = false;
188  this->backGroundColor.r = this->backGroundColor.g = this->backGroundColor.b = std::numeric_limits<float>::quiet_NaN();
189  this->sceneFilter.reset();
190  }
191  };
192 
199  {
200  std::uint8_t minificationFactor;
201  std::uint8_t pyramidLayerNo;
202  };
203 
213  virtual std::shared_ptr<libCZI::IBitmapData> Get(const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, const PyramidLayerInfo& pyramidInfo, const libCZI::ISingleChannelPyramidLayerTileAccessor::Options* pOptions) = 0;
214 
222  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;
223 
231  virtual void Get(libCZI::IBitmapData* pDest, int xPos, int yPos, const IDimCoordinate* planeCoordinate, const PyramidLayerInfo& pyramidInfo, const Options* pOptions) = 0;
232  };
233 
240  {
241  public:
243  struct Options
244  {
250 
254 
256  std::shared_ptr<libCZI::IIndexSet> sceneFilter;
257 
259  void Clear()
260  {
261  this->drawTileBorder = false;
262  this->backGroundColor.r = this->backGroundColor.g = this->backGroundColor.b = std::numeric_limits<float>::quiet_NaN();
263  this->sceneFilter.reset();
264  }
265  };
266 
273  virtual libCZI::IntSize CalcSize(const libCZI::IntRect& roi, float zoom) const = 0;
274 
284  virtual std::shared_ptr<libCZI::IBitmapData> Get(const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) = 0;
285 
293  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;
294 
303  virtual void Get(libCZI::IBitmapData* pDest, const libCZI::IntRect& roi, const libCZI::IDimCoordinate* planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options* pOptions) = 0;
304  };
305 
307  class LIBCZI_API Compositors
308  {
309  public:
311  struct LIBCZI_API ComposeSingleTileOptions
312  {
316 
318  void Clear() { this->drawTileBorder = false; }
319  };
320 
339  static void ComposeSingleChannelTiles(
340  std::function<bool(int index, std::shared_ptr<libCZI::IBitmapData>& src, int& x, int& y)> getTiles,
341  libCZI::IBitmapData* dest,
342  int xPos,
343  int yPos,
344  const ComposeSingleTileOptions* pOptions);
345 
348  {
351  };
352 
353 
361  struct ChannelInfo
362  {
364  float weight;
365 
369 
372 
376  float blackPoint;
377 
381  float whitePoint;
382 
390 
393  const std::uint8_t* ptrLookUpTable;
394 
396  void Clear() { std::memset(this, 0, sizeof(*this)); }
397  };
398 
409  static void ComposeMultiChannel_Bgr24(
410  libCZI::IBitmapData* dest,
411  int channelCount,
412  libCZI::IBitmapData*const* srcBitmaps,
413  const ChannelInfo* channelInfos);
414 
424  static std::shared_ptr<IBitmapData> ComposeMultiChannel_Bgr24(
425  int channelCount,
426  libCZI::IBitmapData*const* srcBitmaps,
427  const ChannelInfo* channelInfos);
428 
439  static std::shared_ptr<IBitmapData> ComposeMultiChannel_Bgr24(
440  int channelCount,
441  std::vector<std::shared_ptr<libCZI::IBitmapData>>::iterator srcBitmapsIterator,
442  const ChannelInfo* channelInfos)
443  {
444  std::vector<IBitmapData*> vecBm; vecBm.reserve(channelCount);
445  for (int i = 0; i < channelCount; ++i)
446  {
447  vecBm.emplace_back((*srcBitmapsIterator).get());
448  ++srcBitmapsIterator;
449  }
450 
451  return ComposeMultiChannel_Bgr24(channelCount, &vecBm[0], channelInfos);
452  }
453  };
454 }
PixelType
An enum representing a pixel-type.
Definition: libCZI_Pixels.h:126
bool sortByM
Definition: libCZI_Compositor.h:80
Definition: libCZI_Pixels.h:166
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:87
Definition: libCZI_Compositor.h:239
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:439
Composition operations are found in this class: multi-tile compositor and multi-channel compositor...
Definition: libCZI_Compositor.h:307
The base interface (all accessor-interface must derive from this).
Definition: libCZI_Compositor.h:45
bool drawTileBorder
Definition: libCZI_Compositor.h:84
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:182
void Clear()
Clears this object to its blank state.
Definition: libCZI_Compositor.h:259
Options for the libCZI::Compositors::ComposeSingleChannelTiles function.
Definition: libCZI_Compositor.h:311
virtual std::shared_ptr< libCZI::IBitmapData > Get(const libCZI::IntRect &roi, const libCZI::IDimCoordinate *planeCoordinate, const PyramidLayerInfo &pyramidInfo, const libCZI::ISingleChannelPyramidLayerTileAccessor::Options *pOptions)=0
Rgb8Color color
The tinting color to be used given as RGB24.
Definition: libCZI_Compositor.h:350
float whitePoint
Definition: libCZI_Compositor.h:381
std::uint8_t pyramidLayerNo
The pyramid layer number.
Definition: libCZI_Compositor.h:201
bool drawTileBorder
Definition: libCZI_Compositor.h:253
int lookUpTableElementCount
Definition: libCZI_Compositor.h:389
RgbFloatColor backGroundColor
Definition: libCZI_Compositor.h:175
AccessorType
Values that represent the accessor types.
Definition: libCZI_Compositor.h:37
Definition: libCZI_Compositor.h:361
A structure representing an R-G-B-color triple (as bytes).
Definition: libCZI_Pixels.h:110
virtual std::shared_ptr< libCZI::IBitmapData > Get(const libCZI::IntRect &roi, const libCZI::IDimCoordinate *planeCoordinate, float zoom, const libCZI::ISingleChannelScalingTileAccessor::Options *pOptions)=0
std::shared_ptr< libCZI::IBitmapData > Get(int xPos, int yPos, int width, int height, const IDimCoordinate *planeCoordinate, const Options *pOptions)
Definition: libCZI_Compositor.h:146
The scaling-single-channel-tile accessor (associated interface: ISingleChannelScalingTileAccessor).
float r
The red component.
Definition: libCZI_Pixels.h:120
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:256
float weight
The weight of the channel.
Definition: libCZI_Compositor.h:364
Interface used to represent a coordinate (in the space of the dimensions identified by DimensionIndex...
Definition: libCZI_DimCoordinate.h:54
Definition: libCZI_Compositor.h:66
RgbFloatColor backGroundColor
Definition: libCZI_Compositor.h:249
bool drawTileBorder
Definition: libCZI_Compositor.h:179
This structure defines the tinting color.
Definition: libCZI_Compositor.h:347
The single-channel-tile accessor (associated interface: ISingleChannelTileAccessor).
RgbFloatColor backGroundColor
Definition: libCZI_Compositor.h:76
Options for controlling the composition operation.
Definition: libCZI_Compositor.h:70
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 ...
float g
The green component.
Definition: libCZI_Pixels.h:121
Options used for this accessor.
Definition: libCZI_Compositor.h:243
void Clear()
Clears this object to its blank/initial state.
Definition: libCZI_Compositor.h:318
A rectangle (with integer coordinates).
Definition: libCZI_Pixels.h:32
A structure representing an R-G-B-color triple (as floats).
Definition: libCZI_Pixels.h:118
float blackPoint
Definition: libCZI_Compositor.h:376
External interfaces, classes, functions and structs are found in the namespace "libCZI".
Definition: libCZI.h:44
void Clear()
All members are set to zero.
Definition: libCZI_Compositor.h:396
virtual libCZI::IntSize CalcSize(const libCZI::IntRect &roi, float zoom) const =0
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:157
const std::uint8_t * ptrLookUpTable
Definition: libCZI_Compositor.h:393
float b
The blue component.
Definition: libCZI_Pixels.h:122
A structure representing a size (width and height) in integers.
Definition: libCZI_Pixels.h:103
The single-channel-pyramidlayer-tile accessor (associated interface: ISingleChannelPyramidLayerTileAc...
std::uint8_t minificationFactor
Factor by which adjacent pyramid-layers are shrunk. Commonly used in CZI are 2 or 3...
Definition: libCZI_Compositor.h:200
Options used for this accessor.
Definition: libCZI_Compositor.h:169
bool drawTileBorder
Definition: libCZI_Compositor.h:315
bool enableTinting
Definition: libCZI_Compositor.h:368
TintingColor tinting
The tinting color (only examined if enableTinting is true).
Definition: libCZI_Compositor.h:371
Definition: libCZI_Compositor.h:165
void Clear()
Clears this object to its blank state.
Definition: libCZI_Compositor.h:185
void Clear()
Clears this object to its blank state.
Definition: libCZI_Compositor.h:90