Skip to content
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

Add ability to read bytes from objc.varlist #205

Closed
ronaldoussoren opened this issue Sep 12, 2017 · 5 comments
Closed

Add ability to read bytes from objc.varlist #205

ronaldoussoren opened this issue Sep 12, 2017 · 5 comments
Labels
enhancement New feature or request

Comments

@ronaldoussoren
Copy link
Owner

Original report by Nickolas Pohilets (Bitbucket: nickolas_pohilets, ).


Use case: CGBitmapContextGetData returns a pointer to raw data, several MBs in size. I would like to pass it to NumPy for further processing. Currently, it gets converted into a tuple of millions of single-byte objects.

A simple solution would be adding a method def as_bytes(self, count: int) -> bytes.

Another alternative is to implement Buffer Protocol

@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


Adding as_bytes would be useful, and I'll look into this. I guess as_memoryview would be more useful because this could avoid copying data.

Implementing the buffer protocol is not possible, this requires knowing the size of the buffer and that's something a varlist object doesn't do.

@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


I'm adding method as_buffer(self, count: int) that returns a writable memory view object that refers to the same memory as the varlist object (for the first count elements of the list).

This makes it possible to directly write to the underlying memory through the buffer, just like you can write to that memory through the item setter of the varlist object. The user is responsible for checking if the memory is writable by checking the API documentation.

@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


Add objc.varlist.as_buffer

This fixes #205

@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


This will be in PyObjC 4.0, which will be released around High Sierra's release (if I read Apple's website correct High Sierra is released sept. 25, with the current state of the 10.13 branch that means PyObjC should be released sometime next week)

@ronaldoussoren
Copy link
Owner Author

Original comment by Ronald Oussoren (Bitbucket: ronaldoussoren, GitHub: ronaldoussoren).


Removing version: 3.1 (automated comment)

@ronaldoussoren ronaldoussoren added major enhancement New feature or request labels Feb 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant