diff options
author | Taco Hoekwater <taco@elvenkind.com> | 2011-04-12 14:17:47 +0000 |
---|---|---|
committer | Taco Hoekwater <taco@elvenkind.com> | 2011-04-12 14:17:47 +0000 |
commit | 307453997ef030ec4dfa1e876feaf0b8b8125bab (patch) | |
tree | ab2054693ba95e9ac8f6e3478b4d0175d893329f /Build/source/libs/poppler/poppler-0.12.4/goo/PNGWriter.cc | |
parent | d95b11a25d3d9e17cc4afb9c8713ef4037567527 (diff) |
check in luatex 0.66.0
git-svn-id: svn://tug.org/texlive/trunk@22059 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/libs/poppler/poppler-0.12.4/goo/PNGWriter.cc')
-rw-r--r-- | Build/source/libs/poppler/poppler-0.12.4/goo/PNGWriter.cc | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/Build/source/libs/poppler/poppler-0.12.4/goo/PNGWriter.cc b/Build/source/libs/poppler/poppler-0.12.4/goo/PNGWriter.cc new file mode 100644 index 00000000000..864c976bc2b --- /dev/null +++ b/Build/source/libs/poppler/poppler-0.12.4/goo/PNGWriter.cc @@ -0,0 +1,110 @@ +//======================================================================== +// +// PNGWriter.cc +// +// This file is licensed under the GPLv2 or later +// +// Copyright (C) 2009 Warren Toomey <wkt@tuhs.org> +// Copyright (C) 2009 Shen Liang <shenzhuxi@gmail.com> +// Copyright (C) 2009 Albert Astals Cid <aacid@kde.org> +// +//======================================================================== + +#include "PNGWriter.h" + +#ifdef ENABLE_LIBPNG + +#include "poppler/Error.h" + +PNGWriter::PNGWriter() +{ +} + +PNGWriter::~PNGWriter() +{ + /* cleanup heap allocation */ + png_destroy_write_struct(&png_ptr, &info_ptr); +} + +bool PNGWriter::init(FILE *f, int width, int height) +{ + /* initialize stuff */ + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (!png_ptr) { + error(-1, "png_create_write_struct failed"); + return false; + } + + info_ptr = png_create_info_struct(png_ptr); + if (!info_ptr) { + error(-1, "png_create_info_struct failed"); + return false; + } + + if (setjmp(png_jmpbuf(png_ptr))) { + error(-1, "png_jmpbuf failed"); + return false; + } + + /* write header */ + png_init_io(png_ptr, f); + if (setjmp(png_jmpbuf(png_ptr))) { + error(-1, "Error during writing header"); + return false; + } + + // Set up the type of PNG image and the compression level + png_set_compression_level(png_ptr, Z_BEST_COMPRESSION); + + png_byte bit_depth = 8; + png_byte color_type = PNG_COLOR_TYPE_RGB; + png_byte interlace_type = PNG_INTERLACE_NONE; + + png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth, color_type, interlace_type, PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT); + + png_write_info(png_ptr, info_ptr); + if (setjmp(png_jmpbuf(png_ptr))) { + error(-1, "error during writing png info bytes"); + return false; + } + + return true; +} + +bool PNGWriter::writePointers(png_bytep *rowPointers) +{ + png_write_image(png_ptr, rowPointers); + /* write bytes */ + if (setjmp(png_jmpbuf(png_ptr))) { + error(-1, "Error during writing bytes"); + return false; + } + + return true; +} + +bool PNGWriter::writeRow(png_bytep *row) +{ + // Write the row to the file + png_write_rows(png_ptr, row, 1); + if (setjmp(png_jmpbuf(png_ptr))) { + error(-1, "error during png row write"); + return false; + } + + return true; +} + +bool PNGWriter::close() +{ + /* end write */ + png_write_end(png_ptr, info_ptr); + if (setjmp(png_jmpbuf(png_ptr))) { + error(-1, "Error during end of write"); + return false; + } + + return true; +} + +#endif |