cdjpeg.h 5.6 KB

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