libCZI
Reading CZI documents made easy
libCZI.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 
27 #include "priv_guiddef.h"
28 #include "libCZI_exceptions.h"
29 #include "libCZI_DimCoordinate.h"
30 #include "libCZI_Pixels.h"
31 #include "libCZI_Metadata.h"
32 #include "libCZI_Utilities.h"
33 #include "libCZI_Compositor.h"
34 #include "libCZI_Site.h"
35 
36 #include <functional>
37 #include <memory>
38 #include <map>
39 #include <limits>
40 
41 // virtual d'tor -> https://isocpp.org/wiki/faq/virtual-functions#virtual-dtors
42 
44 namespace libCZI
45 {
49  enum class SiteObjectType
50  {
51  Default,
53 #if defined(_WIN32)
54  , WithWICDecoder
55 #endif
56  };
57 
58  class ISite;
59 
64  LIBCZI_API ISite* GetDefaultSiteObject(libCZI::SiteObjectType type);
65 
71  LIBCZI_API void SetSiteObject(libCZI::ISite* pSite);
72 
73  class ICZIReader;
74  class IStream;
75  class ISubBlock;
76  class IMetadataSegment;
77  class ISubBlockRepository;
78 
83  LIBCZI_API void GetLibCZIVersion(int* pMajor, int* pMinor);
84 
87  LIBCZI_API std::shared_ptr<ICZIReader> CreateCZIReader();
88 
92  LIBCZI_API std::shared_ptr<IBitmapData> CreateBitmapFromSubBlock(ISubBlock* subBlk);
93 
97  LIBCZI_API std::shared_ptr<ICziMetadata> CreateMetaFromMetadataSegment(IMetadataSegment* metadataSegment);
98 
103  LIBCZI_API std::shared_ptr<IAccessor> CreateAccesor(std::shared_ptr<ISubBlockRepository> repository, AccessorType accessorType);
104 
109  LIBCZI_API std::shared_ptr<IStream> CreateStreamFromFile(const wchar_t* szFilename);
110 
111 
114  class IStream
115  {
116  public:
123  virtual void Read(std::uint64_t offset, void *pv, std::uint64_t size, std::uint64_t* ptrBytesRead) = 0;
124 
125  virtual ~IStream() {}
126  };
127 
130  {
142  int mIndex;
143 
148  double GetZoom() const
149  {
150  if (this->physicalSize.w > this->physicalSize.h)
151  {
152  return double(this->physicalSize.w) / this->logicalRect.w;
153  }
154 
155  return double(this->physicalSize.h) / this->logicalRect.h;
156  }
157  };
158 
161  class ISubBlock
162  {
163  public:
166  {
170  };
171 
174  virtual const SubBlockInfo& GetSubBlockInfo() const = 0;
175 
181  virtual void DangerousGetRawData(MemBlkType type, const void*& ptr, size_t& size) const = 0;
182 
187  virtual std::shared_ptr<const void> GetRawData(MemBlkType type, size_t* ptrSize) = 0;
188 
198  virtual std::shared_ptr<IBitmapData> CreateBitmap() = 0;
199 
200  virtual ~ISubBlock() {};
201 
206  template <class Q>
207  void DangerousGetRawData(MemBlkType type, const Q*& ptr, size_t& size) const
208  {
209  const void* p;
210  this->DangerousGetRawData(type, p, size);
211  ptr = (Q*)p;
212  }
213  };
214 
217  {
218  GUID contentGuid;
219  char contentFileType[9];
220  std::string name;
221  };
222 
225  {
226  public:
229  virtual const AttachmentInfo& GetAttachmentInfo() const = 0;
230 
235  virtual void DangerousGetRawData(const void*& ptr, size_t& size) const = 0;
236 
240  virtual std::shared_ptr<const void> GetRawData(size_t* ptrSize) = 0;
241 
245  template <class Q>
246  void DangerousGetRawData(const Q*& ptr, size_t& size) const
247  {
248  const void* p;
249  this->DangerousGetRawData(p, size);
250  ptr = (Q*)p;
251  }
252  };
253 
256  {
257  public:
260  {
263  };
264 
269  virtual std::shared_ptr<const void> GetRawData(MemBlkType type, size_t* ptrSize) = 0;
270 
276  virtual void DangerousGetRawData(MemBlkType type, const void*& ptr, size_t& size) const = 0;
277 
278  virtual ~IMetadataSegment() {}
279 
282  std::shared_ptr<ICziMetadata> CreateMetaFromMetadataSegment() { return libCZI::CreateMetaFromMetadataSegment(this); }
283  };
284 
287  {
290 
293  };
294 
297  {
301 
305 
309 
313 
317 
321 
326  std::map<int, BoundingBoxes> sceneBoundingBoxes;
327 
332  bool IsMIndexValid() const
333  {
334  return this->minMindex < this->maxMindex ? true : false;
335  }
336 
338  void Invalidate()
339  {
340  this->subBlockCount = -1;
341  this->boundingBox.Invalidate();
342  this->boundingBoxLayer0Only.Invalidate();
343  this->dimBounds.Clear();
344  this->sceneBoundingBoxes.clear();
345  this->minMindex = (std::numeric_limits<int>::max)();
346  this->maxMindex = (std::numeric_limits<int>::min)();
347  }
348  };
349 
352  {
363  {
364  std::uint8_t minificationFactor;
365  std::uint8_t pyramidLayerNo;
366 
370  bool IsLayer0() const { return this->minificationFactor == 0 && this->pyramidLayerNo == 0; }
371 
375  bool IsNotIdentifiedAsPyramidLayer() const { return this->minificationFactor == 0xff && this->pyramidLayerNo == 0xff; }
376  };
377 
380  {
382  int count;
383  };
384 
387  std::map<int, std::vector<PyramidLayerStatistics>> scenePyramidStatistics;
388  };
389 
392  {
393  public:
399  virtual void EnumerateSubBlocks(std::function<bool(int index, const SubBlockInfo& info)> funcEnum) = 0;
400 
409  virtual void EnumSubset(const IDimCoordinate* planeCoordinate, const IntRect* roi, bool onlyLayer0, std::function<bool(int index, const SubBlockInfo& info)> funcEnum) = 0;
410 
416  virtual std::shared_ptr<ISubBlock> ReadSubBlock(int index) = 0;
417 
429  virtual bool TryGetSubBlockInfoOfArbitrarySubBlockInChannel(int channelIndex, SubBlockInfo& info) = 0;
430 
433  virtual SubBlockStatistics GetStatistics() = 0;
434 
440 
441  virtual ~ISubBlockRepository() {}
442  };
443 
446  {
447  public:
448 
455  virtual void EnumerateAttachments(std::function<bool(int index, const AttachmentInfo& info)> funcEnum) = 0;
456 
464  virtual void EnumerateSubset(const char* contentFileType, const char* name, std::function<bool(int index, const AttachmentInfo& infi)> funcEnum) = 0;
465 
471  virtual std::shared_ptr<IAttachment> ReadAttachment(int index) = 0;
472  };
473 
476  {
477  public:
485  virtual void Open(std::shared_ptr<IStream> stream) = 0;
486 
492  virtual std::shared_ptr<IMetadataSegment> ReadMetadataSegment() = 0;
493 
502  virtual std::shared_ptr<IAccessor> CreateAccessor(AccessorType accessorType) = 0;
503 
508  virtual void Close() = 0;
509  public:
512  std::shared_ptr<ISingleChannelTileAccessor> CreateSingleChannelTileAccessor()
513  {
515  }
516 
519  std::shared_ptr<ISingleChannelPyramidLayerTileAccessor> CreateSingleChannelPyramidLayerTileAccessor()
520  {
522  }
523 
526  std::shared_ptr<ISingleChannelScalingTileAccessor> CreateSingleChannelScalingTileAccessor()
527  {
529  }
530  };
531 }
532 
533 #include "libCZI_Helpers.h"
PixelType
An enum representing a pixel-type.
Definition: libCZI_Pixels.h:126
CompressionMode
An enum specifying the compression method.
Definition: libCZI_Pixels.h:143
LIBCZI_API void SetSiteObject(libCZI::ISite *pSite)
IntRect boundingBoxLayer0Only
Definition: libCZI.h:316
Definition: libCZI_Compositor.h:239
An enum constant representing the bitmap-data.
Definition: libCZI.h:168
LIBCZI_API std::shared_ptr< ICZIReader > CreateCZIReader()
LIBCZI_API std::shared_ptr< ICziMetadata > CreateMetaFromMetadataSegment(IMetadataSegment *metadataSegment)
virtual void DangerousGetRawData(const void *&ptr, size_t &size) const =0
std::map< int, std::vector< PyramidLayerStatistics > > scenePyramidStatistics
Definition: libCZI.h:387
LIBCZI_API std::shared_ptr< IStream > CreateStreamFromFile(const wchar_t *szFilename)
Representation of an attachment. An attachment is a binary blob, its inner structure is opaque...
Definition: libCZI.h:224
std::uint8_t minificationFactor
Factor by which adjacent pyramid-layers are shrunk. Commonly used in CZI are 2 or 3...
Definition: libCZI.h:364
CompressionMode mode
The compression mode of the sub-block.
Definition: libCZI.h:132
void DangerousGetRawData(const Q *&ptr, size_t &size) const
Definition: libCZI.h:246
int maxMindex
Definition: libCZI.h:308
The metadata (in UTF8-XML-format)
Definition: libCZI.h:261
The base interface (all accessor-interface must derive from this).
Definition: libCZI_Compositor.h:45
bool IsLayer0() const
Definition: libCZI.h:370
virtual std::shared_ptr< const void > GetRawData(size_t *ptrSize)=0
std::shared_ptr< ISingleChannelPyramidLayerTileAccessor > CreateSingleChannelPyramidLayerTileAccessor()
Definition: libCZI.h:519
bool IsMIndexValid() const
Definition: libCZI.h:332
Interface representing the metadata-segment.
Definition: libCZI.h:255
Implementation of a class representing a coordinate (and implementing the IDimCoordinate-interface).
Definition: libCZI_DimCoordinate.h:143
int w
The width of the rectangle.
Definition: libCZI_Pixels.h:36
SiteObjectType
Definition: libCZI.h:49
bool IsNotIdentifiedAsPyramidLayer() const
Definition: libCZI.h:375
Statistics about all sub-blocks found in a CZI-document.
Definition: libCZI.h:296
std::uint32_t h
The height.
Definition: libCZI_Pixels.h:106
virtual void DangerousGetRawData(MemBlkType type, const void *&ptr, size_t &size) const =0
int h
The height of the rectangle.
Definition: libCZI_Pixels.h:37
virtual bool TryGetSubBlockInfoOfArbitrarySubBlockInChannel(int channelIndex, SubBlockInfo &info)=0
std::uint8_t pyramidLayerNo
The pyramid layer number.
Definition: libCZI.h:365
std::map< int, BoundingBoxes > sceneBoundingBoxes
Definition: libCZI.h:326
void Clear(libCZI::DimensionIndex dimension)
Definition: libCZI_DimCoordinate.h:303
Information about a pyramid-layer.
Definition: libCZI.h:379
virtual std::shared_ptr< ISubBlock > ReadSubBlock(int index)=0
virtual void Read(std::uint64_t offset, void *pv, std::uint64_t size, std::uint64_t *ptrBytesRead)=0
AccessorType
Values that represent the accessor types.
Definition: libCZI_Compositor.h:37
int minMindex
Definition: libCZI.h:304
std::shared_ptr< ICziMetadata > CreateMetaFromMetadataSegment()
Definition: libCZI.h:282
An enum constant representing the default option (which is JXRLib)
This structure gathers the bounding-boxes determined from all sub-blocks and only be those on pyramid...
Definition: libCZI.h:286
Information about an attachment.
Definition: libCZI.h:216
The attachment (not currently used).
Definition: libCZI.h:262
The scaling-single-channel-tile accessor (associated interface: ISingleChannelScalingTileAccessor).
void Invalidate()
Invalidates this object.
Definition: libCZI.h:338
An enum constant representing the metadata.
Definition: libCZI.h:167
Interface used to represent a coordinate (in the space of the dimensions identified by DimensionIndex...
Definition: libCZI_DimCoordinate.h:54
int subBlockCount
Definition: libCZI.h:300
virtual SubBlockStatistics GetStatistics()=0
virtual void EnumerateSubBlocks(std::function< bool(int index, const SubBlockInfo &info)> funcEnum)=0
libCZI::IntSize physicalSize
The physical size of the bitmap (which may be different to the size of logicalRect).
Definition: libCZI.h:140
Definition: libCZI_Compositor.h:66
PyramidLayerInfo layerInfo
This identifies the pyramid-layer.
Definition: libCZI.h:381
int mIndex
The M-index of the sub-block (if available). If not available, it has the value std::numeric_limits<i...
Definition: libCZI.h:142
IntRect boundingBoxLayer0
The bounding-boxes determined only from sub-blocks of pyramid-layer 0.
Definition: libCZI.h:292
char contentFileType[9]
A null-terminated character array identifying the content of the attachment.
Definition: libCZI.h:219
The single-channel-tile accessor (associated interface: ISingleChannelTileAccessor).
std::shared_ptr< ISingleChannelTileAccessor > CreateSingleChannelTileAccessor()
Definition: libCZI.h:512
CDimBounds dimBounds
Definition: libCZI.h:320
virtual void EnumerateSubset(const char *contentFileType, const char *name, std::function< bool(int index, const AttachmentInfo &infi)> funcEnum)=0
virtual const SubBlockInfo & GetSubBlockInfo() const =0
Definition: libCZI_Site.h:67
void DangerousGetRawData(MemBlkType type, const Q *&ptr, size_t &size) const
Definition: libCZI.h:207
Implementation of a class representing an interval (and implementing the libCZI::IDimBounds-interface...
Definition: libCZI_DimCoordinate.h:254
virtual std::shared_ptr< IMetadataSegment > ReadMetadataSegment()=0
virtual std::shared_ptr< const void > GetRawData(MemBlkType type, size_t *ptrSize)=0
virtual void EnumSubset(const IDimCoordinate *planeCoordinate, const IntRect *roi, bool onlyLayer0, std::function< bool(int index, const SubBlockInfo &info)> funcEnum)=0
virtual std::shared_ptr< const void > GetRawData(MemBlkType type, size_t *ptrSize)=0
void Invalidate()
Invalidates this object.
Definition: libCZI_Pixels.h:40
virtual void EnumerateAttachments(std::function< bool(int index, const AttachmentInfo &info)> funcEnum)=0
A rectangle (with integer coordinates).
Definition: libCZI_Pixels.h:32
libCZI::CDimCoordinate coordinate
The coordinate of the sub-block.
Definition: libCZI.h:136
External interfaces, classes, functions and structs are found in the namespace "libCZI".
Definition: libCZI.h:44
An enum constant representing a Site-object using the internal JXRLib.
virtual std::shared_ptr< IBitmapData > CreateBitmap()=0
This interface is used to represent the CZI-file.
Definition: libCZI.h:475
LIBCZI_API ISite * GetDefaultSiteObject(libCZI::SiteObjectType type)
Definition: libCZI.h:114
LIBCZI_API void GetLibCZIVersion(int *pMajor, int *pMinor)
LIBCZI_API std::shared_ptr< IBitmapData > CreateBitmapFromSubBlock(ISubBlock *subBlk)
LIBCZI_API std::shared_ptr< IAccessor > CreateAccesor(std::shared_ptr< ISubBlockRepository > repository, AccessorType accessorType)
virtual void Close()=0
std::shared_ptr< ISingleChannelScalingTileAccessor > CreateSingleChannelScalingTileAccessor()
Definition: libCZI.h:526
PixelType pixelType
The pixel type of the sub-block.
Definition: libCZI.h:134
virtual const AttachmentInfo & GetAttachmentInfo() const =0
Definition: libCZI.h:161
MemBlkType
Values that represent the two different data types found in the metadata-segment. ...
Definition: libCZI.h:259
A structure representing a size (width and height) in integers.
Definition: libCZI_Pixels.h:103
virtual std::shared_ptr< IAttachment > ReadAttachment(int index)=0
MemBlkType
Values that represent the three different data types found in a sub-block.
Definition: libCZI.h:165
The single-channel-pyramidlayer-tile accessor (associated interface: ISingleChannelPyramidLayerTileAc...
virtual void Open(std::shared_ptr< IStream > stream)=0
Interface for the attachment repository. This interface is used to access the attachments in a CZI-fi...
Definition: libCZI.h:445
Interface for sub-block repository. This interface is used to access the sub-blocks in a CZI-file...
Definition: libCZI.h:391
virtual PyramidStatistics GetPyramidStatistics()=0
int count
The number of sub-blocks which are present in the pyramid-layer.
Definition: libCZI.h:382
Statistics about the pyramid-layers.
Definition: libCZI.h:351
IntRect boundingBox
The bounding-box determined from all sub-blocks.
Definition: libCZI.h:289
An enum constant representing the attachment (of a sub-block).
Definition: libCZI.h:169
std::string name
A string identifying the content of the attachment.
Definition: libCZI.h:220
Definition: libCZI_Compositor.h:165
IntRect boundingBox
Definition: libCZI.h:312
Information about a sub-block.
Definition: libCZI.h:129
virtual std::shared_ptr< IAccessor > CreateAccessor(AccessorType accessorType)=0
virtual void DangerousGetRawData(MemBlkType type, const void *&ptr, size_t &size) const =0
libCZI::IntRect logicalRect
The rectangle where the bitmap (in this sub-block) is located.
Definition: libCZI.h:138
GUID contentGuid
A Guid identifying the content of the attachment.
Definition: libCZI.h:218
double GetZoom() const
Definition: libCZI.h:148
std::uint32_t w
The width.
Definition: libCZI_Pixels.h:105