FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Restore special casing of grayscale images in PostScript backend. by anntzer · Pull Request #12871 · matplotlib/matplotlib · GitHub

Repository navigation

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
43 changes: 15 additions & 28 deletions lib/matplotlib/backends/backend_ps.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
A PostScript backend, which can produce both PostScript .ps and .eps.
"""

import binascii
import datetime
import glob
from io import StringIO, TextIOWrapper
Expand All @@ -13,6 +12,7 @@
import shutil
import subprocess
from tempfile import TemporaryDirectory
import textwrap
import time

import numpy as np
Expand Down Expand Up @@ -392,26 +392,8 @@ def _get_font_ttf(self, prop):
font.set_size(size, 72.0)
return font

def _rgb(self, rgba):
h, w = rgba.shape[:2]
rgb = rgba[::-1, :, :3]
return h, w, rgb.tostring()

def _hex_lines(self, s, chars_per_line=128):
s = binascii.b2a_hex(s)
nhex = len(s)
lines = []
for i in range(0, nhex, chars_per_line):
limit = min(i+chars_per_line, nhex)
lines.append(s[i:limit])
return lines

def get_image_magnification(self):
"""
Get the factor by which to magnify images passed to draw_image.
Allows a backend to have images at a different resolution to other
artists.
"""
# docstring inherited
return self.image_magnification

def option_scale_image(self):
Expand All @@ -422,17 +404,22 @@ def option_image_nocomposite(self):
# docstring inherited
return not rcParams['image.composite_image']

def _get_image_h_w_bits_command(self, im):
h, w, bits = self._rgb(im)
imagecmd = "false 3 colorimage"

return h, w, bits, imagecmd

def draw_image(self, gc, x, y, im, transform=None):
# docstring inherited

h, w, bits, imagecmd = self._get_image_h_w_bits_command(im)
hexlines = b'\n'.join(self._hex_lines(bits)).decode('ascii')
h, w = im.shape[:2]
if ((im[..., 3] == 255).all()
and (im[..., 0] == im[..., 1]).all()
and (im[..., 0] == im[..., 2]).all()):
data = im[::-1, ..., 0]
imagecmd = "image"
else:
data = im[::-1, :, :3]
imagecmd = "false 3 colorimage"

# data.tobytes().hex() has no spaces, so can be linewrapped by relying
# on textwrap.fill breaking long words.
hexlines = textwrap.fill(data.tobytes().hex(), 128)

if transform is None:
matrix = "1 0 0 1 0 0"
Expand Down

Back | FazBrowse Home | New Git URL