From 73d7fff16e06efe7d0cb235ac7283f165361e4b5 Mon Sep 17 00:00:00 2001 From: Jerome Leclanche Date: Sun, 18 Feb 2018 04:56:13 +0200 Subject: [PATCH] blp: Separate BLP1 and BLP2 decoding more cleanly --- Tests/images/{ => blp}/blp2_dxt1.blp | Bin Tests/images/{ => blp}/blp2_dxt1.png | Bin src/PIL/BlpImagePlugin.py | 215 +++++++++++++-------------- 3 files changed, 104 insertions(+), 111 deletions(-) rename Tests/images/{ => blp}/blp2_dxt1.blp (100%) rename Tests/images/{ => blp}/blp2_dxt1.png (100%) diff --git a/Tests/images/blp2_dxt1.blp b/Tests/images/blp/blp2_dxt1.blp similarity index 100% rename from Tests/images/blp2_dxt1.blp rename to Tests/images/blp/blp2_dxt1.blp diff --git a/Tests/images/blp2_dxt1.png b/Tests/images/blp/blp2_dxt1.png similarity index 100% rename from Tests/images/blp2_dxt1.png rename to Tests/images/blp/blp2_dxt1.png diff --git a/src/PIL/BlpImagePlugin.py b/src/PIL/BlpImagePlugin.py index fbddb6cdc..d3675a675 100644 --- a/src/PIL/BlpImagePlugin.py +++ b/src/PIL/BlpImagePlugin.py @@ -234,20 +234,6 @@ def decode_dxt5(data): return ret -def getpalette(data): - """ - Helper to transform a BytesIO object into a palette - """ - palette = [] - string = BytesIO(data) - while True: - try: - palette.append(struct.unpack("<4B", string.read(4))) - except struct.error: - break - return palette - - class BLPFormatError(NotImplementedError): pass @@ -259,144 +245,151 @@ class BlpImageFile(ImageFile.ImageFile): format = "BLP" format_description = "Blizzard Mipmap Format" - def _decode_blp1(self): - header = BytesIO(self.fp.read(28 + 16 * 4 + 16 * 4)) + def _open(self): + self.tile = [] + self.magic = self.fp.read(4) + self._read_blp_header() - magic, compression = struct.unpack("<4si", header.read(8)) - encoding, alpha_depth, alpha_encoding, has_mips = struct.unpack( - "<4b", header.read(4) - ) - self.size = struct.unpack("