cdjpeg.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * cdjpeg.h
  3. *
  4. * This file was part of the Independent JPEG Group's software:
  5. * Copyright (C) 1994-1997, Thomas G. Lane.
  6. * Modified 2019 by Guido Vollbeding.
  7. * libjpeg-turbo Modifications:
  8. * Copyright (C) 2017, 2019, 2021, D. R. Commander.
  9. * For conditions of distribution and use, see the accompanying README.ijg
  10. * file.
  11. *
  12. * This file contains common declarations for the sample applications
  13. * cjpeg and djpeg. It is NOT used by the core JPEG library.
  14. */
  15. #define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */
  16. #define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */
  17. #include "jinclude.h"
  18. #include "jpeglib.h"
  19. #include "jerror.h" /* get library error codes too */
  20. #include "cderror.h" /* get application-specific error codes */
  21. /*
  22. * Object interface for cjpeg's source file decoding modules
  23. */
  24. typedef struct cjpeg_source_struct *cjpeg_source_ptr;
  25. struct cjpeg_source_struct {
  26. void (*start_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
  27. JDIMENSION (*get_pixel_rows) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
  28. void (*finish_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
  29. FILE *input_file;
  30. JSAMPARRAY buffer;
  31. JDIMENSION buffer_height;
  32. #ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
  33. JDIMENSION max_pixels;
  34. #endif
  35. };
  36. /*
  37. * Object interface for djpeg's output file encoding modules
  38. */
  39. typedef struct djpeg_dest_struct *djpeg_dest_ptr;
  40. struct djpeg_dest_struct {
  41. /* start_output is called after jpeg_start_decompress finishes.
  42. * The color map will be ready at this time, if one is needed.
  43. */
  44. void (*start_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo);
  45. /* Emit the specified number of pixel rows from the buffer. */
  46. void (*put_pixel_rows) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
  47. JDIMENSION rows_supplied);
  48. /* Finish up at the end of the image. */
  49. void (*finish_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo);
  50. /* Re-calculate buffer dimensions based on output dimensions (for use with
  51. partial image decompression.) If this is NULL, then the output format
  52. does not support partial image decompression (BMP, in particular, cannot
  53. support partial decompression because it uses an inversion buffer to write
  54. the image in bottom-up order.) */
  55. void (*calc_buffer_dimensions) (j_decompress_ptr cinfo,
  56. djpeg_dest_ptr dinfo);
  57. /* Target file spec; filled in by djpeg.c after object is created. */
  58. FILE *output_file;
  59. /* Output pixel-row buffer. Created by module init or start_output.
  60. * Width is cinfo->output_width * cinfo->output_components;
  61. * height is buffer_height.
  62. */
  63. JSAMPARRAY buffer;
  64. JDIMENSION buffer_height;
  65. };
  66. /*
  67. * cjpeg/djpeg may need to perform extra passes to convert to or from
  68. * the source/destination file format. The JPEG library does not know
  69. * about these passes, but we'd like them to be counted by the progress
  70. * monitor. We use an expanded progress monitor object to hold the
  71. * additional pass count.
  72. */
  73. struct cdjpeg_progress_mgr {
  74. struct jpeg_progress_mgr pub; /* fields known to JPEG library */
  75. int completed_extra_passes; /* extra passes completed */
  76. int total_extra_passes; /* total extra */
  77. JDIMENSION max_scans; /* abort if the number of scans exceeds this
  78. value and the value is non-zero */
  79. boolean report; /* whether or not to report progress */
  80. /* last printed percentage stored here to avoid multiple printouts */
  81. int percent_done;
  82. };
  83. typedef struct cdjpeg_progress_mgr *cd_progress_ptr;
  84. /* Module selection routines for I/O modules. */
  85. EXTERN(cjpeg_source_ptr) jinit_read_bmp(j_compress_ptr cinfo,
  86. boolean use_inversion_array);
  87. EXTERN(djpeg_dest_ptr) jinit_write_bmp(j_decompress_ptr cinfo, boolean is_os2,
  88. boolean use_inversion_array);
  89. EXTERN(cjpeg_source_ptr) jinit_read_gif(j_compress_ptr cinfo);
  90. EXTERN(djpeg_dest_ptr) jinit_write_gif(j_decompress_ptr cinfo, boolean is_lzw);
  91. EXTERN(cjpeg_source_ptr) jinit_read_ppm(j_compress_ptr cinfo);
  92. EXTERN(djpeg_dest_ptr) jinit_write_ppm(j_decompress_ptr cinfo);
  93. EXTERN(cjpeg_source_ptr) jinit_read_targa(j_compress_ptr cinfo);
  94. EXTERN(djpeg_dest_ptr) jinit_write_targa(j_decompress_ptr cinfo);
  95. /* cjpeg support routines (in rdswitch.c) */
  96. EXTERN(boolean) read_quant_tables(j_compress_ptr cinfo, char *filename,
  97. boolean force_baseline);
  98. EXTERN(boolean) read_scan_script(j_compress_ptr cinfo, char *filename);
  99. EXTERN(boolean) set_quality_ratings(j_compress_ptr cinfo, char *arg,
  100. boolean force_baseline);
  101. EXTERN(boolean) set_quant_slots(j_compress_ptr cinfo, char *arg);
  102. EXTERN(boolean) set_sample_factors(j_compress_ptr cinfo, char *arg);
  103. /* djpeg support routines (in rdcolmap.c) */
  104. EXTERN(void) read_color_map(j_decompress_ptr cinfo, FILE *infile);
  105. /* common support routines (in cdjpeg.c) */
  106. EXTERN(void) start_progress_monitor(j_common_ptr cinfo,
  107. cd_progress_ptr progress);
  108. EXTERN(void) end_progress_monitor(j_common_ptr cinfo);
  109. EXTERN(boolean) keymatch(char *arg, const char *keyword, int minchars);
  110. EXTERN(FILE *) read_stdin(void);
  111. EXTERN(FILE *) write_stdout(void);
  112. /* miscellaneous useful macros */
  113. #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
  114. #define READ_BINARY "r"
  115. #define WRITE_BINARY "w"
  116. #else
  117. #define READ_BINARY "rb"
  118. #define WRITE_BINARY "wb"
  119. #endif
  120. #ifndef EXIT_FAILURE /* define exit() codes if not provided */
  121. #define EXIT_FAILURE 1
  122. #endif
  123. #ifndef EXIT_SUCCESS
  124. #define EXIT_SUCCESS 0
  125. #endif
  126. #ifndef EXIT_WARNING
  127. #define EXIT_WARNING 2
  128. #endif
  129. #define IsExtRGB(cs) \
  130. (cs == JCS_RGB || (cs >= JCS_EXT_RGB && cs <= JCS_EXT_ARGB))