mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-06-02 12:13:26 +03:00
Simplified code
This commit is contained in:
parent
7e4d8e2f55
commit
b233faf3fd
|
@ -134,10 +134,7 @@ def grabclipboard() -> Image.Image | list[str] | None:
|
|||
import struct
|
||||
|
||||
o = struct.unpack_from("I", data)[0]
|
||||
if data[16] != 0:
|
||||
files = data[o:].decode("utf-16le").split("\0")
|
||||
else:
|
||||
files = data[o:].decode("mbcs").split("\0")
|
||||
files = data[o:].decode("mbcs" if data[16] == 0 else "utf-16le").split("\0")
|
||||
return files[: files.index("")]
|
||||
if isinstance(data, bytes):
|
||||
data = io.BytesIO(data)
|
||||
|
|
|
@ -762,8 +762,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
|||
extra = info.get("extra", b"")
|
||||
|
||||
MAX_BYTES_IN_MARKER = 65533
|
||||
xmp = info.get("xmp")
|
||||
if xmp:
|
||||
if xmp := info.get("xmp"):
|
||||
overhead_len = 29 # b"http://ns.adobe.com/xap/1.0/\x00"
|
||||
max_data_bytes_in_marker = MAX_BYTES_IN_MARKER - overhead_len
|
||||
if len(xmp) > max_data_bytes_in_marker:
|
||||
|
@ -772,8 +771,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
|||
size = o16(2 + overhead_len + len(xmp))
|
||||
extra += b"\xff\xe1" + size + b"http://ns.adobe.com/xap/1.0/\x00" + xmp
|
||||
|
||||
icc_profile = info.get("icc_profile")
|
||||
if icc_profile:
|
||||
if icc_profile := info.get("icc_profile"):
|
||||
overhead_len = 14 # b"ICC_PROFILE\0" + o8(i) + o8(len(markers))
|
||||
max_data_bytes_in_marker = MAX_BYTES_IN_MARKER - overhead_len
|
||||
markers = []
|
||||
|
@ -831,7 +829,6 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
|||
# in a shot. Guessing on the size, at im.size bytes. (raw pixel size is
|
||||
# channels*size, this is a value that's been used in a django patch.
|
||||
# https://github.com/matthewwithanm/django-imagekit/issues/50
|
||||
bufsize = 0
|
||||
if optimize or progressive:
|
||||
# CMYK can be bigger
|
||||
if im.mode == "CMYK":
|
||||
|
@ -848,7 +845,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
|||
else:
|
||||
# The EXIF info needs to be written as one block, + APP1, + one spare byte.
|
||||
# Ensure that our buffer is big enough. Same with the icc_profile block.
|
||||
bufsize = max(bufsize, len(exif) + 5, len(extra) + 1)
|
||||
bufsize = max(len(exif) + 5, len(extra) + 1)
|
||||
|
||||
ImageFile._save(
|
||||
im, fp, [ImageFile._Tile("jpeg", (0, 0) + im.size, 0, rawmode)], bufsize
|
||||
|
|
|
@ -98,7 +98,7 @@ export_imaging_schema(Imaging im, struct ArrowSchema *schema) {
|
|||
}
|
||||
|
||||
/* for now, single block images */
|
||||
if (!(im->blocks_count == 0 || im->blocks_count == 1)) {
|
||||
if (im->blocks_count > 1) {
|
||||
return IMAGING_ARROW_MEMORY_LAYOUT;
|
||||
}
|
||||
|
||||
|
@ -157,7 +157,7 @@ export_single_channel_array(Imaging im, struct ArrowArray *array) {
|
|||
int length = im->xsize * im->ysize;
|
||||
|
||||
/* for now, single block images */
|
||||
if (!(im->blocks_count == 0 || im->blocks_count == 1)) {
|
||||
if (im->blocks_count > 1) {
|
||||
return IMAGING_ARROW_MEMORY_LAYOUT;
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ export_fixed_pixel_array(Imaging im, struct ArrowArray *array) {
|
|||
int length = im->xsize * im->ysize;
|
||||
|
||||
/* for now, single block images */
|
||||
if (!(im->blocks_count == 0 || im->blocks_count == 1)) {
|
||||
if (im->blocks_count > 1) {
|
||||
return IMAGING_ARROW_MEMORY_LAYOUT;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user