mirror of
https://invent.kde.org/frameworks/kimageformats.git
synced 2026-05-28 05:39:08 -04:00
On demand buffer allocation on PCHG decompression
This commit is contained in:
committed by
Albert Astals Cid
parent
d6d67c7b8b
commit
abfda2ce69
@@ -2795,10 +2795,6 @@ static QByteArray pchgFastDecomp(const QByteArray& input, int treeSize, int orig
|
|||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
QByteArray out;
|
|
||||||
out.resize(originalSize);
|
|
||||||
char* outPtr = out.data();
|
|
||||||
|
|
||||||
// Emulate a3 pointer to words:
|
// Emulate a3 pointer to words:
|
||||||
// a2 points to the *last word* => word index (0..treeWords-1)
|
// a2 points to the *last word* => word index (0..treeWords-1)
|
||||||
auto resetA3 = [&]() {
|
auto resetA3 = [&]() {
|
||||||
@@ -2823,10 +2819,9 @@ static QByteArray pchgFastDecomp(const QByteArray& input, int treeSize, int orig
|
|||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
int produced = 0;
|
|
||||||
|
|
||||||
// Main decode loop: produce exactly originalSize bytes
|
// Main decode loop: produce exactly originalSize bytes
|
||||||
while (produced < originalSize) {
|
QByteArray out;
|
||||||
|
while (out.size() < qsizetype(originalSize)) {
|
||||||
if (bits == 0) {
|
if (bits == 0) {
|
||||||
if (!refill()) {
|
if (!refill()) {
|
||||||
// Not enough bits to complete output
|
// Not enough bits to complete output
|
||||||
@@ -2862,7 +2857,7 @@ static QByteArray pchgFastDecomp(const QByteArray& input, int treeSize, int orig
|
|||||||
a3_word = next;
|
a3_word = next;
|
||||||
} else {
|
} else {
|
||||||
// Leaf: emit low 8 bits, reset a3
|
// Leaf: emit low 8 bits, reset a3
|
||||||
outPtr[produced++] = static_cast<char>(w & 0xFF);
|
out.append(static_cast<char>(w & 0xFF));
|
||||||
a3_word = resetA3();
|
a3_word = resetA3();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -2882,7 +2877,7 @@ static QByteArray pchgFastDecomp(const QByteArray& input, int treeSize, int orig
|
|||||||
|
|
||||||
// Non-negative: check bit #8; if set -> leaf
|
// Non-negative: check bit #8; if set -> leaf
|
||||||
if ((w & 0x0100) != 0) {
|
if ((w & 0x0100) != 0) {
|
||||||
outPtr[produced++] = static_cast<char>(w & 0xFF);
|
out.append(static_cast<char>(w & 0xFF));
|
||||||
a3_word = resetA3();
|
a3_word = resetA3();
|
||||||
} else {
|
} else {
|
||||||
// Not a leaf: continue scanning
|
// Not a leaf: continue scanning
|
||||||
|
|||||||
Reference in New Issue
Block a user