pbm2png.c 1.6 KB

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