00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
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;
00031
00032 PLDataSink * pDataSink ;
00033 JOCTET * buffer;
00034 }
00035 datasink_dest_mgr;
00036
00037
00038
00039
00040
00041
00042
00043
00044 METHODDEF(void)
00045 jpeg_mem_dest_init (j_compress_ptr cinfo)
00046 {
00047
00048 datasink_dest_mgr * dest = (datasink_dest_mgr * ) cinfo->dest;
00049
00050
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
00061
00062
00063
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
00084
00085
00086
00087
00088
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
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
00109
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 {
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 }