From 19225a1617db715e197e0b55513d3eb4cd2ff70d Mon Sep 17 00:00:00 2001 From: matyalatte Date: Fri, 20 Oct 2023 02:10:06 +0900 Subject: [PATCH 01/13] fix an error when importing files from some specific directory structures --- addons/blender_dds_addon/ui/import_dds.py | 7 ++++--- changelog.txt | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/addons/blender_dds_addon/ui/import_dds.py b/addons/blender_dds_addon/ui/import_dds.py index 0976d6a..4706d7a 100644 --- a/addons/blender_dds_addon/ui/import_dds.py +++ b/addons/blender_dds_addon/ui/import_dds.py @@ -131,10 +131,11 @@ def import_dds(context, file): def import_dds_rec(context, folder, count=0): """Search a folder recursively, and import found dds files.""" for file in sorted(os.listdir(folder)): - if os.path.isdir(file): - count += import_dds_rec(context, os.path.join(folder, file), count=count) + path = os.path.join(folder, file) + if os.path.isdir(path): + count += import_dds_rec(context, path, count=count) elif file.split('.')[-1].lower() == "dds": - import_dds(context, os.path.join(folder, file)) + import_dds(context, path) count += 1 return count diff --git a/changelog.txt b/changelog.txt index dfe5e3f..5344145 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,6 @@ +ver 0.3.3 +- Fixed an error when importing files from some specific directory structures. + ver 0.3.2 - Fixed an error when importing dds without image editor opened. - Fixed an error when changing workspace with file picker opened. @@ -36,4 +39,4 @@ ver 0.1.1 - Fixed typo ver 0.1.0 -- Initial release \ No newline at end of file +- Initial release From 81ff2263d25bdbea0e37ea7d4479d22bef2bf75c Mon Sep 17 00:00:00 2001 From: matyalatte Date: Sat, 21 Oct 2023 18:12:16 +0900 Subject: [PATCH 02/13] fix a crash when closing Blender after exporting BC6 or BC7 textures --- changelog.txt | 1 + external/Texconv-Custom-DLL | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/changelog.txt b/changelog.txt index 5344145..52f5aa3 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,4 +1,5 @@ ver 0.3.3 +- Fixed a crash when closing Blender after exporting BC6 or BC7 textures. - Fixed an error when importing files from some specific directory structures. ver 0.3.2 diff --git a/external/Texconv-Custom-DLL b/external/Texconv-Custom-DLL index 3b9dc6e..c30e524 160000 --- a/external/Texconv-Custom-DLL +++ b/external/Texconv-Custom-DLL @@ -1 +1 @@ -Subproject commit 3b9dc6eae1e7325b52e9a04b4946e4143d8c4f4a +Subproject commit c30e524bf5fba6544c63e55aa54ead83fb062710 From 5cf72c1c6751d8072e50cd119d4fd44d3ca4239e Mon Sep 17 00:00:00 2001 From: matyalatte Date: Sat, 21 Oct 2023 18:14:27 +0900 Subject: [PATCH 03/13] fix a bug that sRGB formats make textures brighter when exporting --- .github/workflows/build.yml | 4 ++-- .github/workflows/test.yml | 4 ++-- addons/blender_dds_addon/directx/texconv.py | 3 +++ changelog.txt | 1 + docs/How-To-Build.md | 4 ++-- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 234c3af..af8bc9a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -59,13 +59,13 @@ jobs: if: runner.os=='Windows' run: | cd external/Texconv-Custom-DLL/batch_files - ./build_small.bat + ./build.bat - name: build shared library (for Unix) if: runner.os!='Windows' run: | cd external/Texconv-Custom-DLL/shell_scripts - bash build_small.sh + bash build.sh - name: Copy files run: | diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4b694c7..6978149 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -66,13 +66,13 @@ jobs: - name: build dll (for Windows) if: runner.os=='Windows' run: | - external/Texconv-Custom-DLL/batch_files/build_small.bat + external/Texconv-Custom-DLL/batch_files/build.bat cp external/Texconv-Custom-DLL/texconv.dll addons/blender_dds_addon/directx - name: build shared library (for Unix) if: runner.os!='Windows' run: | - bash external/Texconv-Custom-DLL/shell_scripts/build_small.sh + bash external/Texconv-Custom-DLL/shell_scripts/build.sh cp external/Texconv-Custom-DLL/libtexconv.* addons/blender_dds_addon/directx - name: Set up Python v${{ env.python-version }} diff --git a/addons/blender_dds_addon/directx/texconv.py b/addons/blender_dds_addon/directx/texconv.py index 769057f..4deadaa 100644 --- a/addons/blender_dds_addon/directx/texconv.py +++ b/addons/blender_dds_addon/directx/texconv.py @@ -176,6 +176,9 @@ def convert_to_dds(self, file, dds_fmt, out=None, if image_filter != "LINEAR": args += ["-if", image_filter] + if "SRGB" in dds_fmt: + args += ['-srgb'] + if ("BC5" in dds_fmt) and invert_normals: args += ['-inverty'] diff --git a/changelog.txt b/changelog.txt index 52f5aa3..588fe27 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,5 +1,6 @@ ver 0.3.3 - Fixed a crash when closing Blender after exporting BC6 or BC7 textures. +- Fixed a bug that sRGB formats make textures brighter when exporting. - Fixed an error when importing files from some specific directory structures. ver 0.3.2 diff --git a/docs/How-To-Build.md b/docs/How-To-Build.md index 59d6b62..6ad7abc 100644 --- a/docs/How-To-Build.md +++ b/docs/How-To-Build.md @@ -41,13 +41,13 @@ It'll download the file and place it in a proper location. ### for Windows Move to `./Blender-DDS-Addon/external/Texconv-Custom-DLL/batch_files`. -Then, type `build_small.bat`. +Then, type `build.bat`. `texconv.dll` will be generated in `./Blender-DDS-Addon/external/Texconv-Custom-DLL/` ### for Unix/Linux Move to `./Blender-DDS-Addon/external/Texconv-Custom-DLL/shell_scripts`. -Then, type `bash build_small.sh`. +Then, type `bash build.sh`. `libtexconv.so` (or `libtexconv.dylib`) will be generated in `./Blender-DDS-Addon/external/Texconv-Custom-DLL/` ## 4. Copy Texconv From bd7df0d78a2b9e43019c3068020508a112e33222 Mon Sep 17 00:00:00 2001 From: matyalatte Date: Sat, 21 Oct 2023 20:43:57 +0900 Subject: [PATCH 04/13] update version info --- addons/blender_dds_addon/__init__.py | 2 +- docs/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/blender_dds_addon/__init__.py b/addons/blender_dds_addon/__init__.py index 886106a..5bb11c2 100644 --- a/addons/blender_dds_addon/__init__.py +++ b/addons/blender_dds_addon/__init__.py @@ -8,7 +8,7 @@ bl_info = { 'name': 'DDS textures', 'author': 'Matyalatte', - 'version': (0, 3, 2), + 'version': (0, 3, 3), 'blender': (2, 83, 20), 'location': 'Image Editor > Sidebar > DDS Tab', 'description': 'Import and export .dds files', diff --git a/docs/README.md b/docs/README.md index 532e6c6..a5f2747 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -# Blender-DDS-Addon v0.3.2 +# Blender-DDS-Addon v0.3.3 [![Github All Releases](https://img.shields.io/github/downloads/matyalatte/Blender-DDS-Addon/total.svg)]() [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) From be560160f997b2b2b346bce425c9379ced61b883 Mon Sep 17 00:00:00 2001 From: matyalatte Date: Sat, 21 Oct 2023 21:02:22 +0900 Subject: [PATCH 05/13] add an error for ARM devices --- addons/blender_dds_addon/directx/texconv.py | 9 ++++----- addons/blender_dds_addon/directx/util.py | 4 ++++ changelog.txt | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/addons/blender_dds_addon/directx/texconv.py b/addons/blender_dds_addon/directx/texconv.py index 4deadaa..db997d3 100644 --- a/addons/blender_dds_addon/directx/texconv.py +++ b/addons/blender_dds_addon/directx/texconv.py @@ -74,13 +74,12 @@ def load_dll(self, dll_path=None): raise RuntimeError(f'This OS ({util.get_os_name()}) is unsupported.') dirname = os.path.dirname(file_path) dll_path = os.path.join(dirname, dll_name) - dll_path2 = os.path.join(os.path.dirname(dirname), dll_name) # allow ../texconv.dll + + if util.is_arm(): + raise RuntimeError(f'{dll_name} does NOT support ARM devices') if not os.path.exists(dll_path): - if os.path.exists(dll_path2): - dll_path = dll_path2 - else: - raise RuntimeError(f'texconv not found. ({dll_path})') + raise RuntimeError(f'texconv not found. ({dll_path})') self.dll = ctypes.cdll.LoadLibrary(dll_path) DLL = self.dll diff --git a/addons/blender_dds_addon/directx/util.py b/addons/blender_dds_addon/directx/util.py index de87be5..21602e8 100644 --- a/addons/blender_dds_addon/directx/util.py +++ b/addons/blender_dds_addon/directx/util.py @@ -36,3 +36,7 @@ def is_linux(): def is_mac(): return get_os_name() == 'Darwin' + + +def is_arm(): + return 'arm' in platform.machine().lower() diff --git a/changelog.txt b/changelog.txt index 588fe27..9b58796 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ ver 0.3.3 - Fixed a crash when closing Blender after exporting BC6 or BC7 textures. - Fixed a bug that sRGB formats make textures brighter when exporting. - Fixed an error when importing files from some specific directory structures. +- Added an error for ARM devices. ver 0.3.2 - Fixed an error when importing dds without image editor opened. From 0db4c68c6badbe9c7ce779d42c29d91f74353fbd Mon Sep 17 00:00:00 2001 From: matyalatte Date: Sat, 21 Oct 2023 21:11:15 +0900 Subject: [PATCH 06/13] release DLL resources for each operation --- addons/blender_dds_addon/ui/export_dds.py | 6 +++++- addons/blender_dds_addon/ui/import_dds.py | 5 ++++- changelog.txt | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/addons/blender_dds_addon/ui/export_dds.py b/addons/blender_dds_addon/ui/export_dds.py index 72d0bca..34c4bbc 100644 --- a/addons/blender_dds_addon/ui/export_dds.py +++ b/addons/blender_dds_addon/ui/export_dds.py @@ -13,7 +13,7 @@ import numpy as np from ..directx.dds import is_hdr, DDS -from ..directx.texconv import Texconv +from ..directx.texconv import Texconv, unload_texconv from .bpy_util import save_texture, dds_properties_exist, get_image_editor_space, flush_stdout from .texture_list import draw_texture_list @@ -266,6 +266,10 @@ def execute_base(self, context, file=None, directory=None, is_dir=False): print(traceback.format_exc()) self.report({'ERROR'}, e.args[0]) ret = {'CANCELLED'} + + # release DLL resources + unload_texconv() + return ret diff --git a/addons/blender_dds_addon/ui/import_dds.py b/addons/blender_dds_addon/ui/import_dds.py index 4706d7a..3bb6f45 100644 --- a/addons/blender_dds_addon/ui/import_dds.py +++ b/addons/blender_dds_addon/ui/import_dds.py @@ -13,7 +13,7 @@ import numpy as np from ..directx.dds import DDSHeader, DDS -from ..directx.texconv import Texconv +from ..directx.texconv import Texconv, unload_texconv from .bpy_util import get_image_editor_space, load_texture, dds_properties_exist, flush_stdout from .custom_properties import DDS_FMT_NAMES @@ -184,6 +184,9 @@ def execute_base(self, context, files=None, directory=None, is_dir=False): self.report({'ERROR'}, e.args[0]) ret = {'CANCELLED'} + # release DLL resources + unload_texconv() + return ret diff --git a/changelog.txt b/changelog.txt index 9b58796..f3ebb73 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ ver 0.3.3 - Fixed a crash when closing Blender after exporting BC6 or BC7 textures. - Fixed a bug that sRGB formats make textures brighter when exporting. - Fixed an error when importing files from some specific directory structures. +- Made the addon release DLL resources for each operation. - Added an error for ARM devices. ver 0.3.2 From 9c0d1be398e26d4c119334c7ca54ca8d4988ff0e Mon Sep 17 00:00:00 2001 From: matyalatte Date: Sat, 21 Oct 2023 21:14:51 +0900 Subject: [PATCH 07/13] test with Blender 3.6.5 --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6978149..3ed2770 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -37,9 +37,9 @@ jobs: fail-fast: false matrix: include: - # Test with 2.83, 3.3, and 3.5 on Windows + # Test with 2.83, 3.3, and 3.6 on Windows - platform: windows-latest - blender-version: '3.5.1' + blender-version: '3.6.5' - platform: windows-latest blender-version: '3.3.7' From a3b4d8712233c020605a7abe434770f745c5c3d7 Mon Sep 17 00:00:00 2001 From: matyalatte Date: Sun, 22 Oct 2023 00:38:29 +0900 Subject: [PATCH 08/13] latest texconv requires '--' as the end of optoins --- addons/blender_dds_addon/directx/texconv.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/blender_dds_addon/directx/texconv.py b/addons/blender_dds_addon/directx/texconv.py index db997d3..bf467ab 100644 --- a/addons/blender_dds_addon/directx/texconv.py +++ b/addons/blender_dds_addon/directx/texconv.py @@ -205,8 +205,7 @@ def __texconv(self, file, args, out=None, verbose=True, allow_slow_codec=False): if out not in ['.', ''] and not os.path.exists(out): util.mkdir(out) - args += ["-y"] - args += [os.path.normpath(file)] + args += ["-y", "--", os.path.normpath(file)] args_p = [ctypes.c_wchar_p(arg) for arg in args] args_p = (ctypes.c_wchar_p*len(args_p))(*args_p) @@ -235,7 +234,7 @@ def __texassemble(self, file, new_file, args, verbose=True): out = os.path.dirname(new_file) if out not in ['.', ''] and not os.path.exists(out): util.mkdir(out) - args += ["-y", "-o", new_file, file] + args += ["-y", "-o", new_file, "--", file] args_p = [ctypes.c_wchar_p(arg) for arg in args] args_p = (ctypes.c_wchar_p*len(args_p))(*args_p) From cac87d77e151c0bb3300448eb068d999c35162ac Mon Sep 17 00:00:00 2001 From: matyalatte Date: Sun, 22 Oct 2023 01:40:23 +0900 Subject: [PATCH 09/13] update texconv --- external/Texconv-Custom-DLL | 2 +- tests/test_dds.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/external/Texconv-Custom-DLL b/external/Texconv-Custom-DLL index c30e524..ae9cda3 160000 --- a/external/Texconv-Custom-DLL +++ b/external/Texconv-Custom-DLL @@ -1 +1 @@ -Subproject commit c30e524bf5fba6544c63e55aa54ead83fb062710 +Subproject commit ae9cda348f1b2b5e7deb45149b483eb4a1800f05 diff --git a/tests/test_dds.py b/tests/test_dds.py index 820e464..d46d731 100644 --- a/tests/test_dds.py +++ b/tests/test_dds.py @@ -6,13 +6,16 @@ export_dds, texture_list, custom_properties) -from blender_dds_addon.directx.texconv import unload_texconv +from blender_dds_addon.directx.texconv import Texconv, unload_texconv import bpy bpy.utils.register_class(texture_list.DDSTextureListItem) bpy.utils.register_class(custom_properties.DDSCustomProperties) custom_properties.add_custom_props_for_dds() +texconv = Texconv() +texconv.dll.init_com() + def get_test_dds(): test_file = os.path.join("tests", "2d.dds") From efad51f52a627aec2ccb5d8d3ab9086ac83c2983 Mon Sep 17 00:00:00 2001 From: matyalatte Date: Sun, 22 Oct 2023 01:54:09 +0900 Subject: [PATCH 10/13] fix a bug that 'Import from a Directory' can not count files correctly --- addons/blender_dds_addon/ui/import_dds.py | 5 +++-- changelog.txt | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/addons/blender_dds_addon/ui/import_dds.py b/addons/blender_dds_addon/ui/import_dds.py index 3bb6f45..8184f52 100644 --- a/addons/blender_dds_addon/ui/import_dds.py +++ b/addons/blender_dds_addon/ui/import_dds.py @@ -128,12 +128,13 @@ def import_dds(context, file): space.image = tex -def import_dds_rec(context, folder, count=0): +def import_dds_rec(context, folder): """Search a folder recursively, and import found dds files.""" + count = 0 for file in sorted(os.listdir(folder)): path = os.path.join(folder, file) if os.path.isdir(path): - count += import_dds_rec(context, path, count=count) + count += import_dds_rec(context, path) elif file.split('.')[-1].lower() == "dds": import_dds(context, path) count += 1 diff --git a/changelog.txt b/changelog.txt index f3ebb73..d98f42c 100644 --- a/changelog.txt +++ b/changelog.txt @@ -2,6 +2,7 @@ ver 0.3.3 - Fixed a crash when closing Blender after exporting BC6 or BC7 textures. - Fixed a bug that sRGB formats make textures brighter when exporting. - Fixed an error when importing files from some specific directory structures. +- Fixed a bug that the `Import from a Directory` operation can not count DDS files correctly. - Made the addon release DLL resources for each operation. - Added an error for ARM devices. From b9b85843a44950c84b81adee79c0e2bc9e1b97e1 Mon Sep 17 00:00:00 2001 From: matyalatte Date: Sun, 22 Oct 2023 02:10:02 +0900 Subject: [PATCH 11/13] update docs --- docs/README.md | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/docs/README.md b/docs/README.md index a5f2747..d4fff1c 100644 --- a/docs/README.md +++ b/docs/README.md @@ -3,7 +3,6 @@ [![Github All Releases](https://img.shields.io/github/downloads/matyalatte/Blender-DDS-Addon/total.svg)]() [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) ![build](https://github.com/matyalatte/Blender-DDS-Addon/actions/workflows/build.yml/badge.svg) -Buy Me A Coffee Blender addon to import and export dds textures @@ -22,11 +21,9 @@ You can download zip files from [the release page](https://github.com/matyalatte - `blender_dds_addon*_Windows.zip` is for Windows. - `blender_dds_addon*_macOS.zip` is for Mac (10.15 or later). -- `blender_dds_addon*_Linux.zip` is for Ubuntu (20.04 or later). +- `blender_dds_addon*_Linux.zip` is for Linux with GLIBC 2.27+ and GLIBCXX 3.4.26+. -> The linux build only supports Ubuntu due to the glibc dependences. -> If you want to use it on other linux distributions, you should get the lib or build [Texconv](https://github.com/matyalatte/Texconv-Custom-DLL) by yourself. -> (But I don't know if it's possible on your platform.) +> The linux build only supports distributions using GLIBC and GLIBCXX. ## Getting Started @@ -118,7 +115,7 @@ Here is a list of supported formats. -## About Non-2D Textures +## Non-2D Textures The addon supports non-2D textures except for partial cubemaps. See wiki pages for the details. From 9b6d23f17a341fff92515c94c54db307ba1a2dd9 Mon Sep 17 00:00:00 2001 From: matyalatte Date: Sun, 22 Oct 2023 19:01:53 +0900 Subject: [PATCH 12/13] fix an error when exporting BC7_UNORM_SRGB --- external/Texconv-Custom-DLL | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/Texconv-Custom-DLL b/external/Texconv-Custom-DLL index ae9cda3..0c92461 160000 --- a/external/Texconv-Custom-DLL +++ b/external/Texconv-Custom-DLL @@ -1 +1 @@ -Subproject commit ae9cda348f1b2b5e7deb45149b483eb4a1800f05 +Subproject commit 0c924612293485000caf5c313e3006f523ed511d From 89cbb05e2ecfb113d67a3a0e433c9f82479d19d6 Mon Sep 17 00:00:00 2001 From: matyalatte Date: Sun, 22 Oct 2023 20:24:11 +0900 Subject: [PATCH 13/13] fix an error when releasing DLL resources on Linux --- addons/blender_dds_addon/directx/texconv.py | 38 +++++++++++++-------- changelog.txt | 1 + 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/addons/blender_dds_addon/directx/texconv.py b/addons/blender_dds_addon/directx/texconv.py index bf467ab..414aa3d 100644 --- a/addons/blender_dds_addon/directx/texconv.py +++ b/addons/blender_dds_addon/directx/texconv.py @@ -16,24 +16,34 @@ DLL = None +def get_dll_close_from_lib(lib_name): + """Return dll function to unlaod DLL if the library has it.""" + dlpath = find_library(lib_name) + if dlpath is None: + # DLL not found. + return None + try: + lib = ctypes.CDLL(dlpath) + if hasattr(lib, "dlclose"): + return lib.dlclose + except OSError: + pass + # dlclose not found. + return None + + def get_dll_close(): """Get dll function to unload DLL.""" if util.is_windows(): return ctypes.windll.kernel32.FreeLibrary else: - dlpath = find_library("c") - if dlpath is None: - dlpath = find_library("System") - elif dlpath is None: - # Failed to find the path to stdlib. - return None - - try: - stdlib = ctypes.CDLL(dlpath) - return stdlib.dlclose - except OSError: - # Failed to load stdlib. - return None + # Search libc, libdl, and libSystem + for lib_name in ["c", "dl", "System"]: + dlclose = get_dll_close_from_lib(lib_name) + if dlclose is not None: + return dlclose + # Failed to find dlclose + return None def unload_texconv(): @@ -43,7 +53,7 @@ def unload_texconv(): dll_close = get_dll_close() if dll_close is None: - raise RuntimeError("Failed to unload DLL. Restart Blender if you will remove the addon.") + raise RuntimeError("Failed to unload DLL.") handle = DLL._handle dll_close.argtypes = [ctypes.c_void_p] diff --git a/changelog.txt b/changelog.txt index d98f42c..ca3767f 100644 --- a/changelog.txt +++ b/changelog.txt @@ -3,6 +3,7 @@ ver 0.3.3 - Fixed a bug that sRGB formats make textures brighter when exporting. - Fixed an error when importing files from some specific directory structures. - Fixed a bug that the `Import from a Directory` operation can not count DDS files correctly. +- Fixed an error when releasing DLL resources on Linux. - Made the addon release DLL resources for each operation. - Added an error for ARM devices.