Main MRPT website > C++ reference for MRPT 1.5.9
jdatadst.cpp
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 
10 /* this is not a core library module, so it doesn't define JPEG_INTERNALS */
11 #include "jinclude.h"
12 #include "mrpt_jpeglib.h"
13 #include "jerror.h"
14 
15 
16 /* Expanded data destination object for stdio output */
17 
18 typedef struct {
19  struct jpeg_destination_mgr pub; /* public fields */
20 
21  FILE * outfile; /* target stream */
22  JOCTET * buffer; /* start of buffer */
24 
26 
27 #define OUTPUT_BUF_SIZE 4096 /* choose an efficiently fwrite'able size */
28 
29 
30 /*
31  * Initialize destination --- called by jpeg_start_compress
32  * before any data is actually written.
33  */
34 
35 METHODDEF(void)
37 {
38  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
39 
40  /* Allocate the output buffer --- it will be released when done with image */
41  dest->buffer = (JOCTET *)
42  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
44 
45  dest->pub.next_output_byte = dest->buffer;
47 }
48 
49 
50 /*
51  * Empty the output buffer --- called whenever buffer fills up.
52  *
53  * In typical applications, this should write the entire output buffer
54  * (ignoring the current state of next_output_byte & free_in_buffer),
55  * reset the pointer & count to the start of the buffer, and return TRUE
56  * indicating that the buffer has been dumped.
57  *
58  * In applications that need to be able to suspend compression due to output
59  * overrun, a FALSE return indicates that the buffer cannot be emptied now.
60  * In this situation, the compressor will return to its caller (possibly with
61  * an indication that it has not accepted all the supplied scanlines). The
62  * application should resume compression after it has made more room in the
63  * output buffer. Note that there are substantial restrictions on the use of
64  * suspension --- see the documentation.
65  *
66  * When suspending, the compressor will back up to a convenient restart point
67  * (typically the start of the current MCU). next_output_byte & free_in_buffer
68  * indicate where the restart point will be if the current call returns FALSE.
69  * Data beyond this point will be regenerated after resumption, so do not
70  * write it out when emptying the buffer externally.
71  */
72 
73 METHODDEF(boolean)
75 {
76  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
77 
78  if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) !=
79  (size_t) OUTPUT_BUF_SIZE)
80  ERREXIT(cinfo, JERR_FILE_WRITE);
81 
82  dest->pub.next_output_byte = dest->buffer;
84 
85  return TRUE;
86 }
87 
88 
89 /*
90  * Terminate destination --- called by jpeg_finish_compress
91  * after all data has been written. Usually needs to flush buffer.
92  *
93  * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
94  * application must deal with any cleanup that should happen even
95  * for error exit.
96  */
97 
98 METHODDEF(void)
100 {
101  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
102  size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
103 
104  /* Write any data remaining in the buffer */
105  if (datacount > 0) {
106  if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
107  ERREXIT(cinfo, JERR_FILE_WRITE);
108  }
109  fflush(dest->outfile);
110  /* Make sure we wrote the output file OK */
111  if (ferror(dest->outfile))
112  ERREXIT(cinfo, JERR_FILE_WRITE);
113 }
114 
115 
116 /*
117  * Prepare for output to a stdio stream.
118  * The caller must have already opened the stream, and is responsible
119  * for closing it after finishing compression.
120  */
121 
122 GLOBAL(void)
124 {
125  my_dest_ptr dest;
126 
127  /* The destination object is made permanent so that multiple JPEG images
128  * can be written to the same file without re-executing jpeg_stdio_dest.
129  * This makes it dangerous to use this manager and a different destination
130  * manager serially with the same JPEG object, because their private object
131  * sizes may be different. Caveat programmer.
132  */
133  if (cinfo->dest == NULL) { /* first time for this JPEG object? */
134  cinfo->dest = (struct jpeg_destination_mgr *)
135  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
137  }
138 
139  dest = (my_dest_ptr) cinfo->dest;
140  dest->pub.init_destination = init_destination;
141  dest->pub.empty_output_buffer = empty_output_buffer;
142  dest->pub.term_destination = term_destination;
143  dest->outfile = outfile;
144 }
FILE * outfile
Definition: mrpt_jpeglib.h:907
#define JPOOL_PERMANENT
Definition: mrpt_jpeglib.h:745
term_destination(j_compress_ptr cinfo)
Definition: jdatadst.cpp:99
struct jpeg_common_struct * j_common_ptr
Definition: mrpt_jpeglib.h:258
#define ERREXIT(cinfo, code)
Definition: jerror.h:199
#define SIZEOF(object)
Definition: jinclude.h:73
init_destination(j_compress_ptr cinfo)
Definition: jdatadst.cpp:36
#define JFWRITE(file, buf, sizeofbuf)
Definition: jinclude.h:83
struct jpeg_destination_mgr pub
Definition: jdatadst.cpp:19
#define JPOOL_IMAGE
Definition: mrpt_jpeglib.h:746
my_destination_mgr * my_dest_ptr
Definition: jdatadst.cpp:25
#define OUTPUT_BUF_SIZE
Definition: jdatadst.cpp:27
#define TRUE
Definition: jmorecfg.h:230
jpeg_stdio_dest(j_compress_ptr cinfo, FILE *outfile)
Definition: jdatadst.cpp:123
empty_output_buffer(j_compress_ptr cinfo)
Definition: jdatadst.cpp:74
#define GLOBAL(type)
Definition: jmorecfg.h:185
#define METHODDEF(type)
Definition: jmorecfg.h:181
char JOCTET
Definition: jmorecfg.h:112



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at miƩ abr 15 19:30:12 CEST 2020