astc_encoder.enum

The enumeration classes for the ASTC encoder.

  1"""The enumeration classes for the ASTC encoder."""
  2
  3from enum import IntEnum, IntFlag
  4
  5
  6class ASTCProfile(IntEnum):
  7    """A codec color profile.
  8
  9    Attributes
 10    ----------
 11    LDR_SRGB : int = 0
 12        The LDR sRGB color profile.
 13    LDR : int = 1
 14        The LDR linear color profile.
 15    HDR_RGB_LDR_A : int = 2
 16        The HDR RGB with LDR alpha color profile.
 17    HDR : int = 3
 18        The HDR RGB color profile.
 19    """
 20
 21    LDR_SRGB = 0
 22    LDR = 1
 23    HDR_RGB_LDR_A = 2
 24    HDR = 3
 25
 26
 27class ASTCQualityPreset(IntEnum):
 28    """The quality presets.
 29
 30    These values are just presets, the user can set the quality to any value between 0 and 100.
 31
 32    Attributes
 33    ----------
 34    FASTEST : int = 0
 35        The fastest, lowest quality, search preset.
 36    FAST : int = 10
 37        The fast search preset.
 38    MEDIUM : int = 60
 39        The medium quality search preset.
 40    THOROUGH : int = 98
 41        The thorough quality search preset.
 42    VERYTHOROUGH : int = 99
 43        The very thorough quality search preset.
 44    EXHAUSTIVE : int = 100
 45        The exhaustive, highest quality, search preset.
 46    """
 47
 48    FASTEST = 0
 49    FAST = 10
 50    MEDIUM = 60
 51    THOROUGH = 98
 52    VERYTHOROUGH = 99
 53    EXHAUSTIVE = 100
 54
 55
 56class ASTCConfigFlags(IntFlag):
 57    """The configuration flags.
 58
 59    Attributes
 60    ----------
 61    MAP_NORMAL : int = 1 << 0
 62        Enable normal map compression.
 63
 64        Input data will be treated a two component normal map,
 65        storing X and Y, and the codec will optimize for angular error rather than simple linear PSNR.
 66        In this mode the input swizzle should be e.g.
 67        - rrrg (the default ordering for ASTC normals on the command line)
 68        - gggr (the ordering used by BC5n)
 69
 70    USE_DECODE_UNORM8 : int = 1 << 1
 71        Enable compression heuristics that assume use of decode_unorm8 decode mode.
 72
 73        The decode_unorm8 decode mode rounds differently to the decode_fp16 decode mode,
 74        so enabling this flag during compression will allow the compressor to use
 75        the correct rounding when selecting encodings.
 76        This will improve the compressed image quality if your application is using the decode_unorm8 decode mode,
 77        but will reduce image quality if using decode_fp16.
 78        Note that LDR_SRGB images will always use decode_unorm8 for the RGB channels,
 79        irrespective of this setting.
 80
 81    USE_APLHA_WEIGHT : int = 1 << 2
 82        Enable alpha weighting.
 83
 84        The input alpha value is used for transparency, so errors in the RGB components are weighted by
 85        the transparency level. This allows the codec to more accurately encode the alpha value in areas
 86        where the color value is less significant.
 87    USE_PERCEPTUAL : int = 1 << 3
 88        Enable perceptual error metrics.
 89
 90        This mode enables perceptual compression mode, which will optimize for perceptual error rather
 91        than best PSNR. Only some input modes support perceptual error metrics.
 92
 93    SELF_DECOMPRESS_ONLY : int = 1 << 4
 94        Create a self-decompression context.
 95
 96        This mode configures the compressor so that it is only guaranteed to be able to decompress images
 97        that were actually created using the current context.
 98        This is the common case for compression use cases, and setting this flag enables additional optimizations,
 99        but does mean that the context cannot reliably decompress arbitrary ASTC images.
100
101    MAP_RGBM : int = 1 << 6
102        Enable RGBM map compression.
103
104        Input data will be treated as HDR data that has been stored in an LDR RGBM-encoded wrapper format.
105        Data must be preprocessed by the user to be in LDR RGBM format before calling the compression function,
106        this flag is only used to control the use of RGBM-specific heuristics and error metrics.
107
108        **IMPORTANT**:
109
110        The ASTC format is prone to bad failure modes with unconstrained RGBM data;
111        very small M values can round to zero due to quantization and result in black or white pixels.
112        It is highly recommended that the minimum value of M used in the encoding is kept above a lower threshold (try 16 or 32).
113        Applying this threshold reduces the number of very dark colors that can be represented,
114        but is still higher precision than 8-bit LDR.
115
116        When this flag is set the value of ``c rgbm_m_scale`` in the context must be set to the RGBM scale factor used during reconstruction.
117        This defaults to 5 when in RGBM mode.
118        It is recommended that the value of ``c cw_a_weight`` is set to twice the value of the multiplier scale,
119        ensuring that the M value is accurately encoded.
120        This defaults to 10 when in RGBM mode, matching the default scale factor.
121    """
122
123    MAP_NORMAL = 1 << 0
124    USE_DECODE_UNORM8 = 1 << 1
125    USE_APLHA_WEIGHT = 1 << 2
126    USE_PERCEPTUAL = 1 << 3
127    DECOMPRESS_ONLY = 1 << 4
128    SELF_DECOMPRESS_ONLY = 1 << 5
129    MAP_RGBM = 1 << 6
130
131
132class ASTCType(IntEnum):
133    """A texel component data format.
134
135    Attributes
136    ----------
137    U8 : int = 0
138        Unorm 8-bit data per component.
139    F16 : int = 1
140        16-bit float per component.
141    F32 : int = 2
142        32-bit float per component.
143    """
144
145    U8 = 0
146    F16 = 1
147    F32 = 2
148
149
150class ASTCSwizzleComponentSelector(IntEnum):
151    """A codec component swizzle selector.
152
153    Attributes
154    ----------
155    R : int = 0
156        Select the red component.
157    G : int = 1
158        Select the green component.
159    B : int = 2
160        Select the blue component.
161    A : int = 3
162        Select the alpha component.
163    ZERO : int = 4
164        Use a constant zero component.
165    ONE : int = 5
166        Use a constant one component.
167    Z : int = 6
168        Use a reconstructed normal vector Z component.
169    """
170
171    R = 0
172    G = 1
173    B = 2
174    A = 3
175    ZERO = 4
176    ONE = 5
177    Z = 6
178
179
180__all__ = (
181    "ASTCProfile",
182    "ASTCQualityPreset",
183    "ASTCConfigFlags",
184    "ASTCType",
185    "ASTCSwizzleComponentSelector",
186)
class ASTCProfile(enum.IntEnum):
 7class ASTCProfile(IntEnum):
 8    """A codec color profile.
 9
10    Attributes
11    ----------
12    LDR_SRGB : int = 0
13        The LDR sRGB color profile.
14    LDR : int = 1
15        The LDR linear color profile.
16    HDR_RGB_LDR_A : int = 2
17        The HDR RGB with LDR alpha color profile.
18    HDR : int = 3
19        The HDR RGB color profile.
20    """
21
22    LDR_SRGB = 0
23    LDR = 1
24    HDR_RGB_LDR_A = 2
25    HDR = 3

