JBIG2 - text region segment

This commit is contained in:
Jakub Melka
2019-11-01 16:47:30 +01:00
parent ca78f61260
commit fc6985e35a
3 changed files with 535 additions and 99 deletions

View File

@ -320,6 +320,34 @@ unsigned char* convertByteArrayToUcharPtr(QByteArray& data)
return reinterpret_cast<unsigned char*>(data.data());
}
/// This function computes ceil of log base 2 of value. The algorithm is taken
/// from: http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogDeBruijn.
/// License for this function is public domain.
inline constexpr uint8_t log2ceil(uint32_t value)
{
constexpr uint8_t MULTIPLY_DE_BRUIJN_BIT_POSITION[32] =
{
0, 9, 1, 10, 13, 21, 2, 29, 11, 14, 16, 18, 22, 25, 3, 30,
8, 12, 20, 28, 15, 17, 24, 7, 19, 27, 23, 6, 26, 5, 4, 31
};
value |= value >> 1;
value |= value >> 2;
value |= value >> 4;
value |= value >> 8;
value |= value >> 16;
uint8_t logarithm = MULTIPLY_DE_BRUIJN_BIT_POSITION[static_cast<uint32_t>((value * 0x07C4ACDDU) >> 27)];
// Ceil
if ((1U << logarithm) < value)
{
++logarithm;
}
return logarithm;
}
} // namespace pdf
#endif // PDFUTILS_H