File: crwparse.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 (46 lines) | stat: -rw-r--r-- 1,260 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
// ***************************************************************** -*- C++ -*-
// crwparse.cpp, $Rev: 1271 $
// Print the CIFF structure of a CRW file

#include <exiv2/crwimage.hpp>
#include <exiv2/futils.hpp>

#include <iostream>

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

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

    // Ensure that this is a CRW image
    if (!Exiv2::isCrwType(io, false)) {
        if (io.error() || io.eof()) throw Exiv2::Error(14);
        throw Exiv2::Error(33);
    }

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

    // Parse the image, starting with a CIFF header component
    Exiv2::CiffHeader::AutoPtr parseTree(new Exiv2::CiffHeader);
    parseTree->read(buf.pData_, buf.size_);
    parseTree->print(std::cout);

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