ReactOS  0.4.13-dev-990-g6d23816
jdatadst.c File Reference
#include "jinclude.h"
#include "jpeglib.h"
#include "jerror.h"
Include dependency graph for jdatadst.c:

Go to the source code of this file.

Classes

struct  my_destination_mgr
 
struct  my_mem_destination_mgr
 

Macros

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

Typedefs

typedef my_destination_mgrmy_dest_ptr
 
typedef my_mem_destination_mgrmy_mem_dest_ptr
 

Functions

void *malloc JPP ((size_t size))
 
void free JPP ((void *ptr))
 
 init_destination (j_compress_ptr cinfo)
 
 init_mem_destination (j_compress_ptr cinfo)
 
 empty_output_buffer (j_compress_ptr cinfo)
 
 empty_mem_output_buffer (j_compress_ptr cinfo)
 
 term_destination (j_compress_ptr cinfo)
 
 term_mem_destination (j_compress_ptr cinfo)
 
 jpeg_stdio_dest (j_compress_ptr cinfo, FILE *outfile)
 
 jpeg_mem_dest (j_compress_ptr cinfo, unsigned char **outbuffer, unsigned long *outsize)
 

Macro Definition Documentation

◆ OUTPUT_BUF_SIZE

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

Definition at line 40 of file jdatadst.c.

Typedef Documentation

◆ my_dest_ptr

Definition at line 38 of file jdatadst.c.

◆ my_mem_dest_ptr

Definition at line 55 of file jdatadst.c.

Function Documentation

◆ empty_mem_output_buffer()

empty_mem_output_buffer ( j_compress_ptr  cinfo)

Definition at line 123 of file jdatadst.c.

124 {
125  size_t nextsize;
126  JOCTET * nextbuffer;
128 
129  /* Try to allocate new buffer with double size */
130  nextsize = dest->bufsize * 2;
131  nextbuffer = (JOCTET *) malloc(nextsize);
132 
133  if (nextbuffer == NULL)
134  ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
135 
136  MEMCOPY(nextbuffer, dest->buffer, dest->bufsize);
137 
138  if (dest->newbuffer != NULL)
139  free(dest->newbuffer);
140 
141  dest->newbuffer = nextbuffer;
142 
143  dest->pub.next_output_byte = nextbuffer + dest->bufsize;
144  dest->pub.free_in_buffer = dest->bufsize;
145 
146  dest->buffer = nextbuffer;
147  dest->bufsize = nextsize;
148 
149  return TRUE;
150 }
#define TRUE
Definition: types.h:120
#define free
Definition: debug_ros.c:5
my_mem_destination_mgr * my_mem_dest_ptr
Definition: jdatadst.c:55
smooth NULL
Definition: ftsmooth.c:416
#define MEMCOPY(dest, src, size)
Definition: jinclude.h:69
struct jpeg_destination_mgr * dest
Definition: jpeglib.h:295
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:212
char JOCTET
Definition: jmorecfg.h:167
#define malloc
Definition: debug_ros.c:4
static char * dest
Definition: rtl.c:135

Referenced by jpeg_mem_dest().

◆ empty_output_buffer()

empty_output_buffer ( j_compress_ptr  cinfo)

Definition at line 108 of file jdatadst.c.

109 {
110  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
111 
112  if (JFWRITE(dest->outfile, dest->buffer, OUTPUT_BUF_SIZE) !=
114  ERREXIT(cinfo, JERR_FILE_WRITE);
115 
116  dest->pub.next_output_byte = dest->buffer;
117  dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
118 
119  return TRUE;
120 }
#define TRUE
Definition: types.h:120
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
my_destination_mgr * my_dest_ptr
Definition: jdatadst.c:38
#define JFWRITE(file, buf, sizeofbuf)
Definition: jinclude.h:94
__kernel_size_t size_t
Definition: linux.h:237
if(!(yy_init))
Definition: macro.lex.yy.c:714
struct jpeg_destination_mgr * dest
Definition: jpeglib.h:295
static char * dest
Definition: rtl.c:135
#define OUTPUT_BUF_SIZE
Definition: jdatadst.c:40

Referenced by jpeg_stdio_dest().

◆ init_destination()

init_destination ( j_compress_ptr  cinfo)

Definition at line 64 of file jdatadst.c.

65 {
66  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
67 
68  /* Allocate the output buffer --- it will be released when done with image */
69  dest->buffer = (JOCTET *)
70  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
72 
73  dest->pub.next_output_byte = dest->buffer;
74  dest->pub.free_in_buffer = OUTPUT_BUF_SIZE;
75 }
my_destination_mgr * my_dest_ptr
Definition: jdatadst.c:38
#define SIZEOF(_ar)
Definition: calc.h:97
#define JPOOL_IMAGE
Definition: jpeglib.h:808
struct jpeg_destination_mgr * dest
Definition: jpeglib.h:295
char JOCTET
Definition: jmorecfg.h:167
static char * dest
Definition: rtl.c:135
#define OUTPUT_BUF_SIZE
Definition: jdatadst.c:40

Referenced by jpeg_stdio_dest().

◆ init_mem_destination()

init_mem_destination ( j_compress_ptr  cinfo)

Definition at line 78 of file jdatadst.c.

79 {
80  /* no work necessary here */
81 }

Referenced by jpeg_mem_dest().

◆ jpeg_mem_dest()

jpeg_mem_dest ( j_compress_ptr  cinfo,
unsigned char **  outbuffer,
unsigned long outsize 
)

Definition at line 235 of file jdatadst.c.

237 {
239 
240  if (outbuffer == NULL || outsize == NULL) /* sanity check */
241  ERREXIT(cinfo, JERR_BUFFER_SIZE);
242 
243  /* The destination object is made permanent so that multiple JPEG images
244  * can be written to the same buffer without re-executing jpeg_mem_dest.
245  */
246  if (cinfo->dest == NULL) { /* first time for this JPEG object? */
247  cinfo->dest = (struct jpeg_destination_mgr *)
248  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
250  }
251 
252  dest = (my_mem_dest_ptr) cinfo->dest;
253  dest->pub.init_destination = init_mem_destination;
254  dest->pub.empty_output_buffer = empty_mem_output_buffer;
255  dest->pub.term_destination = term_mem_destination;
256  dest->outbuffer = outbuffer;
257  dest->outsize = outsize;
258  dest->newbuffer = NULL;
259 
260  if (*outbuffer == NULL || *outsize == 0) {
261  /* Allocate initial buffer */
262  dest->newbuffer = *outbuffer = (unsigned char *) malloc(OUTPUT_BUF_SIZE);
263  if (dest->newbuffer == NULL)
264  ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 10);
266  }
267 
268  dest->pub.next_output_byte = dest->buffer = *outbuffer;
269  dest->pub.free_in_buffer = dest->bufsize = *outsize;
270 }
term_mem_destination(j_compress_ptr cinfo)
Definition: jdatadst.c:180
unsigned char ** outbuffer
Definition: jpeglib.h:979
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:284
my_mem_destination_mgr * my_mem_dest_ptr
Definition: jdatadst.c:55
#define SIZEOF(_ar)
Definition: calc.h:97
smooth NULL
Definition: ftsmooth.c:416
if(!(yy_init))
Definition: macro.lex.yy.c:714
struct jpeg_destination_mgr * dest
Definition: jpeglib.h:295
unsigned char unsigned long * outsize
Definition: jpeglib.h:979
#define ERREXIT1(cinfo, code, p1)
Definition: jerror.h:212
init_mem_destination(j_compress_ptr cinfo)
Definition: jdatadst.c:78
#define JPOOL_PERMANENT
Definition: jpeglib.h:807
#define malloc
Definition: debug_ros.c:4
static char * dest
Definition: rtl.c:135
#define OUTPUT_BUF_SIZE
Definition: jdatadst.c:40
empty_mem_output_buffer(j_compress_ptr cinfo)
Definition: jdatadst.c:123

