Commit 40fe9ec0 authored by David C. Lonie's avatar David C. Lonie
Browse files

Replace the power-of-two scaling with a clearer implementation.

This implementation is easier to read and performed using only integer
operations.

Change-Id: I97ea7e73e6bbaba14b7dc29d26e1db55e57136e4
parent 41e61435
......@@ -1270,16 +1270,19 @@ void vtkFreeTypeTools::PrepareImageData(vtkImageData *data, int textBbox[4])
textDims[1] = (textBbox[3] - textBbox[2] + 1);
// Calculate the size the image needs to be.
// Scale to the next highest power of 2 if required.
int targetDims[3];
// Scale to the next highest power of 2 if required.
if (this->ScaleToPowerTwo)
{
targetDims[0] =
1 << static_cast<int>(ceil(log(static_cast<double>(textDims[0]+1)) /
log(2.0)));
targetDims[1] =
1 << static_cast<int>(ceil(log(static_cast<double>(textDims[1]+1)) /
log(2.0)));
targetDims[0] = targetDims[1] = 1;
while (targetDims[0] < textDims[0])
{
targetDims[0] *= 2;
}
while (targetDims[1] < textDims[1])
{
targetDims[1] *= 2;
}
}
else
{
......
......@@ -576,12 +576,15 @@ bool vtkMatplotlibMathTextUtilities::PrepareImageData(vtkImageData *data,
// Scale to the next highest power of 2 if required.
if (this->ScaleToPowerOfTwo)
{
newImgDims[0] =
1 << static_cast<int>(ceil(log(static_cast<double>(width+1)) /
log(2.0)));
newImgDims[1] =
1 << static_cast<int>(ceil(log(static_cast<double>(height+1)) /
log(2.0)));
newImgDims[0] = newImgDims[1] = 1;
while (newImgDims[0] < width)
{
newImgDims[0] *= 2;
}
while (newImgDims[1] < height)
{
newImgDims[1] *= 2;
}
}
else
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment