From 7accb24a7d65fe140511f01b461d907a5f2d97a1 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Sun, 8 Sep 2024 18:18:12 +1000 Subject: [PATCH 1/5] Windows build fix for C++ version. --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c008b84a8..f5cce44531 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -41,7 +41,7 @@ if(NOT MSVC) endif () endif() -set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) From 6b44baf8d7f74b04d6d1f95161f399dc77796d69 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Sun, 8 Sep 2024 18:18:50 +1000 Subject: [PATCH 2/5] Windows build fix for example utilities. --- examples/heif_dec.cc | 4 ++-- examples/heif_enc.cc | 2 +- examples/heif_info.cc | 2 +- examples/heif_test.cc | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/examples/heif_dec.cc b/examples/heif_dec.cc index 5e2b9cb213..6703aac963 100644 --- a/examples/heif_dec.cc +++ b/examples/heif_dec.cc @@ -244,7 +244,7 @@ int main(int argc, char** argv) //while ((opt = getopt(argc, argv, "q:s")) != -1) { while (true) { int option_index = 0; - int c = getopt_long(argc, argv, "hq:sd:C:vo:", long_options, &option_index); + int c = getopt_long(argc, argv, (char*)"hq:sd:C:vo:", long_options, &option_index); if (c == -1) { break; } @@ -261,7 +261,7 @@ int main(int argc, char** argv) break; case '?': std::cerr << "\n"; - // fallthrough + [[fallthrough]]; case 'h': show_help(argv[0]); return 0; diff --git a/examples/heif_enc.cc b/examples/heif_enc.cc index 1329d58965..8439353706 100644 --- a/examples/heif_enc.cc +++ b/examples/heif_enc.cc @@ -525,7 +525,7 @@ int main(int argc, char** argv) while (true) { int option_index = 0; - int c = getopt_long(argc, argv, "hq:Lo:vPp:t:b:AEe:C:" + int c = getopt_long(argc, argv, (char*)"hq:Lo:vPp:t:b:AEe:C:" #if WITH_UNCOMPRESSED_CODEC "U" #endif diff --git a/examples/heif_info.cc b/examples/heif_info.cc index c56499d7b6..3f18cceecb 100644 --- a/examples/heif_info.cc +++ b/examples/heif_info.cc @@ -122,7 +122,7 @@ int main(int argc, char** argv) while (true) { int option_index = 0; - int c = getopt_long(argc, argv, "dhv", long_options, &option_index); + int c = getopt_long(argc, argv, (char*)"dhv", long_options, &option_index); if (c == -1) break; diff --git a/examples/heif_test.cc b/examples/heif_test.cc index ec6f8d68cc..7afcd609d7 100644 --- a/examples/heif_test.cc +++ b/examples/heif_test.cc @@ -90,7 +90,7 @@ int main(int argc, char** argv) while (true) { int option_index = 0; - int c = getopt_long(argc, argv, "d:m:hv", long_options, &option_index); + int c = getopt_long(argc, argv, (char*)"d:m:hv", long_options, &option_index); if (c == -1) break; From 6b47b0a55923e14c74c5b0fff680b5663fe07748 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Sun, 8 Sep 2024 18:19:32 +1000 Subject: [PATCH 3/5] Windows alternatives for unistd and friends. --- libheif/box.cc | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/libheif/box.cc b/libheif/box.cc index 746e9cd720..72feeabac9 100644 --- a/libheif/box.cc +++ b/libheif/box.cc @@ -50,7 +50,13 @@ #define M_PI 3.14159265358979323846 #endif -#include // TODO: Windows +#if !defined(_WIN32) && !defined(_WIN64) +#include +#else +#include +#include +#endif + Fraction::Fraction(int32_t num, int32_t den) { @@ -155,7 +161,7 @@ bool Fraction::is_valid() const return denominator != 0; } -uint32_t from_fourcc(const char* string) +static uint32_t from_fourcc(const char* string) { return ((string[0] << 24) | (string[1] << 16) | @@ -1035,7 +1041,7 @@ Error Box_ftyp::parse(BitstreamRange& range) m_major_brand = range.read32(); m_minor_version = range.read32(); - if (get_box_size() <= get_header_size() + 8) { + if (get_box_size() - 8 <= get_header_size()) { // Sanity check. return Error(heif_error_Invalid_input, heif_suberror_Invalid_box_size, @@ -1406,8 +1412,15 @@ void Box_iloc::set_use_tmp_file(bool flag) { m_use_tmpfile = flag; if (flag) { +#if !defined(_WIN32) && !defined(_WIN64) strcpy(m_tmp_filename, "/tmp/libheif-XXXXXX"); m_tmpfile_fd = mkstemp(m_tmp_filename); +#else + char tmpname[L_tmpnam_s]; + // TODO: check return value (errno_t) + tmpnam_s(tmpname, L_tmpnam_s); + _sopen_s(&m_tmpfile_fd, tmpname, _O_CREAT | _O_TEMPORARY | _O_TRUNC | _O_RDWR, _SH_DENYRW, _S_IREAD | _S_IWRITE); +#endif } } @@ -1629,7 +1642,11 @@ Error Box_iloc::append_data(heif_item_id item_ID, extent.length = data.size(); if (m_use_tmpfile && construction_method==0) { +#if !defined(_WIN32) && !defined(_WIN64) ssize_t cnt = ::write(m_tmpfile_fd, data.data(), data.size()); +#else + int cnt = _write(m_tmpfile_fd, data.data(), data.size()); +#endif if (cnt < 0) { std::stringstream sstr; sstr << "Could not write to tmp file: error " << errno; @@ -1883,7 +1900,11 @@ Error Box_iloc::write_mdat_after_iloc(StreamWriter& writer) if (m_use_tmpfile) { std::vector data(extent.length); +#if !defined(_WIN32) && !defined(_WIN64) ssize_t cnt = ::read(m_tmpfile_fd, data.data(), extent.length); +#else + int cnt = _read(m_tmpfile_fd, data.data(), extent.length); +#endif if (cnt<0) { std::stringstream sstr; sstr << "Cannot read tmp data file, error " << errno; @@ -2632,7 +2653,7 @@ Error Box_ipma::parse(BitstreamRange& range) int assoc_cnt = range.read8(); for (int k = 0; k < assoc_cnt; k++) { - PropertyAssociation association; + PropertyAssociation association{}; uint16_t index; if (get_flags() & 1) { @@ -3902,9 +3923,9 @@ Error Box_cmin::write(StreamWriter& writer) const } -std::array mul(const std::array& a, const std::array& b) +static std::array mul(const std::array& a, const std::array& b) { - std::array m; + std::array m{}; m[0] = a[0]*b[0] + a[1]*b[3] + a[2]*b[6]; m[1] = a[0]*b[1] + a[1]*b[4] + a[2]*b[7]; From 7dacb2dad64b543635a76528e73bf1d7ac803d17 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Sun, 8 Sep 2024 10:17:07 +0000 Subject: [PATCH 4/5] examples: add cast for windows compatibility --- examples/heif_thumbnailer.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/heif_thumbnailer.cc b/examples/heif_thumbnailer.cc index 0e53c4d434..1e23c77bb5 100644 --- a/examples/heif_thumbnailer.cc +++ b/examples/heif_thumbnailer.cc @@ -69,7 +69,7 @@ int main(int argc, char** argv) int size = 512; // default thumbnail size bool thumbnail_from_primary_image_only = false; - while ((opt = getopt(argc, argv, "s:hpv")) != -1) { + while ((opt = getopt(argc, argv, (char*)"s:hpv")) != -1) { switch (opt) { case 's': size = atoi(optarg); From 9c5dde76a257b5fa0755a200375648ff5127ed01 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Sun, 8 Sep 2024 10:33:53 +0000 Subject: [PATCH 5/5] back out changes to ftyp parsing --- libheif/box.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libheif/box.cc b/libheif/box.cc index 72feeabac9..c6257f605a 100644 --- a/libheif/box.cc +++ b/libheif/box.cc @@ -1041,7 +1041,7 @@ Error Box_ftyp::parse(BitstreamRange& range) m_major_brand = range.read32(); m_minor_version = range.read32(); - if (get_box_size() - 8 <= get_header_size()) { + if (get_box_size() <= get_header_size() + 8) { // Sanity check. return Error(heif_error_Invalid_input, heif_suberror_Invalid_box_size,