1 #ifndef LIBRARIES_JFIF_H
    2 #define LIBRARIES_JFIF_H
    3 
    4 /*
    5 
    6 	MorphOS Shared JPEGLib
    7 	
    8 	jfif.library include
    9 	
   10 	Copyright © 2003-2004 The MorphOS Development Team, All Rights Reserved.
   11 
   12 */
   13 
   14 #include <sys/types.h>
   15 
   16 
   17 /* jconfig.h/jmorecfg.h mimic */
   18 
   19 
   20 #define BITS_IN_JSAMPLE	8
   21 #define MAX_COMPONENTS	10
   22 
   23 typedef unsigned char JSAMPLE;
   24 typedef short JCOEF;
   25 typedef unsigned char JOCTET;
   26 typedef unsigned int JDIMENSION;
   27 
   28 typedef unsigned char UINT8;
   29 typedef unsigned short UINT16;
   30 
   31 typedef int boolean;
   32 
   33 
   34 #define GETJSAMPLE(value)	((int) (value))
   35 #define GETJOCTET(value)	(value)
   36 
   37 #define MAXJSAMPLE	255
   38 #define CENTERJSAMPLE	128
   39 
   40 #define JPEG_MAX_DIMENSION	65500L
   41 
   42 
   43 #define METHODDEF(type)	static type
   44 #define JMETHOD(type,methodname,arglist)	type (*methodname) arglist
   45 
   46 #ifndef FAR
   47 #define FAR
   48 #endif
   49 
   50 
   51 /* jpeglib.h mimic */
   52 
   53 
   54 #define JPEG_LIB_VERSION	62
   55 
   56 #define DCTSIZE	8
   57 #define DCTSIZE2	64
   58 #define NUM_QUANT_TBLS	4
   59 #define NUM_HUFF_TBLS	4
   60 #define NUM_ARITH_TBLS	16
   61 #define MAX_COMPS_IN_SCAN	4
   62 #define MAX_SAMP_FACTOR	4
   63 #define C_MAX_BLOCKS_IN_MCU	10
   64 #define D_MAX_BLOCKS_IN_MCU	10
   65 
   66 
   67 typedef JSAMPLE *JSAMPROW;
   68 typedef JSAMPROW *JSAMPARRAY;
   69 typedef JSAMPARRAY *JSAMPIMAGE;
   70 
   71 typedef JCOEF JBLOCK[DCTSIZE2];
   72 typedef JBLOCK *JBLOCKROW;
   73 typedef JBLOCKROW *JBLOCKARRAY;
   74 typedef JBLOCKARRAY *JBLOCKIMAGE;
   75 
   76 typedef JCOEF *JCOEFPTR;
   77 
   78 
   79 /* DCT coefficient quantization tables. */
   80 typedef struct {
   81 	UINT16 quantval[DCTSIZE2];
   82 	boolean sent_table;
   83 } JQUANT_TBL;
   84 
   85 
   86 /* Huffman coding tables. */
   87 typedef struct {
   88 	UINT8 bits[17];
   89 	UINT8 huffval[256];
   90 	boolean sent_table;
   91 } JHUFF_TBL;
   92 
   93 
   94 /* Basic info about one component (color channel). */
   95 typedef struct {
   96 	int component_id;
   97 	int component_index;
   98 	int h_samp_factor;
   99 	int v_samp_factor;
  100 	int quant_tbl_no;
  101 	int dc_tbl_no;
  102 	int ac_tbl_no;
  103 	JDIMENSION width_in_blocks;
  104 	JDIMENSION height_in_blocks;
  105 	int DCT_scaled_size;
  106 	JDIMENSION downsampled_width;
  107 	JDIMENSION downsampled_height;
  108 	boolean component_needed;
  109 	int MCU_width;
  110 	int MCU_height;
  111 	int MCU_blocks;
  112 	int MCU_sample_width;
  113 	int last_col_width;
  114 	int last_row_height;
  115 	JQUANT_TBL * quant_table;
  116 	void * dct_table;
  117 } jpeg_component_info;
  118 
  119 
  120 /* The script for encoding a multiple-scan file is an array of these: */
  121 typedef struct {
  122 	int comps_in_scan;
  123 	int component_index[MAX_COMPS_IN_SCAN];
  124 	int Ss, Se;
  125 	int Ah, Al;
  126 } jpeg_scan_info;
  127 
  128 
  129 /* The decompressor can save APPn and COM markers in a list of these: */
  130 typedef struct jpeg_marker_struct * jpeg_saved_marker_ptr;
  131 
  132 struct jpeg_marker_struct {
  133 	jpeg_saved_marker_ptr next;
  134 	UINT8 marker;
  135 	unsigned int original_length;
  136 	unsigned int data_length;
  137 	JOCTET * data;
  138 };
  139 
  140 /* Known color spaces. */
  141 typedef enum {
  142 	JCS_UNKNOWN,
  143 	JCS_GRAYSCALE,
  144 	JCS_RGB,
  145 	JCS_YCbCr,
  146 	JCS_CMYK,
  147 	JCS_YCCK
  148 } J_COLOR_SPACE;
  149 
  150 /* DCT/IDCT algorithm options. */
  151 typedef enum {
  152 	JDCT_ISLOW,
  153 	JDCT_IFAST,
  154 	JDCT_FLOAT
  155 } J_DCT_METHOD;
  156 
  157 #define JDCT_DEFAULT  JDCT_ISLOW
  158 #define JDCT_FASTEST  JDCT_IFAST
  159 
  160 /* Dithering options for decompression. */
  161 typedef enum {
  162 	JDITHER_NONE,
  163 	JDITHER_ORDERED,
  164 	JDITHER_FS
  165 } J_DITHER_MODE;
  166 
  167 
  168 
  169 
  170 #define jpeg_common_fields \
  171 	struct jpeg_error_mgr * err; \
  172 	struct jpeg_memory_mgr * mem; \
  173 	struct jpeg_progress_mgr * progress; \
  174 	void * client_data; \
  175 	boolean is_decompressor; \
  176 	int global_state
  177   
  178 typedef
  179 struct jpeg_common_struct {
  180 	jpeg_common_fields;
  181 } *j_common_ptr;
  182 
  183 
  184 typedef
  185 struct jpeg_compress_struct {
  186 	jpeg_common_fields;
  187 
  188 	struct jpeg_destination_mgr * dest;
  189 
  190 	JDIMENSION image_width;	/* input image width */
  191 	JDIMENSION image_height;	/* input image height */
  192 	int input_components;	/* # of color components in input image */
  193 	J_COLOR_SPACE in_color_space;	/* colorspace of input image */
  194 
  195 	double input_gamma;	/* image gamma of input image */
  196 
  197 	int data_precision;	/* bits of precision in image data */
  198 
  199 	int num_components;	/* # of color components in JPEG image */
  200 	J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  201 
  202 	jpeg_component_info * comp_info;
  203 
  204 	JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  205 
  206 	JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  207 	JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  208 
  209 	UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  210 	UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  211 	UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  212 
  213 	int num_scans;	/* # of entries in scan_info array */
  214 	const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  215 
  216 	boolean raw_data_in;	/* TRUE=caller supplies downsampled data */
  217 	boolean arith_code;	/* TRUE=arithmetic coding, FALSE=Huffman */
  218 	boolean optimize_coding;	/* TRUE=optimize entropy encoding parms */
  219 	boolean CCIR601_sampling;	/* TRUE=first samples are cosited */
  220 	int smoothing_factor;	/* 1..100, or 0 for no input smoothing */
  221 	J_DCT_METHOD dct_method;	/* DCT algorithm selector */
  222 
  223 	unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  224 	int restart_in_rows;	/* if > 0, MCU rows per restart interval */
  225 
  226 	boolean write_JFIF_header;	/* should a JFIF marker be written? */
  227 	UINT8 JFIF_major_version;	/* What to write for the JFIF version number */
  228 	UINT8 JFIF_minor_version;
  229 
  230 	UINT8 density_unit;	/* JFIF code for pixel size units */
  231 	UINT16 X_density;	/* Horizontal pixel density */
  232 	UINT16 Y_density;	/* Vertical pixel density */
  233 	boolean write_Adobe_marker;	/* should an Adobe marker be written? */
  234 
  235 	JDIMENSION next_scanline;	/* 0 .. image_height-1  */
  236 
  237 	boolean progressive_mode;	/* TRUE if scan script uses progressive mode */
  238 	int max_h_samp_factor;	/* largest h_samp_factor */
  239 	int max_v_samp_factor;	/* largest v_samp_factor */
  240 
  241 	JDIMENSION total_iMCU_rows;	/* # of iMCU rows to be input to coef ctlr */
  242 
  243 	int comps_in_scan;	/* # of JPEG components in this scan */
  244 	jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  245 	/* *cur_comp_info[i] describes component that appears i'th in SOS */
  246 
  247 	JDIMENSION MCUs_per_row;	/* # of MCUs across the image */
  248 	JDIMENSION MCU_rows_in_scan;	/* # of MCU rows in the image */
  249 
  250 	int blocks_in_MCU;	/* # of DCT blocks per MCU */
  251 	int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  252 
  253 	int Ss, Se, Ah, Al;	/* progressive JPEG parameters for scan */
  254 
  255 	struct jpeg_comp_master * master;
  256 	struct jpeg_c_main_controller * main;
  257 	struct jpeg_c_prep_controller * prep;
  258 	struct jpeg_c_coef_controller * coef;
  259 	struct jpeg_marker_writer * marker;
  260 	struct jpeg_color_converter * cconvert;
  261 	struct jpeg_downsampler * downsample;
  262 	struct jpeg_forward_dct * fdct;
  263 	struct jpeg_entropy_encoder * entropy;
  264 	jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  265 	int script_space_size;
  266 } *j_compress_ptr;
  267 
  268 
  269 /* Master record for a decompression instance */
  270 typedef
  271 struct jpeg_decompress_struct {
  272 	jpeg_common_fields;	/* Fields shared with jpeg_compress_struct */
  273 
  274 	/* Source of compressed data */
  275 	struct jpeg_source_mgr * src;
  276 
  277 	/* Basic description of image --- filled in by jpeg_read_header(). */
  278 	/* Application may inspect these values to decide how to process image. */
  279 
  280 	JDIMENSION image_width;	/* nominal image width (from SOF marker) */
  281 	JDIMENSION image_height;	/* nominal image height */
  282 	int num_components;	/* # of color components in JPEG image */
  283 	J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  284 
  285 	/* Decompression processing parameters --- these fields must be set before
  286 	 * calling jpeg_start_decompress().  Note that jpeg_read_header() initializes
  287 	 * them to default values.
  288 	 */
  289 
  290 	J_COLOR_SPACE out_color_space; /* colorspace for output */
  291 
  292 	unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  293 
  294 	double output_gamma;	/* image gamma wanted in output */
  295 
  296 	boolean buffered_image;	/* TRUE=multiple output passes */
  297 	boolean raw_data_out;	/* TRUE=downsampled data wanted */
  298 
  299 	J_DCT_METHOD dct_method;	/* IDCT algorithm selector */
  300 	boolean do_fancy_upsampling;	/* TRUE=apply fancy upsampling */
  301 	boolean do_block_smoothing;	/* TRUE=apply interblock smoothing */
  302 
  303 	boolean quantize_colors;	/* TRUE=colormapped output wanted */
  304 	/* the following are ignored if not quantize_colors: */
  305 	J_DITHER_MODE dither_mode;	/* type of color dithering to use */
  306 	boolean two_pass_quantize;	/* TRUE=use two-pass color quantization */
  307 	int desired_number_of_colors;	/* max # colors to use in created colormap */
  308 	/* these are significant only in buffered-image mode: */
  309 	boolean enable_1pass_quant;	/* enable future use of 1-pass quantizer */
  310 	boolean enable_external_quant;/* enable future use of external colormap */
  311 	boolean enable_2pass_quant;	/* enable future use of 2-pass quantizer */
  312 
  313 	/* Description of actual output image that will be returned to application.
  314 	 * These fields are computed by jpeg_start_decompress().
  315 	 * You can also use jpeg_calc_output_dimensions() to determine these values
  316 	 * in advance of calling jpeg_start_decompress().
  317 	 */
  318 
  319 	JDIMENSION output_width;	/* scaled image width */
  320 	JDIMENSION output_height;	/* scaled image height */
  321 	int out_color_components;	/* # of color components in out_color_space */
  322 	int output_components;	/* # of color components returned */
  323 	/* output_components is 1 (a colormap index) when quantizing colors;
  324 	 * otherwise it equals out_color_components.
  325 	 */
  326 	int rec_outbuf_height;	/* min recommended height of scanline buffer */
  327 	/* If the buffer passed to jpeg_read_scanlines() is less than this many rows
  328 	 * high, space and time will be wasted due to unnecessary data copying.
  329 	 * Usually rec_outbuf_height will be 1 or 2, at most 4.
  330 	 */
  331 
  332 	/* When quantizing colors, the output colormap is described by these fields.
  333 	 * The application can supply a colormap by setting colormap non-NULL before
  334 	 * calling jpeg_start_decompress; otherwise a colormap is created during
  335 	 * jpeg_start_decompress or jpeg_start_output.
  336 	 * The map has out_color_components rows and actual_number_of_colors columns.
  337 	 */
  338 	int actual_number_of_colors;	/* number of entries in use */
  339 	JSAMPARRAY colormap;	/* The color map as a 2-D pixel array */
  340 
  341 	/* State variables: these variables indicate the progress of decompression.
  342 	 * The application may examine these but must not modify them.
  343 	 */
  344 
  345 	/* Row index of next scanline to be read from jpeg_read_scanlines().
  346 	 * Application may use this to control its processing loop, e.g.,
  347 	 * "while (output_scanline < output_height)".
  348 	 */
  349 	JDIMENSION output_scanline;	/* 0 .. output_height-1  */
  350 
  351 	/* Current input scan number and number of iMCU rows completed in scan.
  352 	 * These indicate the progress of the decompressor input side.
  353 	 */
  354 	int input_scan_number;	/* Number of SOS markers seen so far */
  355 	JDIMENSION input_iMCU_row;	/* Number of iMCU rows completed */
  356 
  357 	/* The "output scan number" is the notional scan being displayed by the
  358 	 * output side.  The decompressor will not allow output scan/row number
  359 	 * to get ahead of input scan/row, but it can fall arbitrarily far behind.
  360 	 */
  361 	int output_scan_number;	/* Nominal scan number being displayed */
  362 	JDIMENSION output_iMCU_row;	/* Number of iMCU rows read */
  363 
  364 	/* Current progression status.  coef_bits[c][i] indicates the precision
  365 	 * with which component c's DCT coefficient i (in zigzag order) is known.
  366 	 * It is -1 when no data has yet been received, otherwise it is the point
  367 	 * transform (shift) value for the most recent scan of the coefficient
  368 	 * (thus, 0 at completion of the progression).
  369 	 * This pointer is NULL when reading a non-progressive file.
  370 	 */
  371 	int (*coef_bits)[DCTSIZE2];	/* -1 or current Al value for each coef */
  372 
  373 	/* Internal JPEG parameters --- the application usually need not look at
  374 	 * these fields.  Note that the decompressor output side may not use
  375 	 * any parameters that can change between scans.
  376 	 */
  377 
  378 	/* Quantization and Huffman tables are carried forward across input
  379 	 * datastreams when processing abbreviated JPEG datastreams.
  380 	 */
  381 
  382 	JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  383 	/* ptrs to coefficient quantization tables, or NULL if not defined */
  384 
  385 	JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  386 	JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  387 	/* ptrs to Huffman coding tables, or NULL if not defined */
  388 
  389 	/* These parameters are never carried across datastreams, since they
  390 	 * are given in SOF/SOS markers or defined to be reset by SOI.
  391 	 */
  392 
  393 	int data_precision;	/* bits of precision in image data */
  394 
  395 	jpeg_component_info * comp_info;
  396 	/* comp_info[i] describes component that appears i'th in SOF */
  397 
  398 	boolean progressive_mode;	/* TRUE if SOFn specifies progressive mode */
  399 	boolean arith_code;	/* TRUE=arithmetic coding, FALSE=Huffman */
  400 
  401 	UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  402 	UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  403 	UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  404 
  405 	unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  406 
  407 	/* These fields record data obtained from optional markers recognized by
  408 	 * the JPEG library.
  409 	 */
  410 	boolean saw_JFIF_marker;	/* TRUE iff a JFIF APP0 marker was found */
  411 	/* Data copied from JFIF marker; only valid if saw_JFIF_marker is TRUE: */
  412 	UINT8 JFIF_major_version;	/* JFIF version number */
  413 	UINT8 JFIF_minor_version;
  414 	UINT8 density_unit;	/* JFIF code for pixel size units */
  415 	UINT16 X_density;	/* Horizontal pixel density */
  416 	UINT16 Y_density;	/* Vertical pixel density */
  417 	boolean saw_Adobe_marker;	/* TRUE iff an Adobe APP14 marker was found */
  418 	UINT8 Adobe_transform;	/* Color transform code from Adobe marker */
  419 
  420 	boolean CCIR601_sampling;	/* TRUE=first samples are cosited */
  421 
  422 	/* Aside from the specific data retained from APPn markers known to the
  423 	 * library, the uninterpreted contents of any or all APPn and COM markers
  424 	 * can be saved in a list for examination by the application.
  425 	 */
  426 	jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  427 
  428 	/* Remaining fields are known throughout decompressor, but generally
  429 	 * should not be touched by a surrounding application.
  430 	 */
  431 
  432 	/*
  433 	 * These fields are computed during decompression startup
  434 	 */
  435 	int max_h_samp_factor;	/* largest h_samp_factor */
  436 	int max_v_samp_factor;	/* largest v_samp_factor */
  437 
  438 	int min_DCT_scaled_size;	/* smallest DCT_scaled_size of any component */
  439 
  440 	JDIMENSION total_iMCU_rows;	/* # of iMCU rows in image */
  441 	/* The coefficient controller's input and output progress is measured in
  442 	 * units of "iMCU" (interleaved MCU) rows.  These are the same as MCU rows
  443 	 * in fully interleaved JPEG scans, but are used whether the scan is
  444 	 * interleaved or not.  We define an iMCU row as v_samp_factor DCT block
  445 	 * rows of each component.  Therefore, the IDCT output contains
  446 	 * v_samp_factor*DCT_scaled_size sample rows of a component per iMCU row.
  447 	 */
  448 
  449 	JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  450 
  451 	/*
  452 	 * These fields are valid during any one scan.
  453 	 * They describe the components and MCUs actually appearing in the scan.
  454 	 * Note that the decompressor output side must not use these fields.
  455 	 */
  456 	int comps_in_scan;	/* # of JPEG components in this scan */
  457 	jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  458 	/* *cur_comp_info[i] describes component that appears i'th in SOS */
  459 
  460 	JDIMENSION MCUs_per_row;	/* # of MCUs across the image */
  461 	JDIMENSION MCU_rows_in_scan;	/* # of MCU rows in the image */
  462 
  463 	int blocks_in_MCU;	/* # of DCT blocks per MCU */
  464 	int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  465 	/* MCU_membership[i] is index in cur_comp_info of component owning */
  466 	/* i'th block in an MCU */
  467 
  468 	int Ss, Se, Ah, Al;	/* progressive JPEG parameters for scan */
  469 
  470 	/* This field is shared between entropy decoder and marker parser.
  471 	 * It is either zero or the code of a JPEG marker that has been
  472 	 * read from the data source, but has not yet been processed.
  473 	 */
  474 	int unread_marker;
  475 
  476 	/*
  477 	 * Links to decompression subobjects (methods, private variables of modules)
  478 	 */
  479 	struct jpeg_decomp_master * master;
  480 	struct jpeg_d_main_controller * main;
  481 	struct jpeg_d_coef_controller * coef;
  482 	struct jpeg_d_post_controller * post;
  483 	struct jpeg_input_controller * inputctl;
  484 	struct jpeg_marker_reader * marker;
  485 	struct jpeg_entropy_decoder * entropy;
  486 	struct jpeg_inverse_dct * idct;
  487 	struct jpeg_upsampler * upsample;
  488 	struct jpeg_color_deconverter * cconvert;
  489 	struct jpeg_color_quantizer * cquantize;
  490 } *j_decompress_ptr;
  491 
  492 
  493 /* "Object" declarations for JPEG modules that may be supplied or called
  494  * directly by the surrounding application.
  495  * As with all objects in the JPEG library, these structs only define the
  496  * publicly visible methods and state variables of a module.  Additional
  497  * private fields may exist after the public ones.
  498  */
  499 
  500 
  501 #ifdef __cplusplus
  502 extern "C" {
  503 #endif
  504 
  505 /* Error handler object */
  506 
  507 struct jpeg_error_mgr {
  508 	/* Error exit handler: does not return to caller */
  509 	JMETHOD(void, error_exit, (j_common_ptr cinfo));
  510 	/* Conditionally emit a trace or warning message */
  511 	JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  512 	/* Routine that actually outputs a trace or error message */
  513 	JMETHOD(void, output_message, (j_common_ptr cinfo));
  514 	/* Format a message string for the most recent JPEG error or message */
  515 	JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  516 #define JMSG_LENGTH_MAX  200	/* recommended size of format_message buffer */
  517 	/* Reset error state variables at start of a new image */
  518 	JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  519 
  520 	/* The message ID code and any parameters are saved here.
  521 	 * A message can have one string parameter or up to 8 int parameters.
  522 	 */
  523 	int msg_code;
  524 #define JMSG_STR_PARM_MAX  80
  525 	union {
  526 		int i[8];
  527 		char s[JMSG_STR_PARM_MAX];
  528 	} msg_parm;
  529 
  530 	/* Standard state variables for error facility */
  531 
  532 	int trace_level;	/* max msg_level that will be displayed */
  533 
  534 	/* For recoverable corrupt-data errors, we emit a warning message,
  535 	 * but keep going unless emit_message chooses to abort.  emit_message
  536 	 * should count warnings in num_warnings.  The surrounding application
  537 	 * can check for bad data by seeing if num_warnings is nonzero at the
  538 	 * end of processing.
  539 	 */
  540 	long num_warnings;	/* number of corrupt-data warnings */
  541 
  542 	/* These fields point to the table(s) of error message strings.
  543 	 * An application can change the table pointer to switch to a different
  544 	 * message list (typically, to change the language in which errors are
  545 	 * reported).  Some applications may wish to add additional error codes
  546 	 * that will be handled by the JPEG library error mechanism; the second
  547 	 * table pointer is used for this purpose.
  548 	 *
  549 	 * First table includes all errors generated by JPEG library itself.
  550 	 * Error code 0 is reserved for a "no such error string" message.
  551 	 */
  552 	const char * const * jpeg_message_table; /* Library errors */
  553 	int last_jpeg_message;    /* Table contains strings 0..last_jpeg_message */
  554 	/* Second table can be added by application (see cjpeg/djpeg for example).
  555 	 * It contains strings numbered first_addon_message..last_addon_message.
  556 	 */
  557 	const char * const * addon_message_table; /* Non-library errors */
  558 	int first_addon_message;	/* code for first string in addon table */
  559 	int last_addon_message;	/* code for last string in addon table */
  560 };
  561 
  562 
  563 /* Progress monitor object */
  564 
  565 struct jpeg_progress_mgr {
  566 	JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  567 
  568 	long pass_counter;	/* work units completed in this pass */
  569 	long pass_limit;	/* total number of work units in this pass */
  570 	int completed_passes;	/* passes completed so far */
  571 	int total_passes;	/* total number of passes expected */
  572 };
  573 
  574 
  575 /* Data destination object for compression */
  576 
  577 struct jpeg_destination_mgr {
  578 	JOCTET * next_output_byte;	/* => next byte to write in buffer */
  579 	size_t free_in_buffer;	/* # of byte spaces remaining in buffer */
  580 
  581 	JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  582 	JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  583 	JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  584 };
  585 
  586 
  587 /* Data source object for decompression */
  588 
  589 struct jpeg_source_mgr {
  590 	const JOCTET * next_input_byte;	/* => next byte to read from buffer */
  591 	size_t bytes_in_buffer;	/* # of bytes remaining in buffer */
  592 
  593 	JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  594 	JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  595 	JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  596 	JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  597 	JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  598 };
  599 
  600 
  601 /* Memory manager object.
  602  * Allocates "small" objects (a few K total), "large" objects (tens of K),
  603  * and "really big" objects (virtual arrays with backing store if needed).
  604  * The memory manager does not allow individual objects to be freed; rather,
  605  * each created object is assigned to a pool, and whole pools can be freed
  606  * at once.  This is faster and more convenient than remembering exactly what
  607  * to free, especially where malloc()/free() are not too speedy.
  608  * NB: alloc routines never return NULL.  They exit to error_exit if not
  609  * successful.
  610  */
  611 
  612 #define JPOOL_PERMANENT	0	/* lasts until master record is destroyed */
  613 #define JPOOL_IMAGE	1	/* lasts until done with image/datastream */
  614 #define JPOOL_NUMPOOLS	2
  615 
  616 typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  617 typedef struct jvirt_barray_control * jvirt_barray_ptr;
  618 
  619 
  620 struct jpeg_memory_mgr {
  621 	/* Method pointers */
  622 	JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id, size_t sizeofobject));
  623 	JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id, size_t sizeofobject));
  624 	JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id, JDIMENSION samplesperrow, JDIMENSION numrows));
  625 	JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id, JDIMENSION blocksperrow, JDIMENSION numrows));
  626 	JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION samplesperrow, JDIMENSION numrows, JDIMENSION maxaccess));
  627 	JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo, int pool_id, boolean pre_zero, JDIMENSION blocksperrow, JDIMENSION numrows, JDIMENSION maxaccess));
  628 	JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  629 	JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo, jvirt_sarray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable));
  630 	JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo, jvirt_barray_ptr ptr, JDIMENSION start_row, JDIMENSION num_rows, boolean writable));
  631 	JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  632 	JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  633 
  634 	/* Limit on memory allocation for this JPEG object.  (Note that this is
  635 	 * merely advisory, not a guaranteed maximum; it only affects the space
  636 	 * used for virtual-array buffers.)  May be changed by outer application
  637 	 * after creating the JPEG object.
  638 	 */
  639 	long max_memory_to_use;
  640 
  641 	/* Maximum allocation request accepted by alloc_large. */
  642 	long max_alloc_chunk;
  643 };
  644 
  645 
  646 /* Routine signature for application-supplied marker processing methods.
  647  * Need not pass marker code since it is stored in cinfo->unread_marker.
  648  */
  649 typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  650 
  651 
  652 /* Declarations for routines called by application.
  653  * The JPP macro hides prototype parameters from compilers that can't cope.
  654  * Note JPP requires double parentheses.
  655  */
  656 
  657 #define JPP(arglist)	arglist
  658 
  659 
  660 /* Return value (jpeg_read_header) is one of: */
  661 #define JPEG_SUSPENDED		0 /* Suspended due to lack of input data */
  662 #define JPEG_HEADER_OK		1 /* Found valid image datastream */
  663 #define JPEG_HEADER_TABLES_ONLY	2 /* Found valid table-specs-only datastream */
  664 /* If you pass require_image = TRUE (normal case), you need not check for
  665  * a TABLES_ONLY return code; an abbreviated file will cause an error exit.
  666  * JPEG_SUSPENDED is only possible if you use a data source module that can
  667  * give a suspension return (the stdio source module doesn't).
  668  */
  669 
  670 /* Return value (jpeg_consume_input) is one of: */
  671 /* #define JPEG_SUSPENDED	0    Suspended due to lack of input data */
  672 #define JPEG_REACHED_SOS	1 /* Reached start of new scan */
  673 #define JPEG_REACHED_EOI	2 /* Reached end of image */
  674 #define JPEG_ROW_COMPLETED	3 /* Completed one iMCU row */
  675 #define JPEG_SCAN_COMPLETED	4 /* Completed last iMCU row of a scan */
  676 
  677 
  678 #define JPEG_RST0	0xD0
  679 #define JPEG_EOI	0xD9
  680 #define JPEG_APP0	0xE0
  681 #define JPEG_COM	0xFE
  682 
  683 
  684 /* These defintions are sometimes needed by some applications */
  685 #ifdef JPEG_INTERNAL_OPTIONS
  686 
  687 #define RGB_RED		0	/* Offset of Red in an RGB scanline element */
  688 #define RGB_GREEN	1	/* Offset of Green */
  689 #define RGB_BLUE	2	/* Offset of Blue */
  690 #define RGB_PIXELSIZE	3	/* JSAMPLEs per RGB scanline element */
  691 
  692 #endif /* JPEG_INTERNAL_OPTIONS */
  693 
  694 #ifdef __cplusplus
  695 }
  696 #endif
  697 
  698 #endif /* LIBRARIES_JFIF_H */