Skip to content

Commit

Permalink
support int formats, use sRGB for SRGB formats
Browse files Browse the repository at this point in the history
- support int formats
- use sRGB for SRGB formats
- update documents
  • Loading branch information
matyalatte committed Dec 28, 2022
1 parent d75acdc commit 5dff580
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 11 deletions.
2 changes: 1 addition & 1 deletion addons/blender_dds_addon/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
bl_info = {
'name': 'DDS textures',
'author': 'Matyalatte',
'version': (0, 1, 2),
'version': (0, 1, 3),
'blender': (2, 83, 20),
'location': 'Image Editor > Sidebar > DDS Tab',
'description': 'Import and export .dds files',
Expand Down
2 changes: 1 addition & 1 deletion addons/blender_dds_addon/dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class PF_FLAGS(Enum):


def is_hdr(name):
return 'BC6' in name or 'FLOAT' in name
return 'BC6' in name or 'FLOAT' in name or 'INT' in name or 'SNORM' in name


def convertible_to_tga(name):
Expand Down
5 changes: 2 additions & 3 deletions addons/blender_dds_addon/dxgi_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,10 @@ class DXGI_FORMAT(Enum):
DXGI_FORMAT_P208 = 130
DXGI_FORMAT_V208 = 131
DXGI_FORMAT_V408 = 132

# non-official formats
DXGI_FORMAT_ASTC_4X4_TYPELESS = 133
DXGI_FORMAT_ASTC_4X4_UNORM = 134
# DXGI_FORMAT_SAMPLER_FEEDBACK_MIN_MIP_OPAQUE
# DXGI_FORMAT_SAMPLER_FEEDBACK_MIP_REGION_USED_OPAQUE
DXGI_FORMAT_FORCE_UINT = 0xffffffff

@classmethod
def is_valid_format(cls, fmt_name):
Expand Down
11 changes: 10 additions & 1 deletion addons/blender_dds_addon/export_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,15 @@ def save_dds(tex, file, dds_fmt, invert_normals=False, no_mip=False,
Returns:
tex (bpy.types.Image): loaded texture
"""
# Check color space
color_space = tex.colorspace_settings.name
if 'SRGB' in dds_fmt and color_space != 'sRGB':
print("Warning: Specified DXGI format uses sRGB as a color space,"
f"but the texture uses {color_space} in Blender")
elif 'SRGB' not in dds_fmt and color_space not in ['Non-Color', 'Raw']:
print("Warning: Specified DXGI format does not use any color space conversion,"
f"but the texture uses {color_space} in Blender")

if is_hdr(dds_fmt):
ext = '.hdr'
fmt = 'HDR'
Expand Down Expand Up @@ -170,7 +179,7 @@ def get_alt_fmt(fmt):


def is_supported(fmt):
return ('TYPELESS' not in fmt) and ('INT' not in fmt) and \
return ('TYPELESS' not in fmt) and ('ASTC' not in fmt) and\
(len(fmt) > 4) and (fmt not in ["UNKNOWN", "420_OPAQUE"])


Expand Down
11 changes: 10 additions & 1 deletion addons/blender_dds_addon/import_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import numpy as np

from .texconv import Texconv
from .dds import DDSHeader
from .export_dds import get_image_editor_space
from . import util

Expand Down Expand Up @@ -61,7 +62,15 @@ def load_dds(file, invert_normals=False, cubemap_layout='h-cross', texconv=None)
invert_normals=invert_normals)
if temp_tga is None: # if texconv doesn't exist
raise RuntimeError('Failed to convert texture.')
tex = load_texture(temp_tga, name=os.path.basename(temp_tga)[:-4])

# Check color space
dds_header = DDSHeader.read_from_file(temp)
if dds_header.is_srgb():
color_space = 'sRGB'
else:
color_space = 'Non-Color'

tex = load_texture(temp_tga, name=os.path.basename(temp_tga)[:-4], color_space=color_space)

except Exception as e:
if tex is not None:
Expand Down
2 changes: 2 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
ver 0.1.3
- Supported dds files that have no fourCC
- Supported UINT and SINT formats
- Used "sRGB" as a color space for SRGB formats
- Refined codes

ver 0.1.2
Expand Down
2 changes: 1 addition & 1 deletion docs/How-To-Build.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ If you won't use Visual Studio 2022, you could need to edit cmake commands in ba
### for Unix

- xcode (for macOS)
- build-essential (for Linux)
- build-essential (for Ubuntu)
- cmake
- wget

Expand Down
30 changes: 27 additions & 3 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Blender-DDS-Addon v0.1.2
# Blender-DDS-Addon v0.1.3

[![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)
Expand All @@ -23,8 +23,9 @@ You can download zip files from [the release page](https://github.com/matyalatte
- `blender_dds_addon*_macOS.zip` is for Mac (10.15 or later).
- `blender_dds_addon*_Linux.zip` is for Ubuntu (20.04 or later).

If you want to use the addon on other platforms, you need to build [Texconv](https://github.com/matyalatte/Texconv-Custom-DLL) by yourself and zip it with python scripts.
(But I don't know if it's possible on your platform.)
> 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.)
## Getting Started

Expand Down Expand Up @@ -54,29 +55,52 @@ Here is a list of supported formats.
* BC7_UNORM
* BC7_UNORM_SRGB
* R32G32B32A32_FLOAT
* R32G32B32A32_UINT
* R32G32B32A32_SINT
* R32G32B32_FLOAT
* R32G32B32_UINT
* R32G32B32_SINT
* R16G16B16A16_FLOAT
* R16G16B16A16_UNORM
* R16G16B16A16_UINT
* R16G16B16A16_SNORM
* R16G16B16A16_SINT
* R32G32_FLOAT
* R32G32_UINT
* R32G32_SINT
* D32_FLOAT_S8X24_UINT
* R10G10B10A2_UNORM
* R10G10B10A2_UINT
* R11G11B10_FLOAT
* R8G8B8A8_UNORM
* R8G8B8A8_UNORM_SRGB
* R8G8B8A8_UINT
* R8G8B8A8_SNORM
* R8G8B8A8_SINT
* R16G16_FLOAT
* R16G16_UNORM
* R16G16_UINT
* R16G16_SNORM
* R16G16_SINT
* D32_FLOAT
* R32_FLOAT
* R32_UINT
* R32_SINT
* D24_UNORM_S8_UINT
* R8G8_UNORM
* R8G8_UINT
* R8G8_SNORM
* R8G8_SINT
* R16_FLOAT
* D16_UNORM
* R16_UNORM
* R16_UINT
* R16_SNORM
* R16_SINT
* R8_UNORM
* R8_UINT
* R8_SNORM
* R8_SINT
* A8_UNORM
* R1_UNORM
* R9G9B9E5_SHAREDEXP
Expand Down

0 comments on commit 5dff580

Please sign in to comment.