Show More
@@ -798,8 +798,8 b' class Javascript(TextDisplayObject):' | |||||
798 | # constants for identifying png/jpeg/gif/webp data |
|
798 | # constants for identifying png/jpeg/gif/webp data | |
799 | _PNG = b'\x89PNG\r\n\x1a\n' |
|
799 | _PNG = b'\x89PNG\r\n\x1a\n' | |
800 | _JPEG = b'\xff\xd8' |
|
800 | _JPEG = b'\xff\xd8' | |
801 |
_GIF1 = b |
|
801 | _GIF1 = b'GIF87a' | |
802 |
_GIF2 = b |
|
802 | _GIF2 = b'GIF89a' | |
803 | _WEBP = b'WEBP' |
|
803 | _WEBP = b'WEBP' | |
804 |
|
804 | |||
805 |
|
805 | |||
@@ -838,16 +838,18 b' def _gifxy(data):' | |||||
838 | def _webpxy(data): |
|
838 | def _webpxy(data): | |
839 | """read the (width, height) from a WEBP header""" |
|
839 | """read the (width, height) from a WEBP header""" | |
840 | if data[12:16] == b"VP8 ": |
|
840 | if data[12:16] == b"VP8 ": | |
841 |
width, height = struct.unpack( |
|
841 | width, height = struct.unpack("<HH", data[24:30]) | |
842 |
width = |
|
842 | width = width & 0x3FFF | |
843 |
height = |
|
843 | height = height & 0x3FFF | |
844 | return (width, height) |
|
844 | return (width, height) | |
845 | elif data[12:16] == b"VP8L": |
|
845 | elif data[12:16] == b"VP8L": | |
846 |
size_info = struct.unpack( |
|
846 | size_info = struct.unpack("<I", data[21:25])[0] | |
847 | width = 1 + ((size_info & 0x3F) << 8) | (size_info >> 24) |
|
847 | width = 1 + ((size_info & 0x3F) << 8) | (size_info >> 24) | |
848 | height = 1 + ((((size_info >> 8) & 0xF) << 10) | |
|
848 | height = 1 + ( | |
849 |
|
|
849 | (((size_info >> 8) & 0xF) << 10) | |
850 |
|
|
850 | | (((size_info >> 14) & 0x3FC) << 2) | |
|
851 | | ((size_info >> 22) & 0x3) | |||
|
852 | ) | |||
851 | return (width, height) |
|
853 | return (width, height) | |
852 | else: |
|
854 | else: | |
853 | raise ValueError("Not a valid WEBP header") |
|
855 | raise ValueError("Not a valid WEBP header") | |
@@ -855,17 +857,17 b' def _webpxy(data):' | |||||
855 |
|
857 | |||
856 | class Image(DisplayObject): |
|
858 | class Image(DisplayObject): | |
857 |
|
859 | |||
858 |
_read_flags = |
|
860 | _read_flags = "rb" | |
859 |
_FMT_JPEG = |
|
861 | _FMT_JPEG = "jpeg" | |
860 |
_FMT_PNG = |
|
862 | _FMT_PNG = "png" | |
861 |
_FMT_GIF = |
|
863 | _FMT_GIF = "gif" | |
862 |
_FMT_WEBP = |
|
864 | _FMT_WEBP = "webp" | |
863 | _ACCEPTABLE_EMBEDDINGS = [_FMT_JPEG, _FMT_PNG, _FMT_GIF, _FMT_WEBP] |
|
865 | _ACCEPTABLE_EMBEDDINGS = [_FMT_JPEG, _FMT_PNG, _FMT_GIF, _FMT_WEBP] | |
864 | _MIMETYPES = { |
|
866 | _MIMETYPES = { | |
865 |
_FMT_PNG: |
|
867 | _FMT_PNG: "image/png", | |
866 |
_FMT_JPEG: |
|
868 | _FMT_JPEG: "image/jpeg", | |
867 |
_FMT_GIF: |
|
869 | _FMT_GIF: "image/gif", | |
868 |
_FMT_WEBP: |
|
870 | _FMT_WEBP: "image/webp", | |
869 | } |
|
871 | } | |
870 |
|
872 | |||
871 | def __init__( |
|
873 | def __init__( | |
@@ -987,7 +989,7 b' class Image(DisplayObject):' | |||||
987 | format = self._FMT_PNG |
|
989 | format = self._FMT_PNG | |
988 | elif ext == u'gif': |
|
990 | elif ext == u'gif': | |
989 | format = self._FMT_GIF |
|
991 | format = self._FMT_GIF | |
990 |
elif ext == |
|
992 | elif ext == "webp": | |
991 | format = self._FMT_WEBP |
|
993 | format = self._FMT_WEBP | |
992 | else: |
|
994 | else: | |
993 | format = ext.lower() |
|
995 | format = ext.lower() |
General Comments 0
You need to be logged in to leave comments.
Login now