| 1 |
|
| 2 |
#include <stdio.h> |
| 3 |
//#include "ppapi.h" |
| 4 |
#include "pplib.h" |
| 5 |
#include "assert.h" |
| 6 |
|
| 7 |
static int usage (const char *argv0) |
| 8 |
{ |
| 9 |
printf("pplib " pplib_version ", " pplib_author "\n"); |
| 10 |
printf("usage: %s file1.pdf file2.pdf ...\n", argv0); |
| 11 |
return 0; |
| 12 |
} |
| 13 |
|
| 14 |
static void print_result_filter (ppstream *stream, int decode) |
| 15 |
{ |
| 16 |
ppstream_filter info; |
| 17 |
size_t i; |
| 18 |
|
| 19 |
ppstream_filter_info(stream, &info, decode); |
| 20 |
printf(" when %s: /Filter [", decode ? "uncompressed" : "compressed"); |
| 21 |
for (i = 0; i < info.count; ++i) |
| 22 |
printf(" /%s", ppstream_filter_name[info.filters[i]]); |
| 23 |
printf(" ]"); |
| 24 |
if (info.params != NULL) |
| 25 |
{ |
| 26 |
printf(" /DecodeParms ["); |
| 27 |
for (i = 0; i < info.count; ++i) |
| 28 |
printf(" %s", info.params[i] != NULL ? "<<...>>" : "null"); |
| 29 |
printf(" ]"); |
| 30 |
} |
| 31 |
printf("\n"); |
| 32 |
} |
| 33 |
|
| 34 |
static void print_stream_info (ppref *ref, ppstream *stream) |
| 35 |
{ |
| 36 |
size_t length; |
| 37 |
printf("object %lu %lu R\n", (unsigned long)ref->number, (unsigned long)ref->version); |
| 38 |
if (stream->flags & PPSTREAM_FILTER) |
| 39 |
printf(" filtered "); |
| 40 |
else |
| 41 |
printf(" plain "); |
| 42 |
if (stream->flags & PPSTREAM_IMAGE) |
| 43 |
printf("image "); |
| 44 |
else |
| 45 |
printf("stream "); |
| 46 |
if (stream->flags & PPSTREAM_ENCRYPTED) |
| 47 |
printf("encrypted "); |
| 48 |
if (stream->flags & PPSTREAM_NOT_SUPPORTED) |
| 49 |
printf("invalid "); |
| 50 |
if (!ppdict_rget_uint(stream->dict, "Length", &length)) |
| 51 |
length = 0; |
| 52 |
assert(stream->length == length); |
| 53 |
printf("length %lu (/Length %lu)\n", (unsigned long)stream->length, (unsigned long)length); |
| 54 |
print_result_filter(stream, 0); |
| 55 |
print_result_filter(stream, 1); |
| 56 |
} |
| 57 |
|
| 58 |
static void check_stream_chunks (ppstream *stream) |
| 59 |
{ |
| 60 |
size_t sum, size; |
| 61 |
uint8_t *data; |
| 62 |
const int decode[2] = {0, 1}; |
| 63 |
int d; |
| 64 |
|
| 65 |
for (d = 0; d < 2; ++d) |
| 66 |
{ |
| 67 |
for (sum = 0, data = ppstream_first(stream, &size, decode[d]); data != NULL; data = ppstream_next(stream, &size)) |
| 68 |
sum += size; |
| 69 |
ppstream_done(stream); |
| 70 |
ppstream_all(stream, &size, decode[d]); |
| 71 |
ppstream_done(stream); |
| 72 |
assert(sum == size); |
| 73 |
printf(" %s chunks size [%lu]\n", (decode[d] ? "decoded" : "raw"), (unsigned long)size); |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
#define USE_BUFFERS_POOL 1 |
| 78 |
|
| 79 |
int main (int argc, const char **argv) |
| 80 |
{ |
| 81 |
const char *filepath; |
| 82 |
int a; |
| 83 |
ppdoc *pdf; |
| 84 |
ppxref *xref; |
| 85 |
ppxsec *xsec; |
| 86 |
size_t xi; |
| 87 |
ppuint refnum; |
| 88 |
ppref *ref; |
| 89 |
|
| 90 |
if (argc < 2) |
| 91 |
return usage(argv[0]); |
| 92 |
if (USE_BUFFERS_POOL) |
| 93 |
ppstream_init_buffers(); |
| 94 |
for (a = 1; a < argc; ++a) |
| 95 |
{ |
| 96 |
filepath = argv[a]; |
| 97 |
printf("loading %s... ", filepath); |
| 98 |
pdf = ppdoc_load(filepath); |
| 99 |
if (pdf == NULL) |
| 100 |
{ |
| 101 |
printf("failed\n"); |
| 102 |
continue; |
| 103 |
} |
| 104 |
printf("done.\n"); |
| 105 |
for (xref = ppdoc_xref(pdf); xref != NULL; xref = ppxref_prev(xref)) |
| 106 |
{ |
| 107 |
for (xi = 0, xsec = xref->sects; xi < xref->size; ++xi, ++xsec) |
| 108 |
{ |
| 109 |
for (refnum = xsec->first, ref = xsec->refs; refnum <= xsec->last; ++refnum, ++ref) |
| 110 |
{ |
| 111 |
if (ref->object.type != PPSTREAM) |
| 112 |
continue; |
| 113 |
print_stream_info(ref, ref->object.stream); |
| 114 |
check_stream_chunks(ref->object.stream); |
| 115 |
} |
| 116 |
} |
| 117 |
} |
| 118 |
ppdoc_free(pdf); |
| 119 |
} |
| 120 |
if (USE_BUFFERS_POOL) |
| 121 |
ppstream_free_buffers(); |
| 122 |
return 0; |
| 123 |
} |