A codec color profile.

Attributes
  • LDR_SRGB (int = 0): The LDR sRGB color profile.
  • LDR (int = 1): The LDR linear color profile.
  • HDR_RGB_LDR_A (int = 2): The HDR RGB with LDR alpha color profile.
  • HDR (int = 3): The HDR RGB color profile.
LDR_SRGB = <ASTCProfile.LDR_SRGB: 0>
LDR = <ASTCProfile.LDR: 1>
HDR_RGB_LDR_A = <ASTCProfile.HDR_RGB_LDR_A: 2>
HDR = <ASTCProfile.HDR: 3>
class ASTCQualityPreset(enum.IntEnum):
28class ASTCQualityPreset(IntEnum):
29    """The quality presets.
30
31    These values are just presets, the user can set the quality to any value between 0 and 100.
32
33    Attributes
34    ----------
35    FASTEST : int = 0
36        The fastest, lowest quality, search preset.
37    FAST : int = 10
38        The fast search preset.
39    MEDIUM : int = 60
40        The medium quality search preset.
41    THOROUGH : int = 98
42        The thorough quality search preset.
43    VERYTHOROUGH : int = 99
44        The very thorough quality search preset.
45    EXHAUSTIVE : int = 100
46        The exhaustive, highest quality, search preset.
47    """
48
49    FASTEST = 0
50    FAST = 10
51    MEDIUM = 60
52    THOROUGH = 98
53    VERYTHOROUGH = 99
54    EXHAUSTIVE = 100

The quality presets.

These values are just presets, the user can set the quality to any value between 0 and 100.

Attributes
  • FASTEST (int = 0): The fastest, lowest quality, search preset.
  • FAST (int = 10): The fast search preset.
  • MEDIUM (int = 60): The medium quality search preset.
  • THOROUGH (int = 98): The thorough quality search preset.
  • VERYTHOROUGH (int = 99): The very thorough quality search preset.
  • EXHAUSTIVE (int = 100): The exhaustive, highest quality, search preset.
