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

Go to the source code of this file.

Classes

struct  ossimJpegSourceMgr
 for jmp_buf More...
 

Typedefs

typedef ossimJpegSourceMgrossimJpegSourceMgrPtr
 

Functions

void init_source (j_decompress_ptr)
 
boolean fill_input_buffer (j_decompress_ptr cinfo)
 
void skip_input_data (j_decompress_ptr cinfo, long num_bytes)
 
void term_source (j_decompress_ptr)
 
void ossimJpegMemorySrc (jpeg_decompress_struct *cinfo, const ossim_uint8 *buffer, std::size_t bufsize)
 Method which uses memory instead of a FILE* to read from. More...
 

Typedef Documentation

◆ ossimJpegSourceMgrPtr

Definition at line 50 of file ossimJpegMemSrc.cpp.

Function Documentation

◆ fill_input_buffer()

boolean fill_input_buffer ( j_decompress_ptr  cinfo)

Definition at line 79 of file ossimJpegMemSrc.cpp.

References ossimJpegSourceMgr::eoi_buffer, ossimJpegSourceMgr::pub, and TRUE.

Referenced by ossimJpegMemorySrc(), and skip_input_data().

80 {
82 
83  WARNMS(cinfo, JWRN_JPEG_EOF);
84 
85  /* Create a fake EOI marker */
86  src->eoi_buffer[0] = (JOCTET) 0xFF;
87  src->eoi_buffer[1] = (JOCTET) JPEG_EOI;
88  src->pub.next_input_byte = src->eoi_buffer;
89  src->pub.bytes_in_buffer = 2;
90 
91  return TRUE;
92 }
ossimJpegSourceMgr * ossimJpegSourceMgrPtr
struct jpeg_source_mgr pub

◆ init_source()

void init_source ( j_decompress_ptr  )

Definition at line 58 of file ossimJpegMemSrc.cpp.

Referenced by ossimJpegMemorySrc().

59 {
60  /* No work, since jpeg_memory_src set up the buffer pointer and count.
61  * Indeed, if we want to read multiple JPEG images from one buffer,
62  * this *must* not do anything to the pointer.
63  */
64 }

◆ ossimJpegMemorySrc()

void ossimJpegMemorySrc ( jpeg_decompress_struct *  cinfo,
const ossim_uint8 buffer,
std::size_t  bufsize 
)

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

Note
Used in place of "jpeg_stdio_src(&cinfo, infile)".
"unsigned char = JOCTET

Definition at line 148 of file ossimJpegMemSrc.cpp.

References fill_input_buffer(), init_source(), ossimJpegSourceMgr::pub, skip_input_data(), and term_source().

Referenced by ossimJpegCodec::decodeJpeg(), and ossimJpegCodec::getColorSpace().

151 {
153 
154  /* The source object is made permanent so that a series of JPEG images
155  * can be read from a single buffer by calling jpeg_memory_src
156  * only before the first one.
157  * This makes it unsafe to use this manager and a different source
158  * manager serially with the same JPEG object. Caveat programmer.
159  */
160  if (cinfo->src == NULL) { /* first time for this JPEG object? */
161  cinfo->src = (struct jpeg_source_mgr *)
162  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
163  sizeof(ossimJpegSourceMgr));
164  }
165 
166  src = (ossimJpegSourceMgrPtr) cinfo->src;
167  src->pub.init_source = init_source;
168  src->pub.fill_input_buffer = fill_input_buffer;
169  src->pub.skip_input_data = skip_input_data;
170  src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
171  src->pub.term_source = term_source;
172 
173  src->pub.next_input_byte = buffer;
174  src->pub.bytes_in_buffer = bufsize;
175 }
ossimJpegSourceMgr * ossimJpegSourceMgrPtr
void init_source(j_decompress_ptr)
void term_source(j_decompress_ptr)
boolean fill_input_buffer(j_decompress_ptr cinfo)
void skip_input_data(j_decompress_ptr cinfo, long num_bytes)
struct jpeg_source_mgr pub

◆ skip_input_data()

void skip_input_data ( j_decompress_ptr  cinfo,
long  num_bytes 
)

Definition at line 104 of file ossimJpegMemSrc.cpp.

References fill_input_buffer(), if(), and ossimJpegSourceMgr::pub.

Referenced by ossimJpegMemorySrc().

105 {
106  ossimJpegSourceMgrPtr src = (ossimJpegSourceMgrPtr) cinfo->src;
107 
108  if (num_bytes > 0) {
109  while (num_bytes > (long) src->pub.bytes_in_buffer) {
110  num_bytes -= (long) src->pub.bytes_in_buffer;
111  (void) fill_input_buffer(cinfo);
112  /* note we assume that fill_input_buffer will never return FALSE,
113  * so suspension need not be handled.
114  */
115  }
116  src->pub.next_input_byte += (size_t) num_bytes;
117  src->pub.bytes_in_buffer -= (size_t) num_bytes;
118  }
119 }
ossimJpegSourceMgr * ossimJpegSourceMgrPtr
boolean fill_input_buffer(j_decompress_ptr cinfo)
if(yy_init)
struct jpeg_source_mgr pub

◆ term_source()

void term_source ( j_decompress_ptr  )

Definition at line 139 of file ossimJpegMemSrc.cpp.

Referenced by ossimJpegMemorySrc().

140 {
141  /* no work necessary here */
142 }