Skip to content

Commit

Permalink
Update exiv2 dependency to v0.28.0
Browse files Browse the repository at this point in the history
  • Loading branch information
henryborchers committed Oct 18, 2023
1 parent ecbe8bb commit b462a78
Show file tree
Hide file tree
Showing 38 changed files with 91 additions and 94 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if(pyexiv2bind_generate_python_bindings)
add_subdirectory(${libpybind11_SOURCE_DIR} ${libpybind11_BINARY_DIR} EXCLUDE_FROM_ALL)
endif ()
endif(pyexiv2bind_generate_python_bindings)
add_subdirectory(py3exiv2bind/core)
add_subdirectory(src/py3exiv2bind/core)
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES ${PROJECT_SOURCE_DIR}/_skbuild)
include(CTest)
add_subdirectory(tests)
4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# Include the license file
include tox.ini CHANGELOG.rst README.rst CMakeLists.txt tests/CMakeLists.txt requirements.txt requirements-dev.txt
include conanfile.py
include py3exiv2bind/core.pyi
include src/py3exiv2bind/core.pyi
include patches/*.patch
include patches/*.cmake
include pyproject.toml
recursive-include cmake_scripts *.cmake
recursive-include tests *.py *.cpp
recursive-include docs/source *.*
include docs/make.bat docs/Makefile
recursive-include py3exiv2bind *.py *.cpp *.h CMakeLists.txt
recursive-include src/py3exiv2bind *.py *.cpp *.h CMakeLists.txt
16 changes: 11 additions & 5 deletions cmake_scripts/external_exiv22.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ function(patch_exiv2_cmake root)
endfunction()

function(patch_tiff_resolution root)
list(APPEND LINES_TO_BE_REMOVED "{ 0x011a, ifd0Id }, // Exif.Image.XResolution")
list(APPEND LINES_TO_BE_REMOVED "{ 0x011b, ifd0Id }, // Exif.Image.YResolution")
list(APPEND LINES_TO_BE_REMOVED "{ 0x0128, ifd0Id }, // Exif.Image.ResolutionUnit")
list(APPEND LINES_TO_BE_REMOVED "case 0x011a: // Exif.Image.XResolution")
list(APPEND LINES_TO_BE_REMOVED "case 0x011b: // Exif.Image.YResolution")
list(APPEND LINES_TO_BE_REMOVED "case 0x0128: // Exif.Image.ResolutionUnit")

find_file(
tiffimage_int
Expand All @@ -37,14 +37,17 @@ function(patch_tiff_resolution root)
file(READ "${tiffimage_int}" data)
foreach(line ${LINES_TO_BE_REMOVED})
string(REPLACE "${line}" "" data "${data}")
message(STATUS "Removing line \"${line}\" from tiffimage_int.cpp")
endforeach()
file(WRITE "${libexiv2_BINARY_DIR}/tiffimage_int.cpp" "${data}")
message(STATUS "Modified the following source file to allow editing of Exif.Image.XResolution, Exif.Image.YResolution, and Exif.Image.ResolutionUnit: ${tiffimage_int}")
execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different "${libexiv2_BINARY_DIR}/tiffimage_int.cpp" "${tiffimage_int}")
endfunction()

FetchContent_Declare(
libexiv2
URL https://github.com/Exiv2/exiv2/archive/refs/tags/v0.27.6.tar.gz
URL https://github.com/Exiv2/exiv2/archive/refs/tags/v0.28.0.tar.gz
URL_HASH SHA256=04c0675caf4338bb96cd09982f1246d588bcbfe8648c0f5a30b56c7c496f1a0b
# GIT_REPOSITORY https://github.com/Exiv2/exiv2.git
# GIT_TAG ${EXIV2_VERSION_TAG}
# PATCH_COMMAND
Expand All @@ -56,13 +59,16 @@ if (NOT libexiv2_POPULATED)
FetchContent_Populate(libexiv2)
patch_tiff_resolution("${libexiv2_SOURCE_DIR}")
patch_exiv2_cmake("${libexiv2_SOURCE_DIR}")
option(EXIV2_ENABLE_INIH "" OFF)
option(EXIV2_BUILD_EXIV2_COMMAND "" OFF)
set(EXIV2_BUILD_EXIV2_COMMAND OFF CACHE BOOL "")
set(EXIV2_BUILD_SAMPLES OFF CACHE BOOL "")
option(EXIV2_BUILD_SAMPLES "" OFF)
if(MSVC)
option(EXIV2_ENABLE_DYNAMIC_RUNTIME "" ON)
endif()

list(APPEND CMAKE_MODULE_PATH "${libexiv2_SOURCE_DIR}/cmake")
include_directories(${libexiv2_BINARY_DIR})
add_subdirectory(${libexiv2_SOURCE_DIR} ${libexiv2_BINARY_DIR})
endif ()

9 changes: 3 additions & 6 deletions conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,10 @@ class pyexiv2bind(ConanFile):
}

def requirements(self):
# if self.settings.os == "Windows":
# self.requires("Expat/2.2.9@pix4d/stable")
# else:
self.requires("expat/2.4.2")
self.requires("brotli/1.0.9")
self.requires("expat/2.5.0")
self.requires("zlib/1.2.11")
if self.settings.os == "Macos":
self.requires("libiconv/1.16")
self.requires("libiconv/1.17")
def imports(self):
self.copy("*.dll", dst="bin", src="bin") # From bin to bin
self.copy("*.dylib*", dst=".", src="lib") # From lib to bin
Expand Down
38 changes: 19 additions & 19 deletions patches/tiff_resolution_path.patch
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
diff --git a/src/tiffimage_int.cpp b/src/tiffimage_int.cpp
index 7cd6656d..f31272ae 100644
index e62c5228e..a9db0c673 100644
--- a/src/tiffimage_int.cpp
+++ b/src/tiffimage_int.cpp
@@ -1828,14 +1828,14 @@ namespace Exiv2 {
{ 0x0115, ifd0Id }, // Exif.Image.SamplesPerPixel
{ 0x0116, ifd0Id }, // Exif.Image.RowsPerStrip
{ 0x0117, ifd0Id }, // Exif.Image.StripByteCounts
- { 0x011a, ifd0Id }, // Exif.Image.XResolution
- { 0x011b, ifd0Id }, // Exif.Image.YResolution
+// { 0x011a, ifd0Id }, // Exif.Image.XResolution
+// { 0x011b, ifd0Id }, // Exif.Image.YResolution
{ 0x011c, ifd0Id }, // Exif.Image.PlanarConfiguration
{ 0x0122, ifd0Id }, // Exif.Image.GrayResponseUnit
{ 0x0123, ifd0Id }, // Exif.Image.GrayResponseCurve
{ 0x0124, ifd0Id }, // Exif.Image.T4Options
{ 0x0125, ifd0Id }, // Exif.Image.T6Options
- { 0x0128, ifd0Id }, // Exif.Image.ResolutionUnit
+// { 0x0128, ifd0Id }, // Exif.Image.ResolutionUnit
{ 0x0129, ifd0Id }, // Exif.Image.PageNumber
{ 0x012d, ifd0Id }, // Exif.Image.TransferFunction
{ 0x013d, ifd0Id }, // Exif.Image.Predictor
@@ -2237,14 +2237,14 @@ static bool isTiffImageTagLookup(uint16_t tag, IfdId group) {
case 0x0115: // Exif.Image.SamplesPerPixel
case 0x0116: // Exif.Image.RowsPerStrip
case 0x0117: // Exif.Image.StripByteCounts
- case 0x011a: // Exif.Image.XResolution
- case 0x011b: // Exif.Image.YResolution
+// case 0x011a: // Exif.Image.XResolution
+// case 0x011b: // Exif.Image.YResolution
case 0x011c: // Exif.Image.PlanarConfiguration
case 0x0122: // Exif.Image.GrayResponseUnit
case 0x0123: // Exif.Image.GrayResponseCurve
case 0x0124: // Exif.Image.T4Options
case 0x0125: // Exif.Image.T6Options
- case 0x0128: // Exif.Image.ResolutionUnit
+// case 0x0128: // Exif.Image.ResolutionUnit
case 0x0129: // Exif.Image.PageNumber
case 0x012d: // Exif.Image.TransferFunction
case 0x013d: // Exif.Image.Predictor
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ requires = [
"conan>=1.50.0,<2.0"
]
build-backend = "uiucprescon.build"
[tool.pytest.ini_options]
pythonpath = "src"
testpaths = ["tests"]

[tool.cibuildwheel]
test-requires = [
Expand Down
53 changes: 26 additions & 27 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,22 @@
exiv2_extension = Pybind11Extension(
"py3exiv2bind.core",
sources=[
"py3exiv2bind/core/core.cpp",
"py3exiv2bind/core/glue/ExifStrategy.cpp",
"py3exiv2bind/core/glue/glue.cpp",
"py3exiv2bind/core/glue/Image.cpp",
"py3exiv2bind/core/glue/IPTC_Strategy.cpp",
"py3exiv2bind/core/glue/XmpStrategy.cpp",
"py3exiv2bind/core/glue/MetadataProcessor.cpp",
"src/py3exiv2bind/core/core.cpp",
"src/py3exiv2bind/core/glue/ExifStrategy.cpp",
"src/py3exiv2bind/core/glue/glue.cpp",
"src/py3exiv2bind/core/glue/Image.cpp",
"src/py3exiv2bind/core/glue/IPTC_Strategy.cpp",
"src/py3exiv2bind/core/glue/XmpStrategy.cpp",
"src/py3exiv2bind/core/glue/MetadataProcessor.cpp",
],
libraries=[
"exiv2",
],
include_dirs=[
"py3exiv2bind/core/glue",
"src/py3exiv2bind/core/glue",
],
language='c++',
cxx_std=14
cxx_std=17

)
extension_modules.append(exiv2_extension)
Expand Down Expand Up @@ -80,7 +80,6 @@ def platform_specific_configs(self):
sys_root = self.get_cmake_osx_sysroot()
if sys_root is not None:
configs.append(sys_root)
configs.append('-DEXIV2_BUILD_EXIV2_COMMAND:BOOL=ON')
return configs

@staticmethod
Expand Down Expand Up @@ -289,7 +288,7 @@ def build_install_cmake(self, extension: Pybind11Extension):
for ext in build_ext_cmd.extensions:
ext.library_dirs.insert(
0,
os.path.abspath(os.path.join(build_ext_cmd.build_lib, "py3exiv2bind"))
os.path.abspath(os.path.join(build_ext_cmd.build_lib, "src/py3exiv2bind"))
)
build_ext_cmd.include_dirs.insert(
0,
Expand Down Expand Up @@ -411,32 +410,31 @@ def run(self):
metadata_strategy = ConanBuildInfoTXT()
text_md = metadata_strategy.parse(conanbuildinfotext)
for lib in text_md["libs"]:
core_ext.libraries.append(lib)
for path in text_md["lib_paths"]:
core_ext.library_dirs.append(path)
if lib not in core_ext.libraries:
core_ext.libraries.append(lib)
for path in reversed(text_md["lib_paths"]):
core_ext.library_dirs.insert(0, path)

core_ext.include_dirs.append(os.path.join(self.build_temp, "include"))
core_ext.include_dirs.insert(0, os.path.join(self.build_temp, "include"))
if os.name == 'nt':
core_ext.libraries.append("shell32")
core_ext.libraries.append("psapi")
core_ext.libraries.append("Ws2_32")

core_ext.libraries.append("exiv2-xmp")

temp_lib_dir = os.path.join(self.build_temp, "lib")

if temp_lib_dir not in core_ext.library_dirs:
core_ext.library_dirs.insert(0, temp_lib_dir)


exiv2 = ("exiv2", {
"sources": [],
"CMAKE_SOURCE_DIR": os.path.dirname(__file__),
"CMAKE_CONFIG": [
'-Dpyexiv2bind_generate_python_bindings:BOOL=NO',
'-DEXIV2_ENABLE_NLS:BOOL=NO',
'-DEXIV2_ENABLE_VIDEO:BOOL=OFF',
'-DEXIV2_ENABLE_PNG:BOOL=OFF'
'-DEXIV2_ENABLE_PNG:BOOL=OFF',
'-DEXIV2_BUILD_EXIV2_COMMAND:BOOL=OFF'
],
})

Expand All @@ -446,19 +444,19 @@ def run(self):
exiv2_extension = Pybind11Extension(
"py3exiv2bind.core",
sources=[
"py3exiv2bind/core/core.cpp",
"py3exiv2bind/core/glue/ExifStrategy.cpp",
"py3exiv2bind/core/glue/glue.cpp",
"py3exiv2bind/core/glue/Image.cpp",
"py3exiv2bind/core/glue/IPTC_Strategy.cpp",
"py3exiv2bind/core/glue/XmpStrategy.cpp",
"py3exiv2bind/core/glue/MetadataProcessor.cpp",
"src/py3exiv2bind/core/core.cpp",
"src/py3exiv2bind/core/glue/ExifStrategy.cpp",
"src/py3exiv2bind/core/glue/glue.cpp",
"src/py3exiv2bind/core/glue/Image.cpp",
"src/py3exiv2bind/core/glue/IPTC_Strategy.cpp",
"src/py3exiv2bind/core/glue/XmpStrategy.cpp",
"src/py3exiv2bind/core/glue/MetadataProcessor.cpp",
],
libraries=[
"exiv2",
],
include_dirs=[
"py3exiv2bind/core/glue"
"src/py3exiv2bind/core/glue"
],
language='c++',

Expand All @@ -479,5 +477,6 @@ def run(self):
package_data={
"py3exiv2bind": ["py.typed", "core.pyi"],
},
package_dir={"py3exiv2bind": "src/py3exiv2bind"},
cmdclass=cmd_class
)
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ if (pyexiv2bind_generate_python_bindings)
python_extension_module(core)
endif()
set_target_properties(core PROPERTIES
CXX_STANDARD 11
CXX_STANDARD 17
LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/py3exiv2bind
RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/py3exiv2bind
PREFIX "${PYTHON_MODULE_PREFIX}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ PYBIND11_MODULE(core, m) {
.def("is_good", &Image::is_good, "Check if a file is loaded.")
;
pybind11::register_exception<NoIccError>(m, "NoICCError");
pybind11::register_exception<Exiv2::AnyError>(m, "Exiv2AnyError");
pybind11::register_exception<Exiv2::Error>(m, "Exiv2Error");
m.def("set_dpi", &set_dpi,
pybind11::arg("image"),
pybind11::arg("x"),
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ target_include_directories(glue PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRE
$<TARGET_PROPERTY:exiv2lib,INCLUDE_DIRECTORIES>
)
set_target_properties(glue PROPERTIES
CXX_STANDARD 14
CXX_STANDARD 17
)
target_link_libraries(glue PRIVATE exiv2lib)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
std::unordered_map<std::string, std::string> ExifStrategy::load(const Exiv2::Image &image){
try{
return make_dictionary(image.exifData());
}catch (const Exiv2::AnyError &e){
}catch (const Exiv2::Error &e){
// TODO: Handle errors
std::cerr << e.what() <<std::endl;
throw;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
std::unordered_map<std::string, std::string> IPTC_Strategy::load(const Exiv2::Image &image){
try{
return make_dictionary(image.iptcData());
}catch (const Exiv2::AnyError &e){
}catch (const Exiv2::Error &e){
// TODO: Handle errors
std::cerr << e.what() <<std::endl;
throw;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Image::Image(const std::string &filename) : filename(filename) {
image = std::unique_ptr<Exiv2::Image>(Exiv2::ImageFactory::open(filename));
assert(image); // Make sure it's able to read the file
image->readMetadata();
} catch (const Exiv2::AnyError &e) {
} catch (const Exiv2::Error &e) {
std::cerr << e.what() << std::endl;
throw std::runtime_error(e.what());
}
Expand Down Expand Up @@ -99,10 +99,11 @@ std::string Image::get_icc_profile() const {
if (!image->iccProfileDefined()) {
throw NoIccError();
}
const Exiv2::DataBuf *f = image->iccProfile();
for(int i = 0; i < f->size_; i++){
data << f->pData_[i];
Exiv2::DataBuf buffer = image->iccProfile();
for( auto const & byte: buffer){
data << byte;
}

data << std::endl;
return data.str();

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ std::unordered_map<std::string, std::string> XmpStrategy::load(const Exiv2::Imag
try{
return make_dictionary(image.xmpData());

}catch (const Exiv2::AnyError &e){
}catch (const Exiv2::Error &e){
// TODO: Handle errors
std::cerr << e.what() <<std::endl;
throw;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,14 @@ void set_dpi(const std::string &filename, int x, int y){

Exiv2::ExifData metadata = image->exifData();

metadata["Exif.Image.XResolution"] = create_DPI_string(x);
metadata["Exif.Image.YResolution"] = create_DPI_string(y);
metadata["Exif.Image.XResolution"] = Exiv2::URational(x, 1);
metadata["Exif.Image.YResolution"] = Exiv2::URational(y, 1);
metadata["Exif.Image.ResolutionUnit"] = 2;
image->setExifData(metadata);
image->writeMetadata();
image->readMetadata();

}catch (const Exiv2::AnyError &e) {
}catch (const Exiv2::Error &e) {
throw;
}
}

std::string create_DPI_string(int value){
std::ostringstream response;
response << value;
response << "/1";
return response.str();
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <string>
#include <map>
//#include "glue_export.h"

struct metadata_chunk {

Expand All @@ -22,5 +21,4 @@ std::string exiv2_version();

void set_dpi(const std::string &filename, int x, int y);

std::string create_DPI_string(int value);
#endif //SUPERBUILD_GLUE_H
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit b462a78

Please sign in to comment.