Added curve-based color as the canvas background color (red, green, and blue), so it can be animated now.

This commit is contained in:
Jonathan Thomas
2012-11-29 17:28:22 -06:00
parent d3ef1fac13
commit ab4069464a
3 changed files with 33 additions and 7 deletions

View File

@@ -30,6 +30,12 @@ namespace openshot {
return lhs->Position() <= rhs->Position() && lhs->Layer() < rhs->Layer();
}};
struct Color{
Keyframe red; ///<Curve representing the red value (0 - 65536)
Keyframe blue; ///<Curve representing the red value (0 - 65536)
Keyframe green; ///<Curve representing the red value (0 - 65536)
};
/**
* \brief This class represents a timeline
*
@@ -50,7 +56,7 @@ namespace openshot {
Cache final_cache; ///<Final cache of timeline frames
/// Process a new layer of video or audio
void add_layer(tr1::shared_ptr<Frame> new_frame, Clip* source_clip, int clip_frame_number);
void add_layer(tr1::shared_ptr<Frame> new_frame, Clip* source_clip, int clip_frame_number, int timeline_frame_number);
/// Calculate time of a frame number, based on a framerate
float calculate_time(int number, Framerate rate);
@@ -98,6 +104,9 @@ namespace openshot {
Keyframe viewport_x; ///<Curve representing the x coordinate for the viewport
Keyframe viewport_y; ///<Curve representing the y coordinate for the viewport
// Background color
Color color; ///<Background color of timeline canvas
/// Open the reader (and start consuming resources)
void Open();

View File

@@ -55,6 +55,8 @@ int main()
// Create timeline
Timeline t(624, 348, Framerate(24,1), 44100, 2);
t.color.blue.AddPoint(1, 0);
t.color.blue.AddPoint(300, 65000);
// Add some clips
//Clip c1(new FFmpegReader("/home/jonathan/Apps/videcho_site/media/user_files/videos/bd0bf442-3221-11e2-8bf6-001fd00ee3aa.webm"));
@@ -171,8 +173,8 @@ int main()
// Add clips
t.AddClip(&c1);
t.AddClip(&c2);
t.AddClip(&c3);
//t.AddClip(&c2);
//t.AddClip(&c3);
// Create a writer

View File

@@ -11,6 +11,11 @@ Timeline::Timeline(int width, int height, Framerate fps, int sample_rate, int ch
viewport_x = Keyframe(0.0);
viewport_y = Keyframe(0.0);
// Init background color
color.red = Keyframe(0.0);
color.green = Keyframe(0.0);
color.blue = Keyframe(0.0);
// Init cache
int64 bytes = height * width * 4 + (44100 * 2 * 4);
final_cache = Cache(20 * bytes); // 20 frames, 4 colors of chars, 2 audio channels of 4 byte floats
@@ -50,7 +55,7 @@ float Timeline::calculate_time(int number, Framerate rate)
}
// Process a new layer of video or audio
void Timeline::add_layer(tr1::shared_ptr<Frame> new_frame, Clip* source_clip, int clip_frame_number)
void Timeline::add_layer(tr1::shared_ptr<Frame> new_frame, Clip* source_clip, int clip_frame_number, int timeline_frame_number)
{
// Get the clip's frame & image
tr1::shared_ptr<Frame> source_frame;
@@ -60,7 +65,12 @@ void Timeline::add_layer(tr1::shared_ptr<Frame> new_frame, Clip* source_clip, in
/* CREATE BACKGROUND COLOR - needed if this is the 1st layer */
if (new_frame->GetImage()->columns() == 1)
new_frame->AddColor(width, height, "#000000");
{
int red = color.red.GetInt(timeline_frame_number);
int green = color.green.GetInt(timeline_frame_number);
int blue = color.blue.GetInt(timeline_frame_number);
new_frame->AddColor(width, height, Magick::Color(red, green, blue));
}
/* COPY AUDIO - with correct volume */
for (int channel = 0; channel < source_frame->GetAudioChannelsCount(); channel++)
@@ -334,14 +344,19 @@ tr1::shared_ptr<Frame> Timeline::GetFrame(int requested_frame) throw(ReaderClose
int clip_frame_number = round(time_diff * fps.GetFPS()) + 1;
// Add clip's frame as layer
add_layer(new_frame, clip, clip_frame_number);
add_layer(new_frame, clip, clip_frame_number, frame_number);
} else
cout << "FRAME NOT IN CLIP DURATION: frame: " << frame_number << ", pos: " << clip->Position() << ", end: " << clip->End() << endl;
// Check for empty frame image (and fill with color)
if (new_frame->GetImage()->columns() == 1)
new_frame->AddColor(width, height, "#000000");
{
int red = color.red.GetInt(frame_number);
int green = color.green.GetInt(frame_number);
int blue = color.blue.GetInt(frame_number);
new_frame->AddColor(width, height, Magick::Color(red, green, blue));
}
// Add final frame to cache
#pragma omp critical (timeline_cache)