blob: a207aa9a2a633f201b8bfc74f6a542b31e3079e0 [file] [log] [blame]
#include "src/utils/block_parameters_holder.h"
#include <algorithm>
#include "src/utils/common.h"
#include "src/utils/constants.h"
#include "src/utils/logging.h"
#include "src/utils/parameter_tree.h"
#include "src/utils/types.h"
namespace libgav1 {
namespace {
// Returns the number of super block rows/columns for |value4x4| where value4x4
// is either rows4x4 or column4x4.
int RowsOrColumns4x4ToSuperBlocks(int value4x4, bool use_128x128_superblock) {
return use_128x128_superblock ? DivideBy128(MultiplyBy4(value4x4) + 127)
: DivideBy64(MultiplyBy4(value4x4) + 63);
}
} // namespace
BlockParametersHolder::BlockParametersHolder(int rows4x4, int columns4x4,
bool use_128x128_superblock)
: rows4x4_(rows4x4),
columns4x4_(columns4x4),
use_128x128_superblock_(use_128x128_superblock) {}
bool BlockParametersHolder::Init() {
if (!block_parameters_cache_.Reset(rows4x4_, columns4x4_)) {
LIBGAV1_DLOG(ERROR, "block_parameters_cache_.Reset() failed.");
return false;
}
const int rows =
RowsOrColumns4x4ToSuperBlocks(rows4x4_, use_128x128_superblock_);
const int columns =
RowsOrColumns4x4ToSuperBlocks(columns4x4_, use_128x128_superblock_);
const BlockSize sb_size =
use_128x128_superblock_ ? kBlock128x128 : kBlock64x64;
const int multiplier = kNum4x4BlocksWide[sb_size];
if (!trees_.Reset(rows, columns)) {
LIBGAV1_DLOG(ERROR, "trees_.Reset() failed.");
return false;
}
for (int i = 0; i < rows; ++i) {
for (int j = 0; j < columns; ++j) {
trees_[i][j] =
ParameterTree::Create(i * multiplier, j * multiplier, sb_size);
if (trees_[i][j] == nullptr) {
LIBGAV1_DLOG(ERROR, "Allocation of trees_[%d][%d] failed.", i, j);
return false;
}
}
}
return true;
}
void BlockParametersHolder::FillCache(int row4x4, int column4x4,
BlockSize block_size,
BlockParameters* const bp) {
const int row4x4_end =
std::min(row4x4 + kNum4x4BlocksHigh[block_size], rows4x4_);
const int column4x4_end =
std::min(column4x4 + kNum4x4BlocksWide[block_size], columns4x4_);
for (int y = row4x4; y < row4x4_end; ++y) {
for (int x = column4x4; x < column4x4_end; ++x) {
block_parameters_cache_[y][x] = bp;
}
}
}
} // namespace libgav1