FASTEST = <ASTCQualityPreset.FASTEST: 0>
FAST = <ASTCQualityPreset.FAST: 10>
MEDIUM = <ASTCQualityPreset.MEDIUM: 60>
THOROUGH = <ASTCQualityPreset.THOROUGH: 98>
VERYTHOROUGH = <ASTCQualityPreset.VERYTHOROUGH: 99>
EXHAUSTIVE = <ASTCQualityPreset.EXHAUSTIVE: 100>
class ASTCConfigFlags(enum.IntFlag):
 57class ASTCConfigFlags(IntFlag):
 58    """The configuration flags.
 59
 60    Attributes
 61    ----------
 62    MAP_NORMAL : int = 1 << 0
 63        Enable normal map compression.
 64
 65        Input data will be treated a two component normal map,
 66        storing X and Y, and the codec will optimize for angular error rather than simple linear PSNR.
 67        In this mode the input swizzle should be e.g.
 68        - rrrg (the default ordering for ASTC normals on the command line)
 69        - gggr (the ordering used by BC5n)
 70
 71    USE_DECODE_UNORM8 : int = 1 << 1
 72        Enable compression heuristics that assume use of decode_unorm8 decode mode.
 73
 74        The decode_unorm8 decode mode rounds differently to the decode_fp16 decode mode,
 75        so enabling this flag during compression will allow the compressor to use
 76        the correct rounding when selecting encodings.
 77        This will improve the compressed image quality if your application is using the decode_unorm8 decode mode,
 78        but will reduce image quality if using decode_fp16.
 79        Note that LDR_SRGB images will always use decode_unorm8 for the RGB channels,
 80        irrespective of this setting.
 81
 82    USE_APLHA_WEIGHT : int = 1 << 2
 83        Enable alpha weighting.
 84
 85        The input alpha value is used for transparency, so errors in the RGB components are weighted by
 86        the transparency level. This allows the codec to more accurately encode the alpha value in areas
 87        where the color value is less significant.
 88    USE_PERCEPTUAL : int = 1 << 3
 89        Enable perceptual error metrics.
 90
 91        This mode enables perceptual compression mode, which will optimize for perceptual error rather
 92        than best PSNR. Only some input modes support perceptual error metrics.
 93
 94    SELF_DECOMPRESS_ONLY : int = 1 << 4
 95        Create a self-decompression context.
 96
 97        This mode configures the compressor so that it is only guaranteed to be able to decompress images
 98        that were actually created using the current context.
 99        This is the common case for compression use cases, and setting this flag enables additional optimizations,
100        but does mean that the context cannot reliably decompress arbitrary ASTC images.
101
102    MAP_RGBM : int = 1 << 6
103        Enable RGBM map compression.
104
105        Input data will be treated as HDR data that has been stored in an LDR RGBM-encoded wrapper format.
106        Data must be preprocessed by the user to be in LDR RGBM format before calling the compression function,
107        this flag is only used to control the use of RGBM-specific heuristics and error metrics.
108
109        **IMPORTANT**:
110
111        The ASTC format is prone to bad failure modes with unconstrained RGBM data;
112        very small M values can round to zero due to quantization and result in black or white pixels.
113        It is highly recommended that the minimum value of M used in the encoding is kept above a lower threshold (try 16 or 32).
114        Applying this threshold reduces the number of very dark colors that can be represented,
115        but is still higher precision than 8-bit LDR.
116
117        When this flag is set the value of ``c rgbm_m_scale`` in the context must be set to the RGBM scale factor used during reconstruction.
118        This defaults to 5 when in RGBM mode.
119        It is recommended that the value of ``c cw_a_weight`` is set to twice the value of the multiplier scale,
120        ensuring that the M value is accurately encoded.
121        This defaults to 10 when in RGBM mode, matching the default scale factor.
122    """
123
124    MAP_NORMAL = 1 << 0
125    USE_DECODE_UNORM8 = 1 << 1
126    USE_APLHA_WEIGHT = 1 << 2
127    USE_PERCEPTUAL = 1 << 3
128    DECOMPRESS_ONLY = 1 << 4
129    SELF_DECOMPRESS_ONLY = 1 << 5
130    MAP_RGBM = 1 << 6

The configuration flags.

