JPEGDataSource Class Reference

Provides an overridden version of the IJG library source manager, using CCFile's. More...

#include <jpgsrc.h>

List of all members.

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
CCFilem_pInputFile
libJPEG::JOCTET * m_pBuffer


Detailed Description

Provides an overridden version of the IJG library source manager, using CCFile's.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
10/08/96

Definition at line 115 of file jpgsrc.h.


Member Enumeration Documentation

anonymous enum
 

Enumerator:
INPUT_BUF_SIZE 

Definition at line 127 of file jpgsrc.h.

00128     {
00129         INPUT_BUF_SIZE = 4096   /* choose an efficiently fread'able size */
00130     };


Constructor & Destructor Documentation

JPEGDataSource::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.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
08/08/96
Parameters:
pFile : a pointer to a CCFile providing the source for a JPEG filter [INPUTS]

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 }


Member Function Documentation

libJPEG::boolean JPEGDataSource::FillInputBuffer libJPEG::j_decompress_ptr  cinfo  )  [static]
 

Overrides the standard implementation using stdio with a CCFile version.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
08/08/96
Parameters:
cinfo : a pointer to a j_decompress_ptr provided by the IJG routines [INPUTS]
Notes: The following extract from the IJG library explains its purpose:

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 }

libJPEG::boolean JPEGDataSource::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.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
08/08/96
Parameters:
cinfo : a pointer to a CCFile providing the source for a JPEG filter [INPUTS]

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 }

void JPEGDataSource::InitSource libJPEG::j_decompress_ptr  cinfo  )  [static]
 

Initialize source --- called by jpeg_read_header before any data is actually read.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
08/08/96
Parameters:
cinfo : a pointer to a j_decompress_ptr provided by the IJG routines [INPUTS]
Notes: We reset the empty-input-file flag for each image, but we don't clear the input buffer. This is correct behavior for reading a series of images from one source.

Definition at line 197 of file jpgsrc.cpp.

00198 {
00199     JPEGDataSource* pThis = (JPEGDataSource*)cinfo->src;
00200 
00201     pThis->m_bStartOfFile = TRUE;
00202 }

void JPEGDataSource::SkipInputData libJPEG::j_decompress_ptr  cinfo,
long  num_bytes
[static]
 

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).

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
08/08/96
Parameters:
cinfo : a pointer to a j_decompress_ptr provided by the IJG routines [INPUTS]
Writers of suspendable-input applications must note that skip_input_data is not granted the right to give a suspension return. If the skip extends beyond the data currently in the buffer, the buffer can be marked empty so that the next read will cause a fill_input_buffer call that can suspend. Arranging for additional bytes to be discarded before reloading the input buffer is the application writer's problem.

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 }

void JPEGDataSource::TerminateSource libJPEG::j_decompress_ptr  cinfo  )  [static]
 

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.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
08/08/96
Parameters:
cinfo : a pointer to a j_decompress_ptr provided by the IJG routines [INPUTS]
NB: *not* called by jpeg_abort or jpeg_destroy; surrounding application must deal with any cleanup that should happen even for error exit.

Definition at line 355 of file jpgsrc.cpp.

00356 {
00357 //  JPEGDataSource* pThis = (JPEGDataSource*)cinfo->src;
00358   /* no work necessary here */
00359 }


Member Data Documentation

BOOL JPEGDataSource::m_bStartOfFile [private]
 

Definition at line 120 of file jpgsrc.h.

libJPEG::JOCTET* JPEGDataSource::m_pBuffer [private]
 

Definition at line 122 of file jpgsrc.h.

CCFile* JPEGDataSource::m_pInputFile [private]
 

Definition at line 121 of file jpgsrc.h.


The documentation for this class was generated from the following files:
Generated on Sat Nov 10 03:55:35 2007 for Camelot by  doxygen 1.4.4