Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

jmemsrc.cpp

Go to the documentation of this file.
00001 /*
00002  * jmemsrc.c
00003  *
00004  * This file contains a decompression data source which takes a 
00005  * memory region as source. 
00006  * The only thing these routines really do is tell the library where the 
00007  * data is on construction (jpeg_mem_src()). Everything else is there 
00008  * for error checking purposes.
00009  * Adapted from jdatasrc.c 9/96 by Ulrich von Zadow.
00010  */
00011  
00012 /* this is not a core library module, so it doesn't define JPEG_INTERNALS */
00013 
00014 #include "plstdpch.h"
00015 
00016 #include <stdio.h>
00017 
00018 extern "C"
00019 {
00020 #include "jpeglib.h"
00021 #include "jerror.h"
00022 }
00023 #include "jmemsrc.h"
00024 
00025 /*
00026  * Initialize source --- called by jpeg_read_header
00027  * before any data is actually read.
00028  */
00029 
00030 METHODDEF(void)
00031 init_source (j_decompress_ptr cinfo)
00032 {
00033 }
00034 
00035 /*
00036  * Fill the input buffer --- called whenever buffer is emptied.
00037  *
00038  * If this procedure gets called, we have a buffer overrun condition - 
00039  * there is not enough data in the buffer to satisfy the decoder.
00040  * The procedure just generates a warning and feeds the decoder a fake 
00041  * JPEG_EOI marker.
00042  */
00043 
00044 METHODDEF(boolean)
00045 fill_input_buffer (j_decompress_ptr cinfo)
00046 {
00047   struct jpeg_source_mgr * src = cinfo->src;
00048   static JOCTET FakeEOI[] = { 0xFF, JPEG_EOI };
00049 
00050   /* Generate warning */
00051   WARNMS(cinfo, JWRN_JPEG_EOF);
00052   
00053   /* Insert a fake EOI marker */
00054   src->next_input_byte = FakeEOI;
00055   src->bytes_in_buffer = 2;
00056 
00057   return TRUE;
00058 }
00059 
00060 
00061 METHODDEF(void)
00062 skip_input_data (j_decompress_ptr cinfo, long num_bytes)
00063 {
00064   struct jpeg_source_mgr * src = cinfo->src;
00065   
00066   if(num_bytes >= (long)src->bytes_in_buffer)
00067   {
00068     fill_input_buffer(cinfo);
00069     return;
00070   }
00071 
00072   src->bytes_in_buffer -= num_bytes;
00073   src->next_input_byte += num_bytes;
00074 }
00075 
00076 
00077 /*
00078  * Terminate source --- called by jpeg_finish_decompress
00079  * after all data has been read.  Often a no-op.
00080  *
00081  * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
00082  * application must deal with any cleanup that should happen even
00083  * for error exit.
00084  */
00085 
00086 METHODDEF(void)
00087 term_source (j_decompress_ptr cinfo)
00088 {
00089   /* no work necessary here */
00090 }
00091 
00092 
00093 /*
00094  * Prepare for input. This routine tells the jpeg library where to find 
00095  * the data & sets up the function pointers the library needs.
00096  *
00097  * Jo Hagelberg 15.4.99
00098  * added pDataSrc and JMETHOD( notifyCppworld ) for progress notification 
00099  */
00100 
00101 GLOBAL(void)
00102 jpeg_mem_src (
00103               j_decompress_ptr cinfo,
00104               JOCTET * pData,
00105               int FileSize,
00106               void *pDataSrc,
00107               JMETHOD(void, notifyCppWorld, (j_common_ptr))
00108              )
00109 {
00110   struct jpeg_source_mgr * src;
00111 
00112   if (cinfo->src == NULL)
00113   {   /* first time for this JPEG object? */
00114       cinfo->src = (struct jpeg_source_mgr *)
00115         (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
00116                                             sizeof(struct jpeg_source_mgr));
00117   }
00118 
00119   /* Jo Hagelberg 15.4.99               
00120    * added progress notification for JPEG 
00121    */
00122   if ( cinfo->progress == NULL)
00123   {   /* first time and progress notification wanted? */
00124       cinfo->progress = (struct jpeg_progress_mgr *)
00125         (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
00126                                             sizeof(struct jpeg_progress_mgr));
00127       /* static callback function in JpegDecoder */
00128       cinfo->progress->progress_monitor = notifyCppWorld;
00129   }
00130 
00131   /* Jo Hagelberg 15.4.99               
00132    * put CDataSource instance ptr into client data, so we can use it in the callback
00133    * NOTE: define a client data struct if this should be needed for other stuff, too
00134    */
00135   cinfo->client_data = pDataSrc ;
00136 
00137   src = cinfo->src;
00138 
00139   /* Set up function pointers */
00140   src->init_source = init_source;
00141   src->fill_input_buffer = fill_input_buffer;
00142   src->skip_input_data = skip_input_data;
00143   src->resync_to_restart = jpeg_resync_to_restart; /* use default method */
00144   src->term_source = term_source;
00145 
00146   /* Set up data pointer */
00147   src->bytes_in_buffer = FileSize;
00148   src->next_input_byte = pData;
00149 }
00150 /*
00151 /--------------------------------------------------------------------
00152 |
00153 |      $Log: jmemsrc.cpp,v $
00154 |      Revision 1.1  2004/05/21 21:02:52  maxx
00155 |      Initial Version of vuVolume, moderatly changed to make it compile on my windows and linux machine.
00156 |
00157 |      Revision 1.1  2002/11/13 01:58:20  mspindle
00158 |      *** empty log message ***
00159 |
00160 |      Revision 1.3  2001/09/16 20:57:17  uzadow
00161 |      Linux version name prefix changes
00162 |
00163 |      Revision 1.2  2001/09/15 21:02:44  uzadow
00164 |      Cleaned up stdpch.h and config.h to make them internal headers.
00165 |
00166 |      Revision 1.1  2000/10/30 14:32:50  uzadow
00167 |      Removed dependency on jinclude.h
00168 |
00169 |      Revision 1.5  2000/09/01 13:27:07  Administrator
00170 |      Minor bugfixes
00171 |
00172 |
00173 \--------------------------------------------------------------------
00174 */

Generated on Wed Dec 15 21:20:29 2004 for vuVolume by  doxygen 1.3.9.1