-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Rewrite of image infrastructure #5718
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
Changes from all commits
cf11aea
3b7d1bb
c9cae50
4a05302
0aa222a
0793aa2
1384c7c
9148c7f
820479e
fad84c8
64e84ea
0be04c0
a8643f1
5df79f0
b436f1a
dfbc39d
9d3b468
f9d8534
7b32cd8
6e60ebf
dc66ed0
7cccfb3
5073f6e
625e80a
c778cfc
9fe6658
d61ac2a
b3318fd
ffbbf05
fbb55c8
34d6cc8
4c5a3bf
9448208
83f4bc9
d5030a4
55c1abb
fe376c4
5266fde
9285c3a
e2b2bbe
b894683
4e43c8b
8665697
d21a6ed
2d2a126
6d3518a
0b8d693
0f43f68
cd0e7e0
e62832f
e7d54d5
3e532e1
cfad8d9
e52c26f
0469ab7
b391f08
89365c1
7f2f375
9827d1f
5be66de
bd521cd
d6b22a5
fff1d66
da6c00b
c9b2425
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Change in the ``draw_image`` backend API | ||
---------------------------------------- | ||
|
||
The ``draw_image`` method implemented by backends has changed its interface. | ||
|
||
This change is only relevant if the backend declares that it is able | ||
to transform images by returning ``True`` from ``option_scale_image``. | ||
See the ``draw_image`` docstring for more information. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
Improved image support | ||
---------------------- | ||
|
||
Prior to version 2.0, matplotlib resampled images by first applying | ||
the color map and then resizing the result. Since the resampling was | ||
performed on the colored image, this introduced colors in the output | ||
image that didn't actually exist in the color map. Now, images are | ||
resampled first (and entirely in floating-point, if the input image is | ||
floating-point), and then the color map is applied. | ||
|
||
In order to make this important change, the image handling code was | ||
almost entirely rewritten. As a side effect, image resampling uses | ||
less memory and fewer datatype conversions than before. | ||
|
||
The experimental private feature where one could "skew" an image by | ||
setting the private member ``_image_skew_coordinate`` has been | ||
removed. Instead, images will obey the transform of the axes on which | ||
they are drawn. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -490,7 +490,7 @@ namespace agg | |
fg_ptr = (const value_type*)base_type::source().next_y(); | ||
} | ||
|
||
fg >>= image_filter_shift; | ||
fg = color_type::downshift(fg, image_filter_shift); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Has this been fed back to Agg? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, though I've received no response. |
||
if(fg < 0) fg = 0; | ||
if(fg > color_type::full_value()) fg = color_type::full_value(); | ||
span->v = (value_type)fg; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -171,14 +171,18 @@ def draw_image(self, gc, x, y, im): | |
# bbox - not currently used | ||
if _debug: print('%s.%s()' % (self.__class__.__name__, _fn_name())) | ||
|
||
rows, cols, buf = im.color_conv (BYTE_FORMAT) | ||
surface = cairo.ImageSurface.create_for_data ( | ||
buf, cairo.FORMAT_ARGB32, cols, rows, cols*4) | ||
if sys.byteorder == 'little': | ||
im = im[:, :, (2, 1, 0, 3)] | ||
else: | ||
im = im[:, :, (3, 0, 1, 2)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to check that image is RGBA (I am assuming that that is what the 4 bytes that are getting swapped around are for, right)? I am also going to assume that the swaps are correct. I have never been able to remember byte order stuff correctly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RGBA is always passed to draw_image (it's the responsibility of the other layers, not the backend, to make it so). This should be documented as well in I checked the swaps on both x86_64 and an old PPC Mac-running-Linux that I keep around to check byte order issues. Cairo is the only backend we have that requires ARGB in native byte order like this. |
||
surface = cairo.ImageSurface.create_for_data( | ||
memoryview(im.flatten()), cairo.FORMAT_ARGB32, im.shape[1], im.shape[0], | ||
im.shape[1]*4) | ||
ctx = gc.ctx | ||
y = self.height - y - rows | ||
y = self.height - y - im.shape[0] | ||
|
||
ctx.save() | ||
ctx.set_source_surface (surface, x, y) | ||
ctx.set_source_surface(surface, float(x), float(y)) | ||
if gc.get_alpha() != 1.0: | ||
ctx.paint_with_alpha(gc.get_alpha()) | ||
else: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sigh... did we seriously have this private member documented in our examples? That kinda sends mixed messages to our users, doesn't it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it does. Not much we can do except stop doing that going forward. On the up side, the experimental method is also completely redundant to the more flexible and consistent-with-everything-else transforms infrastructure, so this isn't a regression in terms of available functionality.