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

Micropython jpegdec::get_width()/get_height() will always return 0 #894

Closed
Skyler84 opened this issue Jan 12, 2024 · 3 comments
Closed

Micropython jpegdec::get_width()/get_height() will always return 0 #894

Skyler84 opened this issue Jan 12, 2024 · 3 comments
Labels
[- pico graphics library -] bug Something isn't working

Comments

@Skyler84
Copy link
Contributor

Due to the // Just-in-time open of the filename/buffer, get_width and get_height will always return 0 as the jpeg is never actually loaded when these functions are called. This means the user cannot check the size of the jpeg and change the x/y/scale when decoding it based on the size.

This should probably be fixed by loading the jpeg at the time of calling open_file() or open_RAM(), which would also want a close() function.

@Gadgetoid
Copy link
Member

You're right- PNGDEC rectifies this (and avoids the need for close) by opening the file to grab the width/height and store it on the Python object instance-

mp_obj_t _PNG_openFILE(mp_obj_t self_in, mp_obj_t filename) {
_PNG_obj_t *self = MP_OBJ_TO_PTR2(self_in, _PNG_obj_t);
// TODO Check for valid filename, and maybe that file exists?
self->file = filename;
pngdec_open_helper(self);
self->width = self->png->getWidth();
self->height = self->png->getHeight();
self->png->close();
return mp_const_true;
}
// open_RAM
mp_obj_t _PNG_openRAM(mp_obj_t self_in, mp_obj_t buffer) {
_PNG_obj_t *self = MP_OBJ_TO_PTR2(self_in, _PNG_obj_t);
// TODO Check for valid buffer
self->file = buffer;
pngdec_open_helper(self);
self->width = self->png->getWidth();
self->height = self->png->getHeight();
self->png->close();
return mp_const_true;
}

This pattern was never backported to JPEGDEC, but probably should be.

@Skyler84
Copy link
Contributor Author

I've changed #895 to backport the PNGDEC fix, adding width/height to the _JPEG_obj_t and setting those on open(), creating a helper function jpegdec_open_helper(self) and using that in the open functions and decode. I've also reverted my previous changes so it's just the backport (the MP close() binding is removed etc)

@Skyler84
Copy link
Contributor Author

Skyler84 commented Mar 1, 2024

fixed by #899

@Skyler84 Skyler84 closed this as completed Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[- pico graphics library -] bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants