Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "gray" more consistently #7481

Merged
merged 2 commits into from
Oct 20, 2023
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
12 changes: 6 additions & 6 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,7 @@ Changelog (Pillow)
- Cache EXIF information #3498
[Glandos]

- Added transparency for all PNG greyscale modes #3744
- Added transparency for all PNG grayscale modes #3744
[radarhere]

- Fix deprecation warnings in Python 3.8 #3749
Expand Down Expand Up @@ -4693,7 +4693,7 @@ Changelog (Pillow)
- Fix Bicubic interpolation #970
[homm]

- Support for 4-bit greyscale TIFF images #980
- Support for 4-bit grayscale TIFF images #980
[hugovk]

- Updated manifest #957
Expand Down Expand Up @@ -6768,7 +6768,7 @@ The test suite includes 750 individual tests.

- You can now convert directly between all modes supported by
PIL. When converting colour images to "P", PIL defaults to
a "web" palette and dithering. When converting greyscale
a "web" palette and dithering. When converting grayscale
images to "1", PIL uses a thresholding and dithering.

- Added a "dither" option to "convert". By default, "convert"
Expand Down Expand Up @@ -6846,13 +6846,13 @@ The test suite includes 530 individual tests.
- Fixed "paste" to allow a mask also for mode "F" images.

- The BMP driver now saves mode "1" images. When loading images, the mode
is set to "L" for 8-bit files with greyscale palettes, and to "P" for
is set to "L" for 8-bit files with grayscale palettes, and to "P" for
other 8-bit files.

- The IM driver now reads and saves "1" images (file modes "0 1" or "L 1").

- The JPEG and GIF drivers now saves "1" images. For JPEG, the image
is saved as 8-bit greyscale (it will load as mode "L"). For GIF, the
is saved as 8-bit grayscale (it will load as mode "L"). For GIF, the
image will be loaded as a "P" image.

- Fixed a potential buffer overrun in the GIF encoder.
Expand Down Expand Up @@ -7156,7 +7156,7 @@ The test suite includes 400 individual tests.
drawing capabilities can be used to render vector and metafile
formats.

- Added restricted drivers for images from Image Tools (greyscale
- Added restricted drivers for images from Image Tools (grayscale
only) and LabEye/IFUNC (common interchange modes only).

- Some minor improvements to the sample scripts provided in the
Expand Down
4 changes: 2 additions & 2 deletions Tests/test_file_apng.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,13 +231,13 @@ def test_apng_mode():
assert im.getpixel((0, 0)) == (0, 0, 128, 191)
assert im.getpixel((64, 32)) == (0, 0, 128, 191)

with Image.open("Tests/images/apng/mode_greyscale.png") as im:
with Image.open("Tests/images/apng/mode_grayscale.png") as im:
assert im.mode == "L"
im.seek(im.n_frames - 1)
assert im.getpixel((0, 0)) == 128
assert im.getpixel((64, 32)) == 255

with Image.open("Tests/images/apng/mode_greyscale_alpha.png") as im:
with Image.open("Tests/images/apng/mode_grayscale_alpha.png") as im:
assert im.mode == "LA"
im.seek(im.n_frames - 1)
assert im.getpixel((0, 0)) == (128, 191)
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_bmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def test_rle8():
with Image.open("Tests/images/hopper_rle8.bmp") as im:
assert_image_similar_tofile(im.convert("RGB"), "Tests/images/hopper.bmp", 12)

with Image.open("Tests/images/hopper_rle8_greyscale.bmp") as im:
with Image.open("Tests/images/hopper_rle8_grayscale.bmp") as im:
assert_image_equal_tofile(im, "Tests/images/bw_gradient.png")

# This test image has been manually hexedited
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_gif.py
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,7 @@ def test_save_dispose(tmp_path):
def test_dispose2_palette(tmp_path):
out = str(tmp_path / "temp.gif")

# Four colors: white, grey, black, red
# Four colors: white, gray, black, red
circles = [(255, 255, 255), (153, 153, 153), (0, 0, 0), (255, 0, 0)]

im_list = []
Expand Down
2 changes: 1 addition & 1 deletion Tests/test_file_png.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def test_save_p_transparent_black(self, tmp_path):
assert_image(im, "RGBA", (10, 10))
assert im.getcolors() == [(100, (0, 0, 0, 0))]

def test_save_greyscale_transparency(self, tmp_path):
def test_save_grayscale_transparency(self, tmp_path):
for mode, num_transparent in {"1": 1994, "L": 559, "I": 559}.items():
in_file = "Tests/images/" + mode.lower() + "_trns.png"
with Image.open(in_file) as im:
Expand Down
8 changes: 4 additions & 4 deletions Tests/test_imagechops.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
ORANGE = (255, 128, 0)
WHITE = (255, 255, 255)

GREY = 128
GRAY = 128


def test_sanity():
Expand Down Expand Up @@ -121,12 +121,12 @@ def test_constant():
im = Image.new("RGB", (20, 10))

# Act
new = ImageChops.constant(im, GREY)
new = ImageChops.constant(im, GRAY)

# Assert
assert new.size == im.size
assert new.getpixel((0, 0)) == GREY
assert new.getpixel((19, 9)) == GREY
assert new.getpixel((0, 0)) == GRAY
assert new.getpixel((19, 9)) == GRAY


def test_darker_image():
Expand Down
8 changes: 4 additions & 4 deletions Tests/test_imagefont.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,8 @@ def test_multiline_spacing(font):
"orientation", (Image.Transpose.ROTATE_90, Image.Transpose.ROTATE_270)
)
def test_rotated_transposed_font(font, orientation):
img_grey = Image.new("L", (100, 100))
draw = ImageDraw.Draw(img_grey)
img_gray = Image.new("L", (100, 100))
draw = ImageDraw.Draw(img_gray)
word = "testing"

