File: tiffparse.cpp

package info (click to toggle)
exiv2 0.17.1-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 8,668 kB
  • ctags: 5,254
  • sloc: cpp: 43,979; sh: 8,353; ansic: 1,641; makefile: 484; awk: 92; python: 36; sed: 16
file content (71 lines) | stat: -rw-r--r-- 1,885 bytes parent folder | download
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
// ***************************************************************** -*- C++ -*-
// tiffparse.cpp, $Rev: 1271 $
// Print the structure of a TIFF file

#include <exiv2/tiffparser.hpp>
#include <exiv2/tiffcomposite.hpp>
#include <exiv2/tiffvisitor.hpp>
#include <exiv2/tiffimage.hpp>
#include <exiv2/futils.hpp>

#include <iostream>

using namespace Exiv2;

int main(int argc, char* const argv[])
try {
    if (argc != 2) {
        std::cout << "Usage: " << argv[0] << " file\n";
        std::cout << "Print the structure of a TIFF file\n";
        return 1;
    }

    FileIo io(argv[1]);
    if(io.open() != 0) {
        throw Error(9, io.path(), strError());
    }
    IoCloser closer(io);

    // Ensure that this is the correct image type
    if (!isTiffType(io, false)) {
        if (io.error() || io.eof()) throw Error(14);
        throw Error(3, "TIFF");
    }

    // Read the image into a memory buffer
    long len = io.size();
    DataBuf buf(len);
    io.read(buf.pData_, len);
    if (io.error() || io.eof()) throw Error(14);

    TiffHeade2 tiffHeader;
    if (!tiffHeader.read(buf.pData_, buf.size_)) throw Error(3, "TIFF");

    TiffCompFactoryFct createFct = TiffCreator::create;

    TiffComponent::AutoPtr rootDir = createFct(Tag::root, Group::none);
    if (0 == rootDir.get()) {
        throw Error(1, "No root element defined in TIFF structure");
    }
    rootDir->setStart(buf.pData_ + tiffHeader.offset());

    TiffRwState::AutoPtr state(
        new TiffRwState(tiffHeader.byteOrder(), 0, createFct));

    TiffReader reader(buf.pData_,
                      buf.size_,
                      rootDir.get(),
                      state);

    rootDir->accept(reader);

    tiffHeader.print(std::cerr);
    TiffPrinter tiffPrinter(std::cerr);
    rootDir->accept(tiffPrinter);

    return 0;
}
catch (AnyError& e) {
    std::cerr << e << "\n";
    return -1;
}