OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Classes | Macros | Functions
ossimJpegMemDest.cpp File Reference
#include <ossim/imaging/ossimJpegMemDest.h>
#include <cstdlib>
#include <cstdio>
#include <csetjmp>
#include <ostream>
#include <jpeglib.h>

Go to the source code of this file.

Classes

struct  cpp_dest_mgr
 for jmp_buf More...
 

Macros

#define OUTPUT_BUF_SIZE   4096 /* choose an efficiently fwrite'able size */
 

Functions

void init_destination (j_compress_ptr cinfo)
 
boolean empty_output_buffer (j_compress_ptr cinfo)
 
void term_destination (j_compress_ptr cinfo)
 
void jpeg_cpp_stream_dest (jpeg_compress_struct *cinfo, std::ostream &stream)
 Method which uses memory instead of a FILE* to write to. More...
 

Macro Definition Documentation

◆ OUTPUT_BUF_SIZE

#define OUTPUT_BUF_SIZE   4096 /* choose an efficiently fwrite'able size */

Definition at line 29 of file ossimJpegMemDest.cpp.

Referenced by empty_output_buffer(), init_destination(), and term_destination().

Function Documentation

◆ empty_output_buffer()

boolean empty_output_buffer ( j_compress_ptr  cinfo)

Definition at line 43 of file ossimJpegMemDest.cpp.

References cpp_dest_mgr::buffer, OUTPUT_BUF_SIZE, cpp_dest_mgr::pub, cpp_dest_mgr::stream, and TRUE.

Referenced by jpeg_cpp_stream_dest().

44 {
45  cpp_dest_mgr* dest = (cpp_dest_mgr*) cinfo->dest;
46  dest->stream->write ((char*)dest->buffer, OUTPUT_BUF_SIZE);
47 
48  dest->pub.next_output_byte = dest->buffer;
49  dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
50 
51  return TRUE;
52 }
#define OUTPUT_BUF_SIZE
struct jpeg_destination_mgr pub
for jmp_buf
std::ostream * stream

◆ init_destination()

void init_destination ( j_compress_ptr  cinfo)

Definition at line 31 of file ossimJpegMemDest.cpp.

References cpp_dest_mgr::buffer, OUTPUT_BUF_SIZE, and cpp_dest_mgr::pub.

Referenced by jpeg_cpp_stream_dest().

32 {
33  cpp_dest_mgr* dest = (cpp_dest_mgr*) cinfo->dest;
34 
35  /* Allocate the output buffer --- it will be released when done with image */
36  dest->buffer = (JOCTET *)
37  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE, OUTPUT_BUF_SIZE * sizeof(JOCTET));
38 
39  dest->pub.next_output_byte = dest->buffer;
40  dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
41 }
#define OUTPUT_BUF_SIZE
struct jpeg_destination_mgr pub
for jmp_buf

◆ jpeg_cpp_stream_dest()

void jpeg_cpp_stream_dest ( jpeg_compress_struct *  cinfo,
std::ostream &  stream 
)

Method which uses memory instead of a FILE* to write to.

Note
Used in place of "jpeg_stdio_dest(&cinfo, outfile)".

Definition at line 69 of file ossimJpegMemDest.cpp.

References empty_output_buffer(), init_destination(), cpp_dest_mgr::pub, cpp_dest_mgr::stream, and term_destination().

Referenced by ossimJpegCodec::encode(), and ossimPdfWriter::writeJpegTile().

70 {
71  cpp_dest_mgr* dest;
72 
73  /* first time for this JPEG object? */
74  if (cinfo->dest == NULL)
75  cinfo->dest = (struct jpeg_destination_mgr *) malloc (sizeof(cpp_dest_mgr));
76 
77  dest = (cpp_dest_mgr*) cinfo->dest;
78  dest->pub.init_destination = init_destination;
79  dest->pub.empty_output_buffer = empty_output_buffer;
80  dest->pub.term_destination = term_destination;
81  dest->stream = &stream;
82 }
void init_destination(j_compress_ptr cinfo)
struct jpeg_destination_mgr pub
boolean empty_output_buffer(j_compress_ptr cinfo)
void term_destination(j_compress_ptr cinfo)
for jmp_buf
std::ostream * stream

◆ term_destination()

void term_destination ( j_compress_ptr  cinfo)

Definition at line 55 of file ossimJpegMemDest.cpp.

References cpp_dest_mgr::buffer, if(), OUTPUT_BUF_SIZE, cpp_dest_mgr::pub, and cpp_dest_mgr::stream.

Referenced by jpeg_cpp_stream_dest().

56 {
57  cpp_dest_mgr* dest = (cpp_dest_mgr*) cinfo->dest;
58  size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
59 
60  /* Write any data remaining in the buffer */
61  if (datacount > 0)
62  dest->stream->write ((char*)dest->buffer, datacount);
63 
64  dest->stream->flush();
65  free (cinfo->dest);
66 }
if(yy_init)
#define OUTPUT_BUF_SIZE
struct jpeg_destination_mgr pub
for jmp_buf
std::ostream * stream