6 #include "bcpbuffer.inc"
7 #include "bctexture.inc"
8 #include "bcwindowbase.inc"
9 #include "colormodels.h"
12 class PngReadFunction
;
15 // Maximum number of prev or next effects to be pushed onto the stacks.
16 #define MAX_STACK_ELEMENTS 255
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
,
28 int color_model
= BC_RGBA8888
,
29 long bytes_per_line
= -1);
30 VFrame(unsigned char *data
,
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.
45 friend class PngReadFunction
;
47 // Return 1 if the colormodel and dimensions are the same
49 int equivalent(VFrame
*src
, int test_stacks
= 0);
51 // Reallocate a frame without deleting the class
52 int reallocate(unsigned char *data
,
61 void set_memory(unsigned char *data
,
66 void set_compressed_memory(unsigned char *data
,
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
);
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.
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();
102 unsigned char* get_y();
103 unsigned char* get_u();
104 unsigned char* get_v();
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.
119 static int calculate_bytes_per_pixel(int colormodel
);
120 static long calculate_data_size(int w
,
122 int bytes_per_line
= -1,
123 int color_model
= BC_RGB888
);
124 // Get size of uncompressed frame buffer
125 long get_data_size();
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
);
137 // Overlay src onto this with blending and translation of input.
138 // Source and this must have alpha
139 void overlay(VFrame
*src
,
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.
155 // Transfer from PBuffer to RAM. Only used after Playback3D::overlay_sync
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,
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
,
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
);
196 // OpenGL image is in RAM
198 // OpenGL image is in texture
200 // OpenGL image is composited in PBuffer or back buffer
205 int get_texture_id();
206 void set_texture_id(int id
);
207 // Get window ID the texture is bound to
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();
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.
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
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
,
308 long bytes_per_line
);
310 // Convenience storage
312 // Data is pointing to someone else's buffer.
315 // If not set by user, is calculated from color_model
320 // Pointers to the start of each row
321 unsigned char **rows
;
322 // One of the #defines
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
;
333 // Dimensions of frame
335 // Info for reading png images
336 unsigned char *image
;
339 // For writing discontinuous frames in background rendering
340 long sequence_number
;
344 // State of the current texture
346 // State of the current PBuffer
349 // Location of working image if OpenGL playback
352 ArrayList
<char*> prev_effects
;
353 ArrayList
<char*> next_effects
;
362 // c-file-style: "linux"