Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / quicktime / libmjpeg.h
blob15da8fcd8532c7174460b342a7425dd204792a1d
1 /*
2 * This library is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU Lesser General Public License as published
4 * by the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This library is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with this library; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
15 * USA
18 #ifndef LIBMJPEG_H
19 #define LIBMJPEG_H
22 /* Motion JPEG library */
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
32 #include <stdio.h>
33 #include <jpeglib.h>
34 #include <png.h> /* Need setjmp.h as included by png.h */
35 #include "pthread.h"
37 #define MAXFIELDS 2
38 #define QUICKTIME_MJPA_MARKSIZE 40
39 #define QUICKTIME_JPEG_TAG 0x6d6a7067
42 struct mjpeg_error_mgr {
43 struct jpeg_error_mgr pub; /* "public" fields */
44 jmp_buf setjmp_buffer; /* for return to caller */
47 typedef struct mjpeg_error_mgr* mjpeg_error_ptr;
49 #ifndef __alpha__
50 typedef struct
52 } mjpeg_lml_hdr;
54 typedef struct
56 } mjpeg_dc10_hdr;
57 #endif
60 // The compressor structure is shared between decompressors and compressors
61 typedef struct
63 void *mjpeg;
64 int instance;
65 unsigned char *output_buffer; /* Buffer for MJPEG output */
66 long output_size; /* Size of image stored in buffer */
67 long output_allocated; /* Allocated size of output buffer */
68 struct jpeg_decompress_struct jpeg_decompress;
69 struct jpeg_compress_struct jpeg_compress;
70 struct mjpeg_error_mgr jpeg_error;
71 pthread_t tid; /* ID of thread */
72 pthread_mutex_t input_lock, output_lock;
73 int done; /* Flag to end */
74 int error;
75 // Pointer to uncompressed YUV rows
76 // [3 planes][downsampled rows][downsampled pixels]
77 unsigned char **rows[3];
78 /* Temp rows for each MCU */
79 unsigned char **mcu_rows[3];
80 /* Height of the field */
81 int field_h;
82 int coded_field_h;
83 } mjpeg_compressor;
85 typedef struct
87 // Dimensions of user frame buffer
88 int output_w;
89 int output_h;
90 // Dimensions for encoder frame buffer
91 int coded_w, coded_h;
92 int fields;
93 int quality;
94 int use_float;
95 int kludge;
96 int cpus;
97 // Color model of user interface.
98 int color_model;
99 // Color model of compressed data. Since MJPA streams use 4:2:0
100 int jpeg_color_model;
101 // To save on colormodel permutations, we flag grayscale separately and
102 // just set U and V to 0x80.
103 int greyscale;
104 // Error in compression process
105 int error;
107 mjpeg_compressor *compressors[MAXFIELDS];
108 mjpeg_compressor *decompressors[MAXFIELDS];
110 // Temp frame for interlacing
111 // [3 planes][downsampled rows][downsampled pixels]
112 unsigned char *temp_data;
113 unsigned char **temp_rows[3];
114 unsigned char **row_argument, *y_argument, *u_argument, *v_argument;
116 // Buffer passed to user
117 // This can contain one progressive field or two fields with headers
118 unsigned char *output_data;
119 long output_size;
120 long output_allocated;
121 // Offset to field2 in output_data
122 long output_field2;
123 // Buffer passed from user
124 unsigned char *input_data;
125 long input_size;
126 // Offset to field2 in input_data
127 long input_field2;
128 int deinterlace;
129 int rowspan;
131 // Workarounds for thread unsafe libraries
132 pthread_mutex_t decompress_init;
133 int decompress_initialized;
134 } mjpeg_t;
140 // Entry points
141 mjpeg_t* mjpeg_new(int w,
142 int h,
143 int fields);
144 void mjpeg_delete(mjpeg_t *mjpeg);
146 void mjpeg_set_quality(mjpeg_t *mjpeg, int quality);
147 void mjpeg_set_float(mjpeg_t *mjpeg, int use_float);
148 // This is useful when producing realtime NTSC output for a JPEG board.
149 void mjpeg_set_deinterlace(mjpeg_t *mjpeg, int value);
150 void mjpeg_set_cpus(mjpeg_t *mjpeg, int cpus);
151 void mjpeg_set_rowspan(mjpeg_t *mjpeg, int rowspan);
154 int mjpeg_get_fields(mjpeg_t *mjpeg);
156 int mjpeg_decompress(mjpeg_t *mjpeg,
157 unsigned char *buffer,
158 long buffer_len,
159 long input_field2,
160 unsigned char **row_pointers,
161 unsigned char *y_plane,
162 unsigned char *u_plane,
163 unsigned char *v_plane,
164 int color_model,
165 int cpus);
167 int mjpeg_compress(mjpeg_t *mjpeg,
168 unsigned char **row_pointers,
169 unsigned char *y_plane,
170 unsigned char *u_plane,
171 unsigned char *v_plane,
172 int color_model,
173 int cpus);
175 // Get buffer information after compressing
176 unsigned char* mjpeg_output_buffer(mjpeg_t *mjpeg);
177 // Called by decoder
178 long mjpeg_output_field2(mjpeg_t *mjpeg);
179 // Called before inserting markers by user
180 long mjpeg_output_size(mjpeg_t *mjpeg);
181 // Called before inserting markers by user
182 long mjpeg_output_allocated(mjpeg_t *mjpeg);
183 // Called after inserting markers by user to increase the size
184 void mjpeg_set_output_size(mjpeg_t *mjpeg, long output_size);
186 // Retrieve width and height from a buffer of JPEG data
187 void mjpeg_video_size(unsigned char *data, long data_size, int *w, int *h);
191 // Calculate marker contents and insert them into a buffer.
192 // Reallocates the buffer if it isn't big enough so make sure it's big enough
193 // when passing VFrames.
194 // field2_offset is set to -1 if the markers already exist or the field offset
195 // if markers don't already exist.
196 void mjpeg_insert_quicktime_markers(unsigned char **buffer,
197 long *buffer_size,
198 long *buffer_allocated,
199 int fields,
200 long *field2_offset);
201 void mjpeg_insert_avi_markers(unsigned char **buffer,
202 long *buffer_size,
203 long *buffer_allocated,
204 int fields,
205 long *field2_offset);
207 // Get the second field offset from the markers
208 long mjpeg_get_buz_field2(unsigned char *buffer, long buffer_size);
209 long mjpeg_get_lml33_field2(unsigned char *buffer, long buffer_size);
210 long mjpeg_get_quicktime_field2(unsigned char *buffer, long buffer_size);
211 // Field dominance is retrieved for the jpeg decoder. AVI stores field
212 // dominance in each field.
213 long mjpeg_get_avi_field2(unsigned char *buffer,
214 long buffer_size,
215 int *field_dominance);
216 long mjpeg_get_field2(unsigned char *buffer, long buffer_size);
218 #ifdef __cplusplus
220 #endif
222 #endif