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

Image::data() uses bp_size to return a slice. #11

Open
GuillaumeSchmid opened this issue Nov 9, 2023 · 4 comments
Open

Image::data() uses bp_size to return a slice. #11

GuillaumeSchmid opened this issue Nov 9, 2023 · 4 comments

Comments

@GuillaumeSchmid
Copy link
Contributor

I had a strange bug with my camera: image.data() returns an empty slice. I set the camera in unsafe mode.

If I understood correctly, In unsafe mode, bp_size is 0. This value is used by data to return an empty slice.

The data() function uses the following code to build the slice:
let length = self.xi_img.bp_size as usize / size_of::();
I think it would not work in the case of padding as well.

The type of T is u8. If the image is in RGB24, for instance, the calculation is wrong.

I suggest the implementation of a data_unsafe() that would take in template argument the XI image type (XI_RGB24), and deduce the buffer size from width and height. It would work only for buffers with no padding.

In the streamViewer c++ example, there is an example of how to extract the data according to the pixel type.

@GuillaumeSchmid
Copy link
Contributor Author

The image struct could have a pixel_type.
The data function would use this to infer the bytes per pixel and return
the right slice size if bp_size = 0.

@GuillaumeSchmid
Copy link
Contributor Author

Would it be a proper way to handle this problem?
I will try to implement it and test it in my app. Then do a PR draft.

1 similar comment
@GuillaumeSchmid
Copy link
Contributor Author

Would it be a proper way to handle this problem?
I will try to implement it and test it in my app. Then do a PR draft.

@superbort
Copy link
Contributor

PR #12 fixes the issue.

However, under normal circumstances this problem should not appear. "bp_size" should be the correct size of the buffer, even in unsafe mode.

I could not reproduce the 0 in bp_size. Can you please let me know what you did to get this behavior? It is most likely a bug in the C API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants