Skip to content

Commit

Permalink
Merge pull request #19 from sketchfab/r23-store-purchases
Browse files Browse the repository at this point in the history
[#D3D-5835] Updates to R23 and adds purchases download
  • Loading branch information
cedricpinson authored Dec 21, 2020
2 parents db0fe1b + ed27985 commit d06ef20
Show file tree
Hide file tree
Showing 221 changed files with 15,256 additions and 9,969 deletions.
Binary file added dependencies/OSX/PIL/.dylibs/libXau.6.dylib
Binary file not shown.
Binary file modified dependencies/OSX/PIL/.dylibs/libfreetype.6.dylib
Binary file not shown.
Binary file modified dependencies/OSX/PIL/.dylibs/libjpeg.9.dylib
Binary file not shown.
Binary file modified dependencies/OSX/PIL/.dylibs/liblcms2.2.dylib
Binary file not shown.
Binary file modified dependencies/OSX/PIL/.dylibs/liblzma.5.dylib
Binary file not shown.
Binary file removed dependencies/OSX/PIL/.dylibs/libopenjp2.2.1.0.dylib
Binary file not shown.
Binary file not shown.
Binary file modified dependencies/OSX/PIL/.dylibs/libpng16.16.dylib
Binary file not shown.
Binary file modified dependencies/OSX/PIL/.dylibs/libtiff.5.dylib
Binary file not shown.
Binary file modified dependencies/OSX/PIL/.dylibs/libwebp.7.dylib
Binary file not shown.
Binary file modified dependencies/OSX/PIL/.dylibs/libwebpdemux.2.dylib
Binary file not shown.
Binary file modified dependencies/OSX/PIL/.dylibs/libwebpmux.3.dylib
Binary file not shown.
Binary file added dependencies/OSX/PIL/.dylibs/libxcb.1.1.0.dylib
Binary file not shown.
Binary file modified dependencies/OSX/PIL/.dylibs/libz.1.2.11.dylib
Binary file not shown.
35 changes: 13 additions & 22 deletions dependencies/OSX/PIL/BdfFontFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,23 @@
# See the README file for information on usage and redistribution.
#

from __future__ import print_function
"""
Parse X Bitmap Distribution Format (BDF)
"""

from . import Image, FontFile


# --------------------------------------------------------------------
# parse X Bitmap Distribution Format (BDF)
# --------------------------------------------------------------------
from . import FontFile, Image

bdf_slant = {
"R": "Roman",
"I": "Italic",
"O": "Oblique",
"RI": "Reverse Italic",
"RO": "Reverse Oblique",
"OT": "Other"
"OT": "Other",
}

bdf_spacing = {
"P": "Proportional",
"M": "Monospaced",
"C": "Cell"
}
bdf_spacing = {"P": "Proportional", "M": "Monospaced", "C": "Cell"}


def bdf_char(f):
Expand All @@ -50,7 +44,7 @@ def bdf_char(f):
return None
if s[:9] == b"STARTCHAR":
break
id = s[9:].strip().decode('ascii')
id = s[9:].strip().decode("ascii")

# load symbol properties
props = {}
Expand All @@ -59,7 +53,7 @@ def bdf_char(f):
if not s or s[:6] == b"BITMAP":
break
i = s.find(b" ")
props[s[:i].decode('ascii')] = s[i+1:-1].decode('ascii')
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")

# load bitmap
bitmap = []
Expand All @@ -73,7 +67,7 @@ def bdf_char(f):
[x, y, l, d] = [int(p) for p in props["BBX"].split()]
[dx, dy] = [int(p) for p in props["DWIDTH"].split()]

bbox = (dx, dy), (l, -d-y, x+l, -d), (0, 0, x, y)
bbox = (dx, dy), (l, -d - y, x + l, -d), (0, 0, x, y)

try:
im = Image.frombytes("1", (x, y), bitmap, "hex", "1")
Expand All @@ -84,14 +78,11 @@ def bdf_char(f):
return id, int(props["ENCODING"]), bbox, im


##
# Font file plugin for the X11 BDF format.

class BdfFontFile(FontFile.FontFile):
"""Font file plugin for the X11 BDF format."""

def __init__(self, fp):

FontFile.FontFile.__init__(self)
super().__init__()

s = fp.readline()
if s[:13] != b"STARTFONT 2.1":
Expand All @@ -105,10 +96,10 @@ def __init__(self, fp):
if not s or s[:13] == b"ENDPROPERTIES":
break
i = s.find(b" ")
props[s[:i].decode('ascii')] = s[i+1:-1].decode('ascii')
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")
if s[:i] in [b"COMMENT", b"COPYRIGHT"]:
if s.find(b"LogicalFontDescription") < 0:
comments.append(s[i+1:-1].decode('ascii'))
comments.append(s[i + 1 : -1].decode("ascii"))

while True:
c = bdf_char(fp)
Expand Down
87 changes: 37 additions & 50 deletions dependencies/OSX/PIL/BlpImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@

from . import Image, ImageFile


BLP_FORMAT_JPEG = 0

BLP_ENCODING_UNCOMPRESSED = 1
Expand All @@ -47,11 +46,7 @@


def unpack_565(i):
return (
((i >> 11) & 0x1f) << 3,
((i >> 5) & 0x3f) << 2,
(i & 0x1f) << 3
)
return (((i >> 11) & 0x1F) << 3, ((i >> 5) & 0x3F) << 2, (i & 0x1F) << 3)


def decode_dxt1(data, alpha=False):
Expand Down Expand Up @@ -119,12 +114,12 @@ def decode_dxt3(data):

for block in range(blocks):
idx = block * 16
block = data[idx:idx + 16]
block = data[idx : idx + 16]
# Decode next 16-byte block.
bits = struct.unpack_from("<8B", block)
color0, color1 = struct.unpack_from("<HH", block, 8)

code, = struct.unpack_from("<I", block, 12)
(code,) = struct.unpack_from("<I", block, 12)

r0, g0, b0 = unpack_565(color0)
r1, g1, b1 = unpack_565(color1)
Expand All @@ -139,7 +134,7 @@ def decode_dxt3(data):
a >>= 4
else:
high = True
a &= 0xf
a &= 0xF
a *= 17 # We get a value between 0 and 15

color_code = (code >> 2 * (4 * j + i)) & 0x03
Expand Down Expand Up @@ -172,19 +167,17 @@ def decode_dxt5(data):

for block in range(blocks):
idx = block * 16
block = data[idx:idx + 16]
block = data[idx : idx + 16]
# Decode next 16-byte block.
a0, a1 = struct.unpack_from("<BB", block)

bits = struct.unpack_from("<6B", block, 2)
alphacode1 = (
bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24)
)
alphacode1 = bits[2] | (bits[3] << 8) | (bits[4] << 16) | (bits[5] << 24)
alphacode2 = bits[0] | (bits[1] << 8)

