diff options
author | Sebastian Rasmussen <sebras@hotmail.com> | 2010-06-05 17:34:54 +0200 |
---|---|---|
committer | Sebastian Rasmussen <sebras@hotmail.com> | 2010-06-05 17:34:54 +0200 |
commit | ff007e9e3b22219ae2d5ce3518ef8060d28d1371 (patch) | |
tree | 4bee34c1d808d2e2c026dea2f3ead809e44e73c4 | |
parent | 79234cad2c965341dca69da99f64430aed793178 (diff) | |
download | mupdf-ff007e9e3b22219ae2d5ce3518ef8060d28d1371.tar.xz |
Add debug printing for functions.
-rw-r--r-- | mupdf/pdf_function.c | 216 |
1 files changed, 216 insertions, 0 deletions
diff --git a/mupdf/pdf_function.c b/mupdf/pdf_function.c index 6e0a44e8..d112afae 100644 --- a/mupdf/pdf_function.c +++ b/mupdf/pdf_function.c @@ -1554,3 +1554,219 @@ pdf_evalfunction(pdf_function *func, float *in, int inlen, float *out, int outle return fz_okay; } +void +pdf_debugindent(char *prefix, int level, char *suffix) +{ + int i; + + printf("%s", prefix); + + for (i = 0; i < level; i++) + printf(" "); + + printf("%s", suffix); +} + + +void +pdf_debugpsfunccode(psobj *funccode, psobj *code, int level) +{ + int eof, wasop; + + pdf_debugindent("", level, "{"); + + /* Print empty blocks as { }, instead of separating braces on different lines. */ + if (code->type == PSOPERATOR && code->u.op == PSORETURN) + { + printf(" } "); + return; + } + + pdf_debugindent("\n", ++level, ""); + + eof = 0; + wasop = 0; + while (!eof) + { + switch (code->type) + { + case PSINT: + if (wasop) + pdf_debugindent("\n", level, ""); + + printf("%d ", code->u.i); + wasop = 0; + code++; + break; + + case PSREAL: + if (wasop) + pdf_debugindent("\n", level, ""); + + printf("%g ", code->u.f); + wasop = 0; + code++; + break; + + case PSOPERATOR: + if (code->u.op == PSORETURN) + { + printf("\n"); + eof = 1; + } + else if (code->u.op == PSOIF) + { + printf("\n"); + pdf_debugpsfunccode(funccode, &funccode[(code + 2)->u.block], level); + + printf("%s", psopnames[code->u.op]); + code = &funccode[(code + 3)->u.block]; + if (code->type != PSOPERATOR || code->u.op != PSORETURN) + pdf_debugindent("\n", level, ""); + + wasop = 0; + } + else if (code->u.op == PSOIFELSE) + { + printf("\n"); + pdf_debugpsfunccode(funccode, &funccode[(code + 2)->u.block], level); + + printf("\n"); + pdf_debugpsfunccode(funccode, &funccode[(code + 1)->u.block], level); + + printf("%s", psopnames[code->u.op]); + code = &funccode[(code + 3)->u.block]; + if (code->type != PSOPERATOR || code->u.op != PSORETURN) + pdf_debugindent("\n", level, ""); + + wasop = 0; + } + else + { + printf("%s ", psopnames[code->u.op]); + code++; + wasop = 1; + } + break; + } + } + + pdf_debugindent("", --level, "} "); +} + +void +pdf_debugfunctionimp(pdf_function *func, int level) +{ + int i; + + pdf_debugindent("", level, "function {\n"); + + pdf_debugindent("", ++level, ""); + switch (func->type) + { + case SAMPLE: + printf("sampled"); + break; + case EXPONENTIAL: + printf("exponential"); + break; + case STITCHING: + printf("stitching"); + break; + case POSTSCRIPT: + printf("postscript"); + break; + } + + pdf_debugindent("\n", level, ""); + printf("%d input -> %d output\n", func->m, func->n); + + pdf_debugindent("", level, "domain "); + for (i = 0; i < func->m; i++) + printf("%g %g ", func->domain[i][0], func->domain[i][1]); + printf("\n"); + + if (func->hasrange) + { + pdf_debugindent("", level, "range "); + for (i = 0; i < func->n; i++) + printf("%g %g ", func->range[i][0], func->range[i][1]); + printf("\n"); + } + + switch (func->type) + { + case SAMPLE: + pdf_debugindent("", level, ""); + printf("bps: %d\n", func->u.sa.bps); + + pdf_debugindent("", level, ""); + printf("size: [ "); + for (i = 0; i < func->m; i++) + printf("%d ", func->u.sa.size[i]); + printf("]\n"); + + pdf_debugindent("", level, ""); + printf("encode: [ "); + for (i = 0; i < func->m; i++) + printf("%g %g ", func->u.sa.encode[i][0], func->u.sa.encode[i][1]); + printf("]\n"); + + pdf_debugindent("", level, ""); + printf("decode: [ "); + for (i = 0; i < func->m; i++) + printf("%g %g ", func->u.sa.decode[i][0], func->u.sa.decode[i][1]); + printf("]\n"); + break; + + case EXPONENTIAL: + pdf_debugindent("", level, ""); + printf("n: %g\n", func->u.e.n); + + pdf_debugindent("", level, ""); + printf("c0: [ "); + for (i = 0; i < func->n; i++) + printf("%g ", func->u.e.c0[i]); + printf("]\n"); + + pdf_debugindent("", level, ""); + printf("c1: [ "); + for (i = 0; i < func->n; i++) + printf("%g ", func->u.e.c1[i]); + printf("]\n"); + break; + + case STITCHING: + pdf_debugindent("", level, ""); + printf("%d functions\n", func->u.st.k); + + pdf_debugindent("", level, ""); + printf("bounds: [ "); + for (i = 0; i < func->u.st.k - 1; i++) + printf("%g ", func->u.st.bounds[i]); + printf("]\n"); + + pdf_debugindent("", level, ""); + printf("encode: [ "); + for (i = 0; i < func->u.st.k * 2; i++) + printf("%g ", func->u.st.encode[i]); + printf("]\n"); + + for (i = 0; i < func->u.st.k; i++) + pdf_debugfunctionimp(func->u.st.funcs[i], level); + break; + + case POSTSCRIPT: + pdf_debugpsfunccode(func->u.p.code, func->u.p.code, level); + printf("\n"); + break; + } + + pdf_debugindent("", --level, "}\n"); +} + +void +pdf_debugfunction(pdf_function *func) +{ + pdf_debugfunctionimp(func, 0); +} |