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

jmemdest.cpp

Go to the documentation of this file.
00001 /*
00002  * jmemdest.cpp
00003  *
00004  * This file contains a compression data destination which takes a
00005  * memory region as destination.
00006  * The only thing these routines really do is tell the library where the
00007  * data is on construction (jpeg_mem_dest()). Everything else is there
00008  * for error checking purposes.
00009  * Adapted from jdatasrc.c 9/96 by Ulrich von Zadow.
00010  * Adapted from jmemsrc.c 3.6.99 by MS
00011  */
00012 
00013 /* this is not a core library module, so it doesn't define JPEG_INTERNALS */
00014 
00015 #include "plstdpch.h"
00016 #include "pldatasink.h"
00017 
00018 #include <stdio.h>
00019 
00020 #include "jpeglib.h"
00021 #include "jerror.h"
00022 #include "jmemdest.h"
00023 
00024 #include <stdio.h>
00025 
00026 #define JPEG_WORK_BUFFER_SIZE 8192      // 8KB Work Buffer
00027 
00028 typedef struct
00029 {
00030   struct jpeg_destination_mgr pub;       // public fields
00031 
00032   PLDataSink * pDataSink ;                // Data Sink
00033   JOCTET * buffer;
00034 }
00035 datasink_dest_mgr;
00036 
00037 
00038 
00039 /*
00040  * Initialize destination
00041  * before any data is actually written.
00042  */
00043 
00044 METHODDEF(void)
00045 jpeg_mem_dest_init (j_compress_ptr cinfo)
00046 {
00047   /* Set up data pointer */
00048   datasink_dest_mgr *  dest = (datasink_dest_mgr * ) cinfo->dest;
00049 
00050   /* Allocate the output buffer --- it will be released when done with image */
00051   dest->buffer = (JOCTET *)
00052                  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
00053                                              JPEG_WORK_BUFFER_SIZE);
00054 
00055   dest->pub.next_output_byte = dest->buffer;
00056   dest->pub.free_in_buffer = JPEG_WORK_BUFFER_SIZE;
00057 }
00058 
00059 /*
00060  * Flush the output buffer --- called whenever buffer is full.
00061  *
00062  * If this procedure gets called, we have a buffer overrun condition -
00063  * We now send the data to the DataSink
00064  */
00065 
00066 METHODDEF(boolean)
00067 jpeg_mem_dest_empty_output_buffer (j_compress_ptr cinfo)
00068 {
00069   datasink_dest_mgr * dest = (datasink_dest_mgr *) cinfo->dest;
00070 
00071   if (dest->pDataSink->WriteNBytes(JPEG_WORK_BUFFER_SIZE, dest->buffer) !=
00072       (size_t) JPEG_WORK_BUFFER_SIZE)
00073     ERREXIT(cinfo, JERR_FILE_WRITE);
00074 
00075   dest->pub.next_output_byte = dest->buffer;
00076   dest->pub.free_in_buffer = JPEG_WORK_BUFFER_SIZE;
00077 
00078   return true;
00079 }
00080 
00081 
00082 /*
00083  * Terminate source --- called by jpeg_finish_compress
00084  * after all data has been written.
00085  *
00086  * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
00087  * application must deal with any cleanup that should happen even
00088  * for error exit.
00089  */
00090 
00091 METHODDEF(void)
00092 jpeg_mem_dest_term (j_compress_ptr cinfo)
00093 {
00094   datasink_dest_mgr * dest = (datasink_dest_mgr *) cinfo->dest;
00095   size_t datacount = JPEG_WORK_BUFFER_SIZE - dest->pub.free_in_buffer;
00096 
00097   /* Write any data remaining in the buffer */
00098   if (datacount > 0)
00099   {
00100     if (dest->pDataSink->WriteNBytes(datacount, dest->buffer) != datacount)
00101       ERREXIT(cinfo, JERR_FILE_WRITE);
00102   }
00103 
00104 }
00105 
00106 
00107 /*
00108  * Prepare for ouput. This routine tells the jpeg library where to find
00109  * the output buffer & sets up the function pointers the library needs.
00110  *
00111  */
00112 
00113 GLOBAL(void)
00114 jpeg_mem_dest(
00115   j_compress_ptr cinfo,
00116   JOCTET * pData,
00117   int FileSize,
00118   PLDataSink * pDataSink
00119 )
00120 {
00121   datasink_dest_mgr * dest;
00122 
00123   if (cinfo->dest == NULL)
00124   {   /* first time for this JPEG object? */
00125     cinfo->dest = (struct jpeg_destination_mgr *)
00126                   (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
00127                                               sizeof(datasink_dest_mgr));
00128   }
00129 
00130   dest = (datasink_dest_mgr *) cinfo->dest;
00131   dest->pub.init_destination = jpeg_mem_dest_init;
00132   dest->pub.empty_output_buffer = jpeg_mem_dest_empty_output_buffer;
00133   dest->pub.term_destination = jpeg_mem_dest_term;
00134   dest->pDataSink = pDataSink;
00135 }

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