-
-
Notifications
You must be signed in to change notification settings - Fork 153
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
PR: Add utility function to get raw bytes from QImages (compat.py) #355
base: master
Are you sure you want to change the base?
Conversation
Thanks @zjp ! Then this is comming from ChimeraX source code, right? Is there any licensing we should know about? If that is the case I would say that the license should be compatible with MIT (the license we use here) and we should add a note in the function pointing out from where the function is comming from. Besides that adding a tests for this could be nice too :) Maybe @CAM-Gerlach and/or @ccordoba12 have more elements to have in mind. |
There's an equivalent function but it needed adaptation to your project. There's no licensing concerns on your end -- my goal is to upstream this code and remove it from ChimeraX. I'll add tests! |
@zjp, this has a conflict with master now. |
When I get a chance I'll rebase thanks for letting me know! |
If @zjp is the author or otherwise holds the copyright, then by submitting it here they are agreeing to license it under QtPy's license, presuming that corporate contracts don't get in the way. Otherwise, there could theoretically be an issue, but while IANAL and this is not legal advice, the code is probably too short/simple to be covered by copyright protection as an independent work.
Looking forward to it! |
3b15bd9
to
b467e4d
Compare
Thanks @zjp for giving this an update! Just in case, seems like the failing checks are related with coverallsapp/github-action#205 |
I still need to add a test for this function. Do you think it's better to add a small image to the repository, to fetch an image from the internet in the test, or to do a secret third thing? |
Maybe we could create a from qtpy.QtCore import QRectF, QSize, Qt
from qtpy.QtGui import QBrush, QImage, QPainter
image = QImage(QSize(100, 100), QImage.Format_RGB32)
painter = QPainter(image)
painter.setBrush(QBrush(Qt.black))
painter.fillRect(QRectF(0, 0, 100, 100), Qt.black)
image.save("black.png") What do you think ? Also pinging @ccordoba12 just in case for more ideas |
I like it, I think it's a good idea. |
Sounds good to me. |
I've added the test. It seemed sensible to me to test the length of the byte array, but if you immediately think of a better condition let me know. |
I was trying to fill in the color of the QImage in the test the wrong way, which led to a segfault (though curiously not on a couple platforms). Anyway, I think the QImage doesn't need to be filled in at all. A byte representing color will be the same length whether it's (1,1,1,1) or (0,0,0,0). |
We use this utility function in ChimeraX to grab the raw content of a QImage to pass to our renderer. I'm hoping it will be useful to other users as well, and I'm open to feedback about how to make that possible.