Make FloatAutos::get_values() always use a PLAY_FORWARD direction.
[cinelerra_cv/pmdumuid.git] / quicktime / jdatadst.c
bloba4904e6f75e7ceac0ee12d3206af2e7dea60832f
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "jpeg.h"
4 #include "jpeglib.h"
5 #include "jerror.h"
8 /* Expanded data destination object for stdio output */
10 typedef struct {
11 struct jpeg_destination_mgr pub; /* public fields */
13 JOCTET *buffer; /* Pointer to buffer */
14 mjpa_compress_engine *engine;
15 } my_destination_mgr;
17 typedef my_destination_mgr *my_dest_ptr;
21 * Initialize destination --- called by jpeg_start_compress
22 * before any data is actually written.
25 METHODDEF(void)
26 init_destination (j_compress_ptr cinfo)
28 my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
30 /* Set the pointer to the preallocated buffer */
31 dest->buffer = dest->engine->output_buffer;
33 dest->pub.next_output_byte = dest->buffer;
34 dest->pub.free_in_buffer = dest->engine->output_allocated;
39 * Empty the output buffer --- called whenever buffer fills up.
41 * In typical applications, this should write the entire output buffer
42 * (ignoring the current state of next_output_byte & free_in_buffer),
43 * reset the pointer & count to the start of the buffer, and return TRUE
44 * indicating that the buffer has been dumped.
46 * In applications that need to be able to suspend compression due to output
47 * overrun, a FALSE return indicates that the buffer cannot be emptied now.
48 * In this situation, the compressor will return to its caller (possibly with
49 * an indication that it has not accepted all the supplied scanlines). The
50 * application should resume compression after it has made more room in the
51 * output buffer. Note that there are substantial restrictions on the use of
52 * suspension --- see the documentation.
54 * When suspending, the compressor will back up to a convenient restart point
55 * (typically the start of the current MCU). next_output_byte & free_in_buffer
56 * indicate where the restart point will be if the current call returns FALSE.
57 * Data beyond this point will be regenerated after resumption, so do not
58 * write it out when emptying the buffer externally.
61 METHODDEF(boolean)
62 empty_output_buffer (j_compress_ptr cinfo)
64 /* Allocate a bigger buffer. */
65 my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
66 char *new_buffer;
67 int new_size, i;
68 int offset = dest->engine->output_allocated;
70 new_size = dest->engine->output_allocated * 2;
71 new_buffer = malloc(new_size);
72 for(i = 0; i < offset; i++)
73 new_buffer[i] = dest->engine->output_buffer[i];
74 free(dest->engine->output_buffer);
75 dest->engine->output_buffer = new_buffer;
76 dest->engine->output_allocated = new_size;
77 dest->buffer = dest->engine->output_buffer;
79 dest->pub.next_output_byte = dest->buffer + offset;
80 dest->pub.free_in_buffer = dest->engine->output_allocated - offset;
82 return TRUE;
87 * Terminate destination --- called by jpeg_finish_compress
88 * after all data has been written. Usually needs to flush buffer.
90 * NB: *not* called by jpeg_abort or jpeg_destroy; surrounding
91 * application must deal with any cleanup that should happen even
92 * for error exit.
95 METHODDEF(void)
96 term_destination (j_compress_ptr cinfo)
98 /* Just get the length */
99 my_dest_ptr dest = (my_dest_ptr) cinfo->dest;
100 dest->engine->output_size = dest->engine->output_allocated - dest->pub.free_in_buffer;
105 * Prepare for output to a stdio stream.
106 * The caller must have already opened the stream, and is responsible
107 * for closing it after finishing compression.
110 GLOBAL(void)
111 jpeg_buffer_dest (j_compress_ptr cinfo, mjpa_compress_engine *engine)
113 my_dest_ptr dest;
115 /* The destination object is made permanent so that multiple JPEG images
116 * can be written to the same file without re-executing jpeg_stdio_dest.
117 * This makes it dangerous to use this manager and a different destination
118 * manager serially with the same JPEG object, because their private object
119 * sizes may be different. Caveat programmer.
121 if (cinfo->dest == NULL) { /* first time for this JPEG object? */
122 cinfo->dest = (struct jpeg_destination_mgr *)
123 (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
124 sizeof(my_destination_mgr));
127 dest = (my_dest_ptr) cinfo->dest;
128 dest->pub.init_destination = init_destination;
129 dest->pub.empty_output_buffer = empty_output_buffer;
130 dest->pub.term_destination = term_destination;
131 dest->engine = engine;