◆ jpeg_stdio_dest()

jpeg_stdio_dest ( j_compress_ptr  cinfo,
FILE outfile 
)

Definition at line 196 of file jdatadst.c.

197 {
199 
200  /* The destination object is made permanent so that multiple JPEG images
201  * can be written to the same file without re-executing jpeg_stdio_dest.
202  * This makes it dangerous to use this manager and a different destination
203  * manager serially with the same JPEG object, because their private object
204  * sizes may be different. Caveat programmer.
205  */
206  if (cinfo->dest == NULL) { /* first time for this JPEG object? */
207  cinfo->dest = (struct jpeg_destination_mgr *)
208  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
210  }
211 
212  dest = (my_dest_ptr) cinfo->dest;
213  dest->pub.init_destination = init_destination;
214  dest->pub.empty_output_buffer = empty_output_buffer;
215  dest->pub.term_destination = term_destination;
216  dest->outfile = outfile;
217 }
my_destination_mgr * my_dest_ptr
Definition: jdatadst.c:38
struct jpeg_common_struct * j_common_ptr
Definition: jpeglib.h:284
static FILE * outfile
Definition: wrjpgcom.c:81
#define SIZEOF(_ar)
Definition: calc.h:97
term_destination(j_compress_ptr cinfo)
Definition: jdatadst.c:163
smooth NULL
Definition: ftsmooth.c:416
struct jpeg_destination_mgr * dest
Definition: jpeglib.h:295
init_destination(j_compress_ptr cinfo)
Definition: jdatadst.c:64
empty_output_buffer(j_compress_ptr cinfo)
Definition: jdatadst.c:108
#define JPOOL_PERMANENT
Definition: jpeglib.h:807
static char * dest
Definition: rtl.c:135

Referenced by main(), and write_JPEG_file().

◆ JPP() [1/2]

void* malloc JPP ( (size_t size )

◆ JPP() [2/2]

void free JPP ( (void *ptr )

◆ term_destination()

term_destination ( j_compress_ptr  cinfo)

Definition at line 163 of file jdatadst.c.

164 {
165  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
166  size_t datacount = OUTPUT_BUF_SIZE - dest->pub.free_in_buffer;
167 
168  /* Write any data remaining in the buffer */
169  if (datacount > 0) {
170  if (JFWRITE(dest->outfile, dest->buffer, datacount) != datacount)
171  ERREXIT(cinfo, JERR_FILE_WRITE);
172  }
173  JFFLUSH(dest->outfile);
174  /* Make sure we wrote the output file OK */
175  if (JFERROR(dest->outfile))
176  ERREXIT(cinfo, JERR_FILE_WRITE);
177 }
#define ERREXIT(msg)
Definition: rdjpgcom.c:72
my_destination_mgr * my_dest_ptr
Definition: jdatadst.c:38
#define JFERROR(file)
Definition: jinclude.h:97
#define JFWRITE(file, buf, sizeofbuf)
Definition: jinclude.h:94
#define JFFLUSH(file)
Definition: jinclude.h:96
if(!(yy_init))
Definition: macro.lex.yy.c:714
struct jpeg_destination_mgr * dest
Definition: jpeglib.h:295
static char * dest
Definition: rtl.c:135
#define OUTPUT_BUF_SIZE
Definition: jdatadst.c:40

Referenced by jpeg_stdio_dest().

◆ term_mem_destination()

term_mem_destination ( j_compress_ptr  cinfo)

Definition at line 180 of file jdatadst.c.

181 {
183 
184  *dest->outbuffer = dest->buffer;
185  *dest->outsize = dest->bufsize - dest->pub.free_in_buffer;
186 }
my_mem_destination_mgr * my_mem_dest_ptr
Definition: jdatadst.c:55
struct jpeg_destination_mgr * dest
Definition: jpeglib.h:295
static char * dest
Definition: rtl.c:135

Referenced by jpeg_mem_dest().