transposed_font = ImageFont.TransposedFont(font, orientation=orientation)
Expand Down Expand Up @@ -344,8 +344,8 @@ def test_rotated_transposed_font(font, orientation):
),
)
def test_unrotated_transposed_font(font, orientation):
img_grey = Image.new("L", (100, 100))
draw = ImageDraw.Draw(img_grey)
img_gray = Image.new("L", (100, 100))
draw = ImageDraw.Draw(img_gray)
word = "testing"

transposed_font = ImageFont.TransposedFont(font, orientation=orientation)
Expand Down
4 changes: 2 additions & 2 deletions docs/handbook/tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ image. If the image was not read from a file, it is set to None. The size
attribute is a 2-tuple containing width and height (in pixels). The
:py:attr:`~PIL.Image.Image.mode` attribute defines the number and names of the
bands in the image, and also the pixel type and depth. Common modes are “L”
(luminance) for greyscale images, “RGB” for true color images, and “CMYK” for
(luminance) for grayscale images, “RGB” for true color images, and “CMYK” for
pre-press images.

If the file cannot be opened, an :py:exc:`OSError` exception is raised.
Expand Down Expand Up @@ -599,7 +599,7 @@ Controlling the decoder
Some decoders allow you to manipulate the image while reading it from a file.
This can often be used to speed up decoding when creating thumbnails (when
speed is usually more important than quality) and printing to a monochrome
laser printer (when only a greyscale version of the image is needed).
laser printer (when only a grayscale version of the image is needed).

The :py:meth:`~PIL.Image.Image.draft` method manipulates an opened but not yet
loaded image so it as closely as possible matches the given mode and size. This
Expand Down
6 changes: 3 additions & 3 deletions docs/handbook/writing-your-own-image-plugin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Example
The following plugin supports a simple format, which has a 128-byte header
consisting of the words “SPAM” followed by the width, height, and pixel size in
bits. The header fields are separated by spaces. The image data follows
directly after the header, and can be either bi-level, greyscale, or 24-bit
directly after the header, and can be either bi-level, grayscale, or 24-bit
true color.

**SpamImagePlugin.py**::
Expand Down Expand Up @@ -211,9 +211,9 @@ table describes some commonly used **raw modes**:
| ``1;R`` | | 1-bit reversed bilevel, stored with the leftmost pixel in the |
| | | least significant bit. 0 means black, 1 means white. |
+-----------+-------------------------------------------------------------------+
| ``L`` | 8-bit greyscale. 0 means black, 255 means white. |
| ``L`` | 8-bit grayscale. 0 means black, 255 means white. |
+-----------+-------------------------------------------------------------------+
| ``L;I`` | 8-bit inverted greyscale. 0 means white, 255 means black. |
| ``L;I`` | 8-bit inverted grayscale. 0 means white, 255 means black. |
+-----------+-------------------------------------------------------------------+
| ``P`` | 8-bit palette-mapped image. |
+-----------+-------------------------------------------------------------------+
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ImageColor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Functions
.. py:method:: getcolor(color, mode)