Attributes
  • MAP_NORMAL (int = 1 << 0): Enable normal map compression.

    Input data will be treated a two component normal map, storing X and Y, and the codec will optimize for angular error rather than simple linear PSNR. In this mode the input swizzle should be e.g.

    • rrrg (the default ordering for ASTC normals on the command line)
    • gggr (the ordering used by BC5n)
  • USE_DECODE_UNORM8 (int = 1 << 1): Enable compression heuristics that assume use of decode_unorm8 decode mode.

    The decode_unorm8 decode mode rounds differently to the decode_fp16 decode mode, so enabling this flag during compression will allow the compressor to use the correct rounding when selecting encodings. This will improve the compressed image quality if your application is using the decode_unorm8 decode mode, but will reduce image quality if using decode_fp16. Note that LDR_SRGB images will always use decode_unorm8 for the RGB channels, irrespective of this setting.

  • USE_APLHA_WEIGHT (int = 1 << 2): Enable alpha weighting.

    The input alpha value is used for transparency, so errors in the RGB components are weighted by the transparency level. This allows the codec to more accurately encode the alpha value in areas where the color value is less significant.

  • USE_PERCEPTUAL (int = 1 << 3): Enable perceptual error metrics.

    This mode enables perceptual compression mode, which will optimize for perceptual error rather than best PSNR. Only some input modes support perceptual error metrics.

  • SELF_DECOMPRESS_ONLY (int = 1 << 4): Create a self-decompression context.

    This mode configures the compressor so that it is only guaranteed to be able to decompress images that were actually created using the current context. This is the common case for compression use cases, and setting this flag enables additional optimizations, but does mean that the context cannot reliably decompress arbitrary ASTC images.

  • MAP_RGBM (int = 1 << 6): Enable RGBM map compression.

    Input data will be treated as HDR data that has been stored in an LDR RGBM-encoded wrapper format. Data must be preprocessed by the user to be in LDR RGBM format before calling the compression function, this flag is only used to control the use of RGBM-specific heuristics and error metrics.

    IMPORTANT:

    The ASTC format is prone to bad failure modes with unconstrained RGBM data; very small M values can round to zero due to quantization and result in black or white pixels. It is highly recommended that the minimum value of M used in the encoding is kept above a lower threshold (try 16 or 32). Applying this threshold reduces the number of very dark colors that can be represented, but is still higher precision than 8-bit LDR.

    When this flag is set the value of c rgbm_m_scale in the context must be set to the RGBM scale factor used during reconstruction. This defaults to 5 when in RGBM mode. It is recommended that the value of c cw_a_weight is set to twice the value of the multiplier scale, ensuring that the M value is accurately encoded. This defaults to 10 when in RGBM mode, matching the default scale factor.

MAP_NORMAL = <ASTCConfigFlags.MAP_NORMAL: 1>
USE_DECODE_UNORM8 = <ASTCConfigFlags.USE_DECODE_UNORM8: 2>
USE_APLHA_WEIGHT = <ASTCConfigFlags.USE_APLHA_WEIGHT: 4>
USE_PERCEPTUAL = <ASTCConfigFlags.USE_PERCEPTUAL: 8>
DECOMPRESS_ONLY = <ASTCConfigFlags.DECOMPRESS_ONLY: 16>
SELF_DECOMPRESS_ONLY = <ASTCConfigFlags.SELF_DECOMPRESS_ONLY: 32>
MAP_RGBM = <ASTCConfigFlags.MAP_RGBM: 64>
class ASTCType(enum.IntEnum):
133class ASTCType(IntEnum):
134    """A texel component data format.
135
136    Attributes
137    ----------
138    U8 : int = 0
139        Unorm 8-bit data per component.
140    F16 : int = 1
141        16-bit float per component.
142    F32 : int = 2
143        32-bit float per component.
144    """
145
146    U8 = 0
147    F16 = 1
148    F32 = 2

A texel component data format.

Attributes
  • U8 (int = 0): Unorm 8-bit data per component.
  • F16 (int = 1): 16-bit float per component.
  • F32 (int = 2): 32-bit float per component.
U8 = <ASTCType.U8: 0>
F16 = <ASTCType.F16: 1>
F32 = <ASTCType.F32: 2>
class ASTCSwizzleComponentSelector(enum.IntEnum):
151class ASTCSwizzleComponentSelector(IntEnum):
152    """A codec component swizzle selector.
153
154    Attributes
155    ----------
156    R : int = 0
157        Select the red component.
158    G : int = 1
159        Select the green component.
160    B : int = 2
161        Select the blue component.
162    A : int = 3
163        Select the alpha component.
164    ZERO : int = 4
165        Use a constant zero component.
166    ONE : int = 5
167        Use a constant one component.
168    Z : int = 6
169        Use a reconstructed normal vector Z component.
170    """
171
172    R = 0
173    G = 1
174    B = 2
175    A = 3
176    ZERO = 4
177    ONE = 5
178    Z = 6

A codec component swizzle selector.

Attributes
  • R (int = 0): Select the red component.
  • G (int = 1): Select the green component.
  • B (int = 2): Select the blue component.
  • A (int = 3): Select the alpha component.
  • ZERO (int = 4): Use a constant zero component.
  • ONE (int = 5): Use a constant one component.
  • Z (int = 6): Use a reconstructed normal vector Z component.