COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
jdatasrc.cpp File Reference
#include "jinclude.h"
#include "jpeglib.h"
#include "jerror.h"
Include dependency graph for jdatasrc.cpp:

Classes

struct  my_source_mgr
 

Macros

#define INPUT_BUF_SIZE   4096 /* choose an efficiently fread'able size */
 

Typedefs

typedef my_source_mgrmy_src_ptr
 

Functions

static void init_source (j_decompress_ptr cinfo)
 
static boolean fill_input_buffer (j_decompress_ptr cinfo)
 
static void skip_input_data (j_decompress_ptr cinfo, long num_bytes)
 
static void term_source (j_decompress_ptr cinfo)
 
void jpeg_stdio_src (j_decompress_ptr cinfo, FILE *infile)
 

Macro Definition Documentation

#define INPUT_BUF_SIZE   4096 /* choose an efficiently fread'able size */

Typedef Documentation

Function Documentation

static void init_source ( j_decompress_ptr  cinfo)
static
45 {
46  my_src_ptr src = (my_src_ptr) cinfo->src;
47 
48  /* We reset the empty-input-file flag for each image,
49  * but we don't clear the input buffer.
50  * This is correct behavior for reading a series of images from one source.
51  */
52  src->start_of_file = TRUE;
53 }
my_source_mgr * my_src_ptr
Definition: jdatasrc.cpp:33
#define TRUE
Definition: jpleph.cpp:68
struct jpeg_source_mgr * src
Definition: jpeglib.h:420
boolean start_of_file
Definition: jdatasrc.cpp:30
Definition: jdatasrc.cpp:25
static boolean fill_input_buffer ( j_decompress_ptr  cinfo)
static
91 {
92  my_src_ptr src = (my_src_ptr) cinfo->src;
93  size_t nbytes;
94 
95  nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
96 
97  if (nbytes <= 0) {
98  if (src->start_of_file) /* Treat empty input file as fatal error */
99  ERREXIT(cinfo, JERR_INPUT_EMPTY);
100  WARNMS(cinfo, JWRN_JPEG_EOF);
101  /* Insert a fake EOI marker */
102  src->buffer[0] = (JOCTET) 0xFF;
103  src->buffer[1] = (JOCTET) JPEG_EOI;
104  nbytes = 2;
105  }
106 
107  src->pub.next_input_byte = src->buffer;
108  src->pub.bytes_in_buffer = nbytes;
109  src->start_of_file = FALSE;
110 
111  return TRUE;
112 }
my_source_mgr * my_src_ptr
Definition: jdatasrc.cpp:33
JOCTET * buffer
Definition: jdatasrc.cpp:29
#define ERREXIT(cinfo, code)
Definition: jerror.h:205
#define JFREAD(file, buf, sizeofbuf)
Definition: jinclude.h:88
Definition: jerror.h:180
#define FALSE
Definition: jpleph.cpp:69
FILE * infile
Definition: jdatasrc.cpp:28
size_t bytes_in_buffer
Definition: jpeglib.h:732
#define WARNMS(cinfo, code)
Definition: jerror.h:238
#define TRUE
Definition: jpleph.cpp:68
Definition: jerror.h:88
struct jpeg_source_mgr * src
Definition: jpeglib.h:420
#define JPEG_EOI
Definition: jpeglib.h:1054
boolean start_of_file
Definition: jdatasrc.cpp:30
Definition: jdatasrc.cpp:25
struct jpeg_source_mgr pub
Definition: jdatasrc.cpp:26
char JOCTET
Definition: jmorecfg.h:115
const JOCTET * next_input_byte
Definition: jpeglib.h:731
#define INPUT_BUF_SIZE
Definition: jdatasrc.cpp:35
static void skip_input_data ( j_decompress_ptr  cinfo,
long  num_bytes 
)
static
129 {
130  my_src_ptr src = (my_src_ptr) cinfo->src;
131 
132  /* Just a dumb implementation for now. Could use fseek() except
133  * it doesn't work on pipes. Not clear that being smart is worth
134  * any trouble anyway --- large skips are infrequent.
135  */
136  if (num_bytes > 0) {
137  while (num_bytes > (long) src->pub.bytes_in_buffer) {
138  num_bytes -= (long) src->pub.bytes_in_buffer;
139  (void) fill_input_buffer(cinfo);
140  /* note we assume that fill_input_buffer will never return FALSE,
141  * so suspension need not be handled.
142  */
143  }
144  src->pub.next_input_byte += (size_t) num_bytes;
145  src->pub.bytes_in_buffer -= (size_t) num_bytes;
146  }
147 }
my_source_mgr * my_src_ptr
Definition: jdatasrc.cpp:33
size_t bytes_in_buffer
Definition: jpeglib.h:732
struct jpeg_source_mgr * src
Definition: jpeglib.h:420
static boolean fill_input_buffer(j_decompress_ptr cinfo)
Definition: jdatasrc.cpp:90
Definition: jdatasrc.cpp:25
struct jpeg_source_mgr pub
Definition: jdatasrc.cpp:26
const JOCTET * next_input_byte
Definition: jpeglib.h:731
static void term_source ( j_decompress_ptr  cinfo)
static
170 {
171  /* no work necessary here */
172 }
void jpeg_stdio_src ( j_decompress_ptr  cinfo,
FILE *  infile 
)
183 {
184  my_src_ptr src;
185 
186  /* The source object and input buffer are made permanent so that a series
187  * of JPEG images can be read from the same file by calling jpeg_stdio_src
188  * only before the first one. (If we discarded the buffer at the end of
189  * one image, we'd likely lose the start of the next one.)
190  * This makes it unsafe to use this manager and a different source
191  * manager serially with the same JPEG object. Caveat programmer.
192  */
193  if (cinfo->src == NULL) { /* first time for this JPEG object? */
194  cinfo->src = (struct jpeg_source_mgr *)
195  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
197  src = (my_src_ptr) cinfo->src;
198  src->buffer = (JOCTET *)
199  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
201  }
202 
203  src = (my_src_ptr) cinfo->src;
204  src->pub.init_source = init_source;
207  src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
208  src->pub.term_source = term_source;
209  src->infile = infile;
210  src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
211  src->pub.next_input_byte = NULL; /* until buffer loaded */
212 }
boolean(* fill_input_buffer)()
Definition: jpeglib.h:735
my_source_mgr * my_src_ptr
Definition: jdatasrc.cpp:33
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:266
boolean jpeg_resync_to_restart(j_decompress_ptr cinfo, int desired)
Definition: jdmarker.cpp:1192
void(* skip_input_data)()
Definition: jpeglib.h:736
void *(* alloc_small)()
Definition: jpeglib.h:764
JOCTET * buffer
Definition: jdatasrc.cpp:29
boolean(* resync_to_restart)()
Definition: jpeglib.h:737
Definition: jpeglib.h:258
void(* term_source)()
Definition: jpeglib.h:738
#define SIZEOF(object)
Definition: jinclude.h:80
struct jpeg_memory_mgr * mem
Definition: jpeglib.h:417
static void skip_input_data(j_decompress_ptr cinfo, long num_bytes)
Definition: jdatasrc.cpp:128
FILE * infile
Definition: jdatasrc.cpp:28
static void init_source(j_decompress_ptr cinfo)
Definition: jdatasrc.cpp:44
size_t bytes_in_buffer
Definition: jpeglib.h:732
Definition: jpeglib.h:730
struct jpeg_source_mgr * src
Definition: jpeglib.h:420
static boolean fill_input_buffer(j_decompress_ptr cinfo)
Definition: jdatasrc.cpp:90
Definition: jdatasrc.cpp:25
static void term_source(j_decompress_ptr cinfo)
Definition: jdatasrc.cpp:169
struct jpeg_source_mgr pub
Definition: jdatasrc.cpp:26
#define JPOOL_PERMANENT
Definition: jpeglib.h:753
char JOCTET
Definition: jmorecfg.h:115
void(* init_source)()
Definition: jpeglib.h:734
const JOCTET * next_input_byte
Definition: jpeglib.h:731
#define INPUT_BUF_SIZE
Definition: jdatasrc.cpp:35