Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/imgcodecs/src/grfmt_tiff.hpp
16337 views
1
/*M///////////////////////////////////////////////////////////////////////////////////////
2
//
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
//
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
8
//
9
//
10
// License Agreement
11
// For Open Source Computer Vision Library
12
//
13
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
16
//
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
19
//
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
22
//
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
26
//
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
29
//
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
40
//
41
//M*/
42
43
#ifndef _GRFMT_TIFF_H_
44
#define _GRFMT_TIFF_H_
45
46
#include "grfmt_base.hpp"
47
48
#ifdef HAVE_TIFF
49
50
namespace cv
51
{
52
53
// native simple TIFF codec
54
enum TiffCompression
55
{
56
TIFF_UNCOMP = 1,
57
TIFF_HUFFMAN = 2,
58
TIFF_PACKBITS = 32773
59
};
60
61
enum TiffByteOrder
62
{
63
TIFF_ORDER_II = 0x4949,
64
TIFF_ORDER_MM = 0x4d4d
65
};
66
67
68
enum TiffTag
69
{
70
TIFF_TAG_WIDTH = 256,
71
TIFF_TAG_HEIGHT = 257,
72
TIFF_TAG_BITS_PER_SAMPLE = 258,
73
TIFF_TAG_COMPRESSION = 259,
74
TIFF_TAG_PHOTOMETRIC = 262,
75
TIFF_TAG_STRIP_OFFSETS = 273,
76
TIFF_TAG_STRIP_COUNTS = 279,
77
TIFF_TAG_SAMPLES_PER_PIXEL = 277,
78
TIFF_TAG_ROWS_PER_STRIP = 278,
79
TIFF_TAG_PLANAR_CONFIG = 284,
80
TIFF_TAG_COLOR_MAP = 320
81
};
82
83
84
enum TiffFieldType
85
{
86
TIFF_TYPE_BYTE = 1,
87
TIFF_TYPE_SHORT = 3,
88
TIFF_TYPE_LONG = 4
89
};
90
91
92
// libtiff based TIFF codec
93
class TiffDecoder CV_FINAL : public BaseImageDecoder
94
{
95
public:
96
TiffDecoder();
97
virtual ~TiffDecoder() CV_OVERRIDE;
98
99
bool readHeader() CV_OVERRIDE;
100
bool readData( Mat& img ) CV_OVERRIDE;
101
void close();
102
bool nextPage() CV_OVERRIDE;
103
104
size_t signatureLength() const CV_OVERRIDE;
105
bool checkSignature( const String& signature ) const CV_OVERRIDE;
106
ImageDecoder newDecoder() const CV_OVERRIDE;
107
108
protected:
109
void* m_tif;
110
int normalizeChannelsNumber(int channels) const;
111
bool readData_32FC3(Mat& img);
112
bool readData_32FC1(Mat& img);
113
bool m_hdr;
114
size_t m_buf_pos;
115
116
private:
117
TiffDecoder(const TiffDecoder &); // copy disabled
118
TiffDecoder& operator=(const TiffDecoder &); // assign disabled
119
};
120
121
// ... and writer
122
class TiffEncoder CV_FINAL : public BaseImageEncoder
123
{
124
public:
125
TiffEncoder();
126
virtual ~TiffEncoder() CV_OVERRIDE;
127
128
bool isFormatSupported( int depth ) const CV_OVERRIDE;
129
130
bool write( const Mat& img, const std::vector<int>& params ) CV_OVERRIDE;
131
132
bool writemulti(const std::vector<Mat>& img_vec, const std::vector<int>& params) CV_OVERRIDE;
133
134
ImageEncoder newEncoder() const CV_OVERRIDE;
135
136
protected:
137
void writeTag( WLByteStream& strm, TiffTag tag,
138
TiffFieldType fieldType,
139
int count, int value );
140
141
bool writeLibTiff( const std::vector<Mat>& img_vec, const std::vector<int>& params );
142
bool write_32FC3( const Mat& img );
143
bool write_32FC1( const Mat& img );
144
145
private:
146
TiffEncoder(const TiffEncoder &); // copy disabled
147
TiffEncoder& operator=(const TiffEncoder &); // assign disabled
148
};
149
150
}
151
152
#endif // HAVE_TIFF
153
154
#endif/*_GRFMT_TIFF_H_*/
155
156