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 namespace libCZI
26 {
27  class ISubBlockRepository;
28 
30  class LIBCZI_API Utils
31  {
32  public:
39  static char DimensionToChar(libCZI::DimensionIndex dim);
40 
48  static libCZI::DimensionIndex CharToDimension(char c);
49 
55  static int CalcMd5SumHash(libCZI::IBitmapData* bm, std::uint8_t* ptrHash, int hashSize);
56 
63  static int CalcMd5SumHash(const void* ptrData, size_t sizeData, std::uint8_t* ptrHash, int hashSize);
64 
73  static std::vector<std::uint8_t> Create8BitLookUpTableFromSplines(int tableElementCnt, float blackPoint, float whitePoint, const std::vector<libCZI::IDisplaySettings::SplineData>& splineData);
74 
84  static std::vector<std::uint8_t> Create8BitLookUpTableFromGamma(int tableElementCnt, float blackPoint, float whitePoint, float gamma);
85 
90  static std::vector<libCZI::IDisplaySettings::SplineData> CalcSplineDataFromPoints(int pointCnt, std::function< std::tuple<double, double>(int idx)> getPoint);
91 
97  static std::shared_ptr<libCZI::IBitmapData > NearestNeighborResize(libCZI::IBitmapData* bmSrc, int dstWidth, int dstHeight);
98 
106  static std::shared_ptr<libCZI::IBitmapData > NearestNeighborResize(libCZI::IBitmapData* bmSrc, int dstWidth, int dstHeight, const DblRect& roiSrc, const DblRect& roiDest);
107 
114  static float CalcZoom(const libCZI::IntRect& logigalRect, const libCZI::IntSize& physicalSize)
115  {
116  if (physicalSize.w > physicalSize.h)
117  {
118  return float(physicalSize.w) / logigalRect.w;
119  }
120  else
121  {
122  return float(physicalSize.h) / logigalRect.h;
123  }
124  }
125 
131  static const char* PixelTypeToInformalString(libCZI::PixelType pxltp);
132 
136  static std::string DimCoordinateToString(const libCZI::IDimCoordinate* coord);
137 
145  static std::shared_ptr<libCZI::IIndexSet> IndexSetFromString(const std::wstring& s);
146 
155  static libCZI::PixelType TryDeterminePixelTypeForChannel(libCZI::ISubBlockRepository* repository, int channelIdx);
156  };
157 }
PixelType
An enum representing a pixel-type.
Definition: libCZI_Pixels.h:126
A rectangle (with double coordinates).
Definition: libCZI_Pixels.h:91
Definition: libCZI_Pixels.h:166
int w
The width of the rectangle.
Definition: libCZI_Pixels.h:36
std::uint32_t h
The height.
Definition: libCZI_Pixels.h:106
int h
The height of the rectangle.
Definition: libCZI_Pixels.h:37
A bunch of utility functions.
Definition: libCZI_Utilities.h:30
Interface used to represent a coordinate (in the space of the dimensions identified by DimensionIndex...
Definition: libCZI_DimCoordinate.h:54
A rectangle (with integer coordinates).
Definition: libCZI_Pixels.h:32
External interfaces, classes, functions and structs are found in the namespace "libCZI".
Definition: libCZI.h:44
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:103
static float CalcZoom(const libCZI::IntRect &logigalRect, const libCZI::IntSize &physicalSize)
Definition: libCZI_Utilities.h:114
Interface for sub-block repository. This interface is used to access the sub-blocks in a CZI-file...
Definition: libCZI.h:391
std::uint32_t w
The width.
Definition: libCZI_Pixels.h:105