1 /* Copyright (C) 2001-2020 Artifex Software, Inc.
2    All Rights Reserved.
3 
4    This software is provided AS-IS with no warranty, either express or
5    implied.
6 
7    This software is distributed under license and may not be copied,
8    modified or distributed except as expressly authorized under the terms
9    of the license contained in the file LICENSE in this distribution.
10 
11    Refer to licensing information at http://www.artifex.com or contact
12    Artifex Software, Inc.,  1305 Grant Avenue - Suite 200, Novato,
13    CA 94945, U.S.A., +1(415)492-9861, for further information.
14 */
15 
16 /*
17     jbig2dec
18 */
19 
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #include "config_types.h"
23 #elif _WIN32
24 #include "config_win32.h"
25 #endif
26 #ifdef HAVE_STDINT_H
27 #include <stdint.h>
28 #endif
29 
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 
34 #include "jbig2.h"
35 #include "jbig2_image.h"
36 #include "jbig2_image_rw.h"
37 
38 int
main(int argc,char * argv[])39 main(int argc, char *argv[])
40 {
41     Jbig2Ctx *ctx;
42     Jbig2Image *image;
43     int code;
44 
45     /* we need a context for the allocators */
46     ctx = jbig2_ctx_new(NULL, 0, NULL, NULL, NULL);
47 
48     if (argc != 3) {
49         fprintf(stderr, "usage: %s <in.pbm> <out.png>\n\n", argv[0]);
50         return 1;
51     }
52 
53     image = jbig2_image_read_pbm_file(ctx, argv[1]);
54     if (image == NULL) {
55         fprintf(stderr, "error reading pbm file '%s'\n", argv[1]);
56         return 1;
57     } else {
58         fprintf(stderr, "converting %dx%d image to png format\n", image->width, image->height);
59     }
60 
61     code = jbig2_image_write_png_file(image, argv[2]);
62     if (code) {
63         fprintf(stderr, "error writing png file '%s' error %d\n", argv[2], code);
64     }
65 
66     return (code);
67 }
68