From 5f86cfb00581f9e5c902011c9b43334c085f84dc Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Fri, 27 Oct 2023 18:49:07 +0700 Subject: [PATCH] Patch QGIS to include exif orientation tag handling fix --- .../qgis-qt6/exif_orientation_fix.patch | 59 +++++++++++++++++++ vcpkg/overlay/qgis-qt6/portfile.cmake | 1 + 2 files changed, 60 insertions(+) create mode 100644 vcpkg/overlay/qgis-qt6/exif_orientation_fix.patch diff --git a/vcpkg/overlay/qgis-qt6/exif_orientation_fix.patch b/vcpkg/overlay/qgis-qt6/exif_orientation_fix.patch new file mode 100644 index 0000000000..3a85d3d939 --- /dev/null +++ b/vcpkg/overlay/qgis-qt6/exif_orientation_fix.patch @@ -0,0 +1,59 @@ +diff --git a/src/core/raster/qgsexiftools.cpp b/src/core/raster/qgsexiftools.cpp +index f883d7960c6..51a200d37e5 100644 +--- a/src/core/raster/qgsexiftools.cpp ++++ b/src/core/raster/qgsexiftools.cpp +@@ -472,6 +472,7 @@ bool QgsExifTools::tagImage( const QString &imagePath, const QString &tag, const + return false; + + QVariant actualValue; ++ bool actualValueIsUShort = false; + if ( tag == QLatin1String( "Exif.GPSInfo.GPSLatitude" ) || + tag == QLatin1String( "Exif.GPSInfo.GPSLongitude" ) || + tag == QLatin1String( "Exif.GPSInfo.GPSDestLatitude" ) || +@@ -483,6 +484,11 @@ bool QgsExifTools::tagImage( const QString &imagePath, const QString &tag, const + { + actualValue = QStringLiteral( "%1/1000" ).arg( static_cast< int>( std::floor( std::abs( value.toDouble() ) * 1000 ) ) ); + } ++ else if ( tag == QLatin1String( "Exif.Image.Orientation" ) ) ++ { ++ actualValueIsUShort = true; ++ actualValue = value; ++ } + else if ( value.type() == QVariant::DateTime ) + { + const QDateTime dateTime = value.toDateTime(); +@@ -529,8 +535,21 @@ bool QgsExifTools::tagImage( const QString &imagePath, const QString &tag, const + + const bool isXmp = tag.startsWith( QLatin1String( "Xmp." ) ); + image->readMetadata(); +- if ( actualValue.type() == QVariant::Int || +- actualValue.type() == QVariant::LongLong ) ++ if ( actualValueIsUShort ) ++ { ++ if ( isXmp ) ++ { ++ Exiv2::XmpData &xmpData = image->xmpData(); ++ xmpData[tag.toStdString()] = static_cast( actualValue.toLongLong() ); ++ } ++ else ++ { ++ Exiv2::ExifData &exifData = image->exifData(); ++ exifData[tag.toStdString()] = static_cast( actualValue.toLongLong() ); ++ } ++ } ++ else if ( actualValue.type() == QVariant::Int || ++ actualValue.type() == QVariant::LongLong ) + { + if ( isXmp ) + { +@@ -543,8 +562,8 @@ bool QgsExifTools::tagImage( const QString &imagePath, const QString &tag, const + exifData[tag.toStdString()] = static_cast( actualValue.toLongLong() ); + } + } +- if ( actualValue.type() == QVariant::UInt || +- actualValue.type() == QVariant::ULongLong ) ++ else if ( actualValue.type() == QVariant::UInt || ++ actualValue.type() == QVariant::ULongLong ) + { + if ( isXmp ) + { diff --git a/vcpkg/overlay/qgis-qt6/portfile.cmake b/vcpkg/overlay/qgis-qt6/portfile.cmake index 7991b5ff95..650f9dac6a 100644 --- a/vcpkg/overlay/qgis-qt6/portfile.cmake +++ b/vcpkg/overlay/qgis-qt6/portfile.cmake @@ -24,6 +24,7 @@ vcpkg_from_github( snapping_properties.patch # Remove when updating to QGIS 3.34 exiv2-0.28.patch # Remove when updating to QGIS 3.34 profiler.patch # Remove when updating to QGIS 3.34 + exif_orientation_fix.patch # Remove when updating to QGIS 3.34.1 ) file(REMOVE ${SOURCE_PATH}/cmake/FindQtKeychain.cmake)