From ad81fed72e288eae0ce93ef109df7b8e9a3e183f Mon Sep 17 00:00:00 2001 From: Jonathan Thomas Date: Tue, 4 Dec 2012 02:21:01 -0600 Subject: [PATCH] Added alpha to all FFmpegReader source images, which is needed by the timeline class. Also, added alpha to the AddColor() method. Now even the background of the timeline can be transparent, along with all layers... even the bottom layer. --- src/FFmpegReader.cpp | 8 ++++---- src/Frame.cpp | 2 +- src/KeyFrame.cpp | 2 +- src/Main.cpp | 6 +++++- src/Timeline.cpp | 4 ++-- 5 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/FFmpegReader.cpp b/src/FFmpegReader.cpp index 8e0c97f5..f61a3440 100644 --- a/src/FFmpegReader.cpp +++ b/src/FFmpegReader.cpp @@ -32,7 +32,7 @@ void FFmpegReader::InitScalers() for (int x = 0; x < num_of_rescalers; x++) { SwsContext *img_convert_ctx = sws_getContext(info.width, info.height, pCodecCtx->pix_fmt, info.width, - info.height, PIX_FMT_RGB24, SWS_FAST_BILINEAR, NULL, NULL, NULL); + info.height, PIX_FMT_RGBA, SWS_FAST_BILINEAR, NULL, NULL, NULL); // Add rescaler to vector image_rescalers.push_back(img_convert_ctx); @@ -643,13 +643,13 @@ void FFmpegReader::ProcessVideoPacket(int requested_frame) throw OutOfBoundsFrame("Convert Image Broke!", current_frame, video_length); // Determine required buffer size and allocate buffer - numBytes = avpicture_get_size(PIX_FMT_RGB24, width, height); + numBytes = avpicture_get_size(PIX_FMT_RGBA, width, height); buffer = (uint8_t *) av_malloc(numBytes * sizeof(uint8_t)); // Assign appropriate parts of buffer to image planes in pFrameRGB // Note that pFrameRGB is an AVFrame, but AVFrame is a superset // of AVPicture - avpicture_fill((AVPicture *) pFrameRGB, buffer, PIX_FMT_RGB24, width, height); + avpicture_fill((AVPicture *) pFrameRGB, buffer, PIX_FMT_RGBA, width, height); // Resize / Convert to RGB sws_scale(img_convert_ctx, my_frame->data, my_frame->linesize, 0, @@ -661,7 +661,7 @@ void FFmpegReader::ProcessVideoPacket(int requested_frame) f = CreateFrame(current_frame); // Add Image data to frame - f->AddImage(width, height, "RGB", Magick::CharPixel, buffer); + f->AddImage(width, height, "RGBA", Magick::CharPixel, buffer); #pragma omp critical (openshot_cache) // Update working cache diff --git a/src/Frame.cpp b/src/Frame.cpp index cd5e0213..63a30246 100644 --- a/src/Frame.cpp +++ b/src/Frame.cpp @@ -432,7 +432,7 @@ void Frame::AddColor(int width, int height, string color) image = tr1::shared_ptr(new Magick::Image(Magick::Geometry(width, height), Magick::Color(color))); // Give image a transparent background color - image->backgroundColor(Magick::Color("none")); + image->backgroundColor(Magick::Color("#000000ff")); // Update height and width width = image->columns(); diff --git a/src/KeyFrame.cpp b/src/KeyFrame.cpp index c7defa9d..27d5b7a9 100644 --- a/src/KeyFrame.cpp +++ b/src/KeyFrame.cpp @@ -352,7 +352,7 @@ void Keyframe::PrintValues() { for (vector::iterator it = Values.begin() + 1; it != Values.end(); it++) { Coordinate c = *it; - cout << int(round(c.X)) << "\t" << int(round(c.Y)) << "\t" << c.increasing << "\t" << c.repeated.num << "\t" << c.repeated.den << "\t" << c.delta << endl; + cout << int(round(c.X)) << "\t" << c.Y << "\t" << c.increasing << "\t" << c.repeated.num << "\t" << c.repeated.den << "\t" << c.delta << endl; } } diff --git a/src/Main.cpp b/src/Main.cpp index cd399916..b914d985 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -33,6 +33,10 @@ int main() c1.gravity = GRAVITY_LEFT; c1.scale = SCALE_CROP; c1.Layer(0); + c1.End(16.0); + c1.alpha.AddPoint(1, 0.0); + c1.alpha.AddPoint(360, 0.0, LINEAR); + c1.alpha.AddPoint(384, 1.0); // CLIP 2 (wave form) c2.Position(0.0); @@ -77,7 +81,7 @@ int main() // Output stream info w.OutputStreamInfo(); - for (int frame = 1; frame <= 300; frame++) + for (int frame = 1; frame <= 600; frame++) { tr1::shared_ptr f = t.GetFrame(frame); if (f) diff --git a/src/Timeline.cpp b/src/Timeline.cpp index ed620914..c2820d6f 100644 --- a/src/Timeline.cpp +++ b/src/Timeline.cpp @@ -69,7 +69,7 @@ void Timeline::add_layer(tr1::shared_ptr new_frame, Clip* source_clip, in 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)); + new_frame->AddColor(width, height, Magick::Color(red, green, blue, 0)); } /* COPY AUDIO - with correct volume */ @@ -214,7 +214,7 @@ void Timeline::add_layer(tr1::shared_ptr new_frame, Clip* source_clip, in cout << "COMPLEX" << endl; // Use the distort operator, which is very CPU intensive // origin X,Y Scale Angle NewX,NewY - double distort_args[7] = {0,0, sx,sy, r, x-1,y-1 }; + double distort_args[7] = {0,0, sx,sy, r, x,y }; source_image->distort(Magick::ScaleRotateTranslateDistortion, 7, distort_args, false); }