prevent popup deactivation while button_down
[goodguy/history.git] / cinelerra-5.1 / cinelerra / libmjpeg.h
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.
11  *
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
16  */
17
18  #ifndef LIBMJPEG_H
19 #define LIBMJPEG_H
20
21
22 /* Motion JPEG library */
23
24
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30
31
32 #include <stdio.h>
33 #include <jpeglib.h>
34 #include <png.h>
35 #include "pthread.h"
36 #include <setjmp.h>
37
38 #define MAXFIELDS 2
39 #define QUICKTIME_MJPA_MARKSIZE 40
40 #define QUICKTIME_JPEG_TAG 0x6d6a7067
41 #define CODEC_TAG_MJPEG "mjpg"
42 #define CODEC_TAG_JPEG "jpeg"
43
44
45 struct mjpeg_error_mgr {
46   struct jpeg_error_mgr pub;    /* "public" fields */
47   jmp_buf setjmp_buffer;        /* for return to caller */
48 };
49
50 typedef struct mjpeg_error_mgr* mjpeg_error_ptr;
51
52 #ifndef __alpha__
53 typedef struct
54 {
55 } mjpeg_lml_hdr;
56
57 typedef struct
58 {
59 } mjpeg_dc10_hdr;
60 #endif
61
62
63 // The compressor structure is shared between decompressors and compressors
64 typedef struct
65 {
66         void *mjpeg;
67         int instance;
68         unsigned char *output_buffer;    /* Buffer for MJPEG output */
69         long output_size;     /* Size of image stored in buffer */
70         long output_allocated;    /* Allocated size of output buffer */
71         struct jpeg_decompress_struct jpeg_decompress;
72         struct jpeg_compress_struct jpeg_compress;
73         struct mjpeg_error_mgr jpeg_error;
74         pthread_t tid;   /* ID of thread */
75         pthread_mutex_t input_lock, output_lock;
76         int done;     /* Flag to end */
77         int error;
78 // Pointer to uncompressed YUV rows
79 // [3 planes][downsampled rows][downsampled pixels]
80         unsigned char **rows[3];
81 /* Temp rows for each MCU */
82         unsigned char **mcu_rows[3];
83 /* Height of the field */
84         int field_h;
85         int coded_field_h;
86 } mjpeg_compressor;
87
88 typedef struct
89 {
90 // Dimensions of user frame buffer
91         int output_w;
92         int output_h;
93 // Dimensions for encoder frame buffer
94         int coded_w, coded_h;
95         int fields;
96         int quality;
97         int use_float;
98         int kludge;
99         int cpus;
100 // Color model of user interface.
101         int color_model;
102 // Color model of compressed data.  Since MJPA streams use 4:2:0
103     int jpeg_color_model;
104 // To save on colormodel permutations, we flag grayscale separately and
105 // just set U and V to 0x80.
106         int greyscale;
107 // Error in compression process
108         int error;
109
110         mjpeg_compressor *compressors[MAXFIELDS];
111         mjpeg_compressor *decompressors[MAXFIELDS];
112
113 // Temp frame for interlacing
114 // [3 planes][downsampled rows][downsampled pixels]
115         unsigned char *temp_data;
116         unsigned char **temp_rows[3];
117         unsigned char **row_argument, *y_argument, *u_argument, *v_argument;
118
119 // Buffer passed to user
120 // This can contain one progressive field or two fields with headers
121         unsigned char *output_data;
122         long output_size;
123         long output_allocated;
124 // Offset to field2 in output_data
125         long output_field2;
126 // Buffer passed from user
127         unsigned char *input_data;
128         long input_size;
129 // Offset to field2 in input_data
130         long input_field2;
131         int deinterlace;
132         int rowspan;
133
134 // Workarounds for thread unsafe libraries
135         pthread_mutex_t decompress_init;
136         int decompress_initialized;
137 } mjpeg_t;
138
139
140
141
142
143 // Entry points
144 mjpeg_t* mjpeg_new(int w,
145         int h,
146         int fields);
147 void mjpeg_delete(mjpeg_t *mjpeg);
148
149 void mjpeg_set_quality(mjpeg_t *mjpeg, int quality);
150 void mjpeg_set_float(mjpeg_t *mjpeg, int use_float);
151 // This is useful when producing realtime NTSC output for a JPEG board.
152 void mjpeg_set_deinterlace(mjpeg_t *mjpeg, int value);
153 void mjpeg_set_cpus(mjpeg_t *mjpeg, int cpus);
154 void mjpeg_set_rowspan(mjpeg_t *mjpeg, int rowspan);
155
156
157 int mjpeg_get_fields(mjpeg_t *mjpeg);
158
159 int mjpeg_decompress(mjpeg_t *mjpeg,
160         unsigned char *buffer,
161         long buffer_len,
162         long input_field2,
163         unsigned char **row_pointers,
164         unsigned char *y_plane,
165         unsigned char *u_plane,
166         unsigned char *v_plane,
167         int color_model,
168         int cpus);
169
170 int mjpeg_compress(mjpeg_t *mjpeg,
171         unsigned char **row_pointers,
172         unsigned char *y_plane,
173         unsigned char *u_plane,
174         unsigned char *v_plane,
175         int color_model,
176         int cpus);
177
178 // Get buffer information after compressing
179 unsigned char* mjpeg_output_buffer(mjpeg_t *mjpeg);
180 // Called by decoder
181 long mjpeg_output_field2(mjpeg_t *mjpeg);
182 // Called before inserting markers by user
183 long mjpeg_output_size(mjpeg_t *mjpeg);
184 // Called before inserting markers by user
185 long mjpeg_output_allocated(mjpeg_t *mjpeg);
186 // Called after inserting markers by user to increase the size
187 void mjpeg_set_output_size(mjpeg_t *mjpeg, long output_size);
188
189 // Retrieve width and height from a buffer of JPEG data
190 void mjpeg_video_size(unsigned char *data, long data_size, int *w, int *h);
191
192
193
194 // Calculate marker contents and insert them into a buffer.
195 // Reallocates the buffer if it isn't big enough so make sure it's big enough
196 // when passing VFrames.
197 // field2_offset is set to -1 if the markers already exist or the field offset
198 // if markers don't already exist.
199 void mjpeg_insert_quicktime_markers(unsigned char **buffer,
200         long *buffer_size,
201         long *buffer_allocated,
202         int fields,
203         long *field2_offset);
204 void mjpeg_insert_avi_markers(unsigned char **buffer,
205         long *buffer_size,
206         long *buffer_allocated,
207         int fields,
208         long *field2_offset);
209
210 // Get the second field offset from the markers
211 long mjpeg_get_buz_field2(unsigned char *buffer, long buffer_size);
212 long mjpeg_get_lml33_field2(unsigned char *buffer, long buffer_size);
213 long mjpeg_get_quicktime_field2(unsigned char *buffer, long buffer_size);
214 // Field dominance is retrieved for the jpeg decoder.  AVI stores field
215 // dominance in each field.
216 long mjpeg_get_avi_field2(unsigned char *buffer,
217         long buffer_size,
218         int *field_dominance);
219 long mjpeg_get_field2(unsigned char *buffer, long buffer_size);
220
221 #ifdef __cplusplus
222 }
223 #endif
224
225 #endif