color0, color1 = struct.unpack_from("<HH", block, 8)

code, = struct.unpack_from("<I", block, 12)
(code,) = struct.unpack_from("<I", block, 12)

r0, g0, b0 = unpack_565(color0)
r1, g1, b1 = unpack_565(color1)
Expand Down Expand Up @@ -242,6 +235,7 @@ class BlpImageFile(ImageFile.ImageFile):
"""
Blizzard Mipmap Format
"""

format = "BLP"
format_description = "Blizzard Mipmap Format"

Expand All @@ -256,26 +250,24 @@ def _open(self):
decoder = "BLP2"
self.mode = "RGBA" if self._blp_alpha_depth else "RGB"
else:
raise BLPFormatError("Bad BLP magic %r" % (self.magic))
raise BLPFormatError(f"Bad BLP magic {repr(self.magic)}")

self.tile = [
(decoder, (0, 0) + self.size, 0, (self.mode, 0, 1))
]
self.tile = [(decoder, (0, 0) + self.size, 0, (self.mode, 0, 1))]

def _read_blp_header(self):
self._blp_compression, = struct.unpack("<i", self.fp.read(4))
(self._blp_compression,) = struct.unpack("<i", self.fp.read(4))

self._blp_encoding, = struct.unpack("<b", self.fp.read(1))
self._blp_alpha_depth, = struct.unpack("<b", self.fp.read(1))
self._blp_alpha_encoding, = struct.unpack("<b", self.fp.read(1))
self._blp_mips, = struct.unpack("<b", self.fp.read(1))
(self._blp_encoding,) = struct.unpack("<b", self.fp.read(1))
(self._blp_alpha_depth,) = struct.unpack("<b", self.fp.read(1))
(self._blp_alpha_encoding,) = struct.unpack("<b", self.fp.read(1))
(self._blp_mips,) = struct.unpack("<b", self.fp.read(1))

self._size = struct.unpack("<II", self.fp.read(8))

if self.magic == b"BLP1":
# Only present for BLP1
self._blp_encoding, = struct.unpack("<i", self.fp.read(4))
self._blp_subtype, = struct.unpack("<i", self.fp.read(4))
(self._blp_encoding,) = struct.unpack("<i", self.fp.read(4))
(self._blp_subtype,) = struct.unpack("<i", self.fp.read(4))

self._blp_offsets = struct.unpack("<16I", self.fp.read(16 * 4))
self._blp_lengths = struct.unpack("<16I", self.fp.read(16 * 4))
Expand All @@ -290,8 +282,8 @@ def decode(self, buffer):
self.magic = self.fd.read(4)
self._read_blp_header()
self._load()
except struct.error:
raise IOError("Truncated Blp file")
except struct.error as e:
raise OSError("Truncated Blp file") from e
return 0, 0

