TinyTIFF
a lightweight C/C++ library for reading and writing TIFF files
Loading...
Searching...
No Matches
tinytiffreader.hxx
1/*
2 Copyright (c) 2008-2024 Jan W. Krieger (<jan@jkrieger.de>), German Cancer Research Center (DKFZ) & IWR, University of Heidelberg
3
4 This software is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License (LGPL) as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17
18*/
19
20
21#ifndef TINYTIFFREADER_HXX
22#define TINYTIFFREADER_HXX
23
24extern "C" {
25 #include "tinytiffreader.h"
26}
27#include <stdexcept>
28#include <vector>
29
30
31
88template <class Tin, class Tout>
89inline void TinyTIFFReader_readFrame(TinyTIFFReaderFile* tif, Tout* buffer, uint16_t sample=0) {
90 uint32_t wwidth=TinyTIFFReader_getWidth(tif);
91 uint32_t hheight=TinyTIFFReader_getHeight(tif);
92 std::vector<Tin> tmp;
93 tmp.resize(wwidth*hheight);
94 TinyTIFFReader_getSampleData_s(tif, tmp.data(), tmp.size()*sizeof(Tin), sample);
95 for (uint32_t i=0; i<wwidth*hheight; i++) {
96 buffer[i]=static_cast<Tout>(tmp[i]);
97 }
98}
99
157template <class Tin, class Tout>
158inline void TinyTIFFReader_readFrame_s(TinyTIFFReaderFile* tif, Tout* buffer, unsigned long buffer_size, uint16_t sample=0) {
159 uint32_t wwidth=TinyTIFFReader_getWidth(tif);
160 uint32_t hheight=TinyTIFFReader_getHeight(tif);
161 if (buffer_size<wwidth*hheight) throw std::runtime_error("output buffer too small!");
162 std::vector<Tin> tmp;
163 tmp.resize(wwidth*hheight);
164 TinyTIFFReader_getSampleData_s(tif, tmp.data(), tmp.size()*sizeof(Tin), sample);
165 for (uint32_t i=0; i<wwidth*hheight; i++) {
166 buffer[i]=static_cast<Tout>(tmp[i]);
167 }
168}
169#endif // TINYTIFFREADER_HXX
uint32_t TinyTIFFReader_getWidth(TinyTIFFReaderFile *tiff)
return the width of the current frame
Definition tinytiffreader.c:1033
int TinyTIFFReader_getSampleData_s(TinyTIFFReaderFile *tiff, void *buffer, unsigned long buffer_size, uint16_t sample)
read the given sample from the current frame into the given buffer, the byteorder is transformed to t...
Definition tinytiffreader.c:928
uint32_t TinyTIFFReader_getHeight(TinyTIFFReaderFile *tiff)
return the height of the current frame
Definition tinytiffreader.c:1040
void TinyTIFFReader_readFrame_s(TinyTIFFReaderFile *tif, Tout *buffer, unsigned long buffer_size, uint16_t sample=0)
template function that internally calls TinyTIFFReader_getSampleData_s() and copies the data into the...
Definition tinytiffreader.hxx:158
void TinyTIFFReader_readFrame(TinyTIFFReaderFile *tif, Tout *buffer, uint16_t sample=0)
template function that internally calls TinyTIFFReader_getSampleData() and copies the data into the s...
Definition tinytiffreader.hxx:89
Definition tinytiffreader.c:154