-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprepost.cpp
71 lines (66 loc) · 3.7 KB
/
prepost.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "tinytiffreader.h"
//#include "tinytiffwriter.h"
#include <iostream>
int main() {
TinyTIFFReaderFile* tiffr = NULL;
tiffr = TinyTIFFReader_open("C:\\Users\\zongz\\Pictures\\2_0_73um_recon_Export_0001.tif");
//TinyTIFFWriterFile* tif = TinyTIFFWriter_open("myfil.tif", 8, TinyTIFFWriter_UInt, 1, 973, 1013, TinyTIFFWriter_Greyscale);
if (!tiffr) {
std::cout << " ERROR reading (not existent, not accessible or no TIFF file)\n";
}
else {
if (TinyTIFFReader_wasError(tiffr)) {
std::cout << " ERROR:" << TinyTIFFReader_getLastError(tiffr) << "\n";
}
else {
std::cout << " ImageDescription:\n" << TinyTIFFReader_getImageDescription(tiffr) << "\n";
uint32_t frames = TinyTIFFReader_countFrames(tiffr);
std::cout << " frames: " << frames << "\n";
uint32_t frame = 0;
if (TinyTIFFReader_wasError(tiffr)) {
std::cout << " ERROR:" << TinyTIFFReader_getLastError(tiffr) << "\n";
}
else {
do {
const uint32_t width = TinyTIFFReader_getWidth(tiffr);
const uint32_t height = TinyTIFFReader_getHeight(tiffr);
const uint16_t samples = TinyTIFFReader_getSamplesPerPixel(tiffr);
const uint16_t bitspersample = TinyTIFFReader_getBitsPerSample(tiffr, 0);
bool ok = true;
std::cout << " size of frame " << frame << ": " << width << "x" << height << "\n";
std::cout << " each pixel has " << samples << " samples with " << bitspersample << " bits each\n";
if (ok) {
frame++;
// allocate memory for 1 sample from the image
uint8_t* image = (uint8_t*)calloc(width * height, bitspersample / 8);
for (uint16_t sample = 0; sample < samples; sample++) {
// read the sample
TinyTIFFReader_getSampleData(tiffr, image, sample);
if (TinyTIFFReader_wasError(tiffr)) { ok = false; std::cout << " ERROR:" << TinyTIFFReader_getLastError(tiffr) << "\n"; break; }
// HERE WE CAN DO SOMETHING WITH THE SAMPLE FROM THE IMAGE
// IN image (ROW-MAJOR!)
// Note: That you may have to typecast the array image to the
// datatype used in the TIFF-file. You can get the size of each
// sample in bits by calling TinyTIFFReader_getBitsPerSample() and
// the datatype by calling TinyTIFFReader_getSampleFormat().
/* if (frame == 1) {
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
std::cout << int(image[i * width + j]) << ",";
}
std::cout << std::endl;
}
}*/
//TinyTIFFWriter_writeImage(tif, image);
}
free(image);
}
} while (TinyTIFFReader_readNext(tiffr)); // iterate over all frames
std::cout << " read " << frame << " frames\n";
}
}
}
TinyTIFFReader_close(tiffr);
//TinyTIFFWriter_close(tif);
std::cin.get();
}