Skip to content

Commit efcdff2

Browse files
committed
Simplified code
1 parent 3c71559 commit efcdff2

File tree

3 files changed

+7
-13
lines changed

3 files changed

+7
-13
lines changed

src/PIL/ImageGrab.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,10 +134,7 @@ def grabclipboard() -> Image.Image | list[str] | None:
134134
import struct
135135

136136
o = struct.unpack_from("I", data)[0]
137-
if data[16] != 0:
138-
files = data[o:].decode("utf-16le").split("\0")
139-
else:
140-
files = data[o:].decode("mbcs").split("\0")
137+
files = data[o:].decode("mbcs" if data[16] == 0 else "utf-16le").split("\0")
141138
return files[: files.index("")]
142139
if isinstance(data, bytes):
143140
data = io.BytesIO(data)

src/PIL/JpegImagePlugin.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -762,8 +762,7 @@ def validate_qtables(
762762
extra = info.get("extra", b"")
763763

764764
MAX_BYTES_IN_MARKER = 65533
765-
xmp = info.get("xmp")
766-
if xmp:
765+
if xmp := info.get("xmp"):
767766
overhead_len = 29 # b"http://ns.adobe.com/xap/1.0/\x00"
768767
max_data_bytes_in_marker = MAX_BYTES_IN_MARKER - overhead_len
769768
if len(xmp) > max_data_bytes_in_marker:
@@ -772,8 +771,7 @@ def validate_qtables(
772771
size = o16(2 + overhead_len + len(xmp))
773772
extra += b"\xff\xe1" + size + b"http://ns.adobe.com/xap/1.0/\x00" + xmp
774773

775-
icc_profile = info.get("icc_profile")
776-
if icc_profile:
774+
if icc_profile := info.get("icc_profile"):
777775
overhead_len = 14 # b"ICC_PROFILE\0" + o8(i) + o8(len(markers))
778776
max_data_bytes_in_marker = MAX_BYTES_IN_MARKER - overhead_len
779777
markers = []
@@ -831,7 +829,6 @@ def validate_qtables(
831829
# in a shot. Guessing on the size, at im.size bytes. (raw pixel size is
832830
# channels*size, this is a value that's been used in a django patch.
833831
# https://github.com/matthewwithanm/django-imagekit/issues/50
834-
bufsize = 0
835832
if optimize or progressive:
836833
# CMYK can be bigger
837834
if im.mode == "CMYK":
@@ -848,7 +845,7 @@ def validate_qtables(
848845
else:
849846
# The EXIF info needs to be written as one block, + APP1, + one spare byte.
850847
# Ensure that our buffer is big enough. Same with the icc_profile block.
851-
bufsize = max(bufsize, len(exif) + 5, len(extra) + 1)
848+
bufsize = max(len(exif) + 5, len(extra) + 1)
852849

853850
ImageFile._save(
854851
im, fp, [ImageFile._Tile("jpeg", (0, 0) + im.size, 0, rawmode)], bufsize

src/libImaging/Arrow.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export_imaging_schema(Imaging im, struct ArrowSchema *schema) {
9898
}
9999

100100
/* for now, single block images */
101-
if (!(im->blocks_count == 0 || im->blocks_count == 1)) {
101+
if (im->blocks_count > 1) {
102102
return IMAGING_ARROW_MEMORY_LAYOUT;
103103
}
104104

@@ -157,7 +157,7 @@ export_single_channel_array(Imaging im, struct ArrowArray *array) {
157157
int length = im->xsize * im->ysize;
158158

159159
/* for now, single block images */
160-
if (!(im->blocks_count == 0 || im->blocks_count == 1)) {
160+
if (im->blocks_count > 1) {
161161
return IMAGING_ARROW_MEMORY_LAYOUT;
162162
}
163163

@@ -200,7 +200,7 @@ export_fixed_pixel_array(Imaging im, struct ArrowArray *array) {
200200
int length = im->xsize * im->ysize;
201201

202202
/* for now, single block images */
203-
if (!(im->blocks_count == 0 || im->blocks_count == 1)) {
203+
if (im->blocks_count > 1) {
204204
return IMAGING_ARROW_MEMORY_LAYOUT;
205205
}
206206

0 commit comments

Comments
 (0)