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_Metadata2.h"
33 #include "libCZI_Utilities.h"
34 #include "libCZI_Compositor.h"
35 #include "libCZI_Site.h"
36 
37 #include <functional>
38 #include <memory>
39 #include <map>
40 #include <limits>
41 
42 // virtual d'tor -> https://isocpp.org/wiki/faq/virtual-functions#virtual-dtors
43 
45 namespace libCZI
46 {
50  enum class SiteObjectType
51  {
52  Default,
54 #if defined(_WIN32)
55  , WithWICDecoder
56 #endif
57  };
58 
59  class ISite;
60 
66 
72  LIBCZI_API void SetSiteObject(libCZI::ISite* pSite);
73 
74  class ICZIReader;
75  class IStream;
76  class ISubBlock;
77  class IMetadataSegment;
78  class ISubBlockRepository;
79  class IAttachment;
80 
84  {
87 
89  std::string repositoryUrl;
90 
92  std::string repositoryBranch;
93 
95  std::string repositoryTag;
96  };
97 
102  LIBCZI_API void GetLibCZIVersion(int* pMajor, int* pMinor);
103 
106  LIBCZI_API void GetLibCZIBuildInformation(BuildInformation& info);
107 
110  LIBCZI_API std::shared_ptr<ICZIReader> CreateCZIReader();
111 
115  LIBCZI_API std::shared_ptr<IBitmapData> CreateBitmapFromSubBlock(ISubBlock* subBlk);
116 
120  LIBCZI_API std::shared_ptr<ICziMetadata> CreateMetaFromMetadataSegment(IMetadataSegment* metadataSegment);
121 
126  LIBCZI_API std::shared_ptr<IAccessor> CreateAccesor(std::shared_ptr<ISubBlockRepository> repository, AccessorType accessorType);
127 
132  LIBCZI_API std::shared_ptr<IStream> CreateStreamFromFile(const wchar_t* szFilename);
133 
138  LIBCZI_API std::shared_ptr<IStream> CreateStreamFromMemory(std::shared_ptr<const void> ptr, size_t dataSize);
139 
143  LIBCZI_API std::shared_ptr<IStream> CreateStreamFromMemory(IAttachment* attachment);
144 
145 
146 
149  class IStream
150  {
151  public:
158  virtual void Read(std::uint64_t offset, void *pv, std::uint64_t size, std::uint64_t* ptrBytesRead) = 0;
159 
160  virtual ~IStream() {}
161  };
162 
165  {
177  int mIndex;
178 
183  double GetZoom() const
184  {
185  if (this->physicalSize.w > this->physicalSize.h)
186  {
187  return double(this->physicalSize.w) / this->logicalRect.w;
188  }
189 
190  return double(this->physicalSize.h) / this->logicalRect.h;
191  }
192  };
193 
196  class ISubBlock
197  {
198  public:
201  {
204  Attachment
205  };
206 
209  virtual const SubBlockInfo& GetSubBlockInfo() const = 0;
210 
216  virtual void DangerousGetRawData(MemBlkType type, const void*& ptr, size_t& size) const = 0;
217 
222  virtual std::shared_ptr<const void> GetRawData(MemBlkType type, size_t* ptrSize) = 0;
223 
233  virtual std::shared_ptr<IBitmapData> CreateBitmap() = 0;
234 
235  virtual ~ISubBlock() {};
236 
241  template <class Q>
242  void DangerousGetRawData(MemBlkType type, const Q*& ptr, size_t& size) const
243  {
244  const void* p;
245  this->DangerousGetRawData(type, p, size);
246  ptr = static_cast<Q*>(p);
247  }
248  };
249 
252  {
253  GUID contentGuid;
254  char contentFileType[9];
255  std::string name;
256  };
257 
260  {
261  public:
264  virtual const AttachmentInfo& GetAttachmentInfo() const = 0;
265 
270  virtual void DangerousGetRawData(const void*& ptr, size_t& size) const = 0;
271 
275  virtual std::shared_ptr<const void> GetRawData(size_t* ptrSize) = 0;
276 
277  virtual ~IAttachment() {};
278 
282  template <class Q>
283  void DangerousGetRawData(const Q*& ptr, size_t& size) const
284  {
285  const void* p;
286  this->DangerousGetRawData(p, size);
287  ptr = (Q*)p;
288  }
289  };
290 
293  {
294  public:
297  {
299  Attachment
300  };
301 
306  virtual std::shared_ptr<const void> GetRawData(MemBlkType type, size_t* ptrSize) = 0;
307 
313  virtual void DangerousGetRawData(MemBlkType type, const void*& ptr, size_t& size) const = 0;
314 
315  virtual ~IMetadataSegment() {}
316 
319  std::shared_ptr<ICziMetadata> CreateMetaFromMetadataSegment() { return libCZI::CreateMetaFromMetadataSegment(this); }
320  };
321 
324  {
327 
330  };
331 
334  {
338 
342 
346 
350 
354 
358 
363  std::map<int, BoundingBoxes> sceneBoundingBoxes;
364 
369  bool IsMIndexValid() const
370  {
371  return this->minMindex <= this->maxMindex ? true : false;
372  }
373 
375  void Invalidate()
376  {
377  this->subBlockCount = -1;
378  this->boundingBox.Invalidate();
379  this->boundingBoxLayer0Only.Invalidate();
380  this->dimBounds.Clear();
381  this->sceneBoundingBoxes.clear();
382  this->minMindex = (std::numeric_limits<int>::max)();
383  this->maxMindex = (std::numeric_limits<int>::min)();
384  }
385  };
386 
389  {
400  {
401  std::uint8_t minificationFactor;
402  std::uint8_t pyramidLayerNo;
403 
407  bool IsLayer0() const { return this->minificationFactor == 0 && this->pyramidLayerNo == 0; }
408 
412  bool IsNotIdentifiedAsPyramidLayer() const { return this->minificationFactor == 0xff && this->pyramidLayerNo == 0xff; }
413  };
414 
417  {
419  int count;
420  };
421 
424  std::map<int, std::vector<PyramidLayerStatistics>> scenePyramidStatistics;
425  };
426 
428  class LIBCZI_API ISubBlockRepository
429  {
430  public:
436  virtual void EnumerateSubBlocks(std::function<bool(int index, const SubBlockInfo& info)> funcEnum) = 0;
437 
446  virtual void EnumSubset(const IDimCoordinate* planeCoordinate, const IntRect* roi, bool onlyLayer0, std::function<bool(int index, const SubBlockInfo& info)> funcEnum) = 0;
447 
453  virtual std::shared_ptr<ISubBlock> ReadSubBlock(int index) = 0;
454 
466  virtual bool TryGetSubBlockInfoOfArbitrarySubBlockInChannel(int channelIndex, SubBlockInfo& info) = 0;
467 
470  virtual SubBlockStatistics GetStatistics() = 0;
471 
476  virtual PyramidStatistics GetPyramidStatistics() = 0;
477 
478  virtual ~ISubBlockRepository() {}
479  };
480 
482  class LIBCZI_API IAttachmentRepository
483  {
484  public:
485 
492  virtual void EnumerateAttachments(std::function<bool(int index, const AttachmentInfo& info)> funcEnum) = 0;
493 
501  virtual void EnumerateSubset(const char* contentFileType, const char* name, std::function<bool(int index, const AttachmentInfo& infi)> funcEnum) = 0;
502 
503  virtual ~IAttachmentRepository() {};
504 
510  virtual std::shared_ptr<IAttachment> ReadAttachment(int index) = 0;
511  };
512 
515  {
518  GUID fileGuid;
521  };
522 
525  {
526  public:
534  virtual void Open(std::shared_ptr<IStream> stream) = 0;
535 
538  virtual FileHeaderInfo GetFileHeaderInfo() = 0;
539 
545  virtual std::shared_ptr<IMetadataSegment> ReadMetadataSegment() = 0;
546 
555  virtual std::shared_ptr<IAccessor> CreateAccessor(AccessorType accessorType) = 0;
556 
561  virtual void Close() = 0;
562  public:
565  std::shared_ptr<ISingleChannelTileAccessor> CreateSingleChannelTileAccessor()
566  {
567  return std::dynamic_pointer_cast<ISingleChannelTileAccessor, IAccessor>(this->CreateAccessor(libCZI::AccessorType::SingleChannelTileAccessor));
568  }
569 
572  std::shared_ptr<ISingleChannelPyramidLayerTileAccessor> CreateSingleChannelPyramidLayerTileAccessor()
573  {
575  }
576 
579  std::shared_ptr<ISingleChannelScalingTileAccessor> CreateSingleChannelScalingTileAccessor()
580  {
581  return std::dynamic_pointer_cast<ISingleChannelScalingTileAccessor, IAccessor>(this->CreateAccessor(libCZI::AccessorType::SingleChannelScalingTileAccessor));
582  }
583  };
584 }
585 
586 #include "libCZI_Query.h"
587 #include "libCZI_Helpers.h"
std::string compilerIdentification
The compiler identification. This is a free-form string.
Definition: libCZI.h:86
PixelType
An enum representing a pixel-type.
Definition: libCZI_Pixels.h:127
CompressionMode
An enum specifying the compression method.
Definition: libCZI_Pixels.h:144
LIBCZI_API void SetSiteObject(libCZI::ISite *pSite)
IntRect boundingBoxLayer0Only
Definition: libCZI.h:353
Definition: libCZI_Compositor.h:239
An enum constant representing the bitmap-data.
Definition: libCZI.h:203
LIBCZI_API std::shared_ptr< ICZIReader > CreateCZIReader()
LIBCZI_API std::shared_ptr< ICziMetadata > CreateMetaFromMetadataSegment(IMetadataSegment *metadataSegment)
std::map< int, std::vector< PyramidLayerStatistics > > scenePyramidStatistics
Definition: libCZI.h:424
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:259
std::uint8_t minificationFactor
Factor by which adjacent pyramid-layers are shrunk. Commonly used in CZI are 2 or 3...
Definition: libCZI.h:401
CompressionMode mode
The compression mode of the sub-block.
Definition: libCZI.h:167
void DangerousGetRawData(const Q *&ptr, size_t &size) const
Definition: libCZI.h:283
int maxMindex
Definition: libCZI.h:345
The metadata (in UTF8-XML-format)
Definition: libCZI.h:298
The base interface (all accessor-interface must derive from this).
Definition: libCZI_Compositor.h:45
LIBCZI_API void GetLibCZIBuildInformation(BuildInformation &info)
bool IsLayer0() const
Definition: libCZI.h:407
std::shared_ptr< ISingleChannelPyramidLayerTileAccessor > CreateSingleChannelPyramidLayerTileAccessor()
Definition: libCZI.h:572
bool IsMIndexValid() const
Definition: libCZI.h:369
Interface representing the metadata-segment.
Definition: libCZI.h:292
Implementation of a class representing a coordinate (and implementing the IDimCoordinate-interface).
Definition: libCZI_DimCoordinate.h:160
std::string repositoryTag
The tag or hash of the repository - if available.
Definition: libCZI.h:95
int w
The width of the rectangle.
Definition: libCZI_Pixels.h:37
SiteObjectType
Definition: libCZI.h:50
bool IsNotIdentifiedAsPyramidLayer() const
Definition: libCZI.h:412
Statistics about all sub-blocks found in a CZI-document.
Definition: libCZI.h:333
std::uint32_t h
The height.
Definition: libCZI_Pixels.h:107
int h
The height of the rectangle.
Definition: libCZI_Pixels.h:38
std::uint8_t pyramidLayerNo
The pyramid layer number.
Definition: libCZI.h:402
std::map< int, BoundingBoxes > sceneBoundingBoxes
Definition: libCZI.h:363
void Clear(libCZI::DimensionIndex dimension)
Definition: libCZI_DimCoordinate.h:366
Information about a pyramid-layer.
Definition: libCZI.h:416
std::string repositoryUrl
The URL of the repository - if available.
Definition: libCZI.h:89
AccessorType
Values that represent the accessor types.
Definition: libCZI_Compositor.h:37
std::string repositoryBranch
The branch - if available.
Definition: libCZI.h:92
int minMindex
Definition: libCZI.h:341
std::shared_ptr< ICziMetadata > CreateMetaFromMetadataSegment()
Definition: libCZI.h:319
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:323
Information about an attachment.
Definition: libCZI.h:251
The scaling-single-channel-tile accessor (associated interface: ISingleChannelScalingTileAccessor).
void Invalidate()
Invalidates this object.
Definition: libCZI.h:375
An enum constant representing the metadata.
Definition: libCZI.h:202
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:337
libCZI::IntSize physicalSize
The physical size of the bitmap (which may be different to the size of logicalRect).
Definition: libCZI.h:175
Definition: libCZI_Compositor.h:66
PyramidLayerInfo layerInfo
This identifies the pyramid-layer.
Definition: libCZI.h:418
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:177
IntRect boundingBoxLayer0
The bounding-boxes determined only from sub-blocks of pyramid-layer 0.
Definition: libCZI.h:329
The single-channel-tile accessor (associated interface: ISingleChannelTileAccessor).
std::shared_ptr< ISingleChannelTileAccessor > CreateSingleChannelTileAccessor()
Definition: libCZI.h:565
CDimBounds dimBounds
Definition: libCZI.h:357
Definition: libCZI_Site.h:69
Global information about the CZI-file (from the CZI-fileheader-segment).
Definition: libCZI.h:514
void DangerousGetRawData(MemBlkType type, const Q *&ptr, size_t &size) const
Definition: libCZI.h:242
Implementation of a class representing an interval (and implementing the libCZI::IDimBounds-interface...
Definition: libCZI_DimCoordinate.h:299
void Invalidate()
Invalidates this object.
Definition: libCZI_Pixels.h:41
A rectangle (with integer coordinates).
Definition: libCZI_Pixels.h:33
int minorVersion
The minor version.
Definition: libCZI.h:520
libCZI::CDimCoordinate coordinate
The coordinate of the sub-block.
Definition: libCZI.h:171
External interfaces, classes, functions and structs are found in the namespace "libCZI".
Definition: libCZI.h:45
An enum constant representing a Site-object using the internal JXRLib.
This interface is used to represent the CZI-file.
Definition: libCZI.h:524
LIBCZI_API ISite * GetDefaultSiteObject(libCZI::SiteObjectType type)
Definition: libCZI.h:149
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)
std::shared_ptr< ISingleChannelScalingTileAccessor > CreateSingleChannelScalingTileAccessor()
Definition: libCZI.h:579
PixelType pixelType
The pixel type of the sub-block.
Definition: libCZI.h:169
Definition: libCZI.h:196
MemBlkType
Values that represent the two different data types found in the metadata-segment. ...
Definition: libCZI.h:296
A structure representing a size (width and height) in integers.
Definition: libCZI_Pixels.h:104
MemBlkType
Values that represent the three different data types found in a sub-block.
Definition: libCZI.h:200
The single-channel-pyramidlayer-tile accessor (associated interface: ISingleChannelPyramidLayerTileAc...
Interface for the attachment repository. This interface is used to access the attachments in a CZI-fi...
Definition: libCZI.h:482
Interface for sub-block repository. This interface is used to access the sub-blocks in a CZI-file...
Definition: libCZI.h:428
int count
The number of sub-blocks which are present in the pyramid-layer.
Definition: libCZI.h:419
int majorVersion
The major version.
Definition: libCZI.h:519
GUID fileGuid
Definition: libCZI.h:518
Statistics about the pyramid-layers.
Definition: libCZI.h:388
LIBCZI_API std::shared_ptr< IStream > CreateStreamFromMemory(std::shared_ptr< const void > ptr, size_t dataSize)
IntRect boundingBox
The bounding-box determined from all sub-blocks.
Definition: libCZI.h:326
std::string name
A string identifying the content of the attachment.
Definition: libCZI.h:255
Definition: libCZI_Compositor.h:165
IntRect boundingBox
Definition: libCZI.h:349
Information about a sub-block.
Definition: libCZI.h:164
libCZI::IntRect logicalRect
The rectangle where the bitmap (in this sub-block) is located.
Definition: libCZI.h:173
GUID contentGuid
A Guid identifying the content of the attachment.
Definition: libCZI.h:253
Definition: libCZI.h:83
double GetZoom() const
Definition: libCZI.h:183
std::uint32_t w
The width.
Definition: libCZI_Pixels.h:106