Replace the alignment test by a nice function

This commit is contained in:
samcake 2017-05-12 18:25:07 -07:00
parent d734358290
commit f35b0297fa
3 changed files with 7 additions and 3 deletions

View file

@ -22,6 +22,9 @@ uint32_t Header::evalPadding(size_t byteSize) {
return (uint32_t) (3 - (byteSize + 3) % PACKING_SIZE);// padding ? PACKING_SIZE - padding : 0);
}
bool Header::checkAlignment(size_t byteSize) {
return ((byteSize & 0x3) == 0);
}
const Header::Identifier ktx::Header::IDENTIFIER {{
0xAB, 0x4B, 0x54, 0x58, 0x20, 0x31, 0x31, 0xBB, 0x0D, 0x0A, 0x1A, 0x0A
@ -114,7 +117,7 @@ size_t Header::evalFaceSize(uint32_t level) const {
}
size_t Header::evalImageSize(uint32_t level) const {
auto faceSize = evalFaceSize(level);
if ((faceSize < 4) || ((faceSize & 0x3) != 0)) {
if (!checkAlignment(faceSize)) {
return 0;
}
if (numberOfFaces == NUM_CUBEMAPFACES && numberOfArrayElements == 0) {
@ -142,7 +145,7 @@ ImageDescriptors Header::generateImageDescriptors() const {
size_t imageOffset = 0;
for (uint32_t level = 0; level < numberOfMipmapLevels; ++level) {
auto imageSize = static_cast<uint32_t>(evalImageSize(level));
if ((imageSize < 4) || ((imageSize & 0x3) != 0)) {
if (!checkAlignment(imageSize)) {
return ImageDescriptors();
}
if (imageSize == 0) {

View file

@ -309,6 +309,7 @@ namespace ktx {
static const uint32_t REVERSE_ENDIAN_TEST = 0x01020304;
static uint32_t evalPadding(size_t byteSize);
static bool checkAlignment(size_t byteSize);
Header();

View file

@ -151,7 +151,7 @@ namespace ktx {
auto expectedImageSize = header.evalImageSize(images.size());
if (imageSize != expectedImageSize) {
break;
} else if ((imageSize < 4) || (imageSize & 0x3)) {
} else if (!Header::checkAlignment(imageSize)) {
break;
}