Skip to content

Commit

Permalink
Style.
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian committed Nov 12, 2022
1 parent 1012fc4 commit 467dbdb
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
9 changes: 9 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[flake8]
ban-relative-imports = true
inline-quotes = "
ignore =
B008, # Barring function calls in default args. Ha, no.
B306, # See https://github.com/PyCQA/flake8-bugbear/issues/131
W503, # (flake8 default) old PEP8 boolean operator line breaks
E203, # https://black.readthedocs.io/en/latest/contributing/issue_triage.html#black-formatted-code-is-violating-flake8-s-e203
# Not getting in the middle of that one.
2 changes: 1 addition & 1 deletion avif/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from avif._api import AVIFError, Decoder
from avif._api import AVIFError, Decoder # noqa: F401
2 changes: 1 addition & 1 deletion avif/_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
avifResult avifDecoderParse(avifDecoder * decoder);
avifResult avifDecoderNextImage(avifDecoder * decoder);
avifResult avifDecoderNthImage(avifDecoder * decoder, uint32_t frameIndex);
""",
""", # noqa: E501
)


Expand Down
17 changes: 10 additions & 7 deletions avif/pillow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@

def _accept(data):

possible_ftyp = (b'avif', b'avis', b'mif1',)
possible_ftyp = (b"avif", b"avis", b"mif1")

return data[4:8] == b'ftyp' and data[8:12] in possible_ftyp
return data[4:8] == b"ftyp" and data[8:12] in possible_ftyp


class AvifImageFile(ImageFile.ImageFile):

format = 'AVIF'
format = "AVIF"
format_description = "Image container for AV1 video frames"

_current_frame = -1
Expand All @@ -42,7 +42,7 @@ def _open(self):

self.n_frames = self._avif_decoder._decoder.imageCount
self.is_animated = self.n_frames > 1
self.mode = 'RGBA' # only RGBA for now
self.mode = "RGBA" # only RGBA for now
self.rawmode = self.mode
self.tile = []

Expand All @@ -59,7 +59,10 @@ def _get_frame(self):
lib.avifImageYUVToRGB(self.avif_image, self._rgb_plane)

data = bytes(
ffi.unpack(self._rgb_plane.pixels, self._size[0]*self._size[1]*4)
ffi.unpack(
self._rgb_plane.pixels,
self._size[0] * self._size[1] * 4,
),
)

return data
Expand All @@ -82,5 +85,5 @@ def load(self):


Image.register_open(AvifImageFile.format, AvifImageFile, _accept)
Image.register_extension(AvifImageFile.format, '.avif')
Image.register_mime(AvifImageFile.format, 'image/avif')
Image.register_extension(AvifImageFile.format, ".avif")
Image.register_mime(AvifImageFile.format, "image/avif")
2 changes: 2 additions & 0 deletions avif/tests/test_avif.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
def test_it_imports():
import _avif

_avif

from avif import Decoder

Decoder()
7 changes: 4 additions & 3 deletions examples/avif_example_pillow_decode_file.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"""
This example aims to be similar to ``avif_example_decode_file.py`` but it uses Pillow module.
A Pillow-using example similar to ``avif_example_decode_file.py``.
Current limitation is Pillow not supporting 10 and 12 bit modes.
"""

Expand All @@ -8,7 +9,7 @@
from PIL import Image

# activates avif support in Pillow
import avif.pillow
import avif.pillow # noqa: F401


def main():
Expand All @@ -29,5 +30,5 @@ def main():
print(f" * First pixel: RGBA{first_pixel}")


if __name__ == '__main__':
if __name__ == "__main__":
main()

0 comments on commit 467dbdb

Please sign in to comment.