MeshLib C++ Docs
Loading...
Searching...
No Matches
MRTiffIO.h
Go to the documentation of this file.
1#pragma once
2#include "MRMeshFwd.h"
3#if !defined( __EMSCRIPTEN__) && !defined( MRMESH_NO_TIFF )
4#include "MRExpected.h"
5#include "MRVector2.h"
6
7#include <filesystem>
8#include <string>
9
10namespace MR
11{
12
13struct BaseTiffParameters
14{
15 enum class SampleType
16 {
17 Unknown,
18 Uint,
19 Int,
20 Float
21 } sampleType{ SampleType::Unknown };
22
23 enum class ValueType
24 {
25 Unknown,
26 Scalar,
27 RGB,
28 RGBA,
29 } valueType{ ValueType::Unknown };
30
31 // size of internal data in file
32 int bytesPerSample = 0;
33
34 // size of image if not layered, otherwise size of layer
35 Vector2i imageSize;
36
37 bool operator==( const BaseTiffParameters& ) const = default;
38};
39
40struct TiffParameters : BaseTiffParameters
41{
42 // true if tif file is tiled
43 bool tiled = false;
44 Vector2i tileSize;
45 int layers = 1;
46 // tile depth (if several layers)
47 int depth = 0;
48
49 bool operator==( const TiffParameters& ) const = default;
50};
51
52// returns true if given file is tiff
53MRMESH_API bool isTIFFFile( const std::filesystem::path& path );
54
55// reads parameters of tiff file
56MRMESH_API Expected<TiffParameters> readTiffParameters( const std::filesystem::path& path );
57
58struct RawTiffOutput
59{
60 // main output data, should be allocated
61 uint8_t* bytes{ nullptr };
62 // allocated data size
63 size_t size{ 0 };
64 // optional params output
65 TiffParameters* params{ nullptr };
66 // optional pixel to world transform
67 AffineXf3f* p2wXf{ nullptr };
68 // input if true loads tiff file as floats array
69 bool convertToFloat{ true };
70 // min max
71 float* min{ nullptr };
72 float* max{ nullptr };
73};
74
75// load values from tiff to ouput.data
76MRMESH_API Expected<void> readRawTiff( const std::filesystem::path& path, RawTiffOutput& output );
77
79{
80 BaseTiffParameters baseParams;
81 // optional transformation data written to GeoTIFF's ModelTransformationTag
82 const AffineXf3f* xf = nullptr;
83 // optional NoData value written to GDAL_NODATA
84 std::string noData;
85};
86
87// writes bytes to tiff file
88MRMESH_API Expected<void> writeRawTiff( const uint8_t* bytes, const std::filesystem::path& path,
89 const WriteRawTiffParams& params );
90[[deprecated( "use WriteRawTiffParams version instead" )]]
91inline Expected<void> writeRawTiff( const uint8_t* bytes, const std::filesystem::path& path,
92 const BaseTiffParameters& params, const AffineXf3f* xf )
93{
94 return writeRawTiff( bytes, path, { .baseParams = params, .xf = xf } );
95}
96
97}
98
99#endif
#define MRMESH_API
Definition MRMeshFwd.h:80
Definition MRTiffIO.h:14
Definition MRTiffIO.h:59
unsafe TiffParameters()
Definition MRTiffIO.h:79
Definition MRCameraOrientationPlugin.h:8
MRMESH_API Expected< void > readRawTiff(const std::filesystem::path &path, RawTiffOutput &output)
MRMESH_API bool isTIFFFile(const std::filesystem::path &path)
MRMESH_API Expected< TiffParameters > readTiffParameters(const std::filesystem::path &path)
MRMESH_API Expected< void > writeRawTiff(const uint8_t *bytes, const std::filesystem::path &path, const WriteRawTiffParams &params)