-
Notifications
You must be signed in to change notification settings - Fork 45
Fix save() in the quartz backend #645
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
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 |
|---|---|---|
|
|
@@ -186,17 +186,23 @@ def assertImageSavedWithContent(self, filename): | |
| """ Load the image and check that there is some content in it. | ||
| """ | ||
| image = numpy.array(Image.open(filename)) | ||
| # default is expected to be a totally white image | ||
| # Default is expected to be a totally white image. | ||
| # Therefore we check if the whole image is not white. | ||
|
|
||
| # Previously this method checked for red pixels. However this is | ||
| # not [currently] possible with the quartz backend because it writes | ||
| # out image with premultiplied alpha and none of its pixels are the | ||
|
Contributor
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. This is from the
Member
Author
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. It is not. The premultiplied alpha setting happens in the
Member
Author
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. So there are a few constraints here:
We can definitely implement saving RGB/BGR images, but it's a question of time allocation.
Contributor
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. I see, thank you! |
||
| # exact red expected here. | ||
|
|
||
| self.assertEqual(image.shape[:2], (600, 600)) | ||
| if image.shape[2] == 3: | ||
| check = numpy.sum(image == [255, 0, 0], axis=2) == 3 | ||
| check = numpy.sum(image == [255, 255, 255]) != (600 * 600 * 3) | ||
| elif image.shape[2] == 4: | ||
| check = numpy.sum(image == [255, 0, 0, 255], axis=2) == 4 | ||
| check = numpy.sum(image == [255, 255, 255, 255]) != (600 * 600 * 4) | ||
| else: | ||
| self.fail( | ||
| "Pixel size is not 3 or 4, but {0}".format(image.shape[2]) | ||
| ) | ||
| if check.any(): | ||
| if check: | ||
| return | ||
| self.fail("The image looks empty, no red pixels were drawn") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # (C) Copyright 2005-2021 Enthought, Inc., Austin, TX | ||
| # All rights reserved. | ||
| # | ||
| # This software is provided without warranty under the terms of the BSD | ||
| # license included in LICENSE.txt and may be redistributed only under | ||
| # the conditions described in the aforementioned license. The license | ||
| # is also available online at http://www.enthought.com/licenses/BSD.txt | ||
| # | ||
| # Thanks for using Enthought open source! | ||
| import sys | ||
| import unittest | ||
|
|
||
| from kiva.tests.drawing_tester import DrawingImageTester | ||
|
|
||
| is_not_macos = not sys.platform == "darwin" | ||
|
|
||
|
|
||
| @unittest.skipIf(is_not_macos, "Not macOS") | ||
| class TestQuartzDrawing(DrawingImageTester, unittest.TestCase): | ||
| def create_graphics_context(self, width, height, pixel_scale): | ||
| from kiva.quartz import ABCGI | ||
|
|
||
| return ABCGI.CGBitmapContext((width, height)) |
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.
@aaronayres35 A bit more detail for future readers 😉