Browse Source

Trade: fix moving between compressed and uncompressed ImageData.

I mean, yeah, it's all bad, but at least it works now. The upcoming
internal representation will not be this silly CompressedPixelStorage
anymore and then it will become a bit less bad.

For a proper language-lawyer-safe implementation I'd explicitly call
destructors and then in-place-new the other instance and such, but
that's two more branches and thus twice as many chances to mess up.
pull/651/merge
Vladimír Vondruš 1 year ago
parent
commit
ad309d3d0f
  1. 10
      src/Magnum/Trade/ImageData.cpp

10
src/Magnum/Trade/ImageData.cpp

@ -119,11 +119,15 @@ template<UnsignedInt dimensions> ImageData<dimensions>& ImageData<dimensions>::o
swap(_dataFlags, other._dataFlags); swap(_dataFlags, other._dataFlags);
swap(_compressed, other._compressed); swap(_compressed, other._compressed);
swap(_flags, other._flags); swap(_flags, other._flags);
if(_compressed) { /* Because the CompressedPixelStorage is larger than the
uncompressed, copy it if either of the sides is compressed to ensure no
compressed properties are lost. The _storage / _compressedStorage and
_format / _compressedFormat are unions of trivially copyable contents so
copying a type that's not there should be fine. */
if(_compressed || other._compressed) {
swap(_compressedStorage, other._compressedStorage); swap(_compressedStorage, other._compressedStorage);
swap(_compressedFormat, other._compressedFormat); swap(_compressedFormat, other._compressedFormat);
} } else {
else {
swap(_storage, other._storage); swap(_storage, other._storage);
swap(_format, other._format); swap(_format, other._format);
} }

Loading…
Cancel
Save