rdswitch.c File Reference

#include "cdjpeg.h"
#include <ctype.h>

Go to the source code of this file.

Functions

 read_quant_tables (j_compress_ptr cinfo, char *filename, int scale_factor, boolean force_baseline)
 read_text_integer (FILE *file, long *result, int *termchar)
 set_quant_slots (j_compress_ptr cinfo, char *arg)
 set_sample_factors (j_compress_ptr cinfo, char *arg)
 text_getc (FILE *file)


Function Documentation

read_quant_tables ( j_compress_ptr  cinfo,
char *  filename,
int  scale_factor,
boolean  force_baseline 
)

Definition at line 73 of file rdswitch.c.

References DCTSIZE2, FALSE, jpeg_add_quant_table(), NUM_QUANT_TBLS, read_text_integer(), tblno, TRUE, and val.

Referenced by parse_switches().

00076                                : decimal numbers with whitespace between.
00077  * Comments preceded by '#' may be included in the file.
00078  * There may be one to NUM_QUANT_TBLS tables in the file, each of 64 values.
00079  * The tables are implicitly numbered 0,1,etc.
00080  * NOTE: does not affect the qslots mapping, which will default to selecting
00081  * table 0 for luminance (or primary) components, 1 for chrominance components.
00082  * You must use -qslots if you want a different component->table mapping.
00083  */
00084 {
00085   FILE * fp;
00086   int tblno, i, termchar;
00087   long val;
00088   unsigned int table[DCTSIZE2];
00089 
00090   if ((fp = fopen(filename, "r")) == NULL) {
00091     fprintf(stderr, "Can't open table file %s\n", filename);
00092     return FALSE;
00093   }
00094   tblno = 0;
00095 
00096   while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */
00097     if (tblno >= NUM_QUANT_TBLS) {
00098       fprintf(stderr, "Too many tables in file %s\n", filename);
00099       fclose(fp);
00100       return FALSE;
00101     }
00102     table[0] = (unsigned int) val;
00103     for (i = 1; i < DCTSIZE2; i++) {
00104       if (! read_text_integer(fp, &val, &termchar)) {
00105     fprintf(stderr, "Invalid table data in file %s\n", filename);
00106     fclose(fp);
00107     return FALSE;
00108       }
00109       table[i] = (unsigned int) val;
00110     }
00111     jpeg_add_quant_table(cinfo, tblno, table, scale_factor, force_baseline);
00112     tblno++;
00113   }
00114 
00115   if (termchar != EOF) {
00116     fprintf(stderr, "Non-numeric data in file %s\n", filename);
00117     fclose(fp);
00118     return FALSE;
00119   }
00120 
00121   fclose(fp);
00122   return TRUE;
00123 }

read_text_integer ( FILE *  file,
long *  result,
int *  termchar 
)

Definition at line 38 of file rdswitch.c.

References FALSE, text_getc(), TRUE, and val.

Referenced by read_quant_tables().

00041 {
00042   register int ch;
00043   register long val;
00044   
00045   /* Skip any leading whitespace, detect EOF */
00046   do {
00047     ch = text_getc(file);
00048     if (ch == EOF) {
00049       *termchar = ch;
00050       return FALSE;
00051     }
00052   } while (isspace(ch));
00053   
00054   if (! isdigit(ch)) {
00055     *termchar = ch;
00056     return FALSE;
00057   }
00058 
00059   val = ch - '0';
00060   while ((ch = text_getc(file)) != EOF) {
00061     if (! isdigit(ch))
00062       break;
00063     val *= 10;
00064     val += ch - '0';
00065   }
00066   *result = val;
00067   *termchar = ch;
00068   return TRUE;
00069 }

set_quant_slots ( j_compress_ptr  cinfo,
char *  arg 
)

Definition at line 266 of file rdswitch.c.

References FALSE, MAX_COMPONENTS, NUM_QUANT_TBLS, and TRUE.

Referenced by parse_switches().

00271 {
00272   int val = 0;          /* default table # */
00273   int ci;
00274   char ch;
00275 
00276   for (ci = 0; ci < MAX_COMPONENTS; ci++) {
00277     if (*arg) {
00278       ch = ',';         /* if not set by sscanf, will be ',' */
00279       if (sscanf(arg, "%d%c", &val, &ch) < 1)
00280     return FALSE;
00281       if (ch != ',')        /* syntax check */
00282     return FALSE;
00283       if (val < 0 || val >= NUM_QUANT_TBLS) {
00284     fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n",
00285         NUM_QUANT_TBLS-1);
00286     return FALSE;
00287       }
00288       cinfo->comp_info[ci].quant_tbl_no = val;
00289       while (*arg && *arg++ != ',') /* advance to next segment of arg string */
00290     ;
00291     } else {
00292       /* reached end of parameter, set remaining components to last table */
00293       cinfo->comp_info[ci].quant_tbl_no = val;
00294     }
00295   }
00296   return TRUE;
00297 }

set_sample_factors ( j_compress_ptr  cinfo,
char *  arg 
)

Definition at line 301 of file rdswitch.c.

References FALSE, MAX_COMPONENTS, and TRUE.

Referenced by parse_switches().

00306 {
00307   int ci, val1, val2;
00308   char ch1, ch2;
00309 
00310   for (ci = 0; ci < MAX_COMPONENTS; ci++) {
00311     if (*arg) {
00312       ch2 = ',';        /* if not set by sscanf, will be ',' */
00313       if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3)
00314     return FALSE;
00315       if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */
00316     return FALSE;
00317       if (val1 <= 0 || val1 > 4 || val2 <= 0 || val2 > 4) {
00318     fprintf(stderr, "JPEG sampling factors must be 1..4\n");
00319     return FALSE;
00320       }
00321       cinfo->comp_info[ci].h_samp_factor = val1;
00322       cinfo->comp_info[ci].v_samp_factor = val2;
00323       while (*arg && *arg++ != ',') /* advance to next segment of arg string */
00324     ;
00325     } else {
00326       /* reached end of parameter, set remaining components to 1x1 sampling */
00327       cinfo->comp_info[ci].h_samp_factor = 1;
00328       cinfo->comp_info[ci].v_samp_factor = 1;
00329     }
00330   }
00331   return TRUE;
00332 }

text_getc ( FILE *  file  ) 

Definition at line 21 of file rdswitch.c.

Referenced by read_text_integer().

00024 {
00025   register int ch;
00026   
00027   ch = getc(file);
00028   if (ch == '#') {
00029     do {
00030       ch = getc(file);
00031     } while (ch != '\n' && ch != EOF);
00032   }
00033   return ch;
00034 }


Generated on Fri Feb 19 02:31:05 2010 for AVR32 - IJG JPEG Decoder Example by  doxygen 1.5.5