OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Classes | Macros | Typedefs | Functions
ossimJpegStdIOSrc.cpp File Reference
#include <ossim/imaging/ossimJpegStdIOSrc.h>
#include <csetjmp>
#include <jpeglib.h>
#include <jerror.h>

Go to the source code of this file.

Classes

struct  ossimJpegStdIOSourceMgr
 

Macros

#define INPUT_BUF_SIZE   4096 /* choose an efficiently fread'able size */
 for jmp_buf More...
 
#define JFREAD(file, buf, sizeofbuf)   ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
 
#define SIZEOF(object)   ((size_t) sizeof(object))
 

Typedefs

typedef ossimJpegStdIOSourceMgrossimJpegStdIOSourceMgrPtr
 

Functions

void ossimJpegStdIOSrc_init_source (j_decompress_ptr cinfo)
 
boolean ossimJpegStdIOSrc_fill_input_buffer (j_decompress_ptr cinfo)
 
void ossimJpegStdIOSrc_skip_input_data (j_decompress_ptr cinfo, long num_bytes)
 
void ossimJpegStdIOSrc_term_source (j_decompress_ptr cinfo)
 
void ossimJpegStdIOSrc (jpeg_decompress_struct *cinfo, FILE *infile)
 Method which uses memory instead of a FILE* to read from. More...
 

Macro Definition Documentation

◆ INPUT_BUF_SIZE

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

for jmp_buf

for jpeg stuff

Definition at line 43 of file ossimJpegStdIOSrc.cpp.

Referenced by ossimJpegStdIOSrc(), and ossimJpegStdIOSrc_fill_input_buffer().

◆ JFREAD

#define JFREAD (   file,
  buf,
  sizeofbuf 
)    ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))

Definition at line 45 of file ossimJpegStdIOSrc.cpp.

Referenced by ossimJpegStdIOSrc_fill_input_buffer().

◆ SIZEOF

#define SIZEOF (   object)    ((size_t) sizeof(object))

Definition at line 56 of file ossimJpegStdIOSrc.cpp.

Referenced by ossimJpegStdIOSrc().

Typedef Documentation

◆ ossimJpegStdIOSourceMgrPtr

Definition at line 71 of file ossimJpegStdIOSrc.cpp.

Function Documentation

◆ ossimJpegStdIOSrc()

void ossimJpegStdIOSrc ( jpeg_decompress_struct *  cinfo,
FILE *  infile 
)

Method which uses memory instead of a FILE* to read from.

Note
Used in place of "jpeg_stdio_src(&cinfo, infile)".

Definition at line 219 of file ossimJpegStdIOSrc.cpp.

References ossimJpegStdIOSourceMgr::buffer, ossimJpegStdIOSourceMgr::infile, INPUT_BUF_SIZE, ossimJpegStdIOSrc_fill_input_buffer(), ossimJpegStdIOSrc_init_source(), ossimJpegStdIOSrc_skip_input_data(), ossimJpegStdIOSrc_term_source(), ossimJpegStdIOSourceMgr::pub, and SIZEOF.

Referenced by ossimJpegTileSource::restart().

220  {
222 
223  /* The source object and input buffer are made permanent so that a series
224  * of JPEG images can be read from the same file by calling jpeg_stdio_src
225  * only before the first one. (If we discarded the buffer at the end of
226  * one image, we'd likely lose the start of the next one.)
227  * This makes it unsafe to use this manager and a different source
228  * manager serially with the same JPEG object. Caveat programmer.
229  */
230  if (cinfo->src == NULL) { /* first time for this JPEG object? */
231  cinfo->src = (struct jpeg_source_mgr *)
232  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
234  src = (ossimJpegStdIOSourceMgrPtr) cinfo->src;
235  src->buffer = (JOCTET *)
236  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
237  INPUT_BUF_SIZE * SIZEOF(JOCTET));
238  }
239 
240  src = (ossimJpegStdIOSourceMgrPtr) cinfo->src;
241  src->pub.init_source = ossimJpegStdIOSrc_init_source;
242  src->pub.fill_input_buffer = ossimJpegStdIOSrc_fill_input_buffer;
243  src->pub.skip_input_data = ossimJpegStdIOSrc_skip_input_data;
244  src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
245  src->pub.term_source = ossimJpegStdIOSrc_term_source;
246  src->infile = infile;
247  src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
248  src->pub.next_input_byte = NULL; /* until buffer loaded */
249  }
#define SIZEOF(object)
#define INPUT_BUF_SIZE
for jmp_buf
void ossimJpegStdIOSrc_term_source(j_decompress_ptr cinfo)
ossimJpegStdIOSourceMgr * ossimJpegStdIOSourceMgrPtr
struct jpeg_source_mgr pub
void ossimJpegStdIOSrc_skip_input_data(j_decompress_ptr cinfo, long num_bytes)
void ossimJpegStdIOSrc_init_source(j_decompress_ptr cinfo)
boolean ossimJpegStdIOSrc_fill_input_buffer(j_decompress_ptr cinfo)

