class ReaderError(Error):
    pass class Enum(object):
    __slots__ = ('_value', '_name')
    enum_values = None
    xml_tag = None

    def __init__(self, value):
        self._value = value
        self._name = None
        if value is not None:
            self._name = self.enum_values[value]

    @property
    def value(self):
        return self._value

    @property
    def name(self):
        return self._name

    def __str__(self):
        return self._name

    def __repr__(self):
        return '{}({})'.format(self.__class__.__name__, self._value)

    def xml(self, parent):
        xml_tag = self.xml_tag if self.xml_tag else self.__class__.__name__
        root = ET.SubElement(parent, xml_tag)
        root.text = self._name
        return root def write_png(filename, width, height, rows):
    full_filename = filename + '.png'
    out_png = PyPngWriter(width=width, height=height)
    out_png.write_bytearray(full_filename, rows) def output_xml(xml, filename):
def output_xml(xml, filename): def decode_bgra(data, width, height, needs_swap, alpha='yes'):
    if needs_swap:
        conv = 'argb_rgba'
    else:
        conv = 'bgra_rgba'
    return decode32(data, width, height, conv, alpha=alpha) def decode_rgba(data, width, height, needs_swap, alpha='yes'):
    if needs_swap:
        conv = 'abgr_rgba'
    else:
        conv = 'rgba_rgba'
    return decode32(data, width, height, conv, alpha=alpha) def decode_a(data, width, height, needs_swap, alpha='yes'):
    return decode8(data, width, height, 'a_xxxa') def decode_dxt1(data, width, height, needs_swap, alpha='yes'):
    return DxtDecoder(width, height, 'DXT1', data, needs_swap).decode(alpha) def decode_dxt3(data, width, height, needs_swap, alpha='yes'):
    return DxtDecoder(width, height, 'DXT3', data, needs_swap).decode(alpha) def decode_dxt5(data, width, height, needs_swap, alpha='yes'):
    return DxtDecoder(width, height, 'DXT5', data, needs_swap).decode(alpha)
import os
from xnb_parse.type_reader import ReaderError
from xnb_parse.xna_types.xna_primitive import Enum
from xnb_parse.file_formats.png import write_png
from xnb_parse.file_formats.xml_utils import ET
from xnb_parse.file_formats.img_decode import decode_bgra, decode_rgba, decode_a, decode_dxt1, decode_dxt3, decode_dxt5
"""
graphics types
"""

from __future__ import print_function




VERSION_31 = 4
VERSION_40 = 5
CUBE_SIDES = ['+x', '-x', '+y', '-y', '+z', '-z']
FORMAT_COLOR = 1
SURFACE_FORMAT = {
    1: ('Color', decode_bgra),
    2: ('Bgr32', None),
    3: ('Bgra1010102', None),
    4: ('Rgba32', decode_rgba),
    5: ('Rgb32', None),
    6: ('Rgba1010102', None),
    7: ('Rg32', None),
    8: ('Rgba64', None),
    9: ('Bgr565', None),
    10: ('Bgra5551', None),
    11: ('Bgr555', None),
    12: ('Bgra4444', None),
    13: ('Bgr444', None),
    14: ('Bgra2338', None),
    15: ('Alpha8', decode_a),
    16: ('Bgr233', None),
    17: ('Bgr24', None),
    18: ('NormalizedByte2', None),
    19: ('NormalizedByte4', None),
    20: ('NormalizedShort2', None),
    21: ('NormalizedShort4', None),
    22: ('Single', None),
    23: ('Vector2', None),
    24: ('Vector4', None),
    25: ('HalfSingle', None),
    26: ('HalfVector2', None),
    27: ('HalfVector4', None),
    28: ('Dxt1', decode_dxt1),
    29: ('Dxt2', None),
    30: ('Dxt3', decode_dxt3),
    31: ('Dxt4', None),
    32: ('Dxt5', decode_dxt5),
    33: ('Luminance8', None),
    34: ('Luminance16', None),
    35: ('LuminanceAlpha8', None),
    36: ('LuminanceAlpha16', None),
    37: ('Palette8', None),
    38: ('PaletteAlpha16', None),
    39: ('NormalizedLuminance16', None),
    40: ('NormalizedLuminance32', None),
    41: ('NormalizedAlpha1010102', None),
    42: ('NormalizedByte2Computed', None),
    43: ('VideoYuYv', None),
    44: ('VideoUyVy', None),
    45: ('VideoGrGb', None),
    46: ('VideoRgBg', None),
    47: ('Multi2Bgra32', None),
    48: ('Depth24Stencil8', None),
    49: ('Depth24Stencil8Single', None),
    50: ('Depth24Stencil4', None),
    51: ('Depth24', None),
    52: ('Depth32', None),
    54: ('Depth16', None),
    56: ('Depth15Stencil1', None),
}
FORMAT4_COLOR = 0
SURFACE_FORMAT4 = {
    0: ('Color', decode_rgba),
    1: ('Bgr565', None),
    2: ('Bgra5551', None),
    3: ('Bgra4444', None),
    4: ('Dxt1', decode_dxt1),
    5: ('Dxt3', decode_dxt3),

    6: ('Dxt5', decode_dxt5),