mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-05 20:33:24 +03:00
Simplified code
This commit is contained in:
parent
507fefbce4
commit
6ab93935a7
|
@ -82,17 +82,10 @@ class SgiImageFile(ImageFile.ImageFile):
|
||||||
# zsize : channels count
|
# zsize : channels count
|
||||||
zsize = i16(s, 10)
|
zsize = i16(s, 10)
|
||||||
|
|
||||||
# layout
|
|
||||||
layout = bpc, dimension, zsize
|
|
||||||
|
|
||||||
# determine mode from bits/zsize
|
# determine mode from bits/zsize
|
||||||
rawmode = ""
|
|
||||||
try:
|
try:
|
||||||
rawmode = MODES[layout]
|
rawmode = MODES[(bpc, dimension, zsize)]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
|
||||||
|
|
||||||
if rawmode == "":
|
|
||||||
msg = "Unsupported SGI image mode"
|
msg = "Unsupported SGI image mode"
|
||||||
raise ValueError(msg)
|
raise ValueError(msg)
|
||||||
|
|
||||||
|
@ -156,24 +149,15 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
|
||||||
# Run-Length Encoding Compression - Unsupported at this time
|
# Run-Length Encoding Compression - Unsupported at this time
|
||||||
rle = 0
|
rle = 0
|
||||||
|
|
||||||
# Number of dimensions (x,y,z)
|
|
||||||
dim = 3
|
|
||||||
# X Dimension = width / Y Dimension = height
|
# X Dimension = width / Y Dimension = height
|
||||||
x, y = im.size
|
x, y = im.size
|
||||||
if im.mode == "L" and y == 1:
|
|
||||||
dim = 1
|
|
||||||
elif im.mode == "L":
|
|
||||||
dim = 2
|
|
||||||
# Z Dimension: Number of channels
|
# Z Dimension: Number of channels
|
||||||
z = len(im.mode)
|
z = len(im.mode)
|
||||||
|
# Number of dimensions (x,y,z)
|
||||||
if dim in {1, 2}:
|
if im.mode == "L":
|
||||||
z = 1
|
dim = 1 if y == 1 else 2
|
||||||
|
else:
|
||||||
# assert we've got the right number of bands.
|
dim = 3
|
||||||
if len(im.getbands()) != z:
|
|
||||||
msg = f"incorrect number of bands in SGI write: {z} vs {len(im.getbands())}"
|
|
||||||
raise ValueError(msg)
|
|
||||||
|
|
||||||
# Minimum Byte value
|
# Minimum Byte value
|
||||||
pinmin = 0
|
pinmin = 0
|
||||||
|
|
Loading…
Reference in New Issue
Block a user