Final 350 project
Dependencies: uzair Camera_LS_Y201 F7_Ethernet LCD_DISCO_F746NG NetworkAPI SDFileSystem mbed
includes/rdswitch.c@0:791a779d6220, 2017-07-31 (annotated)
- Committer:
- shoaib_ahmed
- Date:
- Mon Jul 31 09:16:35 2017 +0000
- Revision:
- 0:791a779d6220
final project;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
shoaib_ahmed | 0:791a779d6220 | 1 | /* |
shoaib_ahmed | 0:791a779d6220 | 2 | * rdswitch.c |
shoaib_ahmed | 0:791a779d6220 | 3 | * |
shoaib_ahmed | 0:791a779d6220 | 4 | * Copyright (C) 1991-1996, Thomas G. Lane. |
shoaib_ahmed | 0:791a779d6220 | 5 | * Modified 2003-2015 by Guido Vollbeding. |
shoaib_ahmed | 0:791a779d6220 | 6 | * This file is part of the Independent JPEG Group's software. |
shoaib_ahmed | 0:791a779d6220 | 7 | * For conditions of distribution and use, see the accompanying README file. |
shoaib_ahmed | 0:791a779d6220 | 8 | * |
shoaib_ahmed | 0:791a779d6220 | 9 | * This file contains routines to process some of cjpeg's more complicated |
shoaib_ahmed | 0:791a779d6220 | 10 | * command-line switches. Switches processed here are: |
shoaib_ahmed | 0:791a779d6220 | 11 | * -qtables file Read quantization tables from text file |
shoaib_ahmed | 0:791a779d6220 | 12 | * -scans file Read scan script from text file |
shoaib_ahmed | 0:791a779d6220 | 13 | * -quality N[,N,...] Set quality ratings |
shoaib_ahmed | 0:791a779d6220 | 14 | * -qslots N[,N,...] Set component quantization table selectors |
shoaib_ahmed | 0:791a779d6220 | 15 | * -sample HxV[,HxV,...] Set component sampling factors |
shoaib_ahmed | 0:791a779d6220 | 16 | */ |
shoaib_ahmed | 0:791a779d6220 | 17 | |
shoaib_ahmed | 0:791a779d6220 | 18 | #include "cdjpeg.h" /* Common decls for cjpeg/djpeg applications */ |
shoaib_ahmed | 0:791a779d6220 | 19 | #include <ctype.h> /* to declare isdigit(), isspace() */ |
shoaib_ahmed | 0:791a779d6220 | 20 | |
shoaib_ahmed | 0:791a779d6220 | 21 | |
shoaib_ahmed | 0:791a779d6220 | 22 | LOCAL(int) |
shoaib_ahmed | 0:791a779d6220 | 23 | text_getc (FILE * file) |
shoaib_ahmed | 0:791a779d6220 | 24 | /* Read next char, skipping over any comments (# to end of line) */ |
shoaib_ahmed | 0:791a779d6220 | 25 | /* A comment/newline sequence is returned as a newline */ |
shoaib_ahmed | 0:791a779d6220 | 26 | { |
shoaib_ahmed | 0:791a779d6220 | 27 | register int ch; |
shoaib_ahmed | 0:791a779d6220 | 28 | |
shoaib_ahmed | 0:791a779d6220 | 29 | ch = getc(file); |
shoaib_ahmed | 0:791a779d6220 | 30 | if (ch == '#') { |
shoaib_ahmed | 0:791a779d6220 | 31 | do { |
shoaib_ahmed | 0:791a779d6220 | 32 | ch = getc(file); |
shoaib_ahmed | 0:791a779d6220 | 33 | } while (ch != '\n' && ch != EOF); |
shoaib_ahmed | 0:791a779d6220 | 34 | } |
shoaib_ahmed | 0:791a779d6220 | 35 | return ch; |
shoaib_ahmed | 0:791a779d6220 | 36 | } |
shoaib_ahmed | 0:791a779d6220 | 37 | |
shoaib_ahmed | 0:791a779d6220 | 38 | |
shoaib_ahmed | 0:791a779d6220 | 39 | LOCAL(boolean) |
shoaib_ahmed | 0:791a779d6220 | 40 | read_text_integer (FILE * file, long * result, int * termchar) |
shoaib_ahmed | 0:791a779d6220 | 41 | /* Read an unsigned decimal integer from a file, store it in result */ |
shoaib_ahmed | 0:791a779d6220 | 42 | /* Reads one trailing character after the integer; returns it in termchar */ |
shoaib_ahmed | 0:791a779d6220 | 43 | { |
shoaib_ahmed | 0:791a779d6220 | 44 | register int ch; |
shoaib_ahmed | 0:791a779d6220 | 45 | register long val; |
shoaib_ahmed | 0:791a779d6220 | 46 | |
shoaib_ahmed | 0:791a779d6220 | 47 | /* Skip any leading whitespace, detect EOF */ |
shoaib_ahmed | 0:791a779d6220 | 48 | do { |
shoaib_ahmed | 0:791a779d6220 | 49 | ch = text_getc(file); |
shoaib_ahmed | 0:791a779d6220 | 50 | if (ch == EOF) { |
shoaib_ahmed | 0:791a779d6220 | 51 | *termchar = ch; |
shoaib_ahmed | 0:791a779d6220 | 52 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 53 | } |
shoaib_ahmed | 0:791a779d6220 | 54 | } while (isspace(ch)); |
shoaib_ahmed | 0:791a779d6220 | 55 | |
shoaib_ahmed | 0:791a779d6220 | 56 | if (! isdigit(ch)) { |
shoaib_ahmed | 0:791a779d6220 | 57 | *termchar = ch; |
shoaib_ahmed | 0:791a779d6220 | 58 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 59 | } |
shoaib_ahmed | 0:791a779d6220 | 60 | |
shoaib_ahmed | 0:791a779d6220 | 61 | val = ch - '0'; |
shoaib_ahmed | 0:791a779d6220 | 62 | while ((ch = text_getc(file)) != EOF) { |
shoaib_ahmed | 0:791a779d6220 | 63 | if (! isdigit(ch)) |
shoaib_ahmed | 0:791a779d6220 | 64 | break; |
shoaib_ahmed | 0:791a779d6220 | 65 | val *= 10; |
shoaib_ahmed | 0:791a779d6220 | 66 | val += ch - '0'; |
shoaib_ahmed | 0:791a779d6220 | 67 | } |
shoaib_ahmed | 0:791a779d6220 | 68 | *result = val; |
shoaib_ahmed | 0:791a779d6220 | 69 | *termchar = ch; |
shoaib_ahmed | 0:791a779d6220 | 70 | return TRUE; |
shoaib_ahmed | 0:791a779d6220 | 71 | } |
shoaib_ahmed | 0:791a779d6220 | 72 | |
shoaib_ahmed | 0:791a779d6220 | 73 | |
shoaib_ahmed | 0:791a779d6220 | 74 | GLOBAL(boolean) |
shoaib_ahmed | 0:791a779d6220 | 75 | read_quant_tables (j_compress_ptr cinfo, char * filename, boolean force_baseline) |
shoaib_ahmed | 0:791a779d6220 | 76 | /* Read a set of quantization tables from the specified file. |
shoaib_ahmed | 0:791a779d6220 | 77 | * The file is plain ASCII text: decimal numbers with whitespace between. |
shoaib_ahmed | 0:791a779d6220 | 78 | * Comments preceded by '#' may be included in the file. |
shoaib_ahmed | 0:791a779d6220 | 79 | * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values. |
shoaib_ahmed | 0:791a779d6220 | 80 | * The tables are implicitly numbered 0,1,etc. |
shoaib_ahmed | 0:791a779d6220 | 81 | * NOTE: does not affect the qslots mapping, which will default to selecting |
shoaib_ahmed | 0:791a779d6220 | 82 | * table 0 for luminance (or primary) components, 1 for chrominance components. |
shoaib_ahmed | 0:791a779d6220 | 83 | * You must use -qslots if you want a different component->table mapping. |
shoaib_ahmed | 0:791a779d6220 | 84 | */ |
shoaib_ahmed | 0:791a779d6220 | 85 | { |
shoaib_ahmed | 0:791a779d6220 | 86 | FILE * fp; |
shoaib_ahmed | 0:791a779d6220 | 87 | int tblno, i, termchar; |
shoaib_ahmed | 0:791a779d6220 | 88 | long val; |
shoaib_ahmed | 0:791a779d6220 | 89 | unsigned int table[DCTSIZE2]; |
shoaib_ahmed | 0:791a779d6220 | 90 | |
shoaib_ahmed | 0:791a779d6220 | 91 | if ((fp = fopen(filename, "r")) == NULL) { |
shoaib_ahmed | 0:791a779d6220 | 92 | fprintf(stderr, "Can't open table file %s\n", filename); |
shoaib_ahmed | 0:791a779d6220 | 93 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 94 | } |
shoaib_ahmed | 0:791a779d6220 | 95 | tblno = 0; |
shoaib_ahmed | 0:791a779d6220 | 96 | |
shoaib_ahmed | 0:791a779d6220 | 97 | while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */ |
shoaib_ahmed | 0:791a779d6220 | 98 | if (tblno >= NUM_QUANT_TBLS) { |
shoaib_ahmed | 0:791a779d6220 | 99 | fprintf(stderr, "Too many tables in file %s\n", filename); |
shoaib_ahmed | 0:791a779d6220 | 100 | fclose(fp); |
shoaib_ahmed | 0:791a779d6220 | 101 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 102 | } |
shoaib_ahmed | 0:791a779d6220 | 103 | table[0] = (unsigned int) val; |
shoaib_ahmed | 0:791a779d6220 | 104 | for (i = 1; i < DCTSIZE2; i++) { |
shoaib_ahmed | 0:791a779d6220 | 105 | if (! read_text_integer(fp, &val, &termchar)) { |
shoaib_ahmed | 0:791a779d6220 | 106 | fprintf(stderr, "Invalid table data in file %s\n", filename); |
shoaib_ahmed | 0:791a779d6220 | 107 | fclose(fp); |
shoaib_ahmed | 0:791a779d6220 | 108 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 109 | } |
shoaib_ahmed | 0:791a779d6220 | 110 | table[i] = (unsigned int) val; |
shoaib_ahmed | 0:791a779d6220 | 111 | } |
shoaib_ahmed | 0:791a779d6220 | 112 | jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno], |
shoaib_ahmed | 0:791a779d6220 | 113 | force_baseline); |
shoaib_ahmed | 0:791a779d6220 | 114 | tblno++; |
shoaib_ahmed | 0:791a779d6220 | 115 | } |
shoaib_ahmed | 0:791a779d6220 | 116 | |
shoaib_ahmed | 0:791a779d6220 | 117 | if (termchar != EOF) { |
shoaib_ahmed | 0:791a779d6220 | 118 | fprintf(stderr, "Non-numeric data in file %s\n", filename); |
shoaib_ahmed | 0:791a779d6220 | 119 | fclose(fp); |
shoaib_ahmed | 0:791a779d6220 | 120 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 121 | } |
shoaib_ahmed | 0:791a779d6220 | 122 | |
shoaib_ahmed | 0:791a779d6220 | 123 | fclose(fp); |
shoaib_ahmed | 0:791a779d6220 | 124 | return TRUE; |
shoaib_ahmed | 0:791a779d6220 | 125 | } |
shoaib_ahmed | 0:791a779d6220 | 126 | |
shoaib_ahmed | 0:791a779d6220 | 127 | |
shoaib_ahmed | 0:791a779d6220 | 128 | #ifdef C_MULTISCAN_FILES_SUPPORTED |
shoaib_ahmed | 0:791a779d6220 | 129 | |
shoaib_ahmed | 0:791a779d6220 | 130 | LOCAL(boolean) |
shoaib_ahmed | 0:791a779d6220 | 131 | read_scan_integer (FILE * file, long * result, int * termchar) |
shoaib_ahmed | 0:791a779d6220 | 132 | /* Variant of read_text_integer that always looks for a non-space termchar; |
shoaib_ahmed | 0:791a779d6220 | 133 | * this simplifies parsing of punctuation in scan scripts. |
shoaib_ahmed | 0:791a779d6220 | 134 | */ |
shoaib_ahmed | 0:791a779d6220 | 135 | { |
shoaib_ahmed | 0:791a779d6220 | 136 | register int ch; |
shoaib_ahmed | 0:791a779d6220 | 137 | |
shoaib_ahmed | 0:791a779d6220 | 138 | if (! read_text_integer(file, result, termchar)) |
shoaib_ahmed | 0:791a779d6220 | 139 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 140 | ch = *termchar; |
shoaib_ahmed | 0:791a779d6220 | 141 | while (ch != EOF && isspace(ch)) |
shoaib_ahmed | 0:791a779d6220 | 142 | ch = text_getc(file); |
shoaib_ahmed | 0:791a779d6220 | 143 | if (isdigit(ch)) { /* oops, put it back */ |
shoaib_ahmed | 0:791a779d6220 | 144 | if (ungetc(ch, file) == EOF) |
shoaib_ahmed | 0:791a779d6220 | 145 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 146 | ch = ' '; |
shoaib_ahmed | 0:791a779d6220 | 147 | } else { |
shoaib_ahmed | 0:791a779d6220 | 148 | /* Any separators other than ';' and ':' are ignored; |
shoaib_ahmed | 0:791a779d6220 | 149 | * this allows user to insert commas, etc, if desired. |
shoaib_ahmed | 0:791a779d6220 | 150 | */ |
shoaib_ahmed | 0:791a779d6220 | 151 | if (ch != EOF && ch != ';' && ch != ':') |
shoaib_ahmed | 0:791a779d6220 | 152 | ch = ' '; |
shoaib_ahmed | 0:791a779d6220 | 153 | } |
shoaib_ahmed | 0:791a779d6220 | 154 | *termchar = ch; |
shoaib_ahmed | 0:791a779d6220 | 155 | return TRUE; |
shoaib_ahmed | 0:791a779d6220 | 156 | } |
shoaib_ahmed | 0:791a779d6220 | 157 | |
shoaib_ahmed | 0:791a779d6220 | 158 | |
shoaib_ahmed | 0:791a779d6220 | 159 | GLOBAL(boolean) |
shoaib_ahmed | 0:791a779d6220 | 160 | read_scan_script (j_compress_ptr cinfo, char * filename) |
shoaib_ahmed | 0:791a779d6220 | 161 | /* Read a scan script from the specified text file. |
shoaib_ahmed | 0:791a779d6220 | 162 | * Each entry in the file defines one scan to be emitted. |
shoaib_ahmed | 0:791a779d6220 | 163 | * Entries are separated by semicolons ';'. |
shoaib_ahmed | 0:791a779d6220 | 164 | * An entry contains one to four component indexes, |
shoaib_ahmed | 0:791a779d6220 | 165 | * optionally followed by a colon ':' and four progressive-JPEG parameters. |
shoaib_ahmed | 0:791a779d6220 | 166 | * The component indexes denote which component(s) are to be transmitted |
shoaib_ahmed | 0:791a779d6220 | 167 | * in the current scan. The first component has index 0. |
shoaib_ahmed | 0:791a779d6220 | 168 | * Sequential JPEG is used if the progressive-JPEG parameters are omitted. |
shoaib_ahmed | 0:791a779d6220 | 169 | * The file is free format text: any whitespace may appear between numbers |
shoaib_ahmed | 0:791a779d6220 | 170 | * and the ':' and ';' punctuation marks. Also, other punctuation (such |
shoaib_ahmed | 0:791a779d6220 | 171 | * as commas or dashes) can be placed between numbers if desired. |
shoaib_ahmed | 0:791a779d6220 | 172 | * Comments preceded by '#' may be included in the file. |
shoaib_ahmed | 0:791a779d6220 | 173 | * Note: we do very little validity checking here; |
shoaib_ahmed | 0:791a779d6220 | 174 | * jcmaster.c will validate the script parameters. |
shoaib_ahmed | 0:791a779d6220 | 175 | */ |
shoaib_ahmed | 0:791a779d6220 | 176 | { |
shoaib_ahmed | 0:791a779d6220 | 177 | FILE * fp; |
shoaib_ahmed | 0:791a779d6220 | 178 | int scanno, ncomps, termchar; |
shoaib_ahmed | 0:791a779d6220 | 179 | long val; |
shoaib_ahmed | 0:791a779d6220 | 180 | jpeg_scan_info * scanptr; |
shoaib_ahmed | 0:791a779d6220 | 181 | #define MAX_SCANS 100 /* quite arbitrary limit */ |
shoaib_ahmed | 0:791a779d6220 | 182 | jpeg_scan_info scans[MAX_SCANS]; |
shoaib_ahmed | 0:791a779d6220 | 183 | |
shoaib_ahmed | 0:791a779d6220 | 184 | if ((fp = fopen(filename, "r")) == NULL) { |
shoaib_ahmed | 0:791a779d6220 | 185 | fprintf(stderr, "Can't open scan definition file %s\n", filename); |
shoaib_ahmed | 0:791a779d6220 | 186 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 187 | } |
shoaib_ahmed | 0:791a779d6220 | 188 | scanptr = scans; |
shoaib_ahmed | 0:791a779d6220 | 189 | scanno = 0; |
shoaib_ahmed | 0:791a779d6220 | 190 | |
shoaib_ahmed | 0:791a779d6220 | 191 | while (read_scan_integer(fp, &val, &termchar)) { |
shoaib_ahmed | 0:791a779d6220 | 192 | if (scanno >= MAX_SCANS) { |
shoaib_ahmed | 0:791a779d6220 | 193 | fprintf(stderr, "Too many scans defined in file %s\n", filename); |
shoaib_ahmed | 0:791a779d6220 | 194 | fclose(fp); |
shoaib_ahmed | 0:791a779d6220 | 195 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 196 | } |
shoaib_ahmed | 0:791a779d6220 | 197 | scanptr->component_index[0] = (int) val; |
shoaib_ahmed | 0:791a779d6220 | 198 | ncomps = 1; |
shoaib_ahmed | 0:791a779d6220 | 199 | while (termchar == ' ') { |
shoaib_ahmed | 0:791a779d6220 | 200 | if (ncomps >= MAX_COMPS_IN_SCAN) { |
shoaib_ahmed | 0:791a779d6220 | 201 | fprintf(stderr, "Too many components in one scan in file %s\n", |
shoaib_ahmed | 0:791a779d6220 | 202 | filename); |
shoaib_ahmed | 0:791a779d6220 | 203 | fclose(fp); |
shoaib_ahmed | 0:791a779d6220 | 204 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 205 | } |
shoaib_ahmed | 0:791a779d6220 | 206 | if (! read_scan_integer(fp, &val, &termchar)) |
shoaib_ahmed | 0:791a779d6220 | 207 | goto bogus; |
shoaib_ahmed | 0:791a779d6220 | 208 | scanptr->component_index[ncomps] = (int) val; |
shoaib_ahmed | 0:791a779d6220 | 209 | ncomps++; |
shoaib_ahmed | 0:791a779d6220 | 210 | } |
shoaib_ahmed | 0:791a779d6220 | 211 | scanptr->comps_in_scan = ncomps; |
shoaib_ahmed | 0:791a779d6220 | 212 | if (termchar == ':') { |
shoaib_ahmed | 0:791a779d6220 | 213 | if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') |
shoaib_ahmed | 0:791a779d6220 | 214 | goto bogus; |
shoaib_ahmed | 0:791a779d6220 | 215 | scanptr->Ss = (int) val; |
shoaib_ahmed | 0:791a779d6220 | 216 | if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') |
shoaib_ahmed | 0:791a779d6220 | 217 | goto bogus; |
shoaib_ahmed | 0:791a779d6220 | 218 | scanptr->Se = (int) val; |
shoaib_ahmed | 0:791a779d6220 | 219 | if (! read_scan_integer(fp, &val, &termchar) || termchar != ' ') |
shoaib_ahmed | 0:791a779d6220 | 220 | goto bogus; |
shoaib_ahmed | 0:791a779d6220 | 221 | scanptr->Ah = (int) val; |
shoaib_ahmed | 0:791a779d6220 | 222 | if (! read_scan_integer(fp, &val, &termchar)) |
shoaib_ahmed | 0:791a779d6220 | 223 | goto bogus; |
shoaib_ahmed | 0:791a779d6220 | 224 | scanptr->Al = (int) val; |
shoaib_ahmed | 0:791a779d6220 | 225 | } else { |
shoaib_ahmed | 0:791a779d6220 | 226 | /* set non-progressive parameters */ |
shoaib_ahmed | 0:791a779d6220 | 227 | scanptr->Ss = 0; |
shoaib_ahmed | 0:791a779d6220 | 228 | scanptr->Se = DCTSIZE2-1; |
shoaib_ahmed | 0:791a779d6220 | 229 | scanptr->Ah = 0; |
shoaib_ahmed | 0:791a779d6220 | 230 | scanptr->Al = 0; |
shoaib_ahmed | 0:791a779d6220 | 231 | } |
shoaib_ahmed | 0:791a779d6220 | 232 | if (termchar != ';' && termchar != EOF) { |
shoaib_ahmed | 0:791a779d6220 | 233 | bogus: |
shoaib_ahmed | 0:791a779d6220 | 234 | fprintf(stderr, "Invalid scan entry format in file %s\n", filename); |
shoaib_ahmed | 0:791a779d6220 | 235 | fclose(fp); |
shoaib_ahmed | 0:791a779d6220 | 236 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 237 | } |
shoaib_ahmed | 0:791a779d6220 | 238 | scanptr++, scanno++; |
shoaib_ahmed | 0:791a779d6220 | 239 | } |
shoaib_ahmed | 0:791a779d6220 | 240 | |
shoaib_ahmed | 0:791a779d6220 | 241 | if (termchar != EOF) { |
shoaib_ahmed | 0:791a779d6220 | 242 | fprintf(stderr, "Non-numeric data in file %s\n", filename); |
shoaib_ahmed | 0:791a779d6220 | 243 | fclose(fp); |
shoaib_ahmed | 0:791a779d6220 | 244 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 245 | } |
shoaib_ahmed | 0:791a779d6220 | 246 | |
shoaib_ahmed | 0:791a779d6220 | 247 | if (scanno > 0) { |
shoaib_ahmed | 0:791a779d6220 | 248 | /* Stash completed scan list in cinfo structure. |
shoaib_ahmed | 0:791a779d6220 | 249 | * NOTE: for cjpeg's use, JPOOL_IMAGE is the right lifetime for this data, |
shoaib_ahmed | 0:791a779d6220 | 250 | * but if you want to compress multiple images you'd want JPOOL_PERMANENT. |
shoaib_ahmed | 0:791a779d6220 | 251 | */ |
shoaib_ahmed | 0:791a779d6220 | 252 | scanptr = (jpeg_scan_info *) |
shoaib_ahmed | 0:791a779d6220 | 253 | (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, |
shoaib_ahmed | 0:791a779d6220 | 254 | scanno * SIZEOF(jpeg_scan_info)); |
shoaib_ahmed | 0:791a779d6220 | 255 | MEMCOPY(scanptr, scans, scanno * SIZEOF(jpeg_scan_info)); |
shoaib_ahmed | 0:791a779d6220 | 256 | cinfo->scan_info = scanptr; |
shoaib_ahmed | 0:791a779d6220 | 257 | cinfo->num_scans = scanno; |
shoaib_ahmed | 0:791a779d6220 | 258 | } |
shoaib_ahmed | 0:791a779d6220 | 259 | |
shoaib_ahmed | 0:791a779d6220 | 260 | fclose(fp); |
shoaib_ahmed | 0:791a779d6220 | 261 | return TRUE; |
shoaib_ahmed | 0:791a779d6220 | 262 | } |
shoaib_ahmed | 0:791a779d6220 | 263 | |
shoaib_ahmed | 0:791a779d6220 | 264 | #endif /* C_MULTISCAN_FILES_SUPPORTED */ |
shoaib_ahmed | 0:791a779d6220 | 265 | |
shoaib_ahmed | 0:791a779d6220 | 266 | |
shoaib_ahmed | 0:791a779d6220 | 267 | GLOBAL(boolean) |
shoaib_ahmed | 0:791a779d6220 | 268 | set_quality_ratings (j_compress_ptr cinfo, char *arg, boolean force_baseline) |
shoaib_ahmed | 0:791a779d6220 | 269 | /* Process a quality-ratings parameter string, of the form |
shoaib_ahmed | 0:791a779d6220 | 270 | * N[,N,...] |
shoaib_ahmed | 0:791a779d6220 | 271 | * If there are more q-table slots than parameters, the last value is replicated. |
shoaib_ahmed | 0:791a779d6220 | 272 | */ |
shoaib_ahmed | 0:791a779d6220 | 273 | { |
shoaib_ahmed | 0:791a779d6220 | 274 | int val = 75; /* default value */ |
shoaib_ahmed | 0:791a779d6220 | 275 | int tblno; |
shoaib_ahmed | 0:791a779d6220 | 276 | char ch; |
shoaib_ahmed | 0:791a779d6220 | 277 | |
shoaib_ahmed | 0:791a779d6220 | 278 | for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) { |
shoaib_ahmed | 0:791a779d6220 | 279 | if (*arg) { |
shoaib_ahmed | 0:791a779d6220 | 280 | ch = ','; /* if not set by sscanf, will be ',' */ |
shoaib_ahmed | 0:791a779d6220 | 281 | if (sscanf(arg, "%d%c", &val, &ch) < 1) |
shoaib_ahmed | 0:791a779d6220 | 282 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 283 | if (ch != ',') /* syntax check */ |
shoaib_ahmed | 0:791a779d6220 | 284 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 285 | /* Convert user 0-100 rating to percentage scaling */ |
shoaib_ahmed | 0:791a779d6220 | 286 | cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); |
shoaib_ahmed | 0:791a779d6220 | 287 | while (*arg && *arg++ != ',') /* advance to next segment of arg string */ |
shoaib_ahmed | 0:791a779d6220 | 288 | ; |
shoaib_ahmed | 0:791a779d6220 | 289 | } else { |
shoaib_ahmed | 0:791a779d6220 | 290 | /* reached end of parameter, set remaining factors to last value */ |
shoaib_ahmed | 0:791a779d6220 | 291 | cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val); |
shoaib_ahmed | 0:791a779d6220 | 292 | } |
shoaib_ahmed | 0:791a779d6220 | 293 | } |
shoaib_ahmed | 0:791a779d6220 | 294 | jpeg_default_qtables(cinfo, force_baseline); |
shoaib_ahmed | 0:791a779d6220 | 295 | return TRUE; |
shoaib_ahmed | 0:791a779d6220 | 296 | } |
shoaib_ahmed | 0:791a779d6220 | 297 | |
shoaib_ahmed | 0:791a779d6220 | 298 | |
shoaib_ahmed | 0:791a779d6220 | 299 | GLOBAL(boolean) |
shoaib_ahmed | 0:791a779d6220 | 300 | set_quant_slots (j_compress_ptr cinfo, char *arg) |
shoaib_ahmed | 0:791a779d6220 | 301 | /* Process a quantization-table-selectors parameter string, of the form |
shoaib_ahmed | 0:791a779d6220 | 302 | * N[,N,...] |
shoaib_ahmed | 0:791a779d6220 | 303 | * If there are more components than parameters, the last value is replicated. |
shoaib_ahmed | 0:791a779d6220 | 304 | */ |
shoaib_ahmed | 0:791a779d6220 | 305 | { |
shoaib_ahmed | 0:791a779d6220 | 306 | int val = 0; /* default table # */ |
shoaib_ahmed | 0:791a779d6220 | 307 | int ci; |
shoaib_ahmed | 0:791a779d6220 | 308 | char ch; |
shoaib_ahmed | 0:791a779d6220 | 309 | |
shoaib_ahmed | 0:791a779d6220 | 310 | for (ci = 0; ci < MAX_COMPONENTS; ci++) { |
shoaib_ahmed | 0:791a779d6220 | 311 | if (*arg) { |
shoaib_ahmed | 0:791a779d6220 | 312 | ch = ','; /* if not set by sscanf, will be ',' */ |
shoaib_ahmed | 0:791a779d6220 | 313 | if (sscanf(arg, "%d%c", &val, &ch) < 1) |
shoaib_ahmed | 0:791a779d6220 | 314 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 315 | if (ch != ',') /* syntax check */ |
shoaib_ahmed | 0:791a779d6220 | 316 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 317 | if (val < 0 || val >= NUM_QUANT_TBLS) { |
shoaib_ahmed | 0:791a779d6220 | 318 | fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n", |
shoaib_ahmed | 0:791a779d6220 | 319 | NUM_QUANT_TBLS-1); |
shoaib_ahmed | 0:791a779d6220 | 320 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 321 | } |
shoaib_ahmed | 0:791a779d6220 | 322 | cinfo->comp_info[ci].quant_tbl_no = val; |
shoaib_ahmed | 0:791a779d6220 | 323 | while (*arg && *arg++ != ',') /* advance to next segment of arg string */ |
shoaib_ahmed | 0:791a779d6220 | 324 | ; |
shoaib_ahmed | 0:791a779d6220 | 325 | } else { |
shoaib_ahmed | 0:791a779d6220 | 326 | /* reached end of parameter, set remaining components to last table */ |
shoaib_ahmed | 0:791a779d6220 | 327 | cinfo->comp_info[ci].quant_tbl_no = val; |
shoaib_ahmed | 0:791a779d6220 | 328 | } |
shoaib_ahmed | 0:791a779d6220 | 329 | } |
shoaib_ahmed | 0:791a779d6220 | 330 | return TRUE; |
shoaib_ahmed | 0:791a779d6220 | 331 | } |
shoaib_ahmed | 0:791a779d6220 | 332 | |
shoaib_ahmed | 0:791a779d6220 | 333 | |
shoaib_ahmed | 0:791a779d6220 | 334 | GLOBAL(boolean) |
shoaib_ahmed | 0:791a779d6220 | 335 | set_sample_factors (j_compress_ptr cinfo, char *arg) |
shoaib_ahmed | 0:791a779d6220 | 336 | /* Process a sample-factors parameter string, of the form |
shoaib_ahmed | 0:791a779d6220 | 337 | * HxV[,HxV,...] |
shoaib_ahmed | 0:791a779d6220 | 338 | * If there are more components than parameters, "1x1" is assumed for the rest. |
shoaib_ahmed | 0:791a779d6220 | 339 | */ |
shoaib_ahmed | 0:791a779d6220 | 340 | { |
shoaib_ahmed | 0:791a779d6220 | 341 | int ci, val1, val2; |
shoaib_ahmed | 0:791a779d6220 | 342 | char ch1, ch2; |
shoaib_ahmed | 0:791a779d6220 | 343 | |
shoaib_ahmed | 0:791a779d6220 | 344 | for (ci = 0; ci < MAX_COMPONENTS; ci++) { |
shoaib_ahmed | 0:791a779d6220 | 345 | if (*arg) { |
shoaib_ahmed | 0:791a779d6220 | 346 | ch2 = ','; /* if not set by sscanf, will be ',' */ |
shoaib_ahmed | 0:791a779d6220 | 347 | if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3) |
shoaib_ahmed | 0:791a779d6220 | 348 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 349 | if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */ |
shoaib_ahmed | 0:791a779d6220 | 350 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 351 | if (val1 <= 0 || val1 > MAX_SAMP_FACTOR || |
shoaib_ahmed | 0:791a779d6220 | 352 | val2 <= 0 || val2 > MAX_SAMP_FACTOR) { |
shoaib_ahmed | 0:791a779d6220 | 353 | fprintf(stderr, "JPEG sampling factors must be 1..%d\n", MAX_SAMP_FACTOR); |
shoaib_ahmed | 0:791a779d6220 | 354 | return FALSE; |
shoaib_ahmed | 0:791a779d6220 | 355 | } |
shoaib_ahmed | 0:791a779d6220 | 356 | cinfo->comp_info[ci].h_samp_factor = val1; |
shoaib_ahmed | 0:791a779d6220 | 357 | cinfo->comp_info[ci].v_samp_factor = val2; |
shoaib_ahmed | 0:791a779d6220 | 358 | while (*arg && *arg++ != ',') /* advance to next segment of arg string */ |
shoaib_ahmed | 0:791a779d6220 | 359 | ; |
shoaib_ahmed | 0:791a779d6220 | 360 | } else { |
shoaib_ahmed | 0:791a779d6220 | 361 | /* reached end of parameter, set remaining components to 1x1 sampling */ |
shoaib_ahmed | 0:791a779d6220 | 362 | cinfo->comp_info[ci].h_samp_factor = 1; |
shoaib_ahmed | 0:791a779d6220 | 363 | cinfo->comp_info[ci].v_samp_factor = 1; |
shoaib_ahmed | 0:791a779d6220 | 364 | } |
shoaib_ahmed | 0:791a779d6220 | 365 | } |
shoaib_ahmed | 0:791a779d6220 | 366 | return TRUE; |
shoaib_ahmed | 0:791a779d6220 | 367 | } |