Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / guicast / vframe.h
blob8cc69e9140247fe5c645b058d068cdaf1dd0e6e7
1 #ifndef VFRAME_H
2 #define VFRAME_H
4 #include "arraylist.h"
5 #include "bchash.inc"
6 #include "bcpbuffer.inc"
7 #include "bctexture.inc"
8 #include "bcwindowbase.inc"
9 #include "colormodels.h"
10 #include "vframe.inc"
12 class PngReadFunction;
15 // Maximum number of prev or next effects to be pushed onto the stacks.
16 #define MAX_STACK_ELEMENTS 255
20 class VFrame
22 public:
23 // Create new frame with shared data if *data is nonzero.
24 // Pass 0 to *data if private data is desired.
25 VFrame(unsigned char *data,
26 int w,
27 int h,
28 int color_model = BC_RGBA8888,
29 long bytes_per_line = -1);
30 VFrame(unsigned char *data,
31 long y_offset,
32 long u_offset,
33 long v_offset,
34 int w,
35 int h,
36 int color_model = BC_RGBA8888,
37 long bytes_per_line = -1);
38 // Create a frame with the png image
39 VFrame(unsigned char *png_data);
40 VFrame(VFrame &vframe);
41 // Create new frame for compressed data.
42 VFrame();
43 ~VFrame();
45 friend class PngReadFunction;
47 // Return 1 if the colormodel and dimensions are the same
48 // Used by FrameCache
49 int equivalent(VFrame *src, int test_stacks = 0);
51 // Reallocate a frame without deleting the class
52 int reallocate(unsigned char *data,
53 long y_offset,
54 long u_offset,
55 long v_offset,
56 int w,
57 int h,
58 int color_model,
59 long bytes_per_line);
61 void set_memory(unsigned char *data,
62 long y_offset,
63 long u_offset,
64 long v_offset);
66 void set_compressed_memory(unsigned char *data,
67 int data_size,
68 int data_allocated);
70 // Read a PNG into the frame with alpha
71 int read_png(unsigned char *data);
73 // if frame points to the same data as this return 1
74 int equals(VFrame *frame);
75 // Test if frame already matches parameters
76 int params_match(int w, int h, int color_model);
78 long set_shm_offset(long offset);
79 long get_shm_offset();
81 // direct copy with no alpha
82 int copy_from(VFrame *frame);
83 // Required for YUV
84 int clear_frame();
85 int allocate_compressed_data(long bytes);
87 // Sequence number. -1 means invalid. Passing frames to the encoder is
88 // asynchronous. The sequence number must be preserved in the image itself
89 // to encode discontinuous frames.
90 long get_number();
91 void set_number(long number);
93 long get_compressed_allocated();
94 long get_compressed_size();
95 long set_compressed_size(long size);
96 int get_color_model();
97 // Get the data pointer
98 unsigned char* get_data();
99 // return an array of pointers to rows
100 unsigned char** get_rows();
101 // return yuv planes
102 unsigned char* get_y();
103 unsigned char* get_u();
104 unsigned char* get_v();
105 int get_w();
106 int get_h();
107 int get_w_fixed();
108 int get_h_fixed();
109 static int get_scale_tables(int *column_table, int *row_table,
110 int in_x1, int in_y1, int in_x2, int in_y2,
111 int out_x1, int out_y1, int out_x2, int out_y2);
112 int get_bytes_per_pixel();
113 long get_bytes_per_line();
114 // Return 1 if the buffer is shared.
115 int get_shared();
119 static int calculate_bytes_per_pixel(int colormodel);
120 static long calculate_data_size(int w,
121 int h,
122 int bytes_per_line = -1,
123 int color_model = BC_RGB888);
124 // Get size of uncompressed frame buffer
125 long get_data_size();
126 void rotate270();
127 void rotate90();
128 void flip_vert();
130 // Convenience storage.
131 // Returns -1 if not set.
132 int get_field2_offset();
133 int set_field2_offset(int value);
134 // Set keyframe status
135 void set_keyframe(int value);
136 int get_keyframe();
137 // Overlay src onto this with blending and translation of input.
138 // Source and this must have alpha
139 void overlay(VFrame *src,
140 int out_x1,
141 int out_y1);
143 // If the opengl state is RAM, transfer image from RAM to the texture
144 // referenced by this frame.
145 // If the opengl state is TEXTURE, do nothing.
146 // If the opengl state is SCREEN, switch the current drawable to the pbuffer and
147 // transfer the image to the texture with screen_to_texture.
148 // The opengl state is changed to TEXTURE.
149 // If no textures exist, textures are created.
150 // If the textures already exist, they are reused.
151 // Textures are resized to match the current dimensions.
152 // Must be called from a synchronous opengl thread after enable_opengl.
153 void to_texture();
155 // Transfer from PBuffer to RAM. Only used after Playback3D::overlay_sync
156 void to_ram();
158 // Transfer contents of current pbuffer to texture,
159 // creating a new texture if necessary.
160 // Coordinates are the coordinates in the drawable to copy.
161 void screen_to_texture(int x = -1,
162 int y = -1,
163 int w = -1,
164 int h = -1);
166 // Transfer contents of texture to the current drawable.
167 // Just calls the vertex functions but doesn't initialize.
168 // The coordinates are relative to the VFrame size and flipped to make
169 // the texture upright.
170 // The default coordinates are the size of the VFrame.
171 // flip_y flips the texture in the vertical direction and only used when
172 // writing to the final surface.
173 void draw_texture(float in_x1,
174 float in_y1,
175 float in_x2,
176 float in_y2,
177 float out_x1,
178 float out_y1,
179 float out_x2,
180 float out_y2,
181 int flip_y = 0);
182 // Draw the texture using the frame's size as the input and output coordinates.
183 void draw_texture(int flip_y = 0);
187 // ================================ OpenGL functions ===========================
188 // Location of working image if OpenGL playback
189 int get_opengl_state();
190 void set_opengl_state(int value);
191 // OpenGL states
192 enum
194 // Undefined
195 UNKNOWN,
196 // OpenGL image is in RAM
197 RAM,
198 // OpenGL image is in texture
199 TEXTURE,
200 // OpenGL image is composited in PBuffer or back buffer
201 SCREEN
204 // Texture ID
205 int get_texture_id();
206 void set_texture_id(int id);
207 // Get window ID the texture is bound to
208 int get_window_id();
209 int get_texture_w();
210 int get_texture_h();
211 int get_texture_components();
214 // Binds the opengl context to this frame's PBuffer
215 void enable_opengl();
217 // Clears the pbuffer with the right values depending on YUV
218 void clear_pbuffer();
220 // Get the pbuffer
221 BC_PBuffer* get_pbuffer();
223 // Bind the frame's texture to GL_TEXTURE_2D and enable it.
224 // If a texture_unit is supplied, the texture unit is made active
225 // and the commands are run in the right sequence to
226 // initialize it to our preferred specifications.
227 void bind_texture(int texture_unit = -1);
231 // Create a frustum with 0,0 in the upper left and w,-h in the bottom right.
232 // Set preferred opengl settings.
233 static void init_screen(int w, int h);
234 // Calls init_screen with the current frame's dimensions.
235 void init_screen();
237 // Compiles and links the shaders into a program.
238 // Adds the program with put_shader.
239 // Returns the program handle.
240 // Requires a null terminated argument list of shaders to link together.
241 // At least one shader argument must have a main() function. make_shader
242 // replaces all the main() functions with unique functions and calls them in
243 // sequence, so multiple independant shaders can be linked.
244 // x is a placeholder for va_arg and should be 0.
245 static unsigned int make_shader(int x, ...);
246 static void dump_shader(int shader_id);
248 // Because OpenGL is faster if multiple effects are combined, we need
249 // to provide ways for effects to aggregate.
250 // The prev_effect is the object providing the data to read_frame.
251 // The next_effect is the object which called read_frame.
252 // Push and pop are only called from Cinelerra internals, so
253 // if an object calls read_frame with a temporary, the stack before and after
254 // the temporary is lost.
255 void push_prev_effect(char *name);
256 void pop_prev_effect();
257 void push_next_effect(char *name);
258 void pop_next_effect();
259 // These are called by plugins to determine aggregation.
260 // They access any member of the stack based on the number argument.
261 // next effect 0 is the one that called read_frame most recently.
262 // prev effect 0 is the one that filled our call to read_frame.
263 char* get_next_effect(int number = 0);
264 char* get_prev_effect(int number = 0);
266 // It isn't enough to know the name of the neighboring effects.
267 // Relevant configuration parameters must be passed on.
268 BC_Hash* get_params();
270 // Compare stacks and params from 2 images and return 1 if equal.
271 int equal_stacks(VFrame *src);
273 // Copy stacks and params from another frame
274 // Replaces the stacks with the src stacks but only updates the params.
275 void copy_stacks(VFrame *src);
276 // Updates the params with values from src
277 void copy_params(VFrame *src);
279 // This clears the stacks and the param table
280 void clear_stacks();
282 void dump_stacks();
283 void dump_params();
285 private:
287 // Create a PBuffer matching this frame's dimensions and to be
288 // referenced by this frame. Does nothing if the pbuffer already exists.
289 // If the frame is resized, the PBuffer is deleted.
290 // Called by enable_opengl.
291 // This allows PBuffers, textures, and bitmaps to travel through the entire
292 // rendering chain without requiring the user to manage a lot of objects.
293 // Must be called from a synchronous opengl thread after enable_opengl.
294 void create_pbuffer();
298 int clear_objects(int do_opengl);
299 int reset_parameters(int do_opengl);
300 void create_row_pointers();
301 int allocate_data(unsigned char *data,
302 long y_offset,
303 long u_offset,
304 long v_offset,
305 int w,
306 int h,
307 int color_model,
308 long bytes_per_line);
310 // Convenience storage
311 int field2_offset;
312 // Data is pointing to someone else's buffer.
313 int shared;
314 long shm_offset;
315 // If not set by user, is calculated from color_model
316 long bytes_per_line;
317 int bytes_per_pixel;
318 // Image data
319 unsigned char *data;
320 // Pointers to the start of each row
321 unsigned char **rows;
322 // One of the #defines
323 int color_model;
324 // Allocated space for compressed data
325 long compressed_allocated;
326 // Size of stored compressed image
327 long compressed_size;
328 // Pointers to yuv planes
329 unsigned char *y, *u, *v;
330 long y_offset;
331 long u_offset;
332 long v_offset;
333 // Dimensions of frame
334 int w, h;
335 // Info for reading png images
336 unsigned char *image;
337 long image_offset;
338 long image_size;
339 // For writing discontinuous frames in background rendering
340 long sequence_number;
342 // OpenGL support
343 int is_keyframe;
344 // State of the current texture
345 BC_Texture *texture;
346 // State of the current PBuffer
347 BC_PBuffer *pbuffer;
349 // Location of working image if OpenGL playback
350 int opengl_state;
352 ArrayList<char*> prev_effects;
353 ArrayList<char*> next_effects;
354 BC_Hash *params;
358 #endif
360 // Local Variables:
361 // mode: C++
362 // c-file-style: "linux"
363 // End: