Commits

Fredrik Lundh committed 4232865

Added WebP sanity check.

Comments (0)

Files changed (3)

Images/lena.webp

Added
New image

PIL/WebPImagePlugin.py

 
         # read frame tag
         tag = data[0] | (data[1] << 8) | (data[2] << 16)
+
         frame_type = (tag & 1) # 0=key frame, 1=interframe
         version = (((tag >> 1) & 7) > 3)
         show_frame = ((tag >> 4) & 1)
         if frame_type != 0 or not show_frame:
             raise SyntaxError("not a visible WebP frame")
 
-        # size is stored in 2x14 bits
         xsize = ((data[7] << 8) | data[6]) & 0x3fff
         ysize = ((data[9] << 8) | data[8]) & 0x3fff
 
-        self.mode = "RGB" # file is always YUV2
+        self.mode = "RGB" # file is always YCbCr (w. chroma subsampling)
         self.size = xsize, ysize
         self.tile = [("webp", (0, 0) + self.size, 0, (self.mode, 0, 1))]
 

Tests/test_file_webp.py

+from tester import *
+
+from PIL import Image
+from PIL import WebPImagePlugin
+
+codecs = dir(Image.core)
+
+# if "webp_decoder" not in codecs:
+#     skip("webp support not available")
+
+def test_sanity():
+
+    # internal version number
+    # assert_match(Image.core.webp_version, "\d+\.\d+\.\d+(\.\d+)?$")
+
+    im = Image.open("Images/lena.webp")
+    # im.load()
+    assert_equal(im.mode, "RGB")
+    assert_equal(im.size, (128, 128))
+    assert_equal(im.format, "WEBP")