18const qint64 OUTPUT_BUFFER_SIZE = 4096;
20struct KisJPEGDestinationManager :
public jpeg_destination_mgr
22 void writeData(j_compress_ptr cinfo,
const qint64 numBytesToWrite)
24 if (output->write(
reinterpret_cast<const char*
>(buffer), numBytesToWrite) != numBytesToWrite) {
25 ERREXIT(cinfo, JERR_FILE_WRITE);
33typedef KisJPEGDestinationManager* KisJPEGDestinationManagerPtr;
38void init_destination(j_compress_ptr cinfo)
40 KisJPEGDestinationManagerPtr dest = (KisJPEGDestinationManagerPtr)cinfo->dest;
42 dest->buffer = (JOCTET *)
43 (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_IMAGE,
44 OUTPUT_BUFFER_SIZE*
sizeof(JOCTET));
46 dest->next_output_byte = dest->buffer;
47 dest->free_in_buffer = OUTPUT_BUFFER_SIZE;
50boolean empty_output_buffer(j_compress_ptr cinfo)
52 KisJPEGDestinationManagerPtr dest = (KisJPEGDestinationManagerPtr)cinfo->dest;
54 dest->writeData(cinfo, OUTPUT_BUFFER_SIZE);
55 dest->next_output_byte = dest->buffer;
56 dest->free_in_buffer = OUTPUT_BUFFER_SIZE;
61void term_destination(j_compress_ptr cinfo)
63 KisJPEGDestinationManagerPtr dest = (KisJPEGDestinationManagerPtr)cinfo->dest;
64 const qint64 numBytesToWrite = OUTPUT_BUFFER_SIZE-(qint64)dest->free_in_buffer;
66 if (numBytesToWrite > 0) {
67 dest->writeData(cinfo, numBytesToWrite);
79 if (cinfo->dest == 0) {
80 cinfo->dest = (
struct jpeg_destination_mgr *)
81 (*cinfo->mem->alloc_small) ((j_common_ptr)cinfo, JPOOL_PERMANENT,
82 sizeof(KisJPEGDestinationManager));
85 KisJPEGDestinationManagerPtr dest = (KisJPEGDestinationManagerPtr)cinfo->dest;
87 dest->init_destination = init_destination;
88 dest->empty_output_buffer = empty_output_buffer;
89 dest->term_destination = term_destination;
90 dest->output = destinationDevice;
static void writeData(KisPaintDeviceSP pd, const QRect &bounds, QDataStream &out_stream)
void setDestination(j_compress_ptr cinfo, QIODevice *destinationDevice)