------------------------------------------------------------------------------
| 1515 | |
| 1516 | //------------------------------------------------------------------------------ |
| 1517 | void vtkFreeTypeTools::PrepareImageData(vtkImageData* data, int textBbox[4]) |
| 1518 | { |
| 1519 | // Calculate the bbox's dimensions |
| 1520 | int textDims[2]; |
| 1521 | textDims[0] = (textBbox[1] - textBbox[0] + 1); |
| 1522 | textDims[1] = (textBbox[3] - textBbox[2] + 1); |
| 1523 | |
| 1524 | // Calculate the size the image needs to be. |
| 1525 | int targetDims[3]; |
| 1526 | targetDims[0] = textDims[0]; |
| 1527 | targetDims[1] = textDims[1]; |
| 1528 | targetDims[2] = 1; |
| 1529 | // Scale to the next highest power of 2 if required. |
| 1530 | if (this->ScaleToPowerTwo) |
| 1531 | { |
| 1532 | targetDims[0] = vtkMath::NearestPowerOfTwo(targetDims[0]); |
| 1533 | targetDims[1] = vtkMath::NearestPowerOfTwo(targetDims[1]); |
| 1534 | } |
| 1535 | |
| 1536 | // Calculate the target extent of the image. |
| 1537 | int targetExtent[6]; |
| 1538 | targetExtent[0] = textBbox[0]; |
| 1539 | targetExtent[1] = textBbox[0] + targetDims[0] - 1; |
| 1540 | targetExtent[2] = textBbox[2]; |
| 1541 | targetExtent[3] = textBbox[2] + targetDims[1] - 1; |
| 1542 | targetExtent[4] = 0; |
| 1543 | targetExtent[5] = 0; |
| 1544 | |
| 1545 | // Get the actual image extents and increments |
| 1546 | int imageExtent[6]; |
| 1547 | double imageSpacing[3]; |
| 1548 | data->GetExtent(imageExtent); |
| 1549 | data->GetSpacing(imageSpacing); |
| 1550 | |
| 1551 | // Do we need to reallocate the image memory? |
| 1552 | if (data->GetScalarType() != VTK_UNSIGNED_CHAR || data->GetNumberOfScalarComponents() != 4 || |
| 1553 | imageExtent[0] != targetExtent[0] || imageExtent[1] != targetExtent[1] || |
| 1554 | imageExtent[2] != targetExtent[2] || imageExtent[3] != targetExtent[3] || |
| 1555 | imageExtent[4] != targetExtent[4] || imageExtent[5] != targetExtent[5] || |
| 1556 | fabs(imageSpacing[0] - 1.0) > 1e-10 || fabs(imageSpacing[1] - 1.0) > 1e-10 || |
| 1557 | fabs(imageSpacing[2] - 1.0) > 1e-10) |
| 1558 | { |
| 1559 | data->SetSpacing(1.0, 1.0, 1.0); |
| 1560 | data->SetExtent(targetExtent); |
| 1561 | data->AllocateScalars(VTK_UNSIGNED_CHAR, 4); |
| 1562 | } |
| 1563 | |
| 1564 | // Clear the image buffer |
| 1565 | memset(data->GetScalarPointer(), this->DebugTextures ? 64 : 0, |
| 1566 | (data->GetNumberOfPoints() * data->GetNumberOfScalarComponents())); |
| 1567 | } |
| 1568 | |
| 1569 | VTK_ABI_NAMESPACE_END |
| 1570 | // Helper functions for rasterizing the background/frame quad: |
no test coverage detected