Skip to content

Add support for QOI image format#3554

Merged
eXpl0it3r merged 9 commits into
SFML:masterfrom
raineycat:feature/qoi-image-support
Aug 27, 2025
Merged

Add support for QOI image format#3554
eXpl0it3r merged 9 commits into
SFML:masterfrom
raineycat:feature/qoi-image-support

Conversation

@raineycat

Copy link
Copy Markdown
Contributor

Description

This PR implements the image part of #2969. The sf::Image class can now read and write .qoi files, and test cases have been aded for this.

I used the reference implementation, since it was only a single header and fairly easy to implement.

Before trying to load using stb_image, the code just checks the first four bytes of the data it was given, if they match the QOI magic number it will continue trying to load it as a QOI image, otherwise it just falls back to STB.

Tasks

  • Tested on Linux
  • Tested on Windows
  • Tested on macOS
  • Tested on iOS
  • Tested on Android

@raineycat raineycat marked this pull request as ready for review August 19, 2025 00:57
@Bambo-Borris

Copy link
Copy Markdown
Contributor

The reference implementation is a reasonable choice, but there are alternative implementations available (some offering much faster performance). The reference one is just that, a reference for others who want to implement the format. Is there any reason we shouldn't consider one of the alternative implementations here?

@eXpl0it3r

Copy link
Copy Markdown
Member

Do you have an alternative implementation in mind? The ones listed in the official repo that would fit the C/C++ requirement are either C++20 or targeted at embedded applications or WIP.

Most promising would be qoixx, but it‘s C++20.

@Bambo-Borris

Copy link
Copy Markdown
Contributor

Do you have an alternative implementation in mind? The ones listed in the official repo that would fit the C/C++ requirement are either C++20 or targeted at embedded applications or WIP.

Most promising would be qoixx, but it‘s C++20.

Ah, I didn't spot the C++20 requirement. That's a bit of a bummer, but maybe the reference implementation would suffice until v4 when the bump to C++20 happens for SFML.

@raineycat

raineycat commented Aug 19, 2025

Copy link
Copy Markdown
Contributor Author

Ah, I didn't spot the C++20 requirement. That's a bit of a bummer, but maybe the reference implementation would suffice until v4 when the bump to C++20 happens for SFML.

Yeah, I think this sounds reasonable.

I'm not sure why the analyzers are still failing, I added a comment to suppress the no-malloc warning in the wrapper struct, and that suppresses the clang-tidy warning in my IDE at least.

Also, I'm not sure what to do about the formatter, as it keeps trying to put the qoi header in the middle of the STL headers, even with a line break in between, which seems to go against the recommended style.

@raineycat

Copy link
Copy Markdown
Contributor Author

Okay, I think I accidentally removed the comment to supress that warning, I was sure I added it in the last commit.

@ChrisThrasher

ChrisThrasher commented Aug 19, 2025

Copy link
Copy Markdown
Member

Also, I'm not sure what to do about the formatter

The correct fix here is to reconfigure the formatter by adding this header to the list of 3rd party headers here in the .clang-format file. This will ensure it gets put in its own section of #include statements separate from standard library headers.

Regex: '^<(glad|gl|X11|jni|android|stb_|GLES2|vorbis|miniaudio|catch2)'

@raineycat

Copy link
Copy Markdown
Contributor Author

Our code formatting style is defined by what the formatter outputs so just do whatever it says.

Ah, I was referencing the style guidelines on the website, which state that dependency headers should always come before standard llibrary ones. I think it was unhappy because I didn't have them in alphabetical order, in that commit I ran the formatter again and it accepted it.

Comment thread src/SFML/Graphics/Image.cpp Outdated
@eXpl0it3r eXpl0it3r changed the title Feature/qoi image support Add support for QOI image format Aug 20, 2025
Comment thread extlibs/headers/qoi/qoi.h
Comment thread src/SFML/Graphics/Image.cpp Outdated
Comment thread src/SFML/Graphics/Image.cpp Outdated
Comment thread src/SFML/Graphics/Image.cpp
Comment thread src/SFML/Graphics/Image.cpp Outdated
@eXpl0it3r

Copy link
Copy Markdown
Member

Also note, I've rebased your PR to include the latest build fixes from master. You'll have to resync your local version with your GitHub repo

@github-project-automation github-project-automation Bot moved this to Planned in SFML 3.1.0 Aug 20, 2025
@eXpl0it3r eXpl0it3r added this to the 3.1 milestone Aug 20, 2025
@eXpl0it3r eXpl0it3r moved this from Planned to Needs Work in SFML 3.1.0 Aug 20, 2025
@raineycat raineycat requested a review from eXpl0it3r August 21, 2025 08:47
@eXpl0it3r eXpl0it3r moved this from Needs Work to In Review in SFML 3.1.0 Aug 21, 2025

@eXpl0it3r eXpl0it3r left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will have to give this a try, but code looks good to me.

Comment thread src/SFML/Graphics/Image.cpp Outdated
@eXpl0it3r

eXpl0it3r commented Aug 25, 2025

Copy link
Copy Markdown
Member

Rebased onto master and resolved the merge conflict and

@eXpl0it3r

Copy link
Copy Markdown
Member

Test images render correctly

image

@eXpl0it3r eXpl0it3r merged commit df84825 into SFML:master Aug 27, 2025
108 checks passed
@github-project-automation github-project-automation Bot moved this from In Review to Done in SFML 3.1.0 Aug 27, 2025
@eXpl0it3r

Copy link
Copy Markdown
Member

Thank you for implementing this! 🥳

@vittorioromeo

Copy link
Copy Markdown
Member

Thank you @raineycat! <3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants