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
6 changes: 6 additions & 0 deletions Tests/test_imageqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,9 @@ def test_image(mode: str) -> None:
def test_closed_file() -> None:
with warnings.catch_warnings(action="error"):
ImageQt.ImageQt("Tests/images/hopper.gif")


def test_align8to32_deprecation() -> None:
im = hopper("1")
with pytest.warns(DeprecationWarning, match="ImageQt.align8to32"):
ImageQt.align8to32(im.tobytes(), im.width, im.mode)
11 changes: 9 additions & 2 deletions 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,9 +30,16 @@ 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.

JpegImageFile.load_djpeg
~~~~~~~~~~~~~~~~~~~~~~~~
^^^^^^^^^^^^^^^^^^^^^^^^

.. deprecated:: 13.0.0

Expand Down
6 changes: 6 additions & 0 deletions docs/releasenotes/13.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ JpegImageFile.load_djpeg
Use the built-in JPEG decoder instead, or call ``djpeg`` directly and decode the
resulting image with Pillow.

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

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

API changes
===========

Expand Down
12 changes: 10 additions & 2 deletions src/PIL/ImageQt.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from io import BytesIO

from . import Image
from ._deprecate import deprecate
from ._util import is_path

TYPE_CHECKING = False
Expand Down Expand Up @@ -107,6 +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)

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

Expand Down Expand Up @@ -174,10 +176,16 @@ def _toqclass_helper(im: Image.Image | str | QByteArray) -> dict[str, Any]:
raise ValueError(msg)

size = im.size
__data = data or align8to32(im.tobytes(), size[0], im.mode)
if data is None:
# 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}
return {"data": data, "size": size, "format": format, "colortable": colortable}


if qt_is_installed:
Expand Down