Skip to content

Commit

Permalink
gltfpack: Move round functions slightly higher in the file
Browse files Browse the repository at this point in the history
This makes sure we can use them from Basisu encoder, since we're moving
a lot of things around in this change anyway this will help subsequent
changes.
  • Loading branch information
zeux committed Jun 7, 2021
1 parent 293187a commit ffe1db8
Showing 1 changed file with 25 additions and 25 deletions.
50 changes: 25 additions & 25 deletions gltf/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,31 @@ static bool getDimensions(const std::string& data, const char* mime_type, int& w
return false;
}

static int roundPow2(int value)
{
int result = 1;

while (result < value)
result <<= 1;

// to prevent odd texture sizes from increasing the size too much, we round to nearest power of 2 above a certain size
if (value > 128 && result * 3 / 4 > value)
result >>= 1;

return result;
}

static int roundBlock(int value, bool pow2)
{
if (value == 0)
return 4;

if (pow2 && value > 4)
return roundPow2(value);

return (value + 3) & ~3;
}

#ifdef __wasi__
static int execute(const char* cmd, bool ignore_stdout, bool ignore_stderr)
{
Expand Down Expand Up @@ -383,31 +408,6 @@ bool checkKtx(bool verbose)
return rc == 0;
}

static int roundPow2(int value)
{
int result = 1;

while (result < value)
result <<= 1;

// to prevent odd texture sizes from increasing the size too much, we round to nearest power of 2 above a certain size
if (value > 128 && result * 3 / 4 > value)
result >>= 1;

return result;
}

static int roundBlock(int value, bool pow2)
{
if (value == 0)
return 4;

if (pow2 && value > 4)
return roundPow2(value);

return (value + 3) & ~3;
}

bool encodeKtx(const std::string& data, const char* mime_type, std::string& result, const ImageInfo& info, const Settings& settings)
{
int width = 0, height = 0;
Expand Down

0 comments on commit ffe1db8

Please sign in to comment.