shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * cdjpeg.h
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * This file was part of the Independent JPEG Group's software:
shun-iwasawa 82a8f5
 * Copyright (C) 1994-1997, Thomas G. Lane.
shun-iwasawa 82a8f5
 * libjpeg-turbo Modifications:
shun-iwasawa 82a8f5
 * Copyright (C) 2017, D. R. Commander.
shun-iwasawa 82a8f5
 * For conditions of distribution and use, see the accompanying README.ijg
shun-iwasawa 82a8f5
 * file.
shun-iwasawa 82a8f5
 *
shun-iwasawa 82a8f5
 * This file contains common declarations for the sample applications
shun-iwasawa 82a8f5
 * cjpeg and djpeg.  It is NOT used by the core JPEG library.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define JPEG_CJPEG_DJPEG        /* define proper options in jconfig.h */
shun-iwasawa 82a8f5
#define JPEG_INTERNAL_OPTIONS   /* cjpeg.c,djpeg.c need to see xxx_SUPPORTED */
shun-iwasawa 82a8f5
#include "jinclude.h"
shun-iwasawa 82a8f5
#include "jpeglib.h"
shun-iwasawa 82a8f5
#include "jerror.h"             /* get library error codes too */
shun-iwasawa 82a8f5
#include "cderror.h"            /* get application-specific error codes */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Object interface for cjpeg's source file decoding modules
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
typedef struct cjpeg_source_struct *cjpeg_source_ptr;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
struct cjpeg_source_struct {
shun-iwasawa 82a8f5
  void (*start_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
shun-iwasawa 82a8f5
  JDIMENSION (*get_pixel_rows) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
shun-iwasawa 82a8f5
  void (*finish_input) (j_compress_ptr cinfo, cjpeg_source_ptr sinfo);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  FILE *input_file;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  JSAMPARRAY buffer;
shun-iwasawa 82a8f5
  JDIMENSION buffer_height;
shun-iwasawa 82a8f5
};
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * Object interface for djpeg's output file encoding modules
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
typedef struct djpeg_dest_struct *djpeg_dest_ptr;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
struct djpeg_dest_struct {
shun-iwasawa 82a8f5
  /* start_output is called after jpeg_start_decompress finishes.
shun-iwasawa 82a8f5
   * The color map will be ready at this time, if one is needed.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  void (*start_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo);
shun-iwasawa 82a8f5
  /* Emit the specified number of pixel rows from the buffer. */
shun-iwasawa 82a8f5
  void (*put_pixel_rows) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo,
shun-iwasawa 82a8f5
                          JDIMENSION rows_supplied);
shun-iwasawa 82a8f5
  /* Finish up at the end of the image. */
shun-iwasawa 82a8f5
  void (*finish_output) (j_decompress_ptr cinfo, djpeg_dest_ptr dinfo);
shun-iwasawa 82a8f5
  /* Re-calculate buffer dimensions based on output dimensions (for use with
shun-iwasawa 82a8f5
     partial image decompression.)  If this is NULL, then the output format
shun-iwasawa 82a8f5
     does not support partial image decompression (BMP and RLE, in particular,
shun-iwasawa 82a8f5
     cannot support partial decompression because they use an inversion buffer
shun-iwasawa 82a8f5
     to write the image in bottom-up order.) */
shun-iwasawa 82a8f5
  void (*calc_buffer_dimensions) (j_decompress_ptr cinfo,
shun-iwasawa 82a8f5
                                  djpeg_dest_ptr dinfo);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  /* Target file spec; filled in by djpeg.c after object is created. */
shun-iwasawa 82a8f5
  FILE *output_file;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
  /* Output pixel-row buffer.  Created by module init or start_output.
shun-iwasawa 82a8f5
   * Width is cinfo->output_width * cinfo->output_components;
shun-iwasawa 82a8f5
   * height is buffer_height.
shun-iwasawa 82a8f5
   */
shun-iwasawa 82a8f5
  JSAMPARRAY buffer;
shun-iwasawa 82a8f5
  JDIMENSION buffer_height;
shun-iwasawa 82a8f5
};
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/*
shun-iwasawa 82a8f5
 * cjpeg/djpeg may need to perform extra passes to convert to or from
shun-iwasawa 82a8f5
 * the source/destination file format.  The JPEG library does not know
shun-iwasawa 82a8f5
 * about these passes, but we'd like them to be counted by the progress
shun-iwasawa 82a8f5
 * monitor.  We use an expanded progress monitor object to hold the
shun-iwasawa 82a8f5
 * additional pass count.
shun-iwasawa 82a8f5
 */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
