File: prevtest.cpp

package info (click to toggle)
exiv2 0.20-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,080 kB
  • ctags: 6,382
  • sloc: cpp: 56,011; sh: 10,092; ansic: 1,622; makefile: 594; awk: 92; python: 36; sed: 16
file content (47 lines) | stat: -rw-r--r-- 1,433 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
// ***************************************************************** -*- C++ -*-
// prevtest.cpp, $Rev: 1629 $
// Test access to preview images

#include <exiv2/image.hpp>
#include <exiv2/preview.hpp>

#include <string>
#include <iostream>
#include <cassert>

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

    Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(filename);
    assert(image.get() != 0);
    image->readMetadata();

    Exiv2::PreviewManager loader(*image);
    Exiv2::PreviewPropertiesList list = loader.getPreviewProperties();
    for (Exiv2::PreviewPropertiesList::iterator pos = list.begin(); pos != list.end(); pos++) {
        std::cout << pos->mimeType_
                  << " preview, type " << pos->id_ << ", "
                  << pos->size_ << " bytes, "
                  << pos->width_ << 'x' << pos->height_ << " pixels"
                  << "\n";

        Exiv2::PreviewImage preview = loader.getPreviewImage(*pos);
        preview.writeFile(filename + "_"
                          + Exiv2::toString(pos->width_) + "x"
                          + Exiv2::toString(pos->height_));
    }

    // Cleanup
    Exiv2::XmpParser::terminate();
    
    return 0;
}
catch (Exiv2::AnyError& e) {
    std::cout << "Caught Exiv2 exception '" << e << "'\n";
    return -1;
}