| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
This divides the filesize by ~3 by not storing three identical channels
(e.g. compare the size of
```
imshow(np.random.rand(255, 255), cmap="gray")
gca().set_axis_off()
savefig("test.ps")
```
before and after the patch).
|
Does this get tested somehow? Otherwise makes sense to me, unless the performance hit is significant, which I doubt as well... |
Sorry, something went wrong.
|
Those factors are luminance conversions. |
Sorry, something went wrong.
|
Gah, the obvious tests @check_figures_equal(extensions=["eps"])
def test_grayscale_compression(fig_test, fig_ref):
# Fully opaque, grayscale images are saved as single channel. Compare
# with a non-fully opaque image (by making the an all-white pixel
# transparent...) which is saved as three different channels.
t = np.arange(256, dtype="u1").reshape((16, 16))
rgba = np.stack([t, t, t, np.ones_like(t, "u1") * 0xff], 2)
fig_ref.subplots().imshow(rgba)
rgba[-1, -1] = 0
fig_test.subplots().imshow(rgba)
or @check_figures_equal(extensions=["eps"])
def test_grayscale_compression(fig_test, fig_ref):
# Fully opaque, grayscale images are saved as single channel. Compare with
# a non-fully opaque image which is saved as three different channels.
test_data = np.arange(100).reshape((10, 10))
fig_ref.subplots().imshow(test_data, cmap="gray")
fig_test.subplots().imshow(test_data, cmap="gray", alpha=.5)
fail (visibly); I guess there's something about gamma correction being applied in one case and not the other by the renderer... |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This divides the filesize by ~3 by not storing three identical channels
(e.g. compare the size of
imshow(np.random.rand(255, 255), cmap="gray") gca().set_axis_off() savefig("test.ps")before and after the patch).
Looks like some kind of similar functionality was present before mpl2.0, though with some weird magic factors (https://github.com/matplotlib/matplotlib/pull/5718/files#diff-b465967f537465fec4960b152fa49cffL415), and I stumbled on some vestigial leftovers of it (https://github.com/matplotlib/matplotlib/pull/5718/files#diff-b465967f537465fec4960b152fa49cffL457 where the "image" command comes from)...
No hard numbers but I don't think the performance cost (on non-grayscale images) really matters as we're going to iterate through the array just after to serialize it anyways.
Probably the same thing can be done for the pdf backend -- see grayscale parameter of _writeImg.
PR Summary
PR Checklist