◆ ossimJpegStdIOSrc_fill_input_buffer()

boolean ossimJpegStdIOSrc_fill_input_buffer ( j_decompress_ptr  cinfo)

Definition at line 126 of file ossimJpegStdIOSrc.cpp.

References ossimJpegStdIOSourceMgr::buffer, FALSE, ossimJpegStdIOSourceMgr::infile, INPUT_BUF_SIZE, JFREAD, ossimJpegStdIOSourceMgr::pub, ossimJpegStdIOSourceMgr::start_of_file, and TRUE.

Referenced by ossimJpegStdIOSrc(), and ossimJpegStdIOSrc_skip_input_data().

127  {
129  size_t nbytes;
130 
131  nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
132 
133  if (nbytes <= 0) {
134  if (src->start_of_file) /* Treat empty input file as fatal error */
135  ERREXIT(cinfo, JERR_INPUT_EMPTY);
136  WARNMS(cinfo, JWRN_JPEG_EOF);
137  /* Insert a fake EOI marker */
138  src->buffer[0] = (JOCTET) 0xFF;
139  src->buffer[1] = (JOCTET) JPEG_EOI;
140  nbytes = 2;
141  }
142 
143  src->pub.next_input_byte = src->buffer;
144  src->pub.bytes_in_buffer = nbytes;
145  src->start_of_file = FALSE;
146 
147  return TRUE;
148  }
#define INPUT_BUF_SIZE
for jmp_buf
ossimJpegStdIOSourceMgr * ossimJpegStdIOSourceMgrPtr
struct jpeg_source_mgr pub
#define JFREAD(file, buf, sizeofbuf)

◆ ossimJpegStdIOSrc_init_source()

void ossimJpegStdIOSrc_init_source ( j_decompress_ptr  cinfo)

Definition at line 80 of file ossimJpegStdIOSrc.cpp.

References ossimJpegStdIOSourceMgr::start_of_file, and TRUE.

Referenced by ossimJpegStdIOSrc().

81  {
83 
84  /* We reset the empty-input-file flag for each image,
85  * but we don't clear the input buffer.
86  * This is correct behavior for reading a series of images from one source.
87  */
88  src->start_of_file = TRUE;
89  }
ossimJpegStdIOSourceMgr * ossimJpegStdIOSourceMgrPtr

◆ ossimJpegStdIOSrc_skip_input_data()

void ossimJpegStdIOSrc_skip_input_data ( j_decompress_ptr  cinfo,
long  num_bytes 
)

Definition at line 164 of file ossimJpegStdIOSrc.cpp.

References if(), ossimJpegStdIOSrc_fill_input_buffer(), and ossimJpegStdIOSourceMgr::pub.

Referenced by ossimJpegStdIOSrc().

165  {
167 
168  /* Just a dumb implementation for now. Could use fseek() except
169  * it doesn't work on pipes. Not clear that being smart is worth
170  * any trouble anyway --- large skips are infrequent.
171  */
172  if (num_bytes > 0) {
173  while (num_bytes > (long) src->pub.bytes_in_buffer) {
174  num_bytes -= (long) src->pub.bytes_in_buffer;
176  /* note we assume that fill_input_buffer will never return FALSE,
177  * so suspension need not be handled.
178  */
179  }
180  src->pub.next_input_byte += (size_t) num_bytes;
181  src->pub.bytes_in_buffer -= (size_t) num_bytes;
182  }
183  }
ossimJpegStdIOSourceMgr * ossimJpegStdIOSourceMgrPtr
struct jpeg_source_mgr pub
if(yy_init)
boolean ossimJpegStdIOSrc_fill_input_buffer(j_decompress_ptr cinfo)

◆ ossimJpegStdIOSrc_term_source()

void ossimJpegStdIOSrc_term_source ( j_decompress_ptr  cinfo)

Definition at line 205 of file ossimJpegStdIOSrc.cpp.

Referenced by ossimJpegStdIOSrc().

206  {
207  (void)cinfo;
208  /* no work necessary here */
209  }