diff options
Diffstat (limited to 'libtests/png_filter.cc')
-rw-r--r-- | libtests/png_filter.cc | 80 |
1 files changed, 0 insertions, 80 deletions
diff --git a/libtests/png_filter.cc b/libtests/png_filter.cc deleted file mode 100644 index 7494cb7a..00000000 --- a/libtests/png_filter.cc +++ /dev/null @@ -1,80 +0,0 @@ -#include <qpdf/Pl_PNGFilter.hh> -#include <qpdf/Pl_StdioFile.hh> -#include <qpdf/QUtil.hh> - -#include <iostream> -#include <errno.h> -#include <assert.h> -#include <string.h> -#include <stdlib.h> - -void run(char const* filename, bool encode, unsigned int columns, - int bits_per_sample, int samples_per_pixel) -{ - // Decode the file - FILE* in = QUtil::safe_fopen(filename, "rb"); - FILE* o1 = QUtil::safe_fopen("out", "wb"); - Pipeline* out = new Pl_StdioFile("out", o1); - Pipeline* pl = new Pl_PNGFilter( - "png", out, - encode ? Pl_PNGFilter::a_encode : Pl_PNGFilter::a_decode, - columns, samples_per_pixel, bits_per_sample); - assert((2 * (columns + 1)) < 1024); - unsigned char buf[1024]; - size_t len; - while (true) - { - len = fread(buf, 1, (2 * columns) + 1, in); - if (len == 0) - { - break; - } - pl->write(buf, len); - len = fread(buf, 1, 1, in); - if (len == 0) - { - break; - } - pl->write(buf, len); - len = fread(buf, 1, 1, in); - if (len == 0) - { - break; - } - pl->write(buf, len); - } - - pl->finish(); - delete pl; - delete out; - fclose(o1); - fclose(in); - - std::cout << "done" << std::endl; -} - -int main(int argc, char* argv[]) -{ - if (argc != 6) - { - std::cerr << "Usage: png_filter {en,de}code filename" - << " columns samples-per-pixel bits-per-sample" - << std::endl; - exit(2); - } - bool encode = (strcmp(argv[1], "encode") == 0); - char* filename = argv[2]; - int columns = QUtil::string_to_int(argv[3]); - int samples_per_pixel = QUtil::string_to_int(argv[4]); - int bits_per_sample = QUtil::string_to_int(argv[5]); - - try - { - run(filename, encode, columns, bits_per_sample, samples_per_pixel); - } - catch (std::exception& e) - { - std::cout << e.what() << std::endl; - } - return 0; -} |