def _read_palette(self):
Expand All @@ -305,26 +297,25 @@ def _read_palette(self):
return ret

def _read_blp_header(self):
self._blp_compression, = struct.unpack("<i", self.fd.read(4))
(self._blp_compression,) = struct.unpack("<i", self.fd.read(4))

self._blp_encoding, = struct.unpack("<b", self.fd.read(1))
self._blp_alpha_depth, = struct.unpack("<b", self.fd.read(1))
self._blp_alpha_encoding, = struct.unpack("<b", self.fd.read(1))
self._blp_mips, = struct.unpack("<b", self.fd.read(1))
(self._blp_encoding,) = struct.unpack("<b", self.fd.read(1))
(self._blp_alpha_depth,) = struct.unpack("<b", self.fd.read(1))
(self._blp_alpha_encoding,) = struct.unpack("<b", self.fd.read(1))
(self._blp_mips,) = struct.unpack("<b", self.fd.read(1))

self.size = struct.unpack("<II", self.fd.read(8))

if self.magic == b"BLP1":
# Only present for BLP1
self._blp_encoding, = struct.unpack("<i", self.fd.read(4))
self._blp_subtype, = struct.unpack("<i", self.fd.read(4))
(self._blp_encoding,) = struct.unpack("<i", self.fd.read(4))
(self._blp_subtype,) = struct.unpack("<i", self.fd.read(4))

self._blp_offsets = struct.unpack("<16I", self.fd.read(16 * 4))
self._blp_lengths = struct.unpack("<16I", self.fd.read(16 * 4))


class BLP1Decoder(_BLPBaseDecoder):

def _load(self):
if self._blp_compression == BLP_FORMAT_JPEG:
self._decode_jpeg_stream()
Expand All @@ -336,7 +327,7 @@ def _load(self):
_data = BytesIO(self.fd.read(self._blp_lengths[0]))
while True:
try:
offset, = struct.unpack("<B", _data.read(1))
(offset,) = struct.unpack("<B", _data.read(1))
except struct.error:
break
b, g, r, a = palette[offset]
Expand All @@ -345,17 +336,17 @@ def _load(self):
self.set_as_raw(bytes(data))
else:
raise BLPFormatError(
"Unsupported BLP encoding %r" % (self._blp_encoding)
f"Unsupported BLP encoding {repr(self._blp_encoding)}"
)
else:
raise BLPFormatError(
"Unsupported BLP compression %r" % (self._blp_encoding)
f"Unsupported BLP compression {repr(self._blp_encoding)}"
)

def _decode_jpeg_stream(self):
from PIL.JpegImagePlugin import JpegImageFile

jpeg_header_size, = struct.unpack("<I", self.fd.read(4))
(jpeg_header_size,) = struct.unpack("<I", self.fd.read(4))
jpeg_header = self.fd.read(jpeg_header_size)
self.fd.read(self._blp_offsets[0] - self.fd.tell()) # What IS this?
data = self.fd.read(self._blp_lengths[0])
Expand All @@ -368,7 +359,6 @@ def _decode_jpeg_stream(self):


class BLP2Decoder(_BLPBaseDecoder):

def _load(self):
palette = self._read_palette()

Expand All @@ -382,7 +372,7 @@ def _load(self):
_data = BytesIO(self.fd.read(self._blp_lengths[0]))
while True:
try:
offset, = struct.unpack("<B", _data.read(1))
(offset,) = struct.unpack("<B", _data.read(1))
except struct.error:
break
b, g, r, a = palette[offset]
Expand All @@ -393,8 +383,7 @@ def _load(self):
linesize = (self.size[0] + 3) // 4 * 8
for yb in range((self.size[1] + 3) // 4):
for d in decode_dxt1(
self.fd.read(linesize),
alpha=bool(self._blp_alpha_depth)
self.fd.read(linesize), alpha=bool(self._blp_alpha_depth)
):
data += d

Expand All @@ -410,17 +399,15 @@ def _load(self):
for d in decode_dxt5(self.fd.read(linesize)):
data += d
else:
raise BLPFormatError("Unsupported alpha encoding %r" % (
self._blp_alpha_encoding
))
raise BLPFormatError(
f"Unsupported alpha encoding {repr(self._blp_alpha_encoding)}"
)
else:
raise BLPFormatError(
"Unknown BLP encoding %r" % (self._blp_encoding)
)
raise BLPFormatError(f"Unknown BLP encoding {repr(self._blp_encoding)}")

else:
raise BLPFormatError(
"Unknown BLP compression %r" % (self._blp_compression)
f"Unknown BLP compression {repr(self._blp_compression)}"
)

self.set_as_raw(bytes(data))
Expand Down
Loading

0 comments on commit d06ef20

Please sign in to comment.