Skip to content

feat(jpeg): add thumbnail functionality to jpeg reader#5333

Open
antond-weta wants to merge 2 commits into
AcademySoftwareFoundation:mainfrom
antond-weta:jpeg_thumbnail
Open

feat(jpeg): add thumbnail functionality to jpeg reader#5333
antond-weta wants to merge 2 commits into
AcademySoftwareFoundation:mainfrom
antond-weta:jpeg_thumbnail

Conversation

@antond-weta

Copy link
Copy Markdown
Contributor

Description

This adds the thumbnail functionality to the jpeg reader by implementing get_thumbnail().

Tests

I could not find any unit tests related to get_thumbnail(), so I implemented a test in python-thumbnail-jpeg. The test is done in python because we don't expose the thumbnails in oiiotool. The test is pretty basic, it just checks the thumbnail dimensions for now. Happy to add more unit tests if needed.

I am also going to submit another PR soon fixing the thumbnails in raw reader, that will add python-thumbnail-raw, hence the test name.

Checklist:

  • I have read the guidelines on contributions and code review procedures.
  • I have read the Policy on AI Coding Assistants
    and if I used AI coding assistants, I have an Assisted-by: TOOL / MODEL
    line in the pull request description above.
  • I have updated the documentation if my PR adds features or changes
    behavior.
  • I am sure that this PR's changes are tested in the testsuite.
  • I have run and passed the testsuite in CI before submitting the
    PR, by pushing the changes to my fork and seeing that the automated CI
    passed there. (Exceptions: If most tests pass and you can't figure out why
    the remaining ones fail, it's ok to submit the PR and ask for help. Or if
    any failures seem entirely unrelated to your change; sometimes things break
    on the GitHub runners.)
  • My code follows the prevailing code style of this project and I
    fixed any problems reported by the clang-format CI test.
  • If I added or modified a public C++ API call, I have also amended the
    corresponding Python bindings. If altering ImageBufAlgo functions, I also
    exposed the new functionality as oiiotool options.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 23, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: antond-weta / name: Anton Dukhovnikov (b3a4c2b)

@antond-weta
antond-weta marked this pull request as draft July 23, 2026 20:58
Co-authored-by: Ken McGaugh <ken@mcgaugh.co.uk>
Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz>
void
JpgInput::scan_for_thumbnail(cspan<uint8_t> exif)
{
try {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This code performs a basic scan for the subimage tag in the exif, it doesn't check if the found bit pattern is not a part of any other exif data. We may want to move this functionality to exif.cpp, but that may affect any other readers relying on exif.

return false;
}

image_input->close();

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Without this I was getting address sanitiser errors in the image_input's destructor. I couldn't understand the error, and don't really think that it is related to the change.

}

bool
JpgInput::get_thumbnail(ImageBuf& thumb, int subimage)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The get_thumbnail() methods in the TGA input and ImageBuf contain lock guards. Does this method need to be thread safe?

@antond-weta
antond-weta marked this pull request as ready for review July 23, 2026 21:22
@lgritz lgritz changed the title add thumbnail functionality to jpeg reader feat(jpeg): add thumbnail functionality to jpeg reader Jul 27, 2026
Comment thread src/jpeg.imageio/jpeginput.cpp
Comment on lines +909 to +913
if (!result) {
errorfmt(
"failed to initialise an ImageInput object with the thumbnail data");
return false;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that if get_thumbnail, it's sufficient to just return false. But if you really want to return an error message, what you should be returning is image_input->geterror().

Comment on lines +920 to +925
if (!result) {
errorfmt(
"failed to initialise an ImageInput object of type \"jpeg\" with the thumbnail data");
image_input->close();
return false;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Here, too. Either just return false with no error, or do

errorfmt("{}", image_input->geterror());

Comment on lines +872 to +874
} catch (const std::exception& e) {
errorfmt("ERROR scanning for thumbnail: {}", e.what());
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why the try/catch here? Is there anything called inside that will actually throw an exception?

JpgInput::get_thumbnail(ImageBuf& thumb, int subimage)
{
if (!m_decomp_create) {
errorfmt("ImageInput hasn't been initialised properly");

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I truly hate to pick on this, but in this code base we try to uniformly use the American spelling conventions: "initialized"

Co-authored-by: Larry Gritz <lg@larrygritz.com>
Signed-off-by: Anton Dukhovnikov <antond@wetafx.co.nz>
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