#include <jpgsrc.h>
Public Types | |
enum | { INPUT_BUF_SIZE = 4096 } |
Public Member Functions | |
JPEGDataSource (CCFile *pInputFile) | |
Default consturctor for a JPEGDataSource. This constructor sets up the callback functions to be used when the IJG library requires more data to be read from the source given as the argument to this constructor. | |
libJPEG::boolean | InitBuffer (libJPEG::j_decompress_ptr cinfo) |
Initializes the buffer to be used by the m_pFile object. Notes: Uses the IJG library for memory allocation. | |
Static Public Member Functions | |
static void | InitSource (libJPEG::j_decompress_ptr cinfo) |
Initialize source --- called by jpeg_read_header before any data is actually read. | |
static libJPEG::boolean | FillInputBuffer (libJPEG::j_decompress_ptr cinfo) |
Overrides the standard implementation using stdio with a CCFile version. | |
static void | SkipInputData (libJPEG::j_decompress_ptr cinfo, longnum_bytes) |
Overrides the standard implementation using stdio with a CCFile version. Skip data --- used to skip over a potentially large amount of uninteresting data (such as an APPn marker). | |
static void | TerminateSource (libJPEG::j_decompress_ptr cinfo) |
Overrides the standard implementation using stdio with a CCFile version. The following extract from the IJG library explains its purpose: Terminate source --- called by jpeg_finish_decompress after all data has been read. Often a no-op. | |
Private Attributes | |
BOOL | m_bStartOfFile |
CCFile * | m_pInputFile |
libJPEG::JOCTET * | m_pBuffer |
Definition at line 115 of file jpgsrc.h.
|
Definition at line 127 of file jpgsrc.h. 00128 { 00129 INPUT_BUF_SIZE = 4096 /* choose an efficiently fread'able size */ 00130 };
|
|
Default consturctor for a JPEGDataSource. This constructor sets up the callback functions to be used when the IJG library requires more data to be read from the source given as the argument to this constructor.
Definition at line 136 of file jpgsrc.cpp. 00136 : m_pInputFile(pInputFile) 00137 { 00138 m_bStartOfFile = FALSE; // Provide safe defaults 00139 m_pBuffer = NULL; 00140 00141 // Override default "methods" 00142 init_source = InitSource; 00143 fill_input_buffer = FillInputBuffer; 00144 skip_input_data = SkipInputData; 00145 /* 00146 * An additional method that can be provided by data source modules is the 00147 * resync_to_restart method for error recovery in the presence of RST markers. 00148 * For the moment, this source module just uses the default resync method 00149 * provided by the JPEG library. That method assumes that no backtracking 00150 * is possible. 00151 */ 00152 resync_to_restart = libJPEG::jpeg_resync_to_restart; 00153 term_source = TerminateSource; 00154 00155 // Initialize base class!! 00156 bytes_in_buffer = 0; // forces fill_input_buffer on first read 00157 next_input_byte = NULL; // until buffer loaded 00158 }
|
|
Overrides the standard implementation using stdio with a CCFile version.
Fill the input buffer --- called whenever buffer is emptied. In typical applications, this should read fresh data into the buffer (ignoring the current state of next_input_byte & bytes_in_buffer), reset the pointer & count to the start of the buffer, and return TRUE indicating that the buffer has been reloaded. It is not necessary to fill the buffer entirely, only to obtain at least one more byte. There is no such thing as an EOF return. If the end of the file has been reached, the routine has a choice of ERREXIT() or inserting fake data into the buffer. In most cases, generating a warning message and inserting a fake EOI marker is the best course of action --- this will allow the decompressor to output however much of the image is there. However, the resulting error message is misleading if the real problem is an empty input file, so we handle that case specially. In applications that need to be able to suspend compression due to input not being available yet, a FALSE return indicates that no more data can be obtained right now, but more may be forthcoming later. In this situation, the decompressor will return to its caller (with an indication of the number of scanlines it has read, if any). The application should resume decompression after it has loaded more data into the input buffer. Note that there are substantial restrictions on the use of suspension --- see the documentation. When suspending, the decompressor will back up to a convenient restart point (typically the start of the current MCU). next_input_byte & bytes_in_buffer indicate where the restart point will be if the current call returns FALSE. Data beyond this point must be rescanned after resumption, so move it to the front of the buffer rather than discarding it. Definition at line 249 of file jpgsrc.cpp. 00250 { 00251 JPEGDataSource* pThis = (JPEGDataSource*)cinfo->src; 00252 CCFile* pFile = pThis->m_pInputFile; 00253 00254 if (pFile->bad()) 00255 { 00256 JPEGErrorManager* pError = (JPEGErrorManager*)cinfo->err; 00257 pError->ThrowError(_R(IDE_FILEREADERROR)); 00258 } 00259 00260 size_t start = pFile->tellIn(); 00261 pFile->read(pThis->m_pBuffer, INPUT_BUF_SIZE); 00262 size_t nbytes = pFile->tellIn() - start; 00263 if (nbytes < INPUT_BUF_SIZE) 00264 { 00265 // For some reason trying to read too many bytes from a CCFile sets the stream bad 00266 // so don't let it stick some absurd message up 00267 Error::ClearError(); 00268 // & clear any eof signal 00269 pFile->SetGoodState(); 00270 } 00271 if (nbytes <= 0) 00272 { 00273 if (pThis->m_bStartOfFile) // Treat empty input file as fatal error 00274 { 00275 using namespace libJPEG; 00276 ERREXIT(cinfo, JERR_INPUT_EMPTY); 00277 } 00278 00279 using namespace libJPEG; 00280 WARNMS(cinfo, JWRN_JPEG_EOF); 00281 // Insert a fake EOI marker 00282 pThis->m_pBuffer[0] = (JOCTET) 0xFF; 00283 pThis->m_pBuffer[1] = (JOCTET) JPEG_EOI; 00284 nbytes = 2; 00285 } 00286 00287 pThis->next_input_byte = pThis->m_pBuffer; 00288 pThis->bytes_in_buffer = nbytes; 00289 pThis->m_bStartOfFile = FALSE; 00290 00291 return TRUE; 00292 }
|
|
Initializes the buffer to be used by the m_pFile object. Notes: Uses the IJG library for memory allocation.
Definition at line 172 of file jpgsrc.cpp. 00173 { 00174 using namespace libJPEG; 00175 00176 m_pBuffer = (JOCTET *) (*cinfo->mem->alloc_small) 00177 ((j_common_ptr) cinfo, JPOOL_PERMANENT, INPUT_BUF_SIZE * sizeof(JOCTET)); 00178 return (m_pBuffer != NULL); 00179 }
|
|
Initialize source --- called by jpeg_read_header before any data is actually read.
Definition at line 197 of file jpgsrc.cpp. 00198 { 00199 JPEGDataSource* pThis = (JPEGDataSource*)cinfo->src; 00200 00201 pThis->m_bStartOfFile = TRUE; 00202 }
|
|
Overrides the standard implementation using stdio with a CCFile version. Skip data --- used to skip over a potentially large amount of uninteresting data (such as an APPn marker).
Definition at line 314 of file jpgsrc.cpp. 00314 : Correct*/ num_bytes) 00315 { 00316 JPEGDataSource* pThis = (JPEGDataSource*)cinfo->src; 00317 /* Just a dumb implementation for now. Could use fseek() except 00318 * it doesn't work on pipes. Not clear that being smart is worth 00319 * any trouble anyway --- large skips are infrequent. 00320 */ 00321 if (num_bytes > 0) 00322 { 00323 while (num_bytes > (INT32) pThis->bytes_in_buffer) 00324 { 00325 num_bytes -= (INT32) pThis->bytes_in_buffer; 00326 (void)FillInputBuffer(cinfo); 00327 /* note we assume that fill_input_buffer will never return FALSE, 00328 * so suspension need not be handled. 00329 */ 00330 } 00331 pThis->next_input_byte += (size_t) num_bytes; 00332 pThis->bytes_in_buffer -= (size_t) num_bytes; 00333 } 00334 }
|
|
Overrides the standard implementation using stdio with a CCFile version. The following extract from the IJG library explains its purpose: Terminate source --- called by jpeg_finish_decompress after all data has been read. Often a no-op.
Definition at line 355 of file jpgsrc.cpp. 00356 { 00357 // JPEGDataSource* pThis = (JPEGDataSource*)cinfo->src; 00358 /* no work necessary here */ 00359 }
|
|
|
|
|
|
|