Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/PIL/ImageGrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,7 @@
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")

Check warning on line 137 in src/PIL/ImageGrab.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/ImageGrab.py#L137

Added line #L137 was not covered by tests
return files[: files.index("")]
if isinstance(data, bytes):
data = io.BytesIO(data)
Expand Down
9 changes: 3 additions & 6 deletions src/PIL/JpegImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,7 @@ def validate_qtables(
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:
Expand All @@ -772,8 +771,7 @@ def validate_qtables(
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 = []
Expand Down Expand Up @@ -831,7 +829,6 @@ def validate_qtables(
# 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":
Expand All @@ -848,7 +845,7 @@ def validate_qtables(
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
Expand Down
6 changes: 3 additions & 3 deletions src/libImaging/Arrow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down
33 changes: 8 additions & 25 deletions src/libImaging/Draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -439,9 +439,7 @@ draw_horizontal_lines(
* Filled polygon draw function using scan line algorithm.
*/
static inline int
polygon_generic(
Imaging im, int n, Edge *e, int ink, int eofill, hline_handler hline, int hasAlpha
) {
polygon_generic(Imaging im, int n, Edge *e, int ink, int eofill, hline_handler hline) {
Edge **edge_table;
float *xx;
int edge_count = 0;
Expand All @@ -461,6 +459,7 @@ polygon_generic(
return -1;
}

int hasAlpha = hline == hline32rgba;
for (i = 0; i < n; i++) {
if (ymin > e[i].ymin) {
ymin = e[i].ymin;
Expand Down Expand Up @@ -590,21 +589,6 @@ polygon_generic(
return 0;
}

static inline int
polygon8(Imaging im, int n, Edge *e, int ink, int eofill) {
return polygon_generic(im, n, e, ink, eofill, hline8, 0);
}

static inline int
polygon32(Imaging im, int n, Edge *e, int ink, int eofill) {
return polygon_generic(im, n, e, ink, eofill, hline32, 0);
}

static inline int
polygon32rgba(Imaging im, int n, Edge *e, int ink, int eofill) {
return polygon_generic(im, n, e, ink, eofill, hline32rgba, 1);
}

static inline void
add_edge(Edge *e, int x0, int y0, int x1, int y1) {
/* printf("edge %d %d %d %d\n", x0, y0, x1, y1); */
Expand Down Expand Up @@ -641,12 +625,11 @@ typedef struct {
void (*point)(Imaging im, int x, int y, int ink);
void (*hline)(Imaging im, int x0, int y0, int x1, int ink);
void (*line)(Imaging im, int x0, int y0, int x1, int y1, int ink);
int (*polygon)(Imaging im, int n, Edge *e, int ink, int eofill);
} DRAW;

DRAW draw8 = {point8, hline8, line8, polygon8};
DRAW draw32 = {point32, hline32, line32, polygon32};
DRAW draw32rgba = {point32rgba, hline32rgba, line32rgba, polygon32rgba};
DRAW draw8 = {point8, hline8, line8};
DRAW draw32 = {point32, hline32, line32};
DRAW draw32rgba = {point32rgba, hline32rgba, line32rgba};

/* -------------------------------------------------------------------- */
/* Interface */
Expand Down Expand Up @@ -731,7 +714,7 @@ ImagingDrawWideLine(
add_edge(e + 2, vertices[2][0], vertices[2][1], vertices[3][0], vertices[3][1]);
add_edge(e + 3, vertices[3][0], vertices[3][1], vertices[0][0], vertices[0][1]);

draw->polygon(im, 4, e, ink, 0);
polygon_generic(im, 4, e, ink, 0, draw->hline);
}
return 0;
}
Expand Down Expand Up @@ -839,7 +822,7 @@ ImagingDrawPolygon(
if (xy[i * 2] != xy[0] || xy[i * 2 + 1] != xy[1]) {
add_edge(&e[n++], xy[i * 2], xy[i * 2 + 1], xy[0], xy[1]);
}
draw->polygon(im, n, e, ink, 0);
polygon_generic(im, n, e, ink, 0, draw->hline);
free(e);

} else {
Expand Down Expand Up @@ -1989,7 +1972,7 @@ ImagingDrawOutline(

DRAWINIT();

draw->polygon(im, outline->count, outline->edges, ink, 0);
polygon_generic(im, outline->count, outline->edges, ink, 0, draw->hline);

return 0;
}
Loading