include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "pdf.h"
void main() {
pdf_error_t *error = NULL;
pdf_char_t* buf = "\100\101\102"
"\120\120\120";
pdf_size_t buflen = strlen(buf);
pdf_stm_t* stm = pdf_stm_mem_new(buf, buflen, 0, PDF_STM_READ, &error);
pdf_hash_t* hash = pdf_hash_new(&error);
pdf_hash_add_size(hash, "Predictor", 11, &error);
pdf_hash_add_size(hash, "BitsPerComponent", 8, &error);
pdf_hash_add_size(hash, "Colors", 3, &error);
pdf_hash_add_size(hash, "Columns", 1, &error);
pdf_stm_install_filter(stm, PDF_STM_FILTER_PRED_ENC, hash, &error);
pdf_char_t outbuf[100];
pdf_size_t read_bytes;
pdf_stm_read(stm, outbuf, sizeof(outbuf), &read_bytes, &error);
fprintf(stdout, "read bytes: %ld", read_bytes);
/* dump the output buffer */
for (int i = 0; i < read_bytes; i++) {
char* fmt = i%4 ? " %d" : "\n[%d]";
fprintf(stdout, fmt, (int) outbuf[i]);
}
fprintf(stdout, "\n");
if (error) {
fprintf(stderr, "error: %s", pdf_error_get_message(error));
exit(1);
}
exit(0);
}
This program is encoding with the PNG 'sub' filter (/Predictor 11).
Before applying the patch it produces
[11] 64 1 1
[11] 80 0 0
After applying this patch:
[1] 64 1 1
[1] 80 0 0
I'm hoping that someone on the mailing list has time to dust-off gnupdf and look at the attached patch.
Feedback welcome.
Regards,
David