diff options
Diffstat (limited to 'Build/source/libs/xpdf/xpdf-src/splash/SplashBitmap.cc')
-rw-r--r-- | Build/source/libs/xpdf/xpdf-src/splash/SplashBitmap.cc | 51 |
1 files changed, 41 insertions, 10 deletions
diff --git a/Build/source/libs/xpdf/xpdf-src/splash/SplashBitmap.cc b/Build/source/libs/xpdf/xpdf-src/splash/SplashBitmap.cc index aa916179df3..88ce49ca3b4 100644 --- a/Build/source/libs/xpdf/xpdf-src/splash/SplashBitmap.cc +++ b/Build/source/libs/xpdf/xpdf-src/splash/SplashBitmap.cc @@ -25,7 +25,7 @@ SplashBitmap::SplashBitmap(int widthA, int heightA, int rowPad, SplashColorMode modeA, GBool alphaA, - GBool topDown) { + GBool topDown, SplashBitmap *parentA) { // NB: this code checks that rowSize fits in a signed 32-bit // integer, because some code (outside this class) makes that // assumption @@ -63,14 +63,35 @@ SplashBitmap::SplashBitmap(int widthA, int heightA, int rowPad, } rowSize += rowPad - 1; rowSize -= rowSize % rowPad; - data = (SplashColorPtr)gmallocn64(height, rowSize); + + parent = parentA; + oldData = NULL; + oldAlpha = NULL; + oldRowSize = 0; + oldAlphaRowSize = 0; + oldHeight = 0; + if (parent && parent->oldData && + parent->oldRowSize == rowSize && + parent->oldHeight == height) { + data = parent->oldData; + parent->oldData = NULL; + } else { + data = (SplashColorPtr)gmallocn64(height, rowSize); + } if (!topDown) { data += (height - 1) * rowSize; rowSize = -rowSize; } if (alphaA) { alphaRowSize = width; - alpha = (Guchar *)gmallocn64(height, alphaRowSize); + if (parent && parent->oldAlpha && + parent->oldAlphaRowSize == alphaRowSize && + parent->oldHeight == height) { + alpha = parent->oldAlpha; + parent->oldAlpha = NULL; + } else { + alpha = (Guchar *)gmallocn64(height, alphaRowSize); + } } else { alphaRowSize = 0; alpha = NULL; @@ -78,14 +99,24 @@ SplashBitmap::SplashBitmap(int widthA, int heightA, int rowPad, } SplashBitmap::~SplashBitmap() { - if (data) { - if (rowSize < 0) { - gfree(data + (height - 1) * rowSize); - } else { - gfree(data); - } + if (data && rowSize < 0) { + rowSize = -rowSize; + data -= (height - 1) * rowSize; + } + if (parent && rowSize > 10000000 / height) { + gfree(parent->oldData); + gfree(parent->oldAlpha); + parent->oldData = data; + parent->oldAlpha = alpha; + parent->oldRowSize = rowSize; + parent->oldAlphaRowSize = alphaRowSize; + parent->oldHeight = height; + } else { + gfree(data); + gfree(alpha); } - gfree(alpha); + gfree(oldData); + gfree(oldAlpha); } SplashError SplashBitmap::writePNMFile(char *fileName) { |