formatted project by python-black

This commit is contained in:
2026-11-10 09:52:42 +03:00
parent 7cd02da51d
commit 9899ee4676
66 changed files with 2517 additions and 944 deletions
+18 -13
View File
@@ -1,26 +1,31 @@
"""Read JPEG SOF dimensions without external libraries; not a full image decoder."""
from client import Failure, check
def jpeg_size(data):
check(data[:2]==b'\xff\xd8','thumbnail is not JPEG')
check(data[:2] == b"\xff\xd8", "thumbnail is not JPEG")
i = 2
sof = {0xc0,0xc1,0xc2,0xc3,0xc5,0xc6,0xc7,0xc9,0xca,0xcb,0xcd,0xce,0xcf}
sof = {0xC0, 0xC1, 0xC2, 0xC3, 0xC5, 0xC6, 0xC7, 0xC9, 0xCA, 0xCB, 0xCD, 0xCE, 0xCF}
while i < len(data):
check(data[i]==0xff,'invalid JPEG marker')
while i<len(data) and data[i]==0xff:
check(data[i] == 0xFF, "invalid JPEG marker")
while i < len(data) and data[i] == 0xFF:
i += 1
check(i<len(data),'truncated JPEG marker')
check(i < len(data), "truncated JPEG marker")
marker = data[i]
i += 1
if marker in {0xd9,0xda}:
if marker in {0xD9, 0xDA}:
break
if marker in {0x01,0xd8} or 0xd0<=marker<=0xd7:
if marker in {0x01, 0xD8} or 0xD0 <= marker <= 0xD7:
continue
check(i+2<=len(data),'truncated JPEG segment')
length = int.from_bytes(data[i:i+2],'big')
check(length>=2 and i+length<=len(data),'invalid JPEG segment length')
check(i + 2 <= len(data), "truncated JPEG segment")
length = int.from_bytes(data[i : i + 2], "big")
check(length >= 2 and i + length <= len(data), "invalid JPEG segment length")
if marker in sof:
check(length>=8,'invalid JPEG SOF')
return (int.from_bytes(data[i+5:i+7],'big'),int.from_bytes(data[i+3:i+5],'big'))
check(length >= 8, "invalid JPEG SOF")
return (
int.from_bytes(data[i + 5 : i + 7], "big"),
int.from_bytes(data[i + 3 : i + 5], "big"),
)
i += length
raise Failure('JPEG dimensions not found')
raise Failure("JPEG dimensions not found")