Same as :py:func:`~PIL.ImageColor.getrgb`, but converts the RGB value to a
greyscale value if the mode is not color or a palette image. If the string
grayscale value if the mode is not color or a palette image. If the string
cannot be parsed, this function raises a :py:exc:`ValueError` exception.

.. versionadded:: 1.1.4
2 changes: 1 addition & 1 deletion docs/reference/ImageEnhance.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ method:

This class can be used to control the contrast of an image, similar to the
contrast control on a TV set. An
:ref:`enhancement factor <enhancement-factor>` of 0.0 gives a solid grey
:ref:`enhancement factor <enhancement-factor>` of 0.0 gives a solid gray
image, a factor of 1.0 gives the original image, and greater values
increase the contrast of the image.

Expand Down
2 changes: 1 addition & 1 deletion docs/reference/ImageMath.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pixel bits.

Note that the operands are converted to 32-bit signed integers before the
bitwise operation is applied. This means that you’ll get negative values if
you invert an ordinary greyscale image. You can use the and (&) operator to
you invert an ordinary grayscale image. You can use the and (&) operator to
mask off unwanted bits.

Bitwise operators don’t work on floating point images.
Expand Down
4 changes: 2 additions & 2 deletions docs/releasenotes/6.1.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ API Additions
Image.entropy
^^^^^^^^^^^^^
Calculates and returns the entropy for the image. A bilevel image (mode "1") is treated
as a greyscale ("L") image by this method. If a mask is provided, the method employs
as a grayscale ("L") image by this method. If a mask is provided, the method employs
the histogram for those parts of the image where the mask image is non-zero. The mask
image must have the same size as the image, and be either a bi-level image (mode "1") or
a greyscale image ("L").
a grayscale image ("L").

ImageGrab.grab
^^^^^^^^^^^^^^
Expand Down
10 changes: 5 additions & 5 deletions src/PIL/BmpImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,21 +230,21 @@ def _bitmap(self, header=0, offset=0):
else:
padding = file_info["palette_padding"]
palette = read(padding * file_info["colors"])
greyscale = True
grayscale = True
indices = (
(0, 255)
if file_info["colors"] == 2
else list(range(file_info["colors"]))
)

# ----------------- Check if greyscale and ignore palette if so
# ----------------- Check if grayscale and ignore palette if so
for ind, val in enumerate(indices):
rgb = palette[ind * padding : ind * padding + 3]
if rgb != o8(val) * 3:
greyscale = False
grayscale = False

