Skip to content

Commit 219b697

Browse files
MarkCallowViNeek
authored andcommitted
Expose HDR support in Python binding (KhronosGroup#1150)
Fixes KhronosGroup#1145. Additional fixes: - Adds `num_layers` property that was curiously missing. - Exposes ktxTexture[12]_IsHDR in the c API. - Reformats documentation comments for UASTC HDR ktxBasisParams to reduce line width.
1 parent 726eb04 commit 219b697

18 files changed

Lines changed: 597 additions & 52 deletions

interface/python_binding/buildscript.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,16 @@
8181
uint32_t faceSlice,
8282
void *src,
8383
size_t srcSize);
84+
bool ktxTexture_IsHDR(ktxTexture *);
85+
bool ktxTexture_IsTranscodable(ktxTexture *);
86+
bool ktxTexture_NeedsTranscoding(ktxTexture *);
87+
int ktxTexture2_DecodeAstc(void *);
8488
int ktxTexture2_TranscodeBasis(void *, int outputFormat, int transcodeFlags);
8589
int ktxTexture2_DeflateZstd(void *, uint32_t compressionLevel);
86-
uint32_t ktxTexture2_GetOETF(void *);
90+
uint32_t ktxTexture2_GetColorModel_e(void *);
91+
uint32_t ktxTexture2_GetPrimaries_e(void *);
92+
uint32_t ktxTexture2_GetTransferFunction_e(void *);
8793
bool ktxTexture2_GetPremultipliedAlpha(void *);
88-
bool ktxTexture2_NeedsTranscoding(void *);
8994
9095
int ktxHashList_AddKVPair(ktxHashList *, const char *key, unsigned int valueLen, const void *value);
9196
int ktxHashList_DeleteKVPair(ktxHashList *, const char *key);
@@ -108,6 +113,7 @@
108113
uint32_t PY_ktxTexture_get_baseHeight(ktxTexture *);
109114
uint32_t PY_ktxTexture_get_baseDepth(ktxTexture *);
110115
uint32_t PY_ktxTexture_get_numDimensions(ktxTexture *);
116+
uint32_t PY_ktxTexture_get_numLayers(ktxTexture *);
111117
uint32_t PY_ktxTexture_get_numLevels(ktxTexture *);
112118
uint32_t PY_ktxTexture_get_numFaces(ktxTexture *);
113119
uint32_t PY_ktxTexture_get_kvDataLen(ktxTexture *);
@@ -159,7 +165,7 @@
159165
bool perceptual,
160166
char *inputSwizzle);
161167
int PY_ktxTexture2_CompressBasisEx(void *texture,
162-
bool uastc,
168+
uint32_t codec,
163169
bool verbose,
164170
bool noSSE,
165171
uint32_t threadCount,
@@ -182,7 +188,14 @@
182188
float uastcRDOMaxSmoothBlockErrorScale,
183189
float uastcRDOMaxSmoothBlockStdDev,
184190
bool uastcRDODontFavorSimplerModes,
185-
bool uastcRDONoMultithreading);
191+
bool uastcRDONoMultithreading,
192+
uint32_t uastcHDRQuality,
193+
bool uastcHDRUberMode,
194+
bool uastcHDRUltraQuant,
195+
bool uastcHDRFavorAstc,
196+
bool rec2020,
197+
float uastcHDRLambda,
198+
uint32_t uastcHDRLevel);
186199
uint32_t PY_ktxTexture2_get_vkFormat(void *);
187200
uint32_t PY_ktxTexture2_get_supercompressionScheme(void *);
188201
"""

interface/python_binding/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
'sphinx.ext.napoleon',
4242
]
4343

44+
autodoc_member_order = 'bysource'
4445
templates_path = ['_templates']
4546
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
4647

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Copyright (c) 2026, Mark Callow
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
from enum import IntEnum
5+
6+
class KhrDfModel(IntEnum):
7+
"""Model in which the color coordinate space is defined."""
8+
9+
UNSPECIFIED = 0
10+
"""No interpretation of color channels defined."""
11+
12+
RGBSDA = 1
13+
"""Color primaries (red, green, blue) + alpha, depth and stencil."""
14+
15+
YUVSDA = 2
16+
"""Color differences (Y', Cb, Cr) + alpha, depth and stencil."""
17+
18+
YIQSDA = 3
19+
"""Color differences (Y', I, Q) + alpha, depth and stencil."""
20+
21+
LABSDA = 4
22+
"""Perceptual color (CIE L*a*b*) + alpha, depth and stencil."""
23+
24+
CMYKA = 5
25+
"""Subtractive colors (cyan, magenta, yellow, black) + alpha."""
26+
27+
XYZW = 6
28+
"""Non-color coordinate data (X, Y, Z, W)."""
29+
30+
HSVA_ANG = 7
31+
"""Hue, saturation, value, hue angle on color circle, plus alpha."""
32+
33+
HSLA_ANG = 8
34+
"""Hue, saturation, lightness, hue angle on color circle, plus alpha."""
35+
36+
HSVA_HEX = 9
37+
"""Hue, saturation, value, hue on color hexagon, plus alpha."""
38+
39+
HSLA_HEX = 10
40+
"""Hue, saturation, lightness, hue on color hexagon, plus alpha."""
41+
42+
YCGCOA = 11
43+
"""Lightweight approximate color difference (luma, orange, green)."""
44+
45+
YCCBCCRC = 12
46+
"""ITU BT.2020 constant luminance YcCbcCrc."""
47+
48+
ICTCP = 13
49+
"""ITU BT.2100 constant intensity ICtCp."""
50+
51+
CIEXYZ = 14
52+
"""CIE 1931 XYZ color coordinates (X, Y, Z)."""
53+
54+
CIEXYY = 15
55+
"""CIE 1931 xyY color coordinates (X, Y, Y)."""
56+
57+
58+
DXT1A = 128
59+
BC1A = 128
60+
"""Compressed formats start at 128."""
61+
"""
62+
Direct3D (and S3) compressed formats.
63+
DXT1 "channels" are RGB (0), Alpha (1).
64+
DXT1/BC1 with one channel is opaque.
65+
DXT1/BC1 with a cosited alpha sample is transparent.
66+
"""
67+
68+
DXT2 = 129
69+
DXT3 = 129
70+
BC2 = 129
71+
"""DXT2/DXT3/BC2, with explicit 4-bit alpha."""
72+
73+
DXT4 = 130
74+
DXT5 = 130
75+
BC3 = 130
76+
"""DXT4/DXT5/BC3, with interpolated alpha."""
77+
78+
ATI1N = 131
79+
DXT5A = 131
80+
BC4 = 131
81+
"""ATI1n/DXT5A/BC4 - single channel interpolated 8-bit data.
82+
(The UNORM/SNORM variation is recorded in the channel data)."""
83+
84+
ATI2N_XY = 132
85+
DXN = 132
86+
BC5 = 132
87+
"""ATI2n_XY/DXN/BC5 - two channel interpolated 8-bit data.
88+
(The UNORM/SNORM variation is recorded in the channel data)."""
89+
90+
BC6H = 133
91+
"""BC6H - DX11 format for 16-bit float channels."""
92+
93+
BC7 = 134
94+
"""BC7 - DX11 format."""
95+
96+
ETC1 = 160
97+
"""A format of ETC1 indicates that the format shall be decodable
98+
by an ETC1-compliant decoder and not rely on ETC2 features."""
99+
100+
ETC2 = 161
101+
"""A format of ETC2 is permitted to use ETC2 encodings on top of
102+
the baseline ETC1 specification.
103+
The ETC2 format has channels "red", "green", "RGB" and "alpha",
104+
which should be cosited samples.
105+
Punch-through alpha can be distinguished from full alpha by
106+
the plane size in bytes required for the texel block."""
107+
108+
ASTC = 162
109+
"""Adaptive Scalable Texture Compression."""
110+
"""ASTC HDR vs LDR is determined by the float flag in the channel."""
111+
"""ASTC block size can be distinguished by texel block size."""
112+
113+
ETC1S = 163
114+
"""ETC1S is a simplified subset of ETC1."""
115+
116+
PVRTC = 164
117+
PVRTC2 = 165
118+
"""PowerVR Texture Compression."""
119+
120+
UASTC = 166
121+
UASTC_LDR_4x4 = 166
122+
UASTC_HDR_4x4 = 167
123+
UASTC_HDR_6x6 = 168
124+
"""UASTC for BASIS supercompression."""
125+
126+
MAX = 0xFF
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Copyright (c) 2026, Mark Callow
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
from enum import IntEnum
5+
6+
class KhrDfPrimaries(IntEnum):
7+
"""The primary colors of an image."""
8+
9+
UNSPECIFIED = 0
10+
"""No color primaries defined"""
11+
12+
BT709 = 1
13+
"""Color primaries of ITU-R BT.709 and sRGB"""
14+
15+
SRGB = 1
16+
"""Synonym for BT709"""
17+
18+
BT601_EBU = 2
19+
"""Color primaries of ITU-R BT.601 (625-line EBU variant)"""
20+
21+
BT601_SMPTE = 3
22+
"""Color primaries of ITU-R BT.601 (525-line SMPTE C variant)"""
23+
24+
BT2020 = 4
25+
"""Color primaries of ITU-R BT.2020"""
26+
27+
BT2100 = 4
28+
"""ITU-R BT.2100 uses the same primaries as BT.2020"""
29+
30+
CIEXYZ = 5
31+
"""CIE theoretical color coordinate space"""
32+
33+
ACES = 6
34+
"""Academy Color Encoding System primaries"""
35+
36+
ACESCC = 7
37+
"""Color primaries of ACEScc"""
38+
39+
NTSC1953 = 8
40+
"""Legacy NTSC 1953 primaries"""
41+
42+
PAL525 = 9
43+
"""Legacy PAL 525-line primaries"""
44+
45+
DISPLAYP3 = 10
46+
"""Color primaries of Display P3"""
47+
48+
ADOBERGB = 11
49+
"""Color primaries of Adobe RGB (1998)"""
50+
51+
MAX = 0xFF
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Copyright (c) 2026, Mark Callow
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
from enum import IntEnum
5+
6+
class KhrDfTransfer(IntEnum):
7+
"""The transfer function of an image."""
8+
9+
UNSPECIFIED = 0
10+
"""No transfer function defined."""
11+
12+
LINEAR = 1
13+
"""Linear transfer function (value proportional to intensity."""
14+
15+
SRGB = 2
16+
SRGB_EOTF = 2
17+
SCRGB = 2
18+
SCRGB_EOTF = 2
19+
"""Perceptually-linear transfer function of sRGB (~2.2); also used for scRGB."""
20+
21+
ITU = 3
22+
ITU_OETF = 3
23+
BT601 = 3
24+
BT601_OETF = 3
25+
BT709 = 3
26+
BT709_OETF = 3
27+
BT2020 = 3
28+
BT2020_OETF = 3
29+
"""Perceptually-linear transfer function of ITU BT.601, BT.709 and BT.2020 (~1/.45)."""
30+
31+
SMTPE170M = 3
32+
SMTPE170M_OETF = 3
33+
SMTPE170M_EOTF = 3
34+
"""SMTPE170M (digital NTSC) defines an alias for the ITU transfer function (~1/.45) and a linear OOTF."""
35+
36+
NTSC = 4
37+
NTSC_EOTF = 4
38+
"""Perceptually-linear gamma function of original NTSC (simple 2.2 gamma)."""
39+
40+
SLOG = 5
41+
SLOG_OETF = 5
42+
"""Sony S-log used by Sony video cameras."""
43+
44+
SLOG2 = 6
45+
SLOG2_OETF = 6
46+
"""Sony S-log 2 used by Sony video cameras."""
47+
48+
BT1886 = 7
49+
BT1886_EOTF = 7
50+
"""ITU BT.1886 EOTF."""
51+
52+
HLG_OETF = 8
53+
"""ITU BT.2100 HLG OETF (typical scene-referred content), linear light normalized 0..1."""
54+
55+
HLG_EOTF = 9
56+
"""ITU BT.2100 HLG EOTF (nominal HDR display of HLG content), linear light normalized 0..1."""
57+
58+
PQ_EOTF = 10
59+
"""ITU BT.2100 PQ EOTF (typical HDR display-referred PQ content)."""
60+
61+
PQ_OETF = 11
62+
"""ITU BT.2100 PQ OETF (nominal scene described by PQ HDR content)."""
63+
64+
DCIP3 = 12
65+
DCIP3_EOTF = 12
66+
"""DCI P3 transfer function."""
67+
68+
PAL_OETF = 13
69+
"""Legacy PAL OETF."""
70+
71+
PAL625_EOTF = 14
72+
"""Legacy PAL 625-line EOTF."""
73+
74+
ST240 = 15
75+
ST240_OETF = 15
76+
ST240_EOTF = 15
77+
"""Legacy ST240 transfer function."""
78+
79+
ACESCC = 16
80+
ACESCC_OETF = 16
81+
"""ACEScc transfer function."""
82+
83+
ACESCCT = 17
84+
ACESCCT_OETF = 17
85+
"""ACEScct transfer function."""
86+
87+
ADOBERGB = 18
88+
ADOBERGB_EOTF = 18
89+
"""Adobe RGB (1998) transfer function."""
90+
91+
HLG_UNNORMALIZED_OETF = 19
92+
"""Legacy ITU BT.2100 HLG OETF (typical scene-referred content), linear light normalized 0..12."""
93+
94+
MAX = 0xFF
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright (c) 2026, Mark Callow
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
from enum import IntEnum
5+
6+
class KtxBasisCodec(IntEnum):
7+
"""Options specifiying basis codec."""
8+
9+
NONE = 0
10+
"""NONE."""
11+
ETC1S = 1
12+
"""BasisLZ."""
13+
UASTC_LDR_4x4 = 2
14+
"""UASTC."""
15+
UASTC_HDR_4x4 = 3
16+
"""UASTC_HDR_4x4."""
17+
UASTC_HDR_6x6_INTERMEDIATE = 4
18+
"""UASTC_HDR_6x6i."""

0 commit comments

Comments
 (0)