diff --git a/samples/CMakeLists.txt b/samples/CMakeLists.txt index 397680cea2..3e990fbddd 100644 --- a/samples/CMakeLists.txt +++ b/samples/CMakeLists.txt @@ -14,6 +14,7 @@ set(SAMPLES iptceasy.cpp iptcprint.cpp iptctest.cpp + jpegparsetest.cpp key-test.cpp largeiptc-test.cpp mmap-test.cpp diff --git a/samples/jpegparsetest.cpp b/samples/jpegparsetest.cpp new file mode 100644 index 0000000000..086f7b1247 --- /dev/null +++ b/samples/jpegparsetest.cpp @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// Sample program to dump the XMP packet of an image + +#include +#include +#include + +int main(int argc, char* const argv[]) { + try { + if (argc != 2) { + std::cout << "Usage: " << argv[0] << " file\n"; + return EXIT_FAILURE; + } + + auto image = Exiv2::ImageFactory::open(argv[1]); + if (image->imageType() == Exiv2::ImageType::jpeg) { + Exiv2::JpegImage* jpegImage = dynamic_cast(image.get()); + jpegImage->readMetadata(); + std::cout << "Number of color components: " << jpegImage->numColorComponents() << "\n"; + std::cout << "Encoding process: " << jpegImage->encodingProcess() << "\n"; + } + + return EXIT_SUCCESS; + } catch (Exiv2::Error& e) { + std::cout << "Caught Exiv2 exception '" << e << "'\n"; + return EXIT_FAILURE; + } +} diff --git a/tests/bash_tests/test_jpegparse.py b/tests/bash_tests/test_jpegparse.py new file mode 100644 index 0000000000..af9d4aea5b --- /dev/null +++ b/tests/bash_tests/test_jpegparse.py @@ -0,0 +1,13 @@ +# -*- coding: utf-8 -*- + +import system_tests + +class TestExifIPTCXmpTagOutput(metaclass=system_tests.CaseMeta): + url = "https://github.com/Exiv2/exiv2/pull/2279" + + # Test extraction of jpeg specific metadata + filename = "$data_path/exiv2-fujifilm-finepix-s2pro.jpg" + commands = ["$jpegparsetest $filename"] + stderr = [""] * len(commands) + stdout = ["""Number of color components: 3\nEncoding process: Baseline DCT, Huffman coding\n"""] + retval = [0] * len(commands) diff --git a/tests/suite.conf b/tests/suite.conf index be31d32702..c2bf1741e8 100644 --- a/tests/suite.conf +++ b/tests/suite.conf @@ -35,6 +35,7 @@ tiff_test: ${ENV:exiv2_path}/tiff-test largeiptc_test: ${ENV:exiv2_path}/largeiptc-test easyaccess_test: ${ENV:exiv2_path}/easyaccess-test taglist: ${ENV:exiv2_path}/taglist +jpegparsetest: ${ENV:exiv2_path}/jpegparsetest [variables] kerOffsetOutOfRange: Offset out of range