splash/SplashBitmap.cc | 47 ++++++++++++++++++++++++++++++----------------- splash/SplashBitmap.h | 6 ++++++ 2 files changed, 36 insertions(+), 17 deletions(-)
New commits: commit ab9dea663a4df5af8f54c1ff5149254adfd72ce9 Author: Albert Astals Cid <[email protected]> Date: Wed Aug 31 20:34:17 2011 +0200 xpdf303: Add SplashBitmap::writeAlphaPGMFile and SplashBitmap::takeData diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc index 18ce62c..ab5176e 100644 --- a/splash/SplashBitmap.cc +++ b/splash/SplashBitmap.cc @@ -217,6 +217,20 @@ SplashError SplashBitmap::writePNMFile(FILE *f) { return splashOk; } +SplashError SplashBitmap::writeAlphaPGMFile(char *fileName) { + FILE *f; + + if (!alpha) { + return splashErrModeMismatch; + } + if (!(f = fopen(fileName, "wb"))) { + return splashErrOpenFile; + } + fprintf(f, "P5\n%d %d\n255\n", width, height); + fwrite(alpha, 1, width * height, f); + fclose(f); + return splashOk; +} void SplashBitmap::getPixel(int x, int y, SplashColorPtr pixel) { SplashColorPtr p; @@ -268,6 +282,14 @@ Guchar SplashBitmap::getAlpha(int x, int y) { return alpha[y * width + x]; } +SplashColorPtr SplashBitmap::takeData() { + SplashColorPtr data2; + + data2 = data; + data = NULL; + return data2; +} + SplashError SplashBitmap::writeImgFile(SplashImageFileFormat format, char *fileName, int hDPI, int vDPI, const char *compressionString) { FILE *f; SplashError e; diff --git a/splash/SplashBitmap.h b/splash/SplashBitmap.h index 3336507..8bcc941 100644 --- a/splash/SplashBitmap.h +++ b/splash/SplashBitmap.h @@ -65,6 +65,7 @@ public: SplashError writePNMFile(char *fileName); SplashError writePNMFile(FILE *f); + SplashError writeAlphaPGMFile(char *fileName); SplashError writeImgFile(SplashImageFileFormat format, char *fileName, int hDPI, int vDPI, const char *compressionString = ""); SplashError writeImgFile(SplashImageFileFormat format, FILE *f, int hDPI, int vDPI, const char *compressionString = ""); @@ -74,6 +75,11 @@ public: void getRGBLine(int y, SplashColorPtr line); Guchar getAlpha(int x, int y); + // Caller takes ownership of the bitmap data. The SplashBitmap + // object is no longer valid -- the next call should be to the + // destructor. + SplashColorPtr takeData(); + private: int width, height; // size of bitmap commit 6558d735c65a3dca9b9e16de5588c8b8c482f04f Author: Albert Astals Cid <[email protected]> Date: Wed Aug 31 20:30:27 2011 +0200 xpdf303: Write faster diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc index 4f9168c..18ce62c 100644 --- a/splash/SplashBitmap.cc +++ b/splash/SplashBitmap.cc @@ -161,11 +161,7 @@ SplashError SplashBitmap::writePNMFile(FILE *f) { fprintf(f, "P5\n%d %d\n255\n", width, height); row = data; for (y = 0; y < height; ++y) { - p = row; - for (x = 0; x < width; ++x) { - fputc(*p, f); - ++p; - } + fwrite(row, 1, width, f); row += rowSize; } break; @@ -174,13 +170,7 @@ SplashError SplashBitmap::writePNMFile(FILE *f) { fprintf(f, "P6\n%d %d\n255\n", width, height); row = data; for (y = 0; y < height; ++y) { - p = row; - for (x = 0; x < width; ++x) { - fputc(splashRGB8R(p), f); - fputc(splashRGB8G(p), f); - fputc(splashRGB8B(p), f); - p += 3; - } + fwrite(row, 1, 3 * width, f); row += rowSize; } break; commit a9b26d9c35fccc7b46a96acdb2064a9976bd49bd Author: Albert Astals Cid <[email protected]> Date: Wed Aug 31 20:29:58 2011 +0200 xpdf303: Only free data if there is data to free diff --git a/splash/SplashBitmap.cc b/splash/SplashBitmap.cc index 8d30c7e..4f9168c 100644 --- a/splash/SplashBitmap.cc +++ b/splash/SplashBitmap.cc @@ -111,12 +111,13 @@ SplashBitmap::SplashBitmap(int widthA, int heightA, int rowPadA, } } - SplashBitmap::~SplashBitmap() { - if (rowSize < 0) { - gfree(data + (height - 1) * rowSize); - } else { - gfree(data); + if (data) { + if (rowSize < 0) { + gfree(data + (height - 1) * rowSize); + } else { + gfree(data); + } } gfree(alpha); } _______________________________________________ poppler mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/poppler
