diff --git a/Tests/test_imageqt.py b/Tests/test_imageqt.py index 7d56ce5f101..c7a73d41b33 100644 --- a/Tests/test_imageqt.py +++ b/Tests/test_imageqt.py @@ -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) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 70745104483..2d56df15da8 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -21,7 +21,7 @@ ExifTags.IFD.Makernote ``ExifTags.IFD.MakerNote``. Image getdata() -~~~~~~~~~~~~~~~ +^^^^^^^^^^^^^^^ .. deprecated:: 12.1.0 @@ -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 ---------------- diff --git a/docs/releasenotes/13.0.0.rst b/docs/releasenotes/13.0.0.rst index d6d0ff6c40e..5ccec3b1e30 100644 --- a/docs/releasenotes/13.0.0.rst +++ b/docs/releasenotes/13.0.0.rst @@ -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 =========== diff --git a/src/PIL/ImageQt.py b/src/PIL/ImageQt.py index ed747ffefa7..c5d09f00d84 100644 --- a/src/PIL/ImageQt.py +++ b/src/PIL/ImageQt.py @@ -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] @@ -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 @@ -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}