# ------- If all colors are grey, white or black, ditch palette
if greyscale:
# ------- If all colors are gray, white or black, ditch palette
if grayscale:
self._mode = "1" if file_info["colors"] == 2 else "L"
raw_mode = self.mode
else:
Expand Down
16 changes: 8 additions & 8 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -878,12 +878,12 @@ def convert(
"L", "RGB" and "CMYK". The ``matrix`` argument only supports "L"
and "RGB".

When translating a color image to greyscale (mode "L"),
When translating a color image to grayscale (mode "L"),
the library uses the ITU-R 601-2 luma transform::

L = R * 299/1000 + G * 587/1000 + B * 114/1000

The default method of converting a greyscale ("L") or "RGB"
The default method of converting a grayscale ("L") or "RGB"
image into a bilevel (mode "1") image uses Floyd-Steinberg
dither to approximate the original image luminosity levels. If
dither is ``None``, all values larger than 127 are set to 255 (white),
Expand Down Expand Up @@ -1238,7 +1238,7 @@ def draft(self, mode, size):
Configures the image file loader so it returns a version of the
image that as closely as possible matches the given mode and
size. For example, you can use this method to convert a color
JPEG to greyscale while loading it.
JPEG to grayscale while loading it.

If any changes are made, returns a tuple with the chosen ``mode`` and
``box`` with coordinates of the original image within the altered one.
Expand Down Expand Up @@ -1610,13 +1610,13 @@ def histogram(self, mask=None, extrema=None):
than one band, the histograms for all bands are concatenated (for
example, the histogram for an "RGB" image contains 768 values).

A bilevel image (mode "1") is treated as a greyscale ("L") image
A bilevel image (mode "1") is treated as a grayscale ("L") image
by this method.

If a mask is provided, the method returns a histogram for those
parts of the image where the mask image is non-zero. The mask
image must have the same size as the image, and be either a
bi-level image (mode "1") or a greyscale image ("L").
bi-level image (mode "1") or a grayscale image ("L").

:param mask: An optional mask.
:param extrema: An optional tuple of manually-specified extrema.
Expand All @@ -1636,13 +1636,13 @@ def entropy(self, mask=None, extrema=None):
"""
Calculates and returns the entropy for the image.

A bilevel image (mode "1") is treated as a greyscale ("L")
A bilevel image (mode "1") is treated as a grayscale ("L")
image by this method.

If a mask is provided, the method employs the histogram for
those parts of the image where the mask image is non-zero.
The mask image must have the same size as the image, and be
either a bi-level image (mode "1") or a greyscale image ("L").
either a bi-level image (mode "1") or a grayscale image ("L").

:param mask: An optional mask.
:param extrema: An optional tuple of manually-specified extrema.
Expand Down Expand Up @@ -2876,7 +2876,7 @@ class ImageTransformHandler:


def _wedge():
"""Create greyscale wedge (for debugging only)"""
"""Create grayscale wedge (for debugging only)"""

return Image()._new(core.wedge("L"))

Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageChops.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


def constant(image, value):
"""Fill a channel with a given grey level.
"""Fill a channel with a given gray level.

:rtype: :py:class:`~PIL.Image.Image`
"""
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageColor.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def getcolor(color, mode):
"""
Same as :py:func:`~PIL.ImageColor.getrgb` for most modes. However, if
``mode`` is HSV, converts the RGB value to a HSV value, or if ``mode`` is
not color or a palette image, converts the RGB value to a greyscale value.
not color or a palette image, converts the RGB value to a grayscale value.
If the string cannot be parsed, this function raises a :py:exc:`ValueError`
exception.

Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageEnhance.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Contrast(_Enhance):

This class can be used to control the contrast of an image, similar
to the contrast control on a TV set. An enhancement factor of 0.0
gives a solid grey image. A factor of 1.0 gives the original image.
gives a solid gray image. A factor of 1.0 gives the original image.
"""

def __init__(self, image):
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageOps.py
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ def solarize(image, threshold=128):
Invert all pixel values above a threshold.

:param image: The image to solarize.
:param threshold: All pixels above this greyscale level are inverted.
:param threshold: All pixels above this grayscale level are inverted.
:return: An image.
"""
lut = []
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/ImageWin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ class Dib:
"L", "P", or "RGB".

If the display requires a palette, this constructor creates a suitable
palette and associates it with the image. For an "L" image, 128 greylevels
palette and associates it with the image. For an "L" image, 128 graylevels
are allocated. For an "RGB" image, a 6x6x6 colour cube is used, together
with 20 greylevels.
with 20 graylevels.

To make sure that palettes work properly under Windows, you must call the
``palette`` method upon certain events from Windows.
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/PSDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
if im.mode == "1":
dpi = 200 # fax
else:
dpi = 100 # greyscale
dpi = 100 # grayscale

Check warning on line 112 in src/PIL/PSDraw.py

View check run for this annotation

Codecov / codecov/patch

src/PIL/PSDraw.py#L112

Added line #L112 was not covered by tests
# image size (on paper)
x = im.size[0] * 72 / dpi
y = im.size[1] * 72 / dpi
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/PalmImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def _save(im, fp, filename):
if im.encoderinfo.get("bpp") in (1, 2, 4):
# this is 8-bit grayscale, so we shift it to get the high-order bits,
# and invert it because
# Palm does greyscale from white (0) to black (1)
# Palm does grayscale from white (0) to black (1)
bpp = im.encoderinfo["bpp"]
im = im.point(
lambda x, shift=8 - bpp, maxval=(1 << bpp) - 1: maxval - (x >> shift)
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/PcxImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _open(self):
self.fp.seek(-769, io.SEEK_END)
s = self.fp.read(769)
if len(s) == 769 and s[0] == 12:
# check if the palette is linear greyscale
# check if the palette is linear grayscale
for i in range(256):
if s[i * 3 + 1 : i * 3 + 4] != o8(i) * 3:
mode = rawmode = "P"
Expand Down Expand Up @@ -203,7 +203,7 @@ def _save(im, fp, filename):
palette += b"\x00" * (768 - len(palette))
fp.write(palette) # 768 bytes
elif im.mode == "L":
# greyscale palette
# grayscale palette
fp.write(o8(12))
for i in range(256):
fp.write(o8(i) * 3)
Expand Down
Loading
Loading