Fix lottie caching.

This commit is contained in:
John Preston 2019-07-01 14:38:19 +02:00
parent 37689affc5
commit ead212f31b
2 changed files with 15 additions and 0 deletions

View File

@ -517,6 +517,8 @@ bool Cache::renderFrame(
_framesReady = 0;
_data = QByteArray();
return false;
} else if (index + 1 == _framesReady && _data.size() > _offset) {
_data.resize(_offset);
}
if (xored) {
Xor(_previous, _uncompressed);
@ -576,6 +578,8 @@ void Cache::finalizeEncoding() {
if (_data.isEmpty()) {
_data.reserve(size);
writeHeader();
} else {
updateFramesReadyCount();
}
const auto offset = _data.size();
_data.resize(size);
@ -609,6 +613,16 @@ void Cache::writeHeader() {
<< qint32(_framesReady);
}
void Cache::updateFramesReadyCount() {
Expects(_data.size() >= headerSize());
const auto serialized = qint32(_framesReady);
const auto offset = headerSize() - sizeof(qint32);
bytes::copy(
bytes::make_detached_span(_data).subspan(offset),
bytes::object_as_span(&serialized));
}
void Cache::prepareBuffers() {
// 12 bit per pixel in YUV420P.
const auto bytesPerLine = _size.width();

View File

@ -101,6 +101,7 @@ private:
void finalizeEncoding();
void writeHeader();
void updateFramesReadyCount();
[[nodiscard]] bool readHeader(const FrameRequest &request);
[[nodiscard]] ReadResult readCompressedFrame();