JPEGDataDestination Class Reference

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

#include <jpgdest.h>

List of all members.

Public Types

enum  { OUTPUT_BUF_SIZE = BUFSIZ }

Public Member Functions

 JPEGDataDestination (CCFile *pOutputFile)
 Default constructor.
BOOL Init (libJPEG::j_compress_ptr cinfo)
 Initializes the given compression structure with this JPEGDataDestination.

Protected Member Functions

CCFileGetFile () const
 Helper function to return the CCFile associated with this JPEGDataDestination.

Static Protected Member Functions

static void InitDestination (libJPEG::j_compress_ptr cinfo)
 Callback for IJG destination file handler Initialize destination --- called by jpeg_start_compress before any data is actually written.
static libJPEG::boolean EmptyOutputBuffer (libJPEG::j_compress_ptr cinfo)
 Callback for IJG destination file handler Empty the output buffer --- called whenever buffer fills up. Notes: Says IJG docs, "In typical applications, this should write the entire output buffer (ignoring the current state of next_output_byte & free_in_buffer), reset the pointer & count to the start of the buffer, and return TRUE indicating that the buffer has been dumped." Scope: static.
static void TerminateDestination (libJPEG::j_compress_ptr cinfo)
 Terminate destination --- called by jpeg_finish_compress after all data has been written. Usually needs to flush buffer. Notes: *not* called by jpeg_abort or jpeg_destroy; surrounding application must deal with any cleanup that should happen even for error exit.
static JPEGDataDestinationGetThis (libJPEG::j_compress_ptr cinfo)
 Helper function to return the this pointer buried in the cinfo structure.

Private Member Functions

 CC_DECLARE_MEMDUMP (JPEGDataDestination)

Private Attributes

IJGDestMgr m_DestMgr
CCFilem_pOutputFile
libJPEG::JOCTET * m_pBuffer

Classes

class  IJGDestMgr


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 jpgdest.h.


Member Enumeration Documentation

anonymous enum
 

Enumerator:
OUTPUT_BUF_SIZE 

Definition at line 135 of file jpgdest.h.

00136     {
00137         OUTPUT_BUF_SIZE = BUFSIZ    /* choose an efficiently fread'able size */
00138     };


Constructor & Destructor Documentation

JPEGDataDestination::JPEGDataDestination CCFile pOutputFile  ) 
 

Default constructor.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Parameters:
pOutputFile : a pointer to a CCFile providing the destination for the JPEG [INPUTS] output

Definition at line 137 of file jpgdest.cpp.

00138 {
00139     ERROR3IF(pOutputFile == NULL || !pOutputFile->IS_KIND_OF(CCFile), "pOutputFile isn't");
00140 
00141 
00142     m_DestMgr.pThis = this;
00143 
00144     m_DestMgr.init_destination      = InitDestination;
00145     m_DestMgr.empty_output_buffer   = EmptyOutputBuffer;
00146     m_DestMgr.term_destination      = TerminateDestination;
00147 
00148     m_pOutputFile   = pOutputFile;
00149     m_pBuffer       = NULL;
00150 }


Member Function Documentation

JPEGDataDestination::CC_DECLARE_MEMDUMP JPEGDataDestination   )  [private]
 

libJPEG::boolean JPEGDataDestination::EmptyOutputBuffer libJPEG::j_compress_ptr  cinfo  )  [static, protected]
 

Callback for IJG destination file handler Empty the output buffer --- called whenever buffer fills up. Notes: Says IJG docs, "In typical applications, this should write the entire output buffer (ignoring the current state of next_output_byte & free_in_buffer), reset the pointer & count to the start of the buffer, and return TRUE indicating that the buffer has been dumped." Scope: static.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Parameters:
cinfo : a pointer to the IJG compression control structure [INPUTS]

Definition at line 217 of file jpgdest.cpp.

00218 {
00219     JPEGDataDestination* pThis = GetThis(cinfo);
00220     CCFile* pFile = pThis->GetFile();
00221 
00222     // Write out the full buffer
00223     pFile->write(pThis->m_pBuffer, OUTPUT_BUF_SIZE);
00224 
00225     // Check written OK
00226     if (pFile->bad() || pFile->fail())
00227     {
00228         JPEGErrorManager* pError = (JPEGErrorManager*)cinfo->err;
00229         pError->ThrowError(_R(IDE_FILE_WRITE_ERROR));
00230     }
00231 
00232     pThis->m_DestMgr.next_output_byte   = pThis->m_pBuffer;
00233     pThis->m_DestMgr.free_in_buffer = OUTPUT_BUF_SIZE;
00234 
00235   return TRUE;
00236 }

CCFile * JPEGDataDestination::GetFile  )  const [protected]
 

Helper function to return the CCFile associated with this JPEGDataDestination.

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

Definition at line 306 of file jpgdest.cpp.

00307 {
00308     return m_pOutputFile;
00309 }

JPEGDataDestination * JPEGDataDestination::GetThis libJPEG::j_compress_ptr  cinfo  )  [static, protected]
 

Helper function to return the this pointer buried in the cinfo structure.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Parameters:
cinfo : a pointer to the IJG compression control structure [INPUTS]

Definition at line 288 of file jpgdest.cpp.

00289 {
00290     JPEGDataDestination* pThis = ((IJGDestMgr*)(cinfo->dest))->pThis;
00291     ERROR3IF(!pThis->IS_KIND_OF(JPEGDataDestination), "GetThis - pThis isn't");
00292 
00293     return pThis;
00294 }

BOOL JPEGDataDestination::Init libJPEG::j_compress_ptr  cinfo  ) 
 

Initializes the given compression structure with this JPEGDataDestination.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Parameters:
cinfo : a pointer to the IJG compression structure [INPUTS]

Definition at line 163 of file jpgdest.cpp.

00164 {
00165     ERROR3IF(cinfo == NULL, "cinfo NULL");
00166 
00167     cinfo->dest = &m_DestMgr;
00168 
00169     return TRUE;
00170 }

void JPEGDataDestination::InitDestination libJPEG::j_compress_ptr  cinfo  )  [static, protected]
 

Callback for IJG destination file handler Initialize destination --- called by jpeg_start_compress before any data is actually written.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Parameters:
cinfo : a pointer to the IJG compression control structure [INPUTS]

Definition at line 185 of file jpgdest.cpp.

00186 {
00187     using namespace libJPEG;
00188 
00189     JPEGDataDestination* pThis = GetThis(cinfo);
00190 
00191     /* Allocate the output buffer --- it will be released when done with image */
00192     pThis->m_pBuffer = (JOCTET *)(*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00193                   OUTPUT_BUF_SIZE * sizeof(JOCTET));
00194 
00195     pThis->m_DestMgr.next_output_byte = pThis->m_pBuffer;
00196     pThis->m_DestMgr.free_in_buffer = OUTPUT_BUF_SIZE;
00197 }

void JPEGDataDestination::TerminateDestination libJPEG::j_compress_ptr  cinfo  )  [static, protected]
 

Terminate destination --- called by jpeg_finish_compress after all data has been written. Usually needs to flush buffer. Notes: *not* called by jpeg_abort or jpeg_destroy; surrounding application must deal with any cleanup that should happen even for error exit.

Author:
Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
Date:
29/10/96
Parameters:
cinfo : a pointer to the IJG compression control structure [INPUTS]

Definition at line 253 of file jpgdest.cpp.

00254 {
00255     JPEGDataDestination* pThis = GetThis(cinfo);
00256     CCFile* pFile = pThis->GetFile();
00257 
00258     size_t DataCount = OUTPUT_BUF_SIZE - pThis->m_DestMgr.free_in_buffer;
00259 
00260     // Write any data remaining in the buffer
00261     if (DataCount > 0)
00262     {
00263         // Write out the full buffer
00264         pFile->write(pThis->m_pBuffer, DataCount);
00265     }
00266     pFile->flush();
00267 
00268     // Make sure we wrote the output file OK
00269     if (pFile->bad() || pFile->fail())
00270     {
00271         JPEGErrorManager* pError = (JPEGErrorManager*)cinfo->err;
00272         pError->ThrowError(_R(IDE_FILE_WRITE_ERROR));
00273     }
00274 }


Member Data Documentation

IJGDestMgr JPEGDataDestination::m_DestMgr [private]
 

Definition at line 125 of file jpgdest.h.

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

Definition at line 128 of file jpgdest.h.

CCFile* JPEGDataDestination::m_pOutputFile [private]
 

Definition at line 127 of file jpgdest.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