From 37b81c9c801c125b4e595153b065b05b69d02744 Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Tue, 17 Oct 2023 12:25:01 +0200 Subject: [PATCH 01/10] rename heif-convert to heif-dec --- examples/CMakeLists.txt | 18 +++++++++--------- examples/{heif-convert.1 => heif-dec.1} | 0 examples/{heif_convert.cc => heif_dec.cc} | 0 3 files changed, 9 insertions(+), 9 deletions(-) rename examples/{heif-convert.1 => heif-dec.1} (100%) rename examples/{heif_convert.cc => heif_dec.cc} (100%) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 0a519e76c4..c255afa5a0 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -19,19 +19,19 @@ install(TARGETS heif-info RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES heif-info.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) -add_executable(heif-convert ${getopt_sources} +add_executable(heif-dec ${getopt_sources} encoder.cc encoder.h encoder_y4m.cc encoder_y4m.h - heif_convert.cc + heif_dec.cc ../libheif/exif.cc ../libheif/exif.cc common.cc common.h) -target_link_libraries(heif-convert PRIVATE heif) -install(TARGETS heif-convert RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) -install(FILES heif-convert.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) +target_link_libraries(heif-dec PRIVATE heif) +install(TARGETS heif-dec RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) +install(FILES heif-dec.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) add_executable(heif-enc ${getopt_sources} @@ -83,10 +83,10 @@ int main() { add_definitions(-DHAVE_JPEG_WRITE_ICC_PROFILE=1) endif () - target_link_libraries(heif-convert PRIVATE JPEG::JPEG) + target_link_libraries(heif-dec PRIVATE JPEG::JPEG) target_link_libraries(heif-enc PRIVATE JPEG::JPEG) - target_sources(heif-convert PRIVATE encoder_jpeg.cc encoder_jpeg.h) + target_sources(heif-dec PRIVATE encoder_jpeg.cc encoder_jpeg.h) target_sources(heif-enc PRIVATE decoder.h decoder_jpeg.cc decoder_jpeg.h) endif () @@ -95,10 +95,10 @@ find_package(PNG) if (TARGET PNG::PNG) add_definitions(-DHAVE_LIBPNG=1) - target_link_libraries(heif-convert PRIVATE PNG::PNG) + target_link_libraries(heif-dec PRIVATE PNG::PNG) target_link_libraries(heif-enc PRIVATE PNG::PNG) - target_sources(heif-convert PRIVATE encoder_png.cc encoder_png.h) + target_sources(heif-dec PRIVATE encoder_png.cc encoder_png.h) target_sources(heif-enc PRIVATE decoder_png.cc decoder_png.h) add_executable(heif-thumbnailer ${getopt_sources} diff --git a/examples/heif-convert.1 b/examples/heif-dec.1 similarity index 100% rename from examples/heif-convert.1 rename to examples/heif-dec.1 diff --git a/examples/heif_convert.cc b/examples/heif_dec.cc similarity index 100% rename from examples/heif_convert.cc rename to examples/heif_dec.cc From 100d1725269d9af42b6a803d5784eb804b46ea63 Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Tue, 17 Oct 2023 12:25:52 +0200 Subject: [PATCH 02/10] install link from 'heif-convert' to new filename 'heif-dec' --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index a61145b324..10745569c8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -260,6 +260,9 @@ configure_file(libheif.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libheif.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libheif.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) +install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/heif-dec${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/heif-convert${CMAKE_EXECUTABLE_SUFFIX})") + + # --- option(WITH_EXAMPLES "Build examples" ON) From fd1d633a273d01931811e4f21c78e39d7bdca7de Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Tue, 17 Oct 2023 12:28:54 +0200 Subject: [PATCH 03/10] show correct program name in help --- examples/heif_dec.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/heif_dec.cc b/examples/heif_dec.cc index f474901798..e47cc228b0 100644 --- a/examples/heif_dec.cc +++ b/examples/heif_dec.cc @@ -67,9 +67,9 @@ static void show_help(const char* argv0) { - std::cerr << " heif-convert libheif version: " << heif_get_version() << "\n" - << "-------------------------------------------\n" - "Usage: heif-convert [options] [output-image]\n" + std::cerr << " " << argv0 << " libheif version: " << heif_get_version() << "\n" + << "---------------------------------------\n" + "Usage: " << argv0 << " [options] [output-image]\n" "\n" "The program determines the output file format from the output filename suffix.\n" "These suffixes are recognized: jpg, jpeg, png, y4m. If no output filename is specified, 'jpg' is used.\n" From 8055af74671a987cb4ad7f2621848540a7dc6c7f Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Tue, 17 Oct 2023 14:09:35 +0200 Subject: [PATCH 04/10] cmake: move creating the heif-convert symlink to after installing heif-dec (#996) --- CMakeLists.txt | 2 -- examples/CMakeLists.txt | 3 +++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10745569c8..394a484968 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -260,8 +260,6 @@ configure_file(libheif.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libheif.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libheif.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) -install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/heif-dec${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/heif-convert${CMAKE_EXECUTABLE_SUFFIX})") - # --- diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index c255afa5a0..7d981814b1 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -33,6 +33,9 @@ target_link_libraries(heif-dec PRIVATE heif) install(TARGETS heif-dec RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES heif-dec.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) +# create symbolic link from the old name `heif-convert` to `heif-dec` +install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/heif-dec${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/heif-convert${CMAKE_EXECUTABLE_SUFFIX})") + add_executable(heif-enc ${getopt_sources} heif_enc.cc From 87815a5bc0f3fbab8ec7877061afe605510307a5 Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Wed, 18 Oct 2023 11:06:42 +0200 Subject: [PATCH 05/10] On Windows, copy heic-dec to heic-convert instead of using symlink MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Miloš Komarčević <4973094+kmilos@users.noreply.github.com> --- examples/CMakeLists.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7d981814b1..86556dd19b 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -34,7 +34,11 @@ install(TARGETS heif-dec RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) install(FILES heif-dec.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1) # create symbolic link from the old name `heif-convert` to `heif-dec` -install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/heif-dec${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/heif-convert${CMAKE_EXECUTABLE_SUFFIX})") +if(NOT WIN32) + install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/heif-dec${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/heif-convert${CMAKE_EXECUTABLE_SUFFIX})") +else() + install(CODE "execute_process(COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/heif-dec${CMAKE_EXECUTABLE_SUFFIX} ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_BINDIR}/heif-convert${CMAKE_EXECUTABLE_SUFFIX})") +endif() add_executable(heif-enc ${getopt_sources} From c4401efee9ffc0557c7215d42a487fceb4dc4f05 Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Wed, 18 Oct 2023 11:10:11 +0200 Subject: [PATCH 06/10] rename heif-convert to heif-dec in manpage --- README.md | 4 ++-- examples/heif-dec.1 | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c2bc757a4f..076102572b 100644 --- a/README.md +++ b/README.md @@ -305,7 +305,7 @@ This is `libheif` running in JavaScript in your browser. ## Example programs Some example programs are provided in the `examples` directory. -The program `heif-convert` converts all images stored in an HEIF/AVIF file to JPEG or PNG. +The program `heif-dec` converts all images stored in an HEIF/AVIF file to JPEG or PNG. `heif-enc` lets you convert JPEG files to HEIF/AVIF. The program `heif-info` is a simple, minimal decoder that dumps the file structure to the console. @@ -313,7 +313,7 @@ For example convert `example.heic` to JPEGs and one of the JPEGs back to HEIF: ```sh cd examples/ -./heif-convert example.heic example.jpeg +./heif-dec example.heic example.jpeg ./heif-enc example-1.jpeg -o example.heif ``` diff --git a/examples/heif-dec.1 b/examples/heif-dec.1 index 171acbbc78..6bc57858bd 100644 --- a/examples/heif-dec.1 +++ b/examples/heif-dec.1 @@ -1,13 +1,13 @@ .TH HEIF-THUMBNAILER 1 .SH NAME -heif-convert \- convert HEIC/HEIF image +heif-dec \- decode HEIC/HEIF image .SH SYNOPSIS -.B heif-convert +.B heif-dec [\fB\-q\fR \fIQUALITY\fR] .IR filename .IR output[.jpg|.png|.y4m] .SH DESCRIPTION -.B heif-convert +.B heif-dec Convert HEIC/HEIF image to a different image format. .SH OPTIONS .TP From 7b7c0f2fc3efadcfbee27d1e52c66ee5f0be498f Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Wed, 18 Oct 2023 11:10:55 +0200 Subject: [PATCH 07/10] rename heif-convert to heif-dec in CI script --- scripts/run-ci.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/scripts/run-ci.sh b/scripts/run-ci.sh index f28e753055..b2a5b267e5 100755 --- a/scripts/run-ci.sh +++ b/scripts/run-ci.sh @@ -163,19 +163,19 @@ if [ -z "$EMSCRIPTEN_VERSION" ] && [ -z "$CHECK_LICENSES" ] && [ -z "$TARBALL" ] ${BIN_WRAPPER} ./examples/heif-enc${BIN_SUFFIX} --list-encoders echo "List available decoders" - ${BIN_WRAPPER} ./examples/heif-convert${BIN_SUFFIX} --list-decoders + ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} --list-decoders echo "Dumping information of sample file ..." ${BIN_WRAPPER} ./examples/heif-info${BIN_SUFFIX} --dump-boxes examples/example.heic if [ ! -z "$WITH_GRAPHICS" ] && [ ! -z "$WITH_HEIF_DECODER" ]; then echo "Converting sample HEIF file to JPEG ..." - ${BIN_WRAPPER} ./examples/heif-convert${BIN_SUFFIX} examples/example.heic example.jpg + ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} examples/example.heic example.jpg echo "Checking first generated file ..." [ -s "example-1.jpg" ] || exit 1 echo "Checking second generated file ..." [ -s "example-2.jpg" ] || exit 1 echo "Converting sample HEIF file to PNG ..." - ${BIN_WRAPPER} ./examples/heif-convert${BIN_SUFFIX} examples/example.heic example.png + ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} examples/example.heic example.png echo "Checking first generated file ..." [ -s "example-1.png" ] || exit 1 echo "Checking second generated file ..." @@ -183,11 +183,11 @@ if [ -z "$EMSCRIPTEN_VERSION" ] && [ -z "$CHECK_LICENSES" ] && [ -z "$TARBALL" ] fi if [ ! -z "$WITH_GRAPHICS" ] && [ ! -z "$WITH_AVIF_DECODER" ]; then echo "Converting sample AVIF file to JPEG ..." - ${BIN_WRAPPER} ./examples/heif-convert${BIN_SUFFIX} examples/example.avif example.jpg + ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} examples/example.avif example.jpg echo "Checking generated file ..." [ -s "example.jpg" ] || exit 1 echo "Converting sample AVIF file to PNG ..." - ${BIN_WRAPPER} ./examples/heif-convert${BIN_SUFFIX} examples/example.avif example.png + ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} examples/example.avif example.png echo "Checking generated file ..." [ -s "example.png" ] || exit 1 fi @@ -197,14 +197,14 @@ if [ -z "$EMSCRIPTEN_VERSION" ] && [ -z "$CHECK_LICENSES" ] && [ -z "$TARBALL" ] echo "Checking generated file ..." [ -s "output-single.heic" ] || exit 1 echo "Converting back generated heif to JPEG ..." - ${BIN_WRAPPER} ./examples/heif-convert${BIN_SUFFIX} output-single.heic output-single.jpg + ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} output-single.heic output-single.jpg echo "Checking generated file ..." [ -s "output-single.jpg" ] || exit 1 echo "Converting multiple JPEG files to heif ..." ${BIN_WRAPPER} ./examples/heif-enc${BIN_SUFFIX} -o output-multi.heic --verbose --verbose --verbose --thumb 320x240 example-1.jpg example-2.jpg echo "Checking generated file ..." [ -s "output-multi.heic" ] || exit 1 - ${BIN_WRAPPER} ./examples/heif-convert${BIN_SUFFIX} output-multi.heic output-multi.jpg + ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} output-multi.heic output-multi.jpg echo "Checking first generated file ..." [ -s "output-multi-1.jpg" ] || exit 1 echo "Checking second generated file ..." @@ -216,7 +216,7 @@ if [ -z "$EMSCRIPTEN_VERSION" ] && [ -z "$CHECK_LICENSES" ] && [ -z "$TARBALL" ] echo "Checking generated file ..." [ -s "output-jpeg.avif" ] || exit 1 echo "Converting back generated AVIF to JPEG ..." - ${BIN_WRAPPER} ./examples/heif-convert${BIN_SUFFIX} output-jpeg.avif output-jpeg.jpg + ${BIN_WRAPPER} ./examples/heif-dec${BIN_SUFFIX} output-jpeg.avif output-jpeg.jpg echo "Checking generated file ..." [ -s "output-jpeg.jpg" ] || exit 1 fi From 30b696bd36d1414f9b409a1d98d4792b23f81c6e Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Wed, 18 Oct 2023 11:39:30 +0200 Subject: [PATCH 08/10] fix parse error reporting --- libheif/file.cc | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/libheif/file.cc b/libheif/file.cc index 0a7e4e7722..6de322bfdf 100644 --- a/libheif/file.cc +++ b/libheif/file.cc @@ -253,14 +253,19 @@ Error HeifFile::parse_heif_file(BitstreamRange& range) std::shared_ptr box; Error error = Box::read(range, &box); + if (range.error() || range.eof()) { + break; + } + // When an EOF error is returned, this is not really a fatal exception, // but simply the indication that we reached the end of the file. - if (error != Error::Ok) { - return error; + // TODO: this design should be cleaned up + if (error.error_code == heif_error_Invalid_input && error.sub_error_code == heif_suberror_End_of_data) { + break; } - if (range.error() || range.eof()) { - break; + if (error != Error::Ok) { + return error; } m_top_level_boxes.push_back(box); From 4e803dfdfaab8dd72ca47a106e052fd3e7687951 Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Tue, 11 Jun 2024 11:56:57 +0200 Subject: [PATCH 09/10] revert whitespace-only diff --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 394a484968..a61145b324 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -260,7 +260,6 @@ configure_file(libheif.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libheif.pc @ONLY) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libheif.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) - # --- option(WITH_EXAMPLES "Build examples" ON) From 37d5102052c3cc4ea35ea4901ab144f881569f62 Mon Sep 17 00:00:00 2001 From: Dirk Farin Date: Tue, 11 Jun 2024 12:05:45 +0200 Subject: [PATCH 10/10] Revert "fix parse error reporting" as it does not belong into this PR. This reverts commit 30b696bd36d1414f9b409a1d98d4792b23f81c6e. --- libheif/file.cc | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/libheif/file.cc b/libheif/file.cc index 6de322bfdf..0a7e4e7722 100644 --- a/libheif/file.cc +++ b/libheif/file.cc @@ -253,21 +253,16 @@ Error HeifFile::parse_heif_file(BitstreamRange& range) std::shared_ptr box; Error error = Box::read(range, &box); - if (range.error() || range.eof()) { - break; - } - // When an EOF error is returned, this is not really a fatal exception, // but simply the indication that we reached the end of the file. - // TODO: this design should be cleaned up - if (error.error_code == heif_error_Invalid_input && error.sub_error_code == heif_suberror_End_of_data) { - break; - } - if (error != Error::Ok) { return error; } + if (range.error() || range.eof()) { + break; + } + m_top_level_boxes.push_back(box);