cdjpeg.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. * libjpeg-turbo Modifications:
  7. * Copyright (C) 2017, D. R. Commander.
  8. * mozjpeg Modifications:
  9. * Copyright (C) 2014, Mozilla Corporation.
  10. * For conditions of distribution and use, see the accompanying README.ijg 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. #define JPEG_RAW_READER 0
  22. /*
  23. * Object interface for cjpeg's source file decoding modules
  24. */
  25. typedef struct cjpeg_source_struct *cjpeg_source_ptr;
  26. struct cjpeg_source_struct {
  27. void (*start_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
  28. JDIMENSION (*get_pixel_rows) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
  29. void (*finish_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
  30. FILE *input_file;
  31. JSAMPARRAY buffer;
  32. JDIMENSION buffer_height;
  33. #if JPEG_RAW_READER
  34. // For reading JPEG
  35. JSAMPARRAY plane_pointer[4];
  36. #endif
  37. jpeg_saved_marker_ptr marker_list;
  38. };
  39. /*
  40. * Object interface for djpeg's output file encoding modules
  41. */
  42. typedef struct djpeg_dest_struct *djpeg_dest_ptr;
  43. struct djpeg_dest_struct {
  44. /* start_output is called after jpeg_start_decompress finishes.
  45. * The color map will be ready at this time, if one is needed.
  46. */
  47. void (*start_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo);
  48. /* Emit the specified number of pixel rows from the buffer. */
  49. void (*put_pixel_rows) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
  50. JDIMENSION rows_supplied);
  51. /* Finish up at the end of the image. */
  52. void (*finish_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo);
  53. /* Re-calculate buffer dimensions based on output dimensions (for use with
  54. partial image decompression.) If this is NULL, then the output format
  55. does not support partial image decompression (BMP and RLE, in particular,
  56. cannot support partial decompression because they use an inversion buffer
  57. to write the image in bottom-up order.) */
  58. void (*calc_buffer_dimensions) (j_decompress_ptr cinfo,
  59. djpeg_dest_ptr dinfo);
  60. /* Target file spec; filled in by djpeg.c after object is created. */
  61. FILE *output_file;
  62. /* Output pixel-row buffer. Created by module init or start_output.
  63. * Width is cinfo->output_width * cinfo->output_components;
  64. * height is buffer_height.
  65. */
  66. JSAMPARRAY buffer;
  67. JDIMENSION buffer_height;
  68. };
  69. /*
  70. * cjpeg/djpeg may need to perform extra passes to convert to or from
  71. * the source/destination file format. The JPEG library does not know
  72. * about these passes, but we'd like them to be counted by the progress
  73. * monitor. We use an expanded progress monitor object to hold the
  74. * additional pass count.
  75. */
  76. struct cdjpeg_progress_mgr {
  77. struct jpeg_progress_mgr pub; /* fields known to JPEG library */
  78. int completed_extra_passes; /* extra passes completed */
  79. int total_extra_passes; /* total extra */
  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_jpeg (j_compress_ptr cinfo);
  86. EXTERN(cjpeg_source_ptr) jinit_read_png (j_compress_ptr cinfo);
  87. EXTERN(cjpeg_source_ptr) jinit_read_bmp(j_compress_ptr cinfo,
  88. boolean use_inversion_array);
  89. EXTERN(djpeg_dest_ptr) jinit_write_bmp(j_decompress_ptr cinfo, boolean is_os2,
  90. boolean use_inversion_array);
  91. EXTERN(cjpeg_source_ptr) jinit_read_gif(j_compress_ptr cinfo);
  92. EXTERN(djpeg_dest_ptr) jinit_write_gif(j_decompress_ptr cinfo);
  93. EXTERN(cjpeg_source_ptr) jinit_read_ppm(j_compress_ptr cinfo);
  94. EXTERN(djpeg_dest_ptr) jinit_write_ppm(j_decompress_ptr cinfo);
  95. EXTERN(cjpeg_source_ptr) jinit_read_rle(j_compress_ptr cinfo);
  96. EXTERN(djpeg_dest_ptr) jinit_write_rle(j_decompress_ptr cinfo);
  97. EXTERN(cjpeg_source_ptr) jinit_read_targa(j_compress_ptr cinfo);
  98. EXTERN(djpeg_dest_ptr) jinit_write_targa(j_decompress_ptr cinfo);
  99. /* cjpeg support routines (in rdswitch.c) */
  100. EXTERN(boolean) read_quant_tables(j_compress_ptr cinfo, char *filename,
  101. boolean force_baseline);
  102. EXTERN(boolean) read_scan_script(j_compress_ptr cinfo, char *filename);
  103. EXTERN(boolean) set_quality_ratings(j_compress_ptr cinfo, char *arg,
  104. boolean force_baseline);
  105. EXTERN(boolean) set_quant_slots(j_compress_ptr cinfo, char *arg);
  106. EXTERN(boolean) set_sample_factors(j_compress_ptr cinfo, char *arg);
  107. /* djpeg support routines (in rdcolmap.c) */
  108. EXTERN(void) read_color_map(j_decompress_ptr cinfo, FILE *infile);
  109. /* common support routines (in cdjpeg.c) */
  110. EXTERN(void) enable_signal_catcher(j_common_ptr cinfo);
  111. EXTERN(void) start_progress_monitor(j_common_ptr cinfo,
  112. cd_progress_ptr progress);
  113. EXTERN(void) end_progress_monitor(j_common_ptr cinfo);
  114. EXTERN(boolean) keymatch(char *arg, const char *keyword, int minchars);
  115. EXTERN(FILE *) read_stdin(void);
  116. EXTERN(FILE *) write_stdout(void);
  117. /* miscellaneous useful macros */
  118. #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
  119. #define READ_BINARY "r"
  120. #define WRITE_BINARY "w"
  121. #else
  122. #define READ_BINARY "rb"
  123. #define WRITE_BINARY "wb"
  124. #endif
  125. #ifndef EXIT_FAILURE /* define exit() codes if not provided */
  126. #define EXIT_FAILURE 1
  127. #endif
  128. #ifndef EXIT_SUCCESS
  129. #define EXIT_SUCCESS 0
  130. #endif
  131. #ifndef EXIT_WARNING
  132. #define EXIT_WARNING 2
  133. #endif
  134. #define IsExtRGB(cs) \
  135. (cs == JCS_RGB || (cs >= JCS_EXT_RGB && cs <= JCS_EXT_ARGB))