1111LIB_DIR = Path (__file__ ).parent / "lib"
1212BUILD_TOOLS = Path (__file__ ).parent / "build_tools"
1313OPENJPEG_SRC = LIB_DIR / "openjpeg" / "src" / "lib" / "openjp2"
14+ THIRDPARTY_SRC = LIB_DIR / "openjpeg" / "thirdparty"
15+ BIN_SRC = LIB_DIR / "openjpeg" / "src" / "bin" / "common"
1416INTERFACE_SRC = LIB_DIR / "interface"
1517BUILD_DIR = LIB_DIR / "openjpeg" / "build"
1618BACKUP_DIR = BUILD_TOOLS / "backup"
@@ -36,6 +38,8 @@ def build(setup_kwargs: Any) -> Any:
3638 language = "c" ,
3739 include_dirs = [
3840 os .fspath (OPENJPEG_SRC ),
41+ # os.fspath(THIRDPARTY_SRC / "liblcms2" / "src"),
42+ os .fspath (THIRDPARTY_SRC / "liblcms2" / "include" ),
3943 os .fspath (INTERFACE_SRC ),
4044 numpy .get_include (),
4145 ],
@@ -83,6 +87,10 @@ def get_source_files() -> List[Path]:
8387 if fname .suffix == ".c" :
8488 source_files .append (fname )
8589
90+ for name in (THIRDPARTY_SRC / "liblcms2" / "src" ).glob ("*" ):
91+ if name .suffix == ".c" :
92+ source_files .append (name )
93+
8694 source_files = [p .relative_to (Path (__file__ ).parent ) for p in source_files ]
8795 source_files .insert (0 , PACKAGE_DIR / "_openjpeg.pyx" )
8896
@@ -100,6 +108,10 @@ def setup_oj() -> None:
100108
101109 BACKUP_DIR .mkdir (exist_ok = True , parents = True )
102110
111+ # Copy the color space conversion files
112+ for name in ("color.c" , "color.h" ):
113+ shutil .copy (BIN_SRC / name , INTERFACE_SRC / name )
114+
103115 shutil .copy (
104116 LIB_DIR / "openjpeg" / "CMakeLists.txt" ,
105117 BACKUP_DIR / "CMakeLists.txt.backup" ,
@@ -114,6 +126,7 @@ def setup_oj() -> None:
114126 BUILD_TOOLS / "cmake" / "CMakeLists.txt" ,
115127 LIB_DIR / "openjpeg" / "CMakeLists.txt" ,
116128 )
129+
117130 # Edit openjpeg.c to remove the OPJ_API declaration
118131 with p_openjpeg .open ("r" ) as f :
119132 data = f .readlines ()
@@ -128,18 +141,23 @@ def setup_oj() -> None:
128141 if os .path .exists (BUILD_DIR ):
129142 shutil .rmtree (BUILD_DIR )
130143
131- try :
132- os . remove ( INTERFACE_SRC / "opj_config.h" )
133- os .remove (INTERFACE_SRC / "opj_config_private.h" )
134- except :
135- pass
144+ for name in ( "opj_config.h" , "opj_config_private.h" ) :
145+ try :
146+ os .remove (INTERFACE_SRC / name )
147+ except :
148+ pass
136149
137150 os .mkdir (BUILD_DIR )
138151 cur_dir = os .getcwd ()
139152 os .chdir (BUILD_DIR )
140153 subprocess .call (['cmake' , os .fspath ((LIB_DIR / "openjpeg" ).resolve (strict = True ))])
141154 os .chdir (cur_dir )
142155
156+ shutil .copy (
157+ BUILD_DIR / "src" / "bin" / "common" / "opj_apps_config.h" ,
158+ INTERFACE_SRC / "opj_apps_config.h" ,
159+ )
160+
143161 # Turn off JPIP
144162 if os .path .exists (INTERFACE_SRC / "opj_config.h" ):
145163 with open (INTERFACE_SRC / "opj_config.h" , "a" ) as f :
0 commit comments