mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 01:04:29 +03:00
Removed DPI rounding when BMP loading
This commit is contained in:
parent
9d72542c08
commit
0de3beaeaf
Binary file not shown.
Before Width: | Height: | Size: 48 KiB |
|
@ -63,7 +63,7 @@ def test_dpi():
|
||||||
|
|
||||||
output.seek(0)
|
output.seek(0)
|
||||||
with Image.open(output) as reloaded:
|
with Image.open(output) as reloaded:
|
||||||
assert reloaded.info["dpi"] == dpi
|
assert reloaded.info["dpi"] == (72.008961115161, 72.008961115161)
|
||||||
|
|
||||||
|
|
||||||
def test_save_bmp_with_dpi(tmp_path):
|
def test_save_bmp_with_dpi(tmp_path):
|
||||||
|
@ -71,6 +71,7 @@ def test_save_bmp_with_dpi(tmp_path):
|
||||||
# Arrange
|
# Arrange
|
||||||
outfile = str(tmp_path / "temp.jpg")
|
outfile = str(tmp_path / "temp.jpg")
|
||||||
with Image.open("Tests/images/hopper.bmp") as im:
|
with Image.open("Tests/images/hopper.bmp") as im:
|
||||||
|
assert im.info["dpi"] == (95.98654816726399, 95.98654816726399)
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
im.save(outfile, "JPEG", dpi=im.info["dpi"])
|
im.save(outfile, "JPEG", dpi=im.info["dpi"])
|
||||||
|
@ -78,31 +79,17 @@ def test_save_bmp_with_dpi(tmp_path):
|
||||||
# Assert
|
# Assert
|
||||||
with Image.open(outfile) as reloaded:
|
with Image.open(outfile) as reloaded:
|
||||||
reloaded.load()
|
reloaded.load()
|
||||||
assert im.info["dpi"] == reloaded.info["dpi"]
|
assert reloaded.info["dpi"] == (96, 96)
|
||||||
assert im.size == reloaded.size
|
assert reloaded.size == im.size
|
||||||
assert reloaded.format == "JPEG"
|
assert reloaded.format == "JPEG"
|
||||||
|
|
||||||
|
|
||||||
def test_load_dpi_rounding():
|
def test_save_float_dpi(tmp_path):
|
||||||
# Round up
|
|
||||||
with Image.open("Tests/images/hopper.bmp") as im:
|
|
||||||
assert im.info["dpi"] == (96, 96)
|
|
||||||
|
|
||||||
# Round down
|
|
||||||
with Image.open("Tests/images/hopper_roundDown.bmp") as im:
|
|
||||||
assert im.info["dpi"] == (72, 72)
|
|
||||||
|
|
||||||
|
|
||||||
def test_save_dpi_rounding(tmp_path):
|
|
||||||
outfile = str(tmp_path / "temp.bmp")
|
outfile = str(tmp_path / "temp.bmp")
|
||||||
with Image.open("Tests/images/hopper.bmp") as im:
|
with Image.open("Tests/images/hopper.bmp") as im:
|
||||||
im.save(outfile, dpi=(72.2, 72.2))
|
im.save(outfile, dpi=(72.21216100543306, 72.21216100543306))
|
||||||
with Image.open(outfile) as reloaded:
|
with Image.open(outfile) as reloaded:
|
||||||
assert reloaded.info["dpi"] == (72, 72)
|
assert reloaded.info["dpi"] == (72.21216100543306, 72.21216100543306)
|
||||||
|
|
||||||
im.save(outfile, dpi=(72.8, 72.8))
|
|
||||||
with Image.open(outfile) as reloaded:
|
|
||||||
assert reloaded.info["dpi"] == (73, 73)
|
|
||||||
|
|
||||||
|
|
||||||
def test_load_dib():
|
def test_load_dib():
|
||||||
|
|
|
@ -115,9 +115,7 @@ class BmpImageFile(ImageFile.ImageFile):
|
||||||
)
|
)
|
||||||
file_info["colors"] = i32(header_data, 28)
|
file_info["colors"] = i32(header_data, 28)
|
||||||
file_info["palette_padding"] = 4
|
file_info["palette_padding"] = 4
|
||||||
self.info["dpi"] = tuple(
|
self.info["dpi"] = tuple(x / 39.3701 for x in file_info["pixels_per_meter"])
|
||||||
int(x / 39.3701 + 0.5) for x in file_info["pixels_per_meter"]
|
|
||||||
)
|
|
||||||
if file_info["compression"] == self.BITFIELDS:
|
if file_info["compression"] == self.BITFIELDS:
|
||||||
if len(header_data) >= 52:
|
if len(header_data) >= 52:
|
||||||
for idx, mask in enumerate(
|
for idx, mask in enumerate(
|
||||||
|
|
Loading…
Reference in New Issue
Block a user