aboutsummaryrefslogtreecommitdiffstats
path: root/libtests/predictors.cc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2018-01-13 20:32:39 +0100
committerJay Berkenbilt <ejb@ql.org>2018-01-14 01:49:42 +0100
commitbf2fb239d7a39255fe122db50dd5d03f9baa25ae (patch)
treec72455d3976deb3fae772ce9c3b6f2dc8ab5fb33 /libtests/predictors.cc
parent661ed1d28ef03bc61739e4998b8d60005f1f2ee3 (diff)
downloadqpdf-bf2fb239d7a39255fe122db50dd5d03f9baa25ae.tar.zst
Rename png_filter -> predictors
Diffstat (limited to 'libtests/predictors.cc')
-rw-r--r--libtests/predictors.cc91
1 files changed, 91 insertions, 0 deletions
diff --git a/libtests/predictors.cc b/libtests/predictors.cc
new file mode 100644
index 00000000..fe2b90f4
--- /dev/null
+++ b/libtests/predictors.cc
@@ -0,0 +1,91 @@
+#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, char const* filter,
+ bool encode, unsigned int columns,
+ int bits_per_sample, int samples_per_pixel)
+{
+ FILE* in = QUtil::safe_fopen(filename, "rb");
+ FILE* o1 = QUtil::safe_fopen("out", "wb");
+ Pipeline* out = new Pl_StdioFile("out", o1);
+ Pipeline* pl = 0;
+ if (strcmp(filter, "png") == 0)
+ {
+ pl = new Pl_PNGFilter(
+ "png", out,
+ encode ? Pl_PNGFilter::a_encode : Pl_PNGFilter::a_decode,
+ columns, samples_per_pixel, bits_per_sample);
+ }
+ else
+ {
+ std::cerr << "unknown filter " << filter << std::endl;
+ exit(2);
+ }
+ 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 != 7)
+ {
+ std::cerr << "Usage: predictor {png|tiff} {en,de}code filename"
+ << " columns samples-per-pixel bits-per-sample"
+ << std::endl;
+ exit(2);
+ }
+ char* filter = argv[1];
+ bool encode = (strcmp(argv[2], "encode") == 0);
+ char* filename = argv[3];
+ int columns = QUtil::string_to_int(argv[4]);
+ int samples_per_pixel = QUtil::string_to_int(argv[5]);
+ int bits_per_sample = QUtil::string_to_int(argv[6]);
+
+ try
+ {
+ run(filename, filter, encode,
+ columns, bits_per_sample, samples_per_pixel);
+ }
+ catch (std::exception& e)
+ {
+ std::cout << e.what() << std::endl;
+ }
+ return 0;
+}