struct cdjpeg_progress_mgr {
shun-iwasawa 82a8f5
  struct jpeg_progress_mgr pub; /* fields known to JPEG library */
shun-iwasawa 82a8f5
  int completed_extra_passes;   /* extra passes completed */
shun-iwasawa 82a8f5
  int total_extra_passes;       /* total extra */
shun-iwasawa 82a8f5
  /* last printed percentage stored here to avoid multiple printouts */
shun-iwasawa 82a8f5
  int percent_done;
shun-iwasawa 82a8f5
};
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
typedef struct cdjpeg_progress_mgr *cd_progress_ptr;
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* Module selection routines for I/O modules. */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
EXTERN(cjpeg_source_ptr) jinit_read_bmp(j_compress_ptr cinfo,
shun-iwasawa 82a8f5
                                        boolean use_inversion_array);
shun-iwasawa 82a8f5
EXTERN(djpeg_dest_ptr) jinit_write_bmp(j_decompress_ptr cinfo, boolean is_os2,
shun-iwasawa 82a8f5
                                       boolean use_inversion_array);
shun-iwasawa 82a8f5
EXTERN(cjpeg_source_ptr) jinit_read_gif(j_compress_ptr cinfo);
shun-iwasawa 82a8f5
EXTERN(djpeg_dest_ptr) jinit_write_gif(j_decompress_ptr cinfo);
shun-iwasawa 82a8f5
EXTERN(cjpeg_source_ptr) jinit_read_ppm(j_compress_ptr cinfo);
shun-iwasawa 82a8f5
EXTERN(djpeg_dest_ptr) jinit_write_ppm(j_decompress_ptr cinfo);
shun-iwasawa 82a8f5
EXTERN(cjpeg_source_ptr) jinit_read_rle(j_compress_ptr cinfo);
shun-iwasawa 82a8f5
EXTERN(djpeg_dest_ptr) jinit_write_rle(j_decompress_ptr cinfo);
shun-iwasawa 82a8f5
EXTERN(cjpeg_source_ptr) jinit_read_targa(j_compress_ptr cinfo);
shun-iwasawa 82a8f5
EXTERN(djpeg_dest_ptr) jinit_write_targa(j_decompress_ptr cinfo);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* cjpeg support routines (in rdswitch.c) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
EXTERN(boolean) read_quant_tables(j_compress_ptr cinfo, char *filename,
shun-iwasawa 82a8f5
                                  boolean force_baseline);
shun-iwasawa 82a8f5
EXTERN(boolean) read_scan_script(j_compress_ptr cinfo, char *filename);
shun-iwasawa 82a8f5
EXTERN(boolean) set_quality_ratings(j_compress_ptr cinfo, char *arg,
shun-iwasawa 82a8f5
                                    boolean force_baseline);
shun-iwasawa 82a8f5
EXTERN(boolean) set_quant_slots(j_compress_ptr cinfo, char *arg);
shun-iwasawa 82a8f5
EXTERN(boolean) set_sample_factors(j_compress_ptr cinfo, char *arg);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* djpeg support routines (in rdcolmap.c) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
EXTERN(void) read_color_map(j_decompress_ptr cinfo, FILE *infile);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* common support routines (in cdjpeg.c) */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
EXTERN(void) start_progress_monitor(j_common_ptr cinfo,
shun-iwasawa 82a8f5
                                    cd_progress_ptr progress);
shun-iwasawa 82a8f5
EXTERN(void) end_progress_monitor(j_common_ptr cinfo);
shun-iwasawa 82a8f5
EXTERN(boolean) keymatch(char *arg, const char *keyword, int minchars);
shun-iwasawa 82a8f5
EXTERN(FILE *) read_stdin(void);
shun-iwasawa 82a8f5
EXTERN(FILE *) write_stdout(void);
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
/* miscellaneous useful macros */
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#ifdef DONT_USE_B_MODE          /* define mode parameters for fopen() */
shun-iwasawa 82a8f5
#define READ_BINARY     "r"
shun-iwasawa 82a8f5
#define WRITE_BINARY    "w"
shun-iwasawa 82a8f5
#else
shun-iwasawa 82a8f5
#define READ_BINARY     "rb"
shun-iwasawa 82a8f5
#define WRITE_BINARY    "wb"
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#ifndef EXIT_FAILURE            /* define exit() codes if not provided */
shun-iwasawa 82a8f5
#define EXIT_FAILURE  1
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
#ifndef EXIT_SUCCESS
shun-iwasawa 82a8f5
#define EXIT_SUCCESS  0
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
#ifndef EXIT_WARNING
shun-iwasawa 82a8f5
#define EXIT_WARNING  2
shun-iwasawa 82a8f5
#endif
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
#define IsExtRGB(cs) \
shun-iwasawa 82a8f5
  (cs == JCS_RGB || (cs >= JCS_EXT_RGB && cs <= JCS_EXT_ARGB))