-
Notifications
You must be signed in to change notification settings - Fork 44
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
Accept a PIL Image as input to draw_image() #590
Conversation
d5c00cc
to
eab208f
Compare
|
One thing to be careful about - I think Enable uses the agg backend for rendering backbuffers no matter what the Kiva library being used is and then (I suspect) uses This is the relevant code, I think: Lines 766 to 805 in 8bc13b1
Edit: we might be OK - it looks like it tries to create a backbuffer of the same GC type. |
The |
@@ -54,8 +54,7 @@ def _image_default(self): | |||
if components == 4: | |||
img[:, :, 3] = np.linspace(0, 255, num=512*512).reshape(512, 512) | |||
|
|||
pilimg = Image.fromarray(img).convert(mode) | |||
return np.array(pilimg) |
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.
As discussed in #589
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.
The code changes make sense to me and IIUC, the code is implicitly tested. The code definitely looks cleaner - and mostly the same between the various kiva backends.
Not sure if adding unittests make the code easier to understand.
def copy_padded(array): | ||
""" Pad image width to a multiple of 4 pixels, and minimum dims of | ||
12x12. QImage is very particular about its data. | ||
""" | ||
y, x, d = array.shape | ||
pad = (lambda v: (4 - (v % 4)) % 4) | ||
nx = max(x + pad(x), 12) | ||
ny = max(y, 12) | ||
if x == nx and y == ny: | ||
return array | ||
ret = np.zeros((ny, nx, d), dtype=np.uint8) | ||
ret[:y, :x] = array[:] | ||
return ret |
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.
Just to confirm, we don't need to copy and pad the array data - because the use of PIL.Image.Image
means that this is implicitly handled. Correct?
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.
We do, but PIL handles it for us now via PIL.ImageQt.ImageQt
@corranwebster Do you have any more feedback or questions? |
d168b64
to
899c703
Compare
I think I'm good with this. |
Thanks for the feedback |
This adds
Image
from the Python Imaging Library as an acceptable argument fordraw_image
on all relevant kiva backends. Further, it usesImage
internally to handle conversion of color modes to something which is compatible with the color mode of the graphics context.Fixes #574