Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
13 changes: 4 additions & 9 deletions Tests/test_imageqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,7 @@ def test_closed_file() -> None:
ImageQt.ImageQt("Tests/images/hopper.gif")


def test_deprecated_align8to32_matches_new_impl() -> None:
im = hopper("P").resize((113, 113)) # size causes alignment issues
w, h = im.size
with pytest.warns(DeprecationWarning, match="Implement"):
old_b = ImageQt.align8to32(im.tobytes(), w, im.mode)
stride = ImageQt._aligned_stride(w, im.mode)
new_b = im.tobytes("raw", im.mode, stride)
assert old_b == new_b
assert len(old_b) == stride * h
def test_align8to32_deprecation() -> None:
im = hopper("1")
with pytest.warns(DeprecationWarning, match="ImageQt.align8to32"):
ImageQt.align8to32(im.tobytes(), im.width, im.mode)
10 changes: 9 additions & 1 deletion docs/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ ExifTags.IFD.Makernote
``ExifTags.IFD.MakerNote``.

Image getdata()
~~~~~~~~~~~~~~~
^^^^^^^^^^^^^^^

.. deprecated:: 12.1.0

Expand All @@ -30,6 +30,14 @@ Image getdata()
identical, except that it returns a tuple of pixel values, instead of an internal
Pillow data type.

ImageQt align8to32()
^^^^^^^^^^^^^^^^^^^^

.. deprecated:: 13.0.0

``ImageQt.align8to32()`` has been deprecated. This was an undocumented helper function
intended for internal use, so there is no replacement.

Removed features
----------------

Expand Down
7 changes: 4 additions & 3 deletions docs/releasenotes/13.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ ImageCms.ImageCmsProfile.product_name and .product_info
Deprecations
============

TODO
^^^^
ImageQt align8to32()
^^^^^^^^^^^^^^^^^^^^

TODO
``ImageQt.align8to32()`` has been deprecated. This was an undocumented helper function
intended for internal use, so there is no replacement.

API changes
===========
Expand Down
19 changes: 7 additions & 12 deletions src/PIL/ImageQt.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,7 @@ def align8to32(bytes: bytes, width: int, mode: str) -> bytes:
"""
converts each scanline of data from 8 bit to 32 bit aligned
"""
deprecate(
"ImageQt.align8to32", 14, action="Implement a similar function in your code"
)
deprecate("ImageQt.align8to32", 14)

bits_per_pixel = {"1": 1, "L": 8, "P": 8, "I;16": 16}[mode]

Expand All @@ -133,14 +131,6 @@ def align8to32(bytes: bytes, width: int, mode: str) -> bytes:
return b"".join(new_data)


def _aligned_stride(width: int, mode: str) -> int:
# Compute the stride (scanline size) in bytes when aligned
# to Qt's requirement that scanlines be aligned to 4 bytes.
mode_bpp = {"1": 1, "L": 8, "P": 8, "I;16": 16}
bytes_per_line = (mode_bpp[mode] * width + 7) // 8
return (bytes_per_line + 3) & ~3


def _toqclass_helper(im: Image.Image | str | QByteArray) -> dict[str, Any]:
data = None
colortable = None
Expand Down Expand Up @@ -187,7 +177,12 @@ def _toqclass_helper(im: Image.Image | str | QByteArray) -> dict[str, Any]:

size = im.size
if data is None:
data = im.tobytes("raw", im.mode, _aligned_stride(size[0], im.mode))
# Compute the stride (scanline size) in bytes when aligned
# to Qt's requirement that scanlines be aligned to 32 bits.
bpp = {"1": 1, "L": 8, "P": 8, "I;16": 16}[im.mode]
stride = (bpp * size[0] + 31) // 32 * (32 // 8)

data = im.tobytes("raw", im.mode, stride)
if exclusive_fp:
im.close()
return {"data": data, "size": size, "format": format, "colortable": colortable}
Expand Down
Loading