cdjpeg.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * cdjpeg.h
  3. *
  4. * Copyright (C) 1994-1997, Thomas G. Lane.
  5. * Modified 2019 by Guido Vollbeding.
  6. * This file is part of the Independent JPEG Group's software.
  7. * For conditions of distribution and use, see the accompanying README file.
  8. *
  9. * This file contains common declarations for the sample applications
  10. * cjpeg and djpeg. It is NOT used by the core JPEG library.
  11. */
  12. #define JPEG_CJPEG_DJPEG /* define proper options in jconfig.h */
  13. #define JPEG_INTERNAL_OPTIONS /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */
  14. #include "jinclude.h"
  15. #include "jpeglib.h"
  16. #include "jerror.h" /* get library error codes too */
  17. #include "cderror.h" /* get application-specific error codes */
  18. /*
  19. * Object interface for cjpeg's source file decoding modules
  20. */
  21. typedef struct cjpeg_source_struct * cjpeg_source_ptr;
  22. struct cjpeg_source_struct {
  23. JMETHOD(void, start_input, (j_compress_ptr cinfo,
  24. cjpeg_source_ptr sinfo));
  25. JMETHOD(JDIMENSION, get_pixel_rows, (j_compress_ptr cinfo,
  26. cjpeg_source_ptr sinfo));
  27. JMETHOD(void, finish_input, (j_compress_ptr cinfo,
  28. cjpeg_source_ptr sinfo));
  29. FILE *input_file;
  30. JSAMPARRAY buffer;
  31. JDIMENSION buffer_height;
  32. };
  33. /*
  34. * Object interface for djpeg's output file encoding modules
  35. */
  36. typedef struct djpeg_dest_struct * djpeg_dest_ptr;
  37. struct djpeg_dest_struct {
  38. /* start_output is called after jpeg_start_decompress finishes.
  39. * The color map will be ready at this time, if one is needed.
  40. */
  41. JMETHOD(void, start_output, (j_decompress_ptr cinfo,
  42. djpeg_dest_ptr dinfo));
  43. /* Emit the specified number of pixel rows from the buffer. */
  44. JMETHOD(void, put_pixel_rows, (j_decompress_ptr cinfo,
  45. djpeg_dest_ptr dinfo,
  46. JDIMENSION rows_supplied));
  47. /* Finish up at the end of the image. */
  48. JMETHOD(void, finish_output, (j_decompress_ptr cinfo,
  49. djpeg_dest_ptr dinfo));
  50. /* Target file spec; filled in by djpeg.c after object is created. */
  51. FILE * output_file;
  52. /* Output pixel-row buffer. Created by module init or start_output.
  53. * Width is cinfo->output_width * cinfo->output_components;
  54. * height is buffer_height.
  55. */
  56. JSAMPARRAY buffer;
  57. JDIMENSION buffer_height;
  58. };
  59. /*
  60. * cjpeg/djpeg may need to perform extra passes to convert to or from
  61. * the source/destination file format. The JPEG library does not know
  62. * about these passes, but we'd like them to be counted by the progress
  63. * monitor. We use an expanded progress monitor object to hold the
  64. * additional pass count.
  65. */
  66. struct cdjpeg_progress_mgr {
  67. struct jpeg_progress_mgr pub; /* fields known to JPEG library */
  68. int completed_extra_passes; /* extra passes completed */
  69. int total_extra_passes; /* total extra */
  70. /* last printed percentage stored here to avoid multiple printouts */
  71. int percent_done;
  72. };
  73. typedef struct cdjpeg_progress_mgr * cd_progress_ptr;
  74. /* Short forms of external names for systems with brain-damaged linkers. */
  75. #ifdef NEED_SHORT_EXTERNAL_NAMES
  76. #define jinit_read_bmp jIRdBMP
  77. #define jinit_write_bmp jIWrBMP
  78. #define jinit_read_gif jIRdGIF
  79. #define jinit_write_gif jIWrGIF
  80. #define jinit_read_ppm jIRdPPM
  81. #define jinit_write_ppm jIWrPPM
  82. #define jinit_read_rle jIRdRLE
  83. #define jinit_write_rle jIWrRLE
  84. #define jinit_read_targa jIRdTarga
  85. #define jinit_write_targa jIWrTarga
  86. #define read_quant_tables RdQTables
  87. #define read_scan_script RdScnScript
  88. #define set_quality_ratings SetQRates
  89. #define set_quant_slots SetQSlots
  90. #define set_sample_factors SetSFacts
  91. #define read_color_map RdCMap
  92. #define enable_signal_catcher EnSigCatcher
  93. #define start_progress_monitor StProgMon
  94. #define end_progress_monitor EnProgMon
  95. #define read_stdin RdStdin
  96. #define write_stdout WrStdout
  97. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  98. /* Module selection routines for I/O modules. */
  99. EXTERN(cjpeg_source_ptr) jinit_read_bmp JPP((j_compress_ptr cinfo));
  100. EXTERN(djpeg_dest_ptr) jinit_write_bmp JPP((j_decompress_ptr cinfo,
  101. boolean is_os2));
  102. EXTERN(cjpeg_source_ptr) jinit_read_gif JPP((j_compress_ptr cinfo));
  103. EXTERN(djpeg_dest_ptr) jinit_write_gif JPP((j_decompress_ptr cinfo,
  104. boolean is_lzw));
  105. EXTERN(cjpeg_source_ptr) jinit_read_ppm JPP((j_compress_ptr cinfo));
  106. EXTERN(djpeg_dest_ptr) jinit_write_ppm JPP((j_decompress_ptr cinfo));
  107. EXTERN(cjpeg_source_ptr) jinit_read_rle JPP((j_compress_ptr cinfo));
  108. EXTERN(djpeg_dest_ptr) jinit_write_rle JPP((j_decompress_ptr cinfo));
  109. EXTERN(cjpeg_source_ptr) jinit_read_targa JPP((j_compress_ptr cinfo));
  110. EXTERN(djpeg_dest_ptr) jinit_write_targa JPP((j_decompress_ptr cinfo));
  111. /* cjpeg support routines (in rdswitch.c) */
  112. EXTERN(boolean) read_quant_tables JPP((j_compress_ptr cinfo, char * filename,
  113. boolean force_baseline));
  114. EXTERN(boolean) read_scan_script JPP((j_compress_ptr cinfo, char * filename));
  115. EXTERN(boolean) set_quality_ratings JPP((j_compress_ptr cinfo, char *arg,
  116. boolean force_baseline));
  117. EXTERN(boolean) set_quant_slots JPP((j_compress_ptr cinfo, char *arg));
  118. EXTERN(boolean) set_sample_factors JPP((j_compress_ptr cinfo, char *arg));
  119. /* djpeg support routines (in rdcolmap.c) */
  120. EXTERN(void) read_color_map JPP((j_decompress_ptr cinfo, FILE * infile));
  121. /* common support routines (in cdjpeg.c) */
  122. EXTERN(void) enable_signal_catcher JPP((j_common_ptr cinfo));
  123. EXTERN(void) start_progress_monitor JPP((j_common_ptr cinfo,
  124. cd_progress_ptr progress));
  125. EXTERN(void) end_progress_monitor JPP((j_common_ptr cinfo));
  126. EXTERN(boolean) keymatch JPP((char * arg, const char * keyword, int minchars));
  127. EXTERN(FILE *) read_stdin JPP((void));
  128. EXTERN(FILE *) write_stdout JPP((void));
  129. /* miscellaneous useful macros */
  130. #ifdef DONT_USE_B_MODE /* define mode parameters for fopen() */
  131. #define READ_BINARY "r"
  132. #define WRITE_BINARY "w"
  133. #else
  134. #ifdef VMS /* VMS is very nonstandard */
  135. #define READ_BINARY "rb", "ctx=stm"
  136. #define WRITE_BINARY "wb", "ctx=stm"
  137. #else /* standard ANSI-compliant case */
  138. #define READ_BINARY "rb"
  139. #define WRITE_BINARY "wb"
  140. #endif
  141. #endif
  142. #ifndef EXIT_FAILURE /* define exit() codes if not provided */
  143. #define EXIT_FAILURE 1
  144. #endif
  145. #ifndef EXIT_SUCCESS
  146. #ifdef VMS
  147. #define EXIT_SUCCESS 1 /* VMS is very nonstandard */
  148. #else
  149. #define EXIT_SUCCESS 0
  150. #endif
  151. #endif
  152. #ifndef EXIT_WARNING
  153. #ifdef VMS
  154. #define EXIT_WARNING 1 /* VMS is very nonstandard */
  155. #else
  156. #define EXIT_WARNING 2
  157. #endif
  158. #endif