#include <jpgdest.h>
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 | |
CCFile * | GetFile () 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 JPEGDataDestination * | GetThis (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 |
CCFile * | m_pOutputFile |
libJPEG::JOCTET * | m_pBuffer |
Classes | |
class | IJGDestMgr |
Definition at line 115 of file jpgdest.h.
|
Definition at line 135 of file jpgdest.h. 00136 { 00137 OUTPUT_BUF_SIZE = BUFSIZ /* choose an efficiently fread'able size */ 00138 };
|
|
Default constructor.
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 }
|
|
|
|
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.
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 }
|
|
Helper function to return the CCFile associated with this JPEGDataDestination.
Definition at line 306 of file jpgdest.cpp. 00307 { 00308 return m_pOutputFile; 00309 }
|
|
Helper function to return the this pointer buried in the cinfo structure.
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 }
|
|
Initializes the given compression structure with this JPEGDataDestination.
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 }
|
|
Callback for IJG destination file handler Initialize destination --- called by jpeg_start_compress before any data is actually written.
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 }
|
|
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.
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 }
|
|
|
|
|
|
|