/* * rdswitch.c * * This file was part of the Independent JPEG Group's software: * Copyright (C) 1991-1996, Thomas G. Lane. * libjpeg-turbo Modifications: * Copyright (C) 2010, 2018, 2022, D. R. Commander. * For conditions of distribution and use, see the accompanying README.ijg * file. * * This file contains routines to process some of cjpeg's more complicated * command-line switches. Switches processed here are: * -qtables file Read quantization tables from text file * -scans file Read scan script from text file * -quality N[,N,...] Set quality ratings * -qslots N[,N,...] Set component quantization table selectors * -sample HxV[,HxV,...] Set component sampling factors */ #ifdef _MSC_VER #define _CRT_SECURE_NO_DEPRECATE #endif #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ #include <ctype.h> /* to declare isdigit(), isspace() */ LOCAL(int) text_getc(FILE *file) /* Read next char, skipping over any comments (# to end of line) */ /* A comment/newline sequence is returned as a newline */ { … } LOCAL(boolean) read_text_integer(FILE *file, long *result, int *termchar) /* Read an unsigned decimal integer from a file, store it in result */ /* Reads one trailing character after the integer; returns it in termchar */ { … } #if JPEG_LIB_VERSION < 70 static int q_scale_factor[NUM_QUANT_TBLS] = …; #endif GLOBAL(boolean) read_quant_tables(j_compress_ptr cinfo, char *filename, boolean force_baseline) /* Read a set of quantization tables from the specified file. * The file is plain ASCII text: decimal numbers with whitespace between. * Comments preceded by '#' may be included in the file. * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values. * The tables are implicitly numbered 0,1,etc. * NOTE: does not affect the qslots mapping, which will default to selecting * table 0 for luminance (or primary) components, 1 for chrominance components. * You must use -qslots if you want a different component->table mapping. */ { … } #ifdef C_MULTISCAN_FILES_SUPPORTED LOCAL(boolean) read_scan_integer(FILE *file, long *result, int *termchar) /* Variant of read_text_integer that always looks for a non-space termchar; * this simplifies parsing of punctuation in scan scripts. */ { … } GLOBAL(boolean) read_scan_script(j_compress_ptr cinfo, char *filename) /* Read a scan script from the specified text file. * Each entry in the file defines one scan to be emitted. * Entries are separated by semicolons ';'. * An entry contains one to four component indexes, * optionally followed by a colon ':' and four progressive-JPEG parameters. * The component indexes denote which component(s) are to be transmitted * in the current scan. The first component has index 0. * Sequential JPEG is used if the progressive-JPEG parameters are omitted. * The file is free format text: any whitespace may appear between numbers * and the ':' and ';' punctuation marks. Also, other punctuation (such * as commas or dashes) can be placed between numbers if desired. * Comments preceded by '#' may be included in the file. * Note: we do very little validity checking here; * jcmaster.c will validate the script parameters. */ { … } #endif /* C_MULTISCAN_FILES_SUPPORTED */ #if JPEG_LIB_VERSION < 70 /* These are the sample quantization tables given in Annex K (Clause K.1) of * Recommendation ITU-T T.81 (1992) | ISO/IEC 10918-1:1994. * The spec says that the values given produce "good" quality, and * when divided by 2, "very good" quality. */ static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = …; static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = …; LOCAL(void) jpeg_default_qtables(j_compress_ptr cinfo, boolean force_baseline) { … } #endif GLOBAL(boolean) set_quality_ratings(j_compress_ptr cinfo, char *arg, boolean force_baseline) /* Process a quality-ratings parameter string, of the form * N[,N,...] * If there are more q-table slots than parameters, the last value is replicated. */ { … } GLOBAL(boolean) set_quant_slots(j_compress_ptr cinfo, char *arg) /* Process a quantization-table-selectors parameter string, of the form * N[,N,...] * If there are more components than parameters, the last value is replicated. */ { … } GLOBAL(boolean) set_sample_factors(j_compress_ptr cinfo, char *arg) /* Process a sample-factors parameter string, of the form * HxV[,HxV,...] * If there are more components than parameters, "1x1" is assumed for the rest. */ { … }