33#include < algorithm>
44#include < cstring>
55#include < unordered_map>
6+ #include < utility>
67
78#ifdef SOURCEPP_BUILD_WITH_THREADS
89#include < future>
@@ -949,7 +950,7 @@ void VTF::regenerateImageData(ImageFormat newFormat, uint16_t newWidth, uint16_t
949950 this ->setResourceInternal (Resource::TYPE_IMAGE_DATA, newImageData);
950951}
951952
952- std::vector<std::byte> VTF::getParticleSheetFrameRaw (uint16_t & spriteWidth, uint16_t & spriteHeight, uint32_t shtSequenceID, uint32_t shtFrame, uint8_t shtBounds, uint8_t mip, uint16_t frame, uint8_t face, uint16_t slice) const {
953+ std::vector<std::byte> VTF::getParticleSheetFrameDataRaw (uint16_t & spriteWidth, uint16_t & spriteHeight, uint32_t shtSequenceID, uint32_t shtFrame, uint8_t shtBounds, uint8_t mip, uint16_t frame, uint8_t face, uint16_t slice) const {
953954 spriteWidth = 0 ;
954955 spriteHeight = 0 ;
955956
@@ -969,28 +970,34 @@ std::vector<std::byte> VTF::getParticleSheetFrameRaw(uint16_t& spriteWidth, uint
969970 // This will also break if any of the bounds are above 1 or below 0, but that
970971 // hasn't been observed in official textures
971972 const auto & bounds = sequence->frames [shtFrame].bounds [shtBounds];
972- uint16_t left = std::floor (bounds.left * static_cast <float >(this ->getWidth (mip)));
973- uint16_t bottom = std::ceil (bounds.bottom * static_cast <float >(this ->getHeight (mip)));
974- uint16_t right = std::ceil (bounds.right * static_cast <float >(this ->getWidth (mip)));
975- uint16_t top = std::floor (bounds.top * static_cast <float >(this ->getHeight (mip)));
973+ uint16_t x1 = std::clamp< uint16_t >( std:: floor (bounds.x1 * static_cast <float >(this ->getWidth (mip))), 0 , this -> getWidth (mip ));
974+ uint16_t y1 = std::clamp< uint16_t >( std:: ceil ( bounds.y1 * static_cast <float >(this ->getHeight (mip))), 0 , this -> getHeight (mip ));
975+ uint16_t x2 = std::clamp< uint16_t >( std:: ceil ( bounds.x2 * static_cast <float >(this ->getWidth (mip))), 0 , this -> getHeight (mip ));
976+ uint16_t y2 = std::clamp< uint16_t >( std:: floor (bounds.y2 * static_cast <float >(this ->getHeight (mip))), 0 , this -> getWidth (mip ));
976977
977- spriteWidth = (right - left);
978- spriteHeight = (bottom - top);
978+ if (x1 > x2) [[unlikely]] {
979+ std::swap (x1, x2);
980+ }
981+ if (y1 > y2) [[unlikely]] {
982+ std::swap (y1, y2);
983+ }
984+ spriteWidth = x2 - x1;
985+ spriteWidth = y2 - y1;
979986
980- const auto out = ImageConversion::cropImageData (this ->getImageDataRaw (mip, frame, face, slice), this ->getFormat (), this ->getWidth (mip), spriteWidth, left , this ->getHeight (mip), spriteHeight, top );
987+ const auto out = ImageConversion::cropImageData (this ->getImageDataRaw (mip, frame, face, slice), this ->getFormat (), this ->getWidth (mip), spriteWidth, x1 , this ->getHeight (mip), spriteHeight, y1 );
981988 if (out.empty ()) {
982989 spriteWidth = 0 ;
983990 spriteHeight = 0 ;
984991 }
985992 return out;
986993}
987994
988- std::vector<std::byte> VTF::getParticleSheetFrameAs (ImageFormat newFormat, uint16_t & spriteWidth, uint16_t & spriteHeight, uint32_t shtSequenceID, uint32_t shtFrame, uint8_t shtBounds, uint8_t mip, uint16_t frame, uint8_t face, uint16_t slice) const {
989- return ImageConversion::convertImageDataToFormat (this ->getParticleSheetFrameRaw (spriteWidth, spriteHeight, shtSequenceID, shtFrame, shtBounds, mip, frame, face, slice), this ->getFormat (), newFormat, spriteWidth, spriteHeight);
995+ std::vector<std::byte> VTF::getParticleSheetFrameDataAs (ImageFormat newFormat, uint16_t & spriteWidth, uint16_t & spriteHeight, uint32_t shtSequenceID, uint32_t shtFrame, uint8_t shtBounds, uint8_t mip, uint16_t frame, uint8_t face, uint16_t slice) const {
996+ return ImageConversion::convertImageDataToFormat (this ->getParticleSheetFrameDataRaw (spriteWidth, spriteHeight, shtSequenceID, shtFrame, shtBounds, mip, frame, face, slice), this ->getFormat (), newFormat, spriteWidth, spriteHeight);
990997}
991998
992- std::vector<std::byte> VTF::getParticleSheetFrameAsRGBA8888 (uint16_t & spriteWidth, uint16_t & spriteHeight, uint32_t shtSequenceID, uint32_t shtFrame, uint8_t shtBounds, uint8_t mip, uint16_t frame, uint8_t face, uint16_t slice) const {
993- return this ->getParticleSheetFrameAs (ImageFormat::RGBA8888, spriteWidth, spriteHeight, shtSequenceID, shtFrame, shtBounds, mip, frame, face, slice);
999+ std::vector<std::byte> VTF::getParticleSheetFrameDataAsRGBA8888 (uint16_t & spriteWidth, uint16_t & spriteHeight, uint32_t shtSequenceID, uint32_t shtFrame, uint8_t shtBounds, uint8_t mip, uint16_t frame, uint8_t face, uint16_t slice) const {
1000+ return this ->getParticleSheetFrameDataAs (ImageFormat::RGBA8888, spriteWidth, spriteHeight, shtSequenceID, shtFrame, shtBounds, mip, frame, face, slice);
9941001}
9951002
9961003void VTF::setParticleSheetResource (const SHT& value) {
0 commit comments