Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
LIB_DIR = Path(__file__).parent / "lib"
BUILD_TOOLS = Path(__file__).parent / "build_tools"
OPENJPEG_SRC = LIB_DIR / "openjpeg" / "src" / "lib" / "openjp2"
THIRDPARTY_SRC = LIB_DIR / "openjpeg" / "thirdparty"
BIN_SRC = LIB_DIR / "openjpeg" / "src" / "bin" / "common"
INTERFACE_SRC = LIB_DIR / "interface"
BUILD_DIR = LIB_DIR / "openjpeg" / "build"
BACKUP_DIR = BUILD_TOOLS / "backup"
Expand All @@ -36,6 +38,7 @@ def build(setup_kwargs: Any) -> Any:
language="c",
include_dirs=[
os.fspath(OPENJPEG_SRC),
os.fspath(THIRDPARTY_SRC / "liblcms2" / "include"),
os.fspath(INTERFACE_SRC),
numpy.get_include(),
],
Expand Down Expand Up @@ -83,6 +86,10 @@ def get_source_files() -> List[Path]:
if fname.suffix == ".c":
source_files.append(fname)

for name in (THIRDPARTY_SRC / "liblcms2" / "src").glob("*"):
if name.suffix == ".c":
source_files.append(name)

source_files = [p.relative_to(Path(__file__).parent) for p in source_files]
source_files.insert(0, PACKAGE_DIR / "_openjpeg.pyx")

Expand All @@ -100,6 +107,10 @@ def setup_oj() -> None:

BACKUP_DIR.mkdir(exist_ok=True, parents=True)

# Copy the color space conversion files
for name in ("color.c", "color.h"):
shutil.copy(BIN_SRC / name, INTERFACE_SRC / name)

shutil.copy(
LIB_DIR / "openjpeg" / "CMakeLists.txt",
BACKUP_DIR / "CMakeLists.txt.backup",
Expand All @@ -114,6 +125,7 @@ def setup_oj() -> None:
BUILD_TOOLS / "cmake" / "CMakeLists.txt",
LIB_DIR / "openjpeg" / "CMakeLists.txt",
)

# Edit openjpeg.c to remove the OPJ_API declaration
with p_openjpeg.open("r") as f:
data = f.readlines()
Expand All @@ -128,18 +140,23 @@ def setup_oj() -> None:
if os.path.exists(BUILD_DIR):
shutil.rmtree(BUILD_DIR)

try:
os.remove(INTERFACE_SRC / "opj_config.h")
os.remove(INTERFACE_SRC / "opj_config_private.h")
except:
pass
for name in ("opj_config.h", "opj_config_private.h"):
try:
os.remove(INTERFACE_SRC / name)
except:
pass

os.mkdir(BUILD_DIR)
cur_dir = os.getcwd()
os.chdir(BUILD_DIR)
subprocess.call(['cmake', os.fspath((LIB_DIR / "openjpeg").resolve(strict=True))])
os.chdir(cur_dir)

shutil.copy(
BUILD_DIR / "src" / "bin" / "common" / "opj_apps_config.h",
INTERFACE_SRC / "opj_apps_config.h",
)

# Turn off JPIP
if os.path.exists(INTERFACE_SRC / "opj_config.h"):
with open(INTERFACE_SRC / "opj_config.h", "a") as f:
Expand Down
1 change: 1 addition & 0 deletions docs/changes/v2.5.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Changes

* Bits above the precision are now ignored when encoding (:issue:`104`)
* Supported Python versions are 3.9 to 3.14.
* Update to openjpeg v2.5.3
Loading
Loading