jmemdst.c
Go to the documentation of this file.
1 /*
2  * jmemdst.c
3  *
4  * Copyright (C) 1994-1996, Toshihiro Matsui, Electrotechnical Laboratory
5  */
6 
7 #include <stdio.h>
8 #include <jpeglib.h>
9 #include <jerror.h>
10 
11 /* Expanded data destination object for stdio output */
12 
13 typedef struct {
14  struct jpeg_destination_mgr pub; /* public fields */
15  JOCTET * buffer; /* start of buffer */
18 
20 
21 /*
22  * Initialize destination --- called by jpeg_start_compress
23  * before any data is actually written.
24  */
25 
26 
27 METHODDEF(void)
28 init_destination (j_compress_ptr cinfo)
29 {
30  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
31 
32  dest->pub.next_output_byte = dest->buffer;
33  dest->pub.free_in_buffer = *dest->data_count_ptr;
34 }
35 
36 /*
37  * Empty the output buffer --- called whenever buffer fills up.
38  *
39  * In typical applications, this should write the entire output buffer
40  * (ignoring the current state of next_output_byte & free_in_buffer),
41  * reset the pointer & count to the start of the buffer, and return TRUE
42  * indicating that the buffer has been dumped.
43  *
44  * In applications that need to be able to suspend compression due to output
45  * overrun, a FALSE return indicates that the buffer cannot be emptied now.
46  * In this situation, the compressor will return to its caller (possibly with
47  * an indication that it has not accepted all the supplied scanlines). The
48  * application should resume compression after it has made more room in the
49  * output buffer. Note that there are substantial restrictions on the use of
50  * suspension --- see the documentation.
51  *
52  * When suspending, the compressor will back up to a convenient restart point
53  * (typically the start of the current MCU). next_output_byte & free_in_buffer
54  * indicate where the restart point will be if the current call returns FALSE.
55  * Data beyond this point will be regenerated after resumption, so do not
56  * write it out when emptying the buffer externally.
57  */
58 
59 METHODDEF(boolean)
60 empty_output_buffer (j_compress_ptr cinfo)
61 {
62  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
63 
64 
65  fprintf(stderr, " : jpeg compression buffer overflow >%ld\n",
66  *dest->data_count_ptr);
67 
68  dest->pub.next_output_byte = dest->buffer;
69  dest->pub.free_in_buffer = *dest->data_count_ptr;
70 
71  return TRUE;
72 }
73 
74 /*
75  * Terminate destination --- called by jpeg_finish_compress
76  * after all data has been written. Usually needs to flush buffer.
77  *
78  * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
79  * application must deal with any cleanup that should happen even
80  * for error exit.
81  */
82 
83 METHODDEF(void)
84 term_destination (j_compress_ptr cinfo)
85 {
86  my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
87  size_t datacount = *dest->data_count_ptr - dest->pub.free_in_buffer;
88 
89  *dest->data_count_ptr = datacount;
90  }
91 
92 
93 GLOBAL(void)
94 jpeg_memio_dest (j_compress_ptr cinfo, JOCTET *jpegimgbuf, long *size)
95 {
96  my_dest_ptr dest;
97 
98  /* RGB image (provided by the main) is compressed into jpegimgbuf
99  * and the size of the resulted JPEG data appears in the size.
100  * The size should hold the maximum size of the jpegimgbuf at the beginning.
101  */
102 
103  if (cinfo->dest == NULL) { /* first time for this JPEG object? */
104  cinfo->dest = (struct jpeg_destination_mgr *)
105  (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
106  sizeof(my_destination_mgr));
107  }
108 
109  dest = (my_dest_ptr) cinfo->dest;
110  dest->pub.init_destination = init_destination;
111  dest->pub.empty_output_buffer = empty_output_buffer;
112  dest->pub.term_destination = term_destination;
113  dest->buffer = jpegimgbuf;
114  dest->data_count_ptr = size;
115 }
jpeg_memio_dest(j_compress_ptr cinfo, JOCTET *jpegimgbuf, long *size)
Definition: jmemdst.c:94
init_destination(j_compress_ptr cinfo)
Definition: jmemdst.c:28
struct jpeg_destination_mgr pub
Definition: jmemdst.c:14
#define TRUE
Definition: arith.h:19
term_destination(j_compress_ptr cinfo)
Definition: jmemdst.c:84
empty_output_buffer(j_compress_ptr cinfo)
Definition: jmemdst.c:60
JOCTET * buffer
Definition: jmemdst.c:15
#define NULL
Definition: transargv.c:8
my_destination_mgr * my_dest_ptr
Definition: jmemdst.c:19
long * data_count_ptr
Definition: jmemdst.c:16


euslisp
Author(s): Toshihiro Matsui
autogenerated on Fri Feb 21 2020 03:20:54