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

BasisImporter: flip Y on import, if not done already #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/MagnumPlugins/BasisImporter/BasisImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,9 @@ Containers::Optional<ImageData2D> BasisImporter::doImage2D(UnsignedInt index) {
CORRADE_INTERNAL_ASSERT_OUTPUT(_state->transcoder->get_image_level_desc(_state->in.data(), _state->in.size(), index, level, origWidth, origHeight, totalBlocks));

/* No flags used by transcode_image_level() by default */
const std::uint32_t flags = 0;
if(!_state->fileInfo.m_y_flipped) {
/** @todo replace with the flag once the PR is submitted */
Warning{} << "Trade::BasisImporter::image2D(): the image was not encoded Y-flipped, imported data will have wrong orientation";
//flags |= basist::basisu_transcoder::cDecodeFlagsFlipY;
}
std::uint32_t flags = 0;
if(!_state->fileInfo.m_y_flipped)
flags |= basist::basisu_transcoder::cDecodeFlagsFlipY;

Vector2i size{Int(origWidth), Int(origHeight)};
UnsignedInt dataSize, rowStride, outputSizeInBlocksOrPixels, outputRowsInPixels;
Expand Down
17 changes: 0 additions & 17 deletions src/MagnumPlugins/BasisImporter/BasisImporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,23 +111,6 @@ OpenGL, OpenGL ES and WebGL extensions, in its full ugly glory:

<b></b>

@m_class{m-block m-warning}

@par Y-flipping
While all importers for uncompressed image data are doing an Y-flip on
import to have origin at the bottom (as expected by OpenGL), it's a
non-trivial operation with compressed images. In case of Basis, you can
pass a `-y_flip` flag to the `basisu` tool to Y-flip the image
* *during encoding*, however right now there's no way do so on import. To
inform the user, the importer checks for the Y-flip flag in the file and if
it's not there, prints a warning about the data having wrong orientation.
@par
To account for this on the application side for files that you don't have a
control of, flip texture coordinates of the mesh or patch texture data
loading in the shader.

<b></b>

@m_class{m-block m-success}

@thirdparty This plugin makes use of the
Expand Down
11 changes: 3 additions & 8 deletions src/MagnumPlugins/BasisImporter/Test/BasisImporterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,14 +281,8 @@ void BasisImporterTest::rgbUncompressedNoFlip() {
CORRADE_VERIFY(importer->openFile(Utility::Directory::join(BASISIMPORTER_TEST_DIR,
"rgb-noflip.basis")));

Containers::Optional<Trade::ImageData2D> image;
std::ostringstream out;
{
Warning redirectWarning{&out};
image = importer->image2D(0);
}
Containers::Optional<Trade::ImageData2D> image = importer->image2D(0);
CORRADE_VERIFY(image);
CORRADE_COMPARE(out.str(), "Trade::BasisImporter::image2D(): the image was not encoded Y-flipped, imported data will have wrong orientation\n");
CORRADE_VERIFY(!image->isCompressed());
CORRADE_COMPARE(image->format(), PixelFormat::RGBA8Unorm);
CORRADE_COMPARE(image->size(), (Vector2i{63, 27}));
Expand All @@ -298,7 +292,8 @@ void BasisImporterTest::rgbUncompressedNoFlip() {
if(_manager.loadState("PngImporter") == PluginManager::LoadState::NotFound)
CORRADE_SKIP("PngImporter plugin not found, cannot test contents");

CORRADE_COMPARE_WITH(Containers::arrayCast<Color3ub>(image->pixels<Color4ub>().flipped<0>()),
/* Flipping is done on import */
CORRADE_COMPARE_WITH(Containers::arrayCast<Color3ub>(image->pixels<Color4ub>()),
Utility::Directory::join(BASISIMPORTER_TEST_DIR, "rgb-63x27.png"),
/* There are moderately significant compression artifacts */
(DebugTools::CompareImageToFile{_manager, 49.67f, 8.326f}));
Expand Down