Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Inline some image-handling code for postscript. #13102

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

Merged
merged 1 commit into from
Jan 5, 2019
Merged
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
30 changes: 7 additions & 23 deletions lib/matplotlib/backends/backend_ps.py
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,20 +392,6 @@ 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.
Expand All @@ -422,17 +408,15 @@ 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]
imagecmd = "false 3 colorimage"
data = im[::-1, :, :3] # Vertically flipped rgb values.
# 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