Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/PIL/_binary.py: 68%
28 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1#
2# The Python Imaging Library.
3# $Id$
4#
5# Binary input/output support routines.
6#
7# Copyright (c) 1997-2003 by Secret Labs AB
8# Copyright (c) 1995-2003 by Fredrik Lundh
9# Copyright (c) 2012 by Brian Crowell
10#
11# See the README file for information on usage and redistribution.
12#
15"""Binary input/output support routines."""
18from struct import pack, unpack_from
21def i8(c):
22 return c if c.__class__ is int else c[0]
25def o8(i):
26 return bytes((i & 255,))
29# Input, le = little endian, be = big endian
30def i16le(c, o=0):
31 """
32 Converts a 2-bytes (16 bits) string to an unsigned integer.
34 :param c: string containing bytes to convert
35 :param o: offset of bytes to convert in string
36 """
37 return unpack_from("<H", c, o)[0]
40def si16le(c, o=0):
41 """
42 Converts a 2-bytes (16 bits) string to a signed integer.
44 :param c: string containing bytes to convert
45 :param o: offset of bytes to convert in string
46 """
47 return unpack_from("<h", c, o)[0]
50def si16be(c, o=0):
51 """
52 Converts a 2-bytes (16 bits) string to a signed integer, big endian.
54 :param c: string containing bytes to convert
55 :param o: offset of bytes to convert in string
56 """
57 return unpack_from(">h", c, o)[0]
60def i32le(c, o=0):
61 """
62 Converts a 4-bytes (32 bits) string to an unsigned integer.
64 :param c: string containing bytes to convert
65 :param o: offset of bytes to convert in string
66 """
67 return unpack_from("<I", c, o)[0]
70def si32le(c, o=0):
71 """
72 Converts a 4-bytes (32 bits) string to a signed integer.
74 :param c: string containing bytes to convert
75 :param o: offset of bytes to convert in string
76 """
77 return unpack_from("<i", c, o)[0]
80def i16be(c, o=0):
81 return unpack_from(">H", c, o)[0]
84def i32be(c, o=0):
85 return unpack_from(">I", c, o)[0]
88# Output, le = little endian, be = big endian
89def o16le(i):
90 return pack("<H", i)
93def o32le(i):
94 return pack("<I", i)
97def o16be(i):
98 return pack(">H", i)
101def o32be(i):
102 return pack(">I", i)