Skip to content

Commit

Permalink
Merge pull request #17 from matyalatte/dev
Browse files Browse the repository at this point in the history
v0.3.5 update
  • Loading branch information
matyalatte committed Mar 17, 2024
2 parents f9e6eb2 + 1a95b86 commit 210fda0
Show file tree
Hide file tree
Showing 19 changed files with 101 additions and 64 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
outputs:
tag: ${{ steps.check-tag.outputs.tag }}
steps:

- name: Check tag
id: check-tag
run: |
Expand All @@ -26,7 +26,7 @@ jobs:
fi
echo "tag=$TAG" >> "$GITHUB_OUTPUT"
shell: bash

- name: Create Release Draft
id: create-release
uses: softprops/action-gh-release@v1
Expand All @@ -47,20 +47,20 @@ jobs:
runs-on: ${{ matrix.os }}
needs: setup
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive

- name: get sal.h (for Unix)
if: runner.os!='Windows'
run: bash external/Texconv-Custom-DLL/shell_scripts/get_sal.sh

- name: build dll (for Windows)
if: runner.os=='Windows'
run: |
cd external/Texconv-Custom-DLL/batch_files
./build.bat
- name: build shared library (for Unix)
if: runner.os!='Windows'
run: |
Expand All @@ -75,7 +75,7 @@ jobs:
cp LICENSE release/${{ env.ZIP_NAME }}
cp external/Texconv-Custom-DLL/*texconv.* release/${{ env.ZIP_NAME }}/directx
shell: bash

- name: Archive Release
uses: thedoctor0/zip-release@master
with:
Expand Down
57 changes: 30 additions & 27 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
name: Test

on:
pull_request:
branches:
- main
workflow_dispatch:

jobs:
Expand All @@ -9,21 +12,21 @@ jobs:
runs-on: windows-latest
steps:
- name: Setup Python
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: 3.7.x
architecture: x64
- uses: actions/checkout@v3

- uses: actions/checkout@v4

- name: Install
run: pip install flake8 pylint

- name: Run flake8
run: flake8
run: pip install flake8 pylint codespell

- name: Run pylint
run: python for_dev/lint.py --path=addons/blender_dds_addon
- name: Run scripts
run: |
flake8
python for_dev/lint.py --path=addons/blender_dds_addon
codespell -S ".git,.pytest_cache,external,htmlcov"
test:
# Most code is from pytest-blender's workflow by mondeja.
Expand All @@ -42,52 +45,52 @@ jobs:
blender-version: '4.0.2'

- platform: windows-latest
blender-version: '3.6.7'
blender-version: '3.6.9'

- platform: windows-latest
blender-version: '3.3.14'
blender-version: '3.3.16'

- platform: windows-latest
blender-version: '2.83.20'

# Test with 3.6 on Unix/Linux systems
- platform: ubuntu-latest
blender-version: '3.6.7'
blender-version: '3.6.9'

- platform: macos-latest
blender-version: '3.6.7'
blender-version: '3.6.9'

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
submodules: recursive

- name: get sal.h (for Unix)
if: runner.os!='Windows'
run: bash external/Texconv-Custom-DLL/shell_scripts/get_sal.sh

- name: build dll (for Windows)
if: runner.os=='Windows'
run: |
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.sh
cp external/Texconv-Custom-DLL/libtexconv.* addons/blender_dds_addon/directx
- name: Set up Python v${{ env.python-version }}
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: ${{ env.python-version }}

- name: Upgrade PIP
run: python -m pip install --upgrade pip

- name: Cache Blender ${{ matrix.blender-version }}
uses: actions/cache@v3
uses: actions/cache@v4
id: cache-blender
with:
path: |
Expand All @@ -105,7 +108,7 @@ jobs:
python -m pip list
blender-downloader ${{ matrix.blender-version }} --extract --remove-compressed --print-blender-executable --quiet | Out-File -FilePath _blender-executable-path.txt
get-content _blender-executable-path.txt
# Download Blender on Linux and MacOS
- name: Download Blender ${{ matrix.blender-version }}
if: |
Expand All @@ -117,7 +120,7 @@ jobs:
python -m pip list
printf "%s" "$(blender-downloader ${{ matrix.blender-version }} --extract --remove-compressed --print-blender-executable --quiet)" > _blender-executable-path.txt
cat _blender-executable-path.txt
# Install dependencies on Windows
- name: Install dependencies for Windows
if: runner.os == 'Windows'
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2022 matyalatte
Copyright (c) 2022-2024 matyalatte

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion addons/blender_dds_addon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
bl_info = {
'name': 'DDS textures',
'author': 'Matyalatte',
'version': (0, 3, 4),
'version': (0, 3, 5),
'blender': (2, 83, 20),
'location': 'Image Editor > Sidebar > DDS Tab',
'description': 'Import and export .dds files',
Expand Down
17 changes: 12 additions & 5 deletions addons/blender_dds_addon/directx/dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ def has_pitch(flags):
class DDS_CAPS(IntEnum):
CUBEMAP = 0x8 # DDSCAPS_COMPLEX
MIPMAP = 0x400008 # DDSCAPS_COMPLEX | DDSCAPS_MIPMAP
REQUIERD = 0x1000 # DDSCAPS_TEXTURE
REQUIRED = 0x1000 # DDSCAPS_TEXTURE

@staticmethod
def get_caps(has_mips, is_cube):
caps = DDS_CAPS.REQUIERD
caps = DDS_CAPS.REQUIRED
if has_mips:
caps |= DDS_CAPS.MIPMAP
if is_cube:
Expand Down Expand Up @@ -235,8 +235,10 @@ class DX10Header(c.LittleEndianStructure):
]

def get_dxgi(self):
if self.dxgi_format > DXGI_FORMAT.get_max():
if self.dxgi_format not in [fmt.value for fmt in DXGI_FORMAT]:
raise RuntimeError(f"Unsupported DXGI format detected. ({self.dxgi_format})")
if "ASTC" in DXGI_FORMAT(self.dxgi_format).name:
raise RuntimeError(f"ASTC textures are not supported. ({self.dxgi_format})")
return DXGI_FORMAT(self.dxgi_format)

def update(self, dxgi_format, is_cube, is_3d, array_size):
Expand Down Expand Up @@ -322,8 +324,6 @@ def read(f):
raise RuntimeError("Not DDS file.")
if head.dx10_header.resource_dimension == 2:
raise RuntimeError("1D textures are unsupported.")
if (head.is_array() or head.is_3d()) and head.has_mips():
raise RuntimeError(f"Loaded {head.get_texture_type()} texture has mipmaps. This is unexpected.")

return head

Expand Down Expand Up @@ -400,6 +400,13 @@ def is_signed(self):
def is_canonical(self):
return self.fourCC not in UNCANONICAL_FOURCC

def is_supported(self):
if self.dxgi_format not in [fmt.value for fmt in DXGI_FORMAT]:
return False
if "ASTC" in DXGI_FORMAT(self.dxgi_format).name:
return False
return True

def is_partial_cube(self):
return DDS_CAPS2.is_partial_cube(self.caps2)

Expand Down
15 changes: 4 additions & 11 deletions addons/blender_dds_addon/directx/dxgi_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class DXGI_FORMAT(IntEnum):
P208 = 130
V208 = 131
V408 = 132
A4B4G4R4_UNORM = 191

# non-official formats
ASTC_4X4_TYPELESS = 133
Expand All @@ -139,27 +140,19 @@ class DXGI_FORMAT(IntEnum):
def is_valid_format(cls, fmt_name):
return fmt_name in cls._member_names_

@staticmethod
def get_max():
return 134

@staticmethod
def get_max_canonical():
return 132

@staticmethod
def get_signed(fmt):
name = fmt.name
splitted = name.split("_")
num_type = splitted[-1]
name_split = name.split("_")
num_type = name_split[-1]

new_num_types = {
"UNORM": "SNORM",
"UINT": "SINT"
}

if num_type in new_num_types:
name = "_".join(splitted[:-1] + new_num_types[num_type])
name = "_".join(name_split[:-1] + new_num_types[num_type])
else:
return fmt

Expand Down
7 changes: 4 additions & 3 deletions addons/blender_dds_addon/directx/texconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def convert_to_tga(self, file, out=None, cubemap_layout="h-cross", invert_normal

dds_header = DDSHeader.read_from_file(file)

if dds_header.dxgi_format.value > DXGI_FORMAT.get_max_canonical():
if not dds_header.is_supported():
raise RuntimeError(
f"DDS converter does NOT support {dds_header.get_format_as_str()}.\n"
"Use '.dds' as an export format."
Expand Down Expand Up @@ -172,7 +172,8 @@ def convert_to_dds(self, file, dds_fmt, out=None,
if is_hdr(dds_fmt) and ext != 'hdr':
raise RuntimeError(f'Use .hdr for HDR textures. ({file})')
if ('BC6' in dds_fmt or 'BC7' in dds_fmt) and (not util.is_windows()) and (not allow_slow_codec):
raise RuntimeError(f'Can NOT use CPU codec for {dds_fmt}. Or enable the "Allow Slow Codec" option.')
raise RuntimeError(f'Can NOT export {dds_fmt} textures on this platform.'
' Or enable the "Allow Slow Codec" option.')

if not DXGI_FORMAT.is_valid_format(dds_fmt):
raise RuntimeError(f'Not DXGI format. ({dds_fmt})')
Expand Down Expand Up @@ -234,7 +235,7 @@ def __texconv(self, file, args, out=None, verbose=True, allow_slow_codec=False):
return out

def __cube_to_image(self, file, new_file, args, cubemap_layout="h-cross", verbose=True):
"""Genarate an image from a cubemap with texassemble."""
"""Generate an image from a cubemap with texassemble."""
if cubemap_layout.endswith("-fnz"):
cubemap_layout = cubemap_layout[:-4]
args = [cubemap_layout] + args
Expand Down
2 changes: 1 addition & 1 deletion addons/blender_dds_addon/directx/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@


def mkdir(directory):
"""Make dirctory."""
"""Make directory."""
os.makedirs(directory, exist_ok=True)


Expand Down
2 changes: 1 addition & 1 deletion addons/blender_dds_addon/ui/custom_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class DDSCustomProperties(DDSPropBase, PropertyGroup):
"""Properties for dds info."""
dxgi_format: EnumProperty(
name='DXGI format',
items=[('NONE', 'None', 'Skip this image when excuting the export opration.')] + DDS_FMT_ITEMS,
items=[('NONE', 'None', 'Skip this image when executing the export operation.')] + DDS_FMT_ITEMS,
description="DXGI format for DDS",
default='NONE'
)
Expand Down
2 changes: 1 addition & 1 deletion addons/blender_dds_addon/ui/export_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ def execute(self, context):


class DDS_PT_export_panel(bpy.types.Panel):
"""UI panel for improt function."""
"""UI panel for export function."""
bl_label = "Export as DDS"
bl_idname = 'DDS_PT_export_panel'
bl_space_type = "IMAGE_EDITOR"
Expand Down
2 changes: 1 addition & 1 deletion addons/blender_dds_addon/ui/import_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def execute(self, context):


class DDS_PT_import_panel(bpy.types.Panel):
"""UI panel for improt function."""
"""UI panel for import function."""
bl_label = "Import DDS"
bl_idname = 'DDS_PT_import_panel'
bl_space_type = "IMAGE_EDITOR"
Expand Down
6 changes: 6 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
ver 0.3.5
- Fixed typos
- Added support for texture arrays with mipmaps
- Updated DirectXTex to mar2024 release
- Added support for A4B4G4R4_UNORM

ver 0.3.4
- Fixed a bug that SNORM textures are broken when importing and exporting.

Expand Down
9 changes: 8 additions & 1 deletion docs/For-Dev.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@ Then, type `python for_dev\lint.py --path=addons\blender_dds_addon` in `./Blende
You will get results like `PyLint Passed | Score:...`.
The score should be more than 7.

## Codespell

[Codespell](https://github.com/codespell-project/codespell) is a spell checker for source codes.
Install it with `pip install codespell`.
Then, type `codespell -S ".git,.pytest_cache,external,htmlcov"`.
You should get no messages from codespell.

## pytest-blender

[pytest-blender](https://github.com/mondeja/pytest-blender) is a pytest plugin for Blender testing.
Expand Down Expand Up @@ -59,7 +66,7 @@ pytest tests\ -svv --blender-executable "%BLENDER_EXE%"
You can run scripts on remote servers for your repositories.
There are 2 workflows for the addon.

- Test: Run flake8, pylint, and pytest to check your codes.
- Test: Run flake8, pylint, codespell, and pytest to check your codes.
- Build: Build Texconv and zip it with python scripts.

See here if you want to use the workflows.
Expand Down
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Blender-DDS-Addon v0.3.4
# Blender-DDS-Addon v0.3.5

[![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)
Expand Down Expand Up @@ -112,6 +112,7 @@ Here is a list of supported formats.
* B8G8R8A8_UNORM_SRGB
* B8G8R8X8_UNORM_SRGB
* B4G4R4A4_UNORM
* A4B4G4R4_UNORM

</details>

Expand Down
Loading

0 comments on commit 210fda0

Please sign in to comment.