ReactOS  0.4.13-dev-986-g029b8f2
rdswitch.c File Reference
#include "cdjpeg.h"
#include <ctype.h>
Include dependency graph for rdswitch.c:

Go to the source code of this file.

Functions

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

Function Documentation

◆ read_quant_tables()

read_quant_tables ( j_compress_ptr  cinfo,
char filename,
boolean  force_baseline 
)

Definition at line 75 of file rdswitch.c.

85 {
86  FILE * fp;
87  int tblno, i, termchar;
88  long val;
89  unsigned int table[DCTSIZE2];
90 
91  if ((fp = fopen(filename, "r")) == NULL) {
92  fprintf(stderr, "Can't open table file %s\n", filename);
93  return FALSE;
94  }
95  tblno = 0;
96 
97  while (read_text_integer(fp, &val, &termchar)) { /* read 1st element of table */
98  if (tblno >= NUM_QUANT_TBLS) {
99  fprintf(stderr, "Too many tables in file %s\n", filename);
100  fclose(fp);
101  return FALSE;
102  }
103  table[0] = (unsigned int) val;
104  for (i = 1; i < DCTSIZE2; i++) {
105  if (! read_text_integer(fp, &val, &termchar)) {
106  fprintf(stderr, "Invalid table data in file %s\n", filename);
107  fclose(fp);
108  return FALSE;
109  }
110  table[i] = (unsigned int) val;
111  }
112  jpeg_add_quant_table(cinfo, tblno, table, cinfo->q_scale_factor[tblno],
114  tblno++;
115  }
116 
117  if (termchar != EOF) {
118  fprintf(stderr, "Non-numeric data in file %s\n", filename);
119  fclose(fp);
120  return FALSE;
121  }
122 
123  fclose(fp);
124  return TRUE;
125 }
char boolean force_baseline
Definition: cdjpeg.h:134
#define TRUE
Definition: types.h:120
#define NUM_QUANT_TBLS
Definition: jpeglib.h:52
const char * filename
Definition: ioapi.h:135
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
smooth NULL
Definition: ftsmooth.c:416
read_text_integer(FILE *file, long *result, int *termchar)
Definition: rdswitch.c:40
#define DCTSIZE2
Definition: jpeglib.h:51
GLuint GLfloat * val
Definition: glext.h:7180
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
_Check_return_ _CRTIMP FILE *__cdecl fopen(_In_z_ const char *_Filename, _In_z_ const char *_Mode)
jpeg_add_quant_table(j_compress_ptr cinfo, int which_tbl, const unsigned int *basic_table, int scale_factor, boolean force_baseline)
Definition: jcparam.c:24
#define EOF
Definition: stdio.h:24
int q_scale_factor[NUM_QUANT_TBLS]
Definition: jpeglib.h:337
FILE * stderr
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31

Referenced by parse_switches().

◆ read_text_integer()

read_text_integer ( FILE file,
long result,
int termchar 
)

Definition at line 40 of file rdswitch.c.

43 {
44  register int ch;
45  register long val;
46 
47  /* Skip any leading whitespace, detect EOF */
48  do {
49  ch = text_getc(file);
50  if (ch == EOF) {
51  *termchar = ch;
52  return FALSE;
53  }
54  } while (isspace(ch));
55 
56  if (! isdigit(ch)) {
57  *termchar = ch;
58  return FALSE;
59  }
60 
61  val = ch - '0';
62  while ((ch = text_getc(file)) != EOF) {
63  if (! isdigit(ch))
64  break;
65  val *= 10;
66  val += ch - '0';
67  }
68  *result = val;
69  *termchar = ch;
70  return TRUE;
71 }
#define isspace(c)
Definition: acclib.h:69
#define TRUE
Definition: types.h:120
text_getc(FILE *file)
Definition: rdswitch.c:23
#define isdigit(c)
Definition: acclib.h:68
GLuint GLfloat * val
Definition: glext.h:7180
#define EOF
Definition: stdio.h:24
GLuint64EXT * result
Definition: glext.h:11304
Definition: fci.c:126

Referenced by read_quant_tables().

◆ set_quality_ratings()

set_quality_ratings ( j_compress_ptr  cinfo,
char arg,
boolean  force_baseline 
)

Definition at line 268 of file rdswitch.c.

273 {
274  int val = 75; /* default value */
275  int tblno;
276  char ch;
277 
278  for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
279  if (*arg) {
280  ch = ','; /* if not set by sscanf, will be ',' */
281  if (sscanf(arg, "%d%c", &val, &ch) < 1)
282  return FALSE;
283  if (ch != ',') /* syntax check */
284  return FALSE;
285  /* Convert user 0-100 rating to percentage scaling */
286  cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val);
287  while (*arg && *arg++ != ',') /* advance to next segment of arg string */
288  ;
289  } else {
290  /* reached end of parameter, set remaining factors to last value */
291  cinfo->q_scale_factor[tblno] = jpeg_quality_scaling(val);
292  }
293  }
295  return TRUE;
296 }
char boolean force_baseline
Definition: cdjpeg.h:134
#define TRUE
Definition: types.h:120
#define NUM_QUANT_TBLS
Definition: jpeglib.h:52
jpeg_default_qtables(j_compress_ptr cinfo, boolean force_baseline)
Definition: jcparam.c:91
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
GLuint GLfloat * val
Definition: glext.h:7180
int q_scale_factor[NUM_QUANT_TBLS]
Definition: jpeglib.h:337
jpeg_quality_scaling(int quality)
Definition: jcparam.c:123

Referenced by parse_switches().

◆ set_quant_slots()

set_quant_slots ( j_compress_ptr  cinfo,
char arg 
)

Definition at line 300 of file rdswitch.c.

305 {
306  int val = 0; /* default table # */
307  int ci;
308  char ch;
309 
310  for (ci = 0; ci < MAX_COMPONENTS; ci++) {
311  if (*arg) {
312  ch = ','; /* if not set by sscanf, will be ',' */
313  if (sscanf(arg, "%d%c", &val, &ch) < 1)
314  return FALSE;
315  if (ch != ',') /* syntax check */
316  return FALSE;
318  fprintf(stderr, "JPEG quantization tables are numbered 0..%d\n",
319  NUM_QUANT_TBLS-1);
320  return FALSE;
321  }
322  cinfo->comp_info[ci].quant_tbl_no = val;
323  while (*arg && *arg++ != ',') /* advance to next segment of arg string */
324  ;
325  } else {
326  /* reached end of parameter, set remaining components to last table */
327  cinfo->comp_info[ci].quant_tbl_no = val;
328  }
329  }
330  return TRUE;
331 }
#define TRUE
Definition: types.h:120
#define NUM_QUANT_TBLS
Definition: jpeglib.h:52
#define MAX_COMPONENTS
Definition: jmorecfg.h:45
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
GLuint GLfloat * val
Definition: glext.h:7180
FILE * stderr
jpeg_component_info * comp_info
Definition: jpeglib.h:333

Referenced by parse_switches().

◆ set_sample_factors()

set_sample_factors ( j_compress_ptr  cinfo,
char arg 
)

Definition at line 335 of file rdswitch.c.

340 {
341  int ci, val1, val2;
342  char ch1, ch2;
343 
344  for (ci = 0; ci < MAX_COMPONENTS; ci++) {
345  if (*arg) {
346  ch2 = ','; /* if not set by sscanf, will be ',' */
347  if (sscanf(arg, "%d%c%d%c", &val1, &ch1, &val2, &ch2) < 3)
348  return FALSE;
349  if ((ch1 != 'x' && ch1 != 'X') || ch2 != ',') /* syntax check */
350  return FALSE;
351  if (val1 <= 0 || val1 > MAX_SAMP_FACTOR ||
352  val2 <= 0 || val2 > MAX_SAMP_FACTOR) {
353  fprintf(stderr, "JPEG sampling factors must be 1..%d\n", MAX_SAMP_FACTOR);
354  return FALSE;
355  }
356  cinfo->comp_info[ci].h_samp_factor = val1;
357  cinfo->comp_info[ci].v_samp_factor = val2;
358  while (*arg && *arg++ != ',') /* advance to next segment of arg string */
359  ;
360  } else {
361  /* reached end of parameter, set remaining components to 1x1 sampling */
362  cinfo->comp_info[ci].h_samp_factor = 1;
363  cinfo->comp_info[ci].v_samp_factor = 1;
364  }
365  }
366  return TRUE;
367 }
#define TRUE
Definition: types.h:120
#define MAX_COMPONENTS
Definition: jmorecfg.h:45
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_ _CRTIMP int __cdecl sscanf(_In_z_ const char *_Src, _In_z_ _Scanf_format_string_ const char *_Format,...)
#define MAX_SAMP_FACTOR
Definition: jpeglib.h:56
FILE * stderr
jpeg_component_info * comp_info
Definition: jpeglib.h:333

Referenced by parse_switches().

◆ text_getc()

text_getc ( FILE file)

Definition at line 23 of file rdswitch.c.

26 {
27  register int ch;
28 
29  ch = getc(file);
30  if (ch == '#') {
31  do {
32  ch = getc(file);
33  } while (ch != '\n' && ch != EOF);
34  }
35  return ch;
36 }
_Check_return_ _CRTIMP int __cdecl getc(_Inout_ FILE *_File)
#define EOF
Definition: stdio.h:24
Definition: fci.c:126

Referenced by read_text_integer().