You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
1.8 KiB
C++
72 lines
1.8 KiB
C++
19 years ago
|
// ***************************************************************** -*- C++ -*-
|
||
|
// tiffparse.cpp, $Rev$
|
||
|
// Print the structure of a TIFF file
|
||
|
|
||
18 years ago
|
#include <exiv2/tiffparser.hpp>
|
||
|
#include <exiv2/tiffcomposite.hpp>
|
||
|
#include <exiv2/tiffvisitor.hpp>
|
||
|
#include <exiv2/tiffimage.hpp>
|
||
|
#include <exiv2/futils.hpp>
|
||
19 years ago
|
|
||
|
#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");
|
||
|
|
||
19 years ago
|
TiffCompFactoryFct createFct = TiffCreator::create;
|
||
|
|
||
|
TiffComponent::AutoPtr rootDir = createFct(Tag::root, Group::none);
|
||
19 years ago
|
if (0 == rootDir.get()) {
|
||
|
throw Error(1, "No root element defined in TIFF structure");
|
||
|
}
|
||
18 years ago
|
rootDir->setStart(buf.pData_ + tiffHeader.offset());
|
||
19 years ago
|
|
||
|
TiffRwState::AutoPtr state(
|
||
|
new TiffRwState(tiffHeader.byteOrder(), 0, createFct));
|
||
|
|
||
19 years ago
|
TiffReader reader(buf.pData_,
|
||
|
buf.size_,
|
||
19 years ago
|
rootDir.get(),
|
||
|
state);
|
||
|
|
||
19 years ago
|
rootDir->accept(reader);
|
||
19 years ago
|
|
||
|
tiffHeader.print(std::cerr);
|
||
19 years ago
|
TiffPrinter tiffPrinter(std::cerr);
|
||
|
rootDir->accept(tiffPrinter);
|
||
19 years ago
|
|
||
|
return 0;
|
||
|
}
|
||
|
catch (AnyError& e) {
|
||
|
std::cerr << e << "\n";
|
||
|
return -1;
|
||
|
}
|