libCZI
Reading CZI documents made easy
libCZI_Utilities.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 "libCZI_Metadata.h"
26 
27 namespace libCZI
28 {
29  class ISubBlockRepository;
30  class IDisplaySettings;
31 
33  class LIBCZI_API Utils
34  {
35  public:
42  static char DimensionToChar(libCZI::DimensionIndex dim);
43 
51  static libCZI::DimensionIndex CharToDimension(char c);
52 
58  static int CalcMd5SumHash(libCZI::IBitmapData* bm, std::uint8_t* ptrHash, int hashSize);
59 
66  static int CalcMd5SumHash(const void* ptrData, size_t sizeData, std::uint8_t* ptrHash, int hashSize);
67 
76  static std::vector<std::uint8_t> Create8BitLookUpTableFromSplines(int tableElementCnt, float blackPoint, float whitePoint, const std::vector<libCZI::IDisplaySettings::SplineData>& splineData);
77 
87  static std::vector<std::uint8_t> Create8BitLookUpTableFromGamma(int tableElementCnt, float blackPoint, float whitePoint, float gamma);
88 
93  static std::vector<libCZI::IDisplaySettings::SplineData> CalcSplineDataFromPoints(int pointCnt, std::function< std::tuple<double, double>(int idx)> getPoint);
94 
100  static std::shared_ptr<libCZI::IBitmapData > NearestNeighborResize(libCZI::IBitmapData* bmSrc, int dstWidth, int dstHeight);
101 
109  static std::shared_ptr<libCZI::IBitmapData > NearestNeighborResize(libCZI::IBitmapData* bmSrc, int dstWidth, int dstHeight, const DblRect& roiSrc, const DblRect& roiDest);
110 
117  static float CalcZoom(const libCZI::IntRect& logicalRect, const libCZI::IntSize& physicalSize)
118  {
119  if (physicalSize.w > physicalSize.h)
120  {
121  return float(physicalSize.w) / logicalRect.w;
122  }
123  else
124  {
125  return float(physicalSize.h) / logicalRect.h;
126  }
127  }
128 
135  static float CalcZoom(const libCZI::IntSize& logicalSize, const libCZI::IntSize& physicalSize)
136  {
137  if (physicalSize.w > physicalSize.h)
138  {
139  return float(physicalSize.w) / logicalSize.w;
140  }
141  else
142  {
143  return float(physicalSize.h) / logicalSize.h;
144  }
145  }
146 
152  static const char* PixelTypeToInformalString(libCZI::PixelType pixeltype);
153 
159  static const char* CompressionModeToInformalString(libCZI::CompressionMode compressionMode);
160 
164  static std::string DimCoordinateToString(const libCZI::IDimCoordinate* coord);
165 
170  static bool StringToDimCoordinate(const char* sz, libCZI::CDimCoordinate* coord);
171 
175  static std::string DimBoundsToString(const libCZI::IDimBounds* bounds);
176 
184  static std::shared_ptr<libCZI::IIndexSet> IndexSetFromString(const std::wstring& s);
185 
194  static libCZI::PixelType TryDeterminePixelTypeForChannel(libCZI::ISubBlockRepository* repository, int channelIdx);
195 
206  static int Compare(const IDimCoordinate* a, const IDimCoordinate* b);
207 
214  static bool HasSameDimensions(const IDimCoordinate* a, const IDimCoordinate* b);
215 
224  static bool EnumAllCoordinates(const libCZI::CDimBounds& bounds, const std::function<bool(std::uint64_t, const libCZI::CDimCoordinate& coord)>& func);
225 
229  static void FillBitmap(libCZI::IBitmapData* bm, const libCZI::RgbFloatColor& floatColor);
230  };
231 }
PixelType
An enum representing a pixel-type.
Definition: libCZI_Pixels.h:127
A rectangle (with double coordinates).
Definition: libCZI_Pixels.h:92
Definition: libCZI_Pixels.h:167
CompressionMode
An enum specifying the compression method.
Definition: libCZI_Pixels.h:144
Interface used to represent an interval (for several dimensions).
Definition: libCZI_DimCoordinate.h:95
Implementation of a class representing a coordinate (and implementing the IDimCoordinate-interface).
Definition: libCZI_DimCoordinate.h:160
int w
The width of the rectangle.
Definition: libCZI_Pixels.h:37
std::uint32_t h
The height.
Definition: libCZI_Pixels.h:107
int h
The height of the rectangle.
Definition: libCZI_Pixels.h:38
A bunch of utility functions.
Definition: libCZI_Utilities.h:33
Interface used to represent a coordinate (in the space of the dimensions identified by DimensionIndex...
Definition: libCZI_DimCoordinate.h:54
Implementation of a class representing an interval (and implementing the libCZI::IDimBounds-interface...
Definition: libCZI_DimCoordinate.h:299
static float CalcZoom(const libCZI::IntRect &logicalRect, const libCZI::IntSize &physicalSize)
Definition: libCZI_Utilities.h:117
A rectangle (with integer coordinates).
Definition: libCZI_Pixels.h:33
A structure representing an R-G-B-color triple (as floats).
Definition: libCZI_Pixels.h:119
External interfaces, classes, functions and structs are found in the namespace "libCZI".
Definition: libCZI.h:45
DimensionIndex
Values that represent dimension indexes.
Definition: libCZI_DimCoordinate.h:34
A structure representing a size (width and height) in integers.
Definition: libCZI_Pixels.h:104
Interface for sub-block repository. This interface is used to access the sub-blocks in a CZI-file...
Definition: libCZI.h:428
static float CalcZoom(const libCZI::IntSize &logicalSize, const libCZI::IntSize &physicalSize)
Definition: libCZI_Utilities.h:135
std::uint32_t w
The width.
Definition: libCZI_Pixels.h:106