Comments (3)
And something similar on another file:
--- source
+++ first pass
@@ -1,6 +1,6 @@
-#
+#
# The Python Imaging Library.
# $Id$
#
# SGI image file handling
#
@@ -18,17 +18,14 @@
# Copyright (c) 1997 by Secret Labs AB.
# Copyright (c) 1995 by Fredrik Lundh.
#
# See the README file for information on usage and redistribution.
#
-
-
from . import Image, ImageFile
from ._binary import i8, o8, i16be as i16
import struct
import os
-
__version__ = "0.3"
def _accept(prefix):
@@ -41,125 +38,110 @@
(2, 1, 1): "L;16B",
(2, 2, 1): "L;16B",
(1, 3, 3): "RGB",
(2, 3, 3): "RGB;16B",
(1, 3, 4): "RGBA",
- (2, 3, 4): "RGBA;16B"
+ (2, 3, 4): "RGBA;16B",
}
##
# Image plugin for SGI images.
class SgiImageFile(ImageFile.ImageFile):
-
format = "SGI"
format_description = "SGI Image File Format"
def _open(self):
-
# HEAD
headlen = 512
s = self.fp.read(headlen)
-
# magic number : 474
if i16(s) != 474:
raise ValueError("Not an SGI image file")
# compression : verbatim or RLE
compression = i8(s[2])
-
# bpc : 1 or 2 bytes (8bits or 16bits)
bpc = i8(s[3])
-
# dimension : 1, 2 or 3 (depending on xsize, ysize and zsize)
dimension = i16(s[4:])
-
# xsize : width
xsize = i16(s[6:])
-
# ysize : height
ysize = i16(s[8:])
-
# zsize : channels count
zsize = i16(s[10:])
-
# layout
layout = bpc, dimension, zsize
-
# determine mode from bits/zsize
rawmode = ""
try:
rawmode = MODES[layout]
except KeyError:
pass
-
if rawmode == "":
raise ValueError("Unsupported SGI image mode")
self.size = xsize, ysize
self.mode = rawmode.split(";")[0]
-
# orientation -1 : scanlines begins at the bottom-left corner
orientation = -1
-
# decoder info
if compression == 0:
pagesize = xsize * ysize * bpc
if bpc == 2:
- self.tile = [("SGI16", (0, 0) + self.size,
- headlen, (self.mode, 0, orientation))]
+ self.tile = [
+ ("SGI16", (0, 0) + self.size, headlen, (self.mode, 0, orientation))
+ ]
else:
self.tile = []
offset = headlen
for layer in self.mode:
self.tile.append(
- ("raw", (0, 0) + self.size,
- offset, (layer, 0, orientation)))
+ ("raw", (0, 0) + self.size, offset, (layer, 0, orientation))
+ )
offset += pagesize
elif compression == 1:
- self.tile = [("sgi_rle", (0, 0) + self.size,
- headlen, (rawmode, orientation, bpc))]
+ self.tile = [
+ ("sgi_rle", (0, 0) + self.size, headlen, (rawmode, orientation, bpc))
+ ]
def _save(im, fp, filename):
if im.mode != "RGB" and im.mode != "RGBA" and im.mode != "L":
raise ValueError("Unsupported SGI image mode")
# Get the keyword arguments
info = im.encoderinfo
-
# Byte-per-pixel precision, 1 = 8bits per pixel
bpc = info.get("bpc", 1)
-
if bpc not in (1, 2):
raise ValueError("Unsupported number of bytes per pixel")
# Flip the image, since the origin of SGI file is the bottom-left corner
orientation = -1
# Define the file as SGI File Format
magicNumber = 474
# Run-Length Encoding Compression - Unsupported at this time
rle = 0
-
# Number of dimensions (x,y,z)
dim = 3
# X Dimension = width / Y Dimension = height
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 = len(im.mode)
-
if dim == 1 or dim == 2:
z = 1
-
# assert we've got the right number of bands.
if len(im.getbands()) != z:
- raise ValueError("incorrect number of bands in SGI write: %s vs %s" %
- (z, len(im.getbands())))
+ raise ValueError(
+ "incorrect number of bands in SGI write: %s vs %s" % (z, len(im.getbands()))
+ )
# Minimum Byte value
pinmin = 0
# Maximum Byte value (255 = 8bits per pixel)
pinmax = 255
@@ -181,18 +163,15 @@
fp.write(struct.pack('4s', b'')) # dummy
fp.write(struct.pack('79s', imgName)) # truncates to 79 chars
fp.write(struct.pack('s', b'')) # force null byte after imgname
fp.write(struct.pack('>l', colormap))
fp.write(struct.pack('404s', b'')) # dummy
-
rawmode = 'L'
if bpc == 2:
rawmode = 'L;16B'
-
for channel in im.split():
fp.write(channel.tobytes('raw', rawmode, 0, orientation))
-
fp.close()
class SGI16Decoder(ImageFile.PyDecoder):
_pulls_fd = True
@@ -200,28 +179,24 @@
def decode(self, buffer):
rawmode, stride, orientation = self.args
pagesize = self.state.xsize * self.state.ysize
zsize = len(self.mode)
self.fd.seek(512)
-
for band in range(zsize):
channel = Image.new('L', (self.state.xsize, self.state.ysize))
- channel.frombytes(self.fd.read(2 * pagesize), 'raw',
- 'L;16B', stride, orientation)
+ channel.frombytes(
+ self.fd.read(2 * pagesize), 'raw', 'L;16B', stride, orientation
+ )
self.im.putband(channel.im, band)
-
return -1, 0
-#
+
+#
# registry
-
-
Image.register_decoder("SGI16", SGI16Decoder)
Image.register_open(SgiImageFile.format, SgiImageFile, _accept)
Image.register_save(SgiImageFile.format, _save)
Image.register_mime(SgiImageFile.format, "image/sgi")
Image.register_mime(SgiImageFile.format, "image/rgb")
-
Image.register_extensions(SgiImageFile.format, [".bw", ".rgb", ".rgba", ".sgi"])
-
# End of file
--- first pass
+++ second pass
@@ -195,8 +195,9 @@
Image.register_decoder("SGI16", SGI16Decoder)
Image.register_open(SgiImageFile.format, SgiImageFile, _accept)
Image.register_save(SgiImageFile.format, _save)
Image.register_mime(SgiImageFile.format, "image/sgi")
Image.register_mime(SgiImageFile.format, "image/rgb")
-Image.register_extensions(SgiImageFile.format, [".bw", ".rgb", ".rgba", ".sgi"])
-# End of file
-
+Image.register_extensions(
+ SgiImageFile.format, [".bw", ".rgb", ".rgba", ".sgi"]
+) # End of file
+
from black.
This is the same as #18. I'm working on a fix.
from black.
Thanks for your detailed reports! This is very helpful.
✨ 🍰 ✨
from black.
Related Issues (20)
- black could more efficiently skip directories listed in .gitignore HOT 2
- Allow valid version specifier when specifying Black version in `pyproject.toml` HOT 2
- Black failed to reformat HOT 1
- Cannot parse nested f-strings if the same quote char is used inside and outside. HOT 2
- global config not possible if project contains a `pyproject.toml`
- Error in the setup docs for black. HOT 4
- INTERNAL ERROR: Black produced code that is not equivalent to the source HOT 6
- Make Readability your main focus. HOT 2
- Cannot parse multiline f-string starting with backslash `\` HOT 2
- Offer more architectures in GitHub releases
- black formatter not working when file contains several comments HOT 4
- Newlines between classes do not get added when the last method of one ends with ellipses
- Crash on f-string with `\{` HOT 8
- Black does not add trailing commas when using typed_params_trailing_comma HOT 1
- Add more documentation about preview style features
- `--line-ranges` formats lines outside of range HOT 3
- Black fails to format f strings in function kwargs with dictionaries HOT 1
- Improve vim plugin error message if vim is too old or python support is missing HOT 1
- Support Python 3.13 free-threaded build HOT 3
- Black won't format file as it produces invalid code HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from black.