Fix non-square video-emoji.

This commit is contained in:
John Preston 2022-07-08 10:45:01 +04:00
parent 11fbc8112f
commit 4127b68675
1 changed files with 26 additions and 3 deletions

View File

@ -168,9 +168,13 @@ EmojiGenerator::Frame EmojiGenerator::Impl::renderCurrent(
if (!scaled.isEmpty() && rotationSwapWidthHeight()) {
scaled.transpose();
}
if (!GoodStorageForFrame(storage, scaled)) {
storage = CreateFrameStorage(scaled);
if (!GoodStorageForFrame(storage, size)) {
storage = CreateFrameStorage(size);
}
const auto dx = (size.width() - scaled.width()) / 2;
const auto dy = (size.height() - scaled.height()) / 2;
Assert(dx >= 0 && dy >= 0 && (!dx || !dy));
const auto srcFormat = (frame->format == AV_PIX_FMT_NONE)
? _codec->pix_fmt
: frame->format;
@ -180,7 +184,7 @@ EmojiGenerator::Frame EmojiGenerator::Impl::renderCurrent(
const auto bgra = (srcFormat == AV_PIX_FMT_BGRA);
const auto withAlpha = bgra || (srcFormat == AV_PIX_FMT_YUVA420P);
const auto dstPerLine = storage.bytesPerLine();
auto dst = storage.bits();
auto dst = storage.bits() + dx * sizeof(int32) + dy * dstPerLine;
if (srcSize == dstSize && bgra) {
const auto srcPerLine = frame->linesize[0];
const auto perLine = std::min(srcPerLine, dstPerLine);
@ -211,6 +215,25 @@ EmojiGenerator::Frame EmojiGenerator::Impl::renderCurrent(
dstData,
dstLinesize);
}
if (dx && size.height() > 0) {
auto dst = storage.bits();
const auto line = scaled.width() * sizeof(int32);
memset(dst, 0, dx * sizeof(int32));
dst += dx * sizeof(int32);
for (auto y = 0; y != size.height() - 1; ++y) {
memset(dst + line, 0, (dstPerLine - line));
dst += dstPerLine;
}
dst += line;
memset(dst, 0, (size.width() - scaled.width() - dx) * sizeof(int32));
} else if (dy && size.width() > 0) {
const auto dst = storage.bits();
memset(dst, 0, dstPerLine * dy);
memset(
dst + dstPerLine * (dy + scaled.height()),
0,
dstPerLine * (size.height() - scaled.height() - dy));
}
if (withAlpha) {
PremultiplyInplace(storage);
}