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

MP jpegdec: fix width/height functions by opening file/buffer earlier #895

Closed
wants to merge 3 commits into from

Conversation

Skyler84
Copy link
Contributor

References #894
Open file/buffer in open function rather than on demand.
Also adds a close function for the user.

Open file/buffer in open function rather than on demand.
Also adds a close function for the user.
@Gadgetoid
Copy link
Member

Thank you!

I think we should probably copy the pattern from the PNG image parsing, since introducing a requirement on calling close now will no doubt break people's code in unexpected ways.

PNGDEC's bindings open the file, read out the dimensions, then close it until it's ready to be decoded:

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;
}

@Gadgetoid
Copy link
Member

Gadgetoid commented Jan 16, 2024

Sorry I totally missed that you'd updated the PR! Will look into what's making the CI unhappy.

Looks like it's self->decode_callback should just be JPEGDraw and the int result = -1 is needed at the top of _JPEG_decode

Otherwise, thank you!

having moved the opening code i'd missed the result variable getting reused later.
Copy link
Contributor Author

@Skyler84 Skyler84 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd been silly and missed an int declaration was all. should build fine now

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

Successfully merging this pull request may close these issues.

2 participants