5 #include "bcpbuffer.inc"
6 #include "bctexture.inc"
7 #include "colormodels.h"
10 class PngReadFunction
;
13 // Maximum number of prev or next effects to be pushed onto the stacks.
14 #define MAX_STACK_ELEMENTS 255
21 // Create new frame with shared data if *data is nonzero.
22 // Pass 0 to *data if private data is desired.
23 VFrame(unsigned char *data
,
26 int color_model
= BC_RGBA8888
,
27 long bytes_per_line
= -1);
28 VFrame(unsigned char *data
,
34 int color_model
= BC_RGBA8888
,
35 long bytes_per_line
= -1);
36 // Create a frame with the png image
37 VFrame(unsigned char *png_data
);
38 VFrame(VFrame
&vframe
);
39 // Create new frame for compressed data.
43 friend class PngReadFunction
;
45 // Return 1 if the colormodel and dimensions are the same
47 int equivalent(VFrame
*src
);
49 // Reallocate a frame without deleting the class
50 int reallocate(unsigned char *data
,
59 void set_memory(unsigned char *data
,
64 void set_compressed_memory(unsigned char *data
,
68 // Read a PNG into the frame with alpha
69 int read_png(unsigned char *data
);
71 // if frame points to the same data as this return 1
72 int equals(VFrame
*frame
);
73 // Test if frame already matches parameters
74 int params_match(int w
, int h
, int color_model
);
76 long set_shm_offset(long offset
);
77 long get_shm_offset();
79 // direct copy with no alpha
80 int copy_from(VFrame
*frame
);
83 int allocate_compressed_data(long bytes
);
85 // Sequence number. -1 means invalid. Passing frames to the encoder is
86 // asynchronous. The sequence number must be preserved in the image itself
87 // to encode discontinuous frames.
89 void set_number(long number
);
91 long get_compressed_allocated();
92 long get_compressed_size();
93 long set_compressed_size(long size
);
94 int get_color_model();
95 // Get the data pointer
96 unsigned char* get_data();
97 // return an array of pointers to rows
98 unsigned char** get_rows();
100 unsigned char* get_y();
101 unsigned char* get_u();
102 unsigned char* get_v();
107 static int get_scale_tables(int *column_table
, int *row_table
,
108 int in_x1
, int in_y1
, int in_x2
, int in_y2
,
109 int out_x1
, int out_y1
, int out_x2
, int out_y2
);
110 int get_bytes_per_pixel();
111 long get_bytes_per_line();
112 static int calculate_bytes_per_pixel(int colormodel
);
113 static long calculate_data_size(int w
,
115 int bytes_per_line
= -1,
116 int color_model
= BC_RGB888
);
117 // Get size of uncompressed frame buffer
118 long get_data_size();
123 // Convenience storage.
124 // Returns -1 if not set.
125 int get_field2_offset();
126 int set_field2_offset(int value
);
127 // Set keyframe status
128 void set_keyframe(int value
);
130 // Overlay src onto this with blending and translation of input.
131 // Source and this must have alpha
132 void overlay(VFrame
*src
,
136 // If the opengl state is RAM, transfer image from RAM to the texture
137 // referenced by this frame.
138 // If the opengl state is TEXTURE, do nothing.
139 // If the opengl state is SCREEN, switch the current drawable to the pbuffer and
140 // transfer the image to the texture with screen_to_texture.
141 // The opengl state is changed to TEXTURE.
142 // If no textures exist, textures are created.
143 // If the textures already exist, they are reused.
144 // Textures are resized to match the current dimensions.
145 // Must be called from a synchronous opengl thread after enable_opengl.
149 // Transfer contents of current pbuffer to texture,
150 // creating a new texture if necessary.
151 // Coordinates are the coordinates in the drawable to copy.
152 void screen_to_texture(int x
= -1,
157 // Transfer contents of texture to the current drawable.
158 // Just calls the vertex functions but doesn't initialize.
159 // The coordinates are relative to the VFrame size and flipped to make
160 // the texture upright.
161 // The default coordinates are the size of the VFrame.
162 // flip_y flips the texture in the vertical direction and only used when
163 // writing to the final surface.
164 void draw_texture(float in_x1
,
173 // Draw the texture using the frame's size as the input and output coordinates.
174 void draw_texture(int flip_y
= 0);
178 // ================================ OpenGL functions ===========================
179 // Location of working image if OpenGL playback
180 int get_opengl_state();
181 void set_opengl_state(int value
);
187 // OpenGL image is in RAM
189 // OpenGL image is in texture
191 // OpenGL image is composited in PBuffer or back buffer
196 int get_texture_id();
199 int get_texture_components();
202 // Binds the opengl context to this frame's PBuffer
203 void enable_opengl();
205 // Clears the pbuffer with the right values depending on YUV
206 void clear_pbuffer();
209 // Bind the frame's texture to GL_TEXTURE_2D and enable it.
210 // If a texture_unit is supplied, the texture unit is made active
211 // and the commands are run in the right sequence to
212 // initialize it to our preferred specifications.
213 void bind_texture(int texture_unit
= -1);
217 // Create a frustum with 0,0 in the upper left and w,-h in the bottom right.
218 // Set preferred opengl settings.
219 static void init_screen(int w
, int h
);
220 // Calls init_screen with the current frame's dimensions.
223 // Compiles and links the shaders into a program.
224 // Adds the program with put_shader.
225 // Returns the program handle.
226 // Requires a null terminated argument list of shaders to link together.
227 // At least one shader argument must have a main() function. make_shader
228 // replaces all the main() functions with unique functions and calls them in
229 // sequence, so multiple independant shaders can be linked.
230 // x is a placeholder for va_arg and should be 0.
231 static unsigned int make_shader(int x
, ...);
232 static void dump_shader(int shader_id
);
234 // Because OpenGL is faster if multiple effects are combined, we need
235 // to provide ways for effects to aggregate.
236 // The prev_effect is the object providing the data to read_frame.
237 // The next_effect is the object which called read_frame.
238 // Push and pop are only called from Cinelerra internals, so
239 // if an object calls read_frame with a temporary, the stack before and after
240 // the temporary is lost.
241 void push_prev_effect(char *name
);
242 void pop_prev_effect();
243 void push_next_effect(char *name
);
244 void pop_next_effect();
247 // Copy stacks and params from another frame
248 // Replaces the stacks with the src stacks but only updates the params.
249 void copy_stacks(VFrame
*src
);
251 // This clears the stacks and the param table
257 // Create a PBuffer matching this frame's dimensions and to be
258 // referenced by this frame. Does nothing if the pbuffer already exists.
259 // If the frame is resized, the PBuffer is deleted.
260 // Called by enable_opengl.
261 // This allows PBuffers, textures, and bitmaps to travel through the entire
262 // rendering chain without requiring the user to manage a lot of objects.
263 // Must be called from a synchronous opengl thread after enable_opengl.
264 void create_pbuffer();
268 int clear_objects(int do_opengl
);
269 int reset_parameters(int do_opengl
);
270 void create_row_pointers();
271 int allocate_data(unsigned char *data
,
278 long bytes_per_line
);
280 // Convenience storage
282 // Data is pointing to someone else's buffer.
285 // If not set by user, is calculated from color_model
290 // Pointers to the start of each row
291 unsigned char **rows
;
292 // One of the #defines
294 // Allocated space for compressed data
295 long compressed_allocated
;
296 // Size of stored compressed image
297 long compressed_size
;
298 // Pointers to yuv planes
299 unsigned char *y
, *u
, *v
;
303 // Dimensions of frame
305 // Info for reading png images
306 unsigned char *image
;
309 // For writing discontinuous frames in background rendering
310 long sequence_number
;
314 // State of the current texture
316 // State of the current PBuffer
319 // Location of working image if OpenGL playback
322 ArrayList
<char*> prev_effects
;
323 ArrayList
<char*> next_effects
;