OpenShot Library | libopenshot
0.2.5
|
Go to the documentation of this file.
31 #include "../include/QtImageReader.h"
32 #include "../include/Settings.h"
33 #include "../include/Clip.h"
34 #include "../include/CacheMemory.h"
35 #include <QtCore/QString>
36 #include <QtGui/QImage>
37 #include <QtGui/QPainter>
80 if (path.toLower().endsWith(
".svg") || path.toLower().endsWith(
".svgz")) {
82 ResvgRenderer renderer(path);
83 if (renderer.isValid()) {
85 image = std::shared_ptr<QImage>(
new QImage(renderer.defaultSize(), QImage::Format_ARGB32_Premultiplied));
86 image->fill(Qt::transparent);
88 QPainter p(image.get());
98 image = std::shared_ptr<QImage>(
new QImage());
99 success = image->load(path);
104 throw InvalidFile(
"File could not be opened.", path.toStdString());
108 image = std::shared_ptr<QImage>(
new QImage(image->convertToFormat(QImage::Format_RGBA8888)));
168 throw ReaderClosed(
"The Image is closed. Call Open() before calling this method.", path.toStdString());
189 float max_scale_x =
parent->scale_x.GetMaxPoint().co.Y;
190 float max_scale_y =
parent->scale_y.GetMaxPoint().co.Y;
191 max_width = std::max(
float(max_width), max_width * max_scale_x);
192 max_height = std::max(
float(max_height), max_height * max_scale_y);
196 float max_scale_x =
parent->scale_x.GetMaxPoint().co.Y;
197 float max_scale_y =
parent->scale_y.GetMaxPoint().co.Y;
198 QSize width_size(max_width * max_scale_x,
201 max_height * max_scale_y);
203 if (width_size.width() >= max_width && width_size.height() >= max_height) {
204 max_width = std::max(max_width, width_size.width());
205 max_height = std::max(max_height, width_size.height());
208 max_width = std::max(max_width, height_size.width());
209 max_height = std::max(max_height, height_size.height());
220 if (!cached_image || (max_size.width() != max_width || max_size.height() != max_height)) {
222 bool rendered =
false;
227 if (path.toLower().endsWith(
".svg") || path.toLower().endsWith(
".svgz")) {
229 ResvgRenderer renderer(path);
230 if (renderer.isValid()) {
232 QSize svg_size(renderer.defaultSize().width(), renderer.defaultSize().height());
233 svg_size.scale(max_width, max_height, Qt::KeepAspectRatio);
236 cached_image = std::shared_ptr<QImage>(
new QImage(QSize(svg_size.width(), svg_size.height()), QImage::Format_ARGB32_Premultiplied));
237 cached_image->fill(Qt::transparent);
240 QPainter p(cached_image.get());
251 cached_image = std::shared_ptr<QImage>(
new QImage(image->scaled(max_width, max_height, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
254 cached_image = std::shared_ptr<QImage>(
new QImage(cached_image->convertToFormat(QImage::Format_RGBA8888)));
257 max_size.setWidth(max_width);
258 max_size.setHeight(max_height);
265 image_frame->
AddImage(cached_image);
283 root[
"type"] =
"QtImageReader";
284 root[
"path"] = path.toStdString();
300 catch (
const std::exception& e)
303 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
314 if (!root[
"path"].isNull())
315 path = QString::fromStdString(root[
"path"].asString());
const Json::Value stringToJson(const std::string value)
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
juce::CriticalSection getFrameCriticalSection
Section lock for multiple threads.
This namespace is the default namespace for all code in the openshot library.
This class represents a clip (used to arrange readers on the timeline)
This class represents a fraction.
openshot::ReaderInfo info
Information about the current media file.
openshot::ClipBase * parent
QtImageReader(std::string path)
Current max_size as calculated with Clip properties
openshot::ClipBase * GetClip()
Parent clip object of this reader (which can be unparented and NULL)
float duration
Length of time (in seconds)
This class represents a single frame of video (i.e. image & audio data)
Json::Value JsonValue() const override
Generate Json::Value for this object.
bool has_video
Determines if this file has a video stream.
int width
The width of the video (in pixesl)
int64_t video_length
The number of frames in the video stream.
int height
The height of the video (in pixels)
int num
Numerator for the fraction.
int MAX_HEIGHT
Maximum height for image data (useful for optimzing for a smaller preview or render)
int den
Denominator for the fraction.
void Reduce()
Reduce this fraction (i.e. 640/480 = 4/3)
bool has_audio
Determines if this file has an audio stream.
void Open()
Open File - which is called by the constructor automatically.
Exception for invalid JSON.
int64_t file_size
Size of file (in bytes)
void AddImage(int new_width, int new_height, int bytes_per_pixel, QImage::Format type, const unsigned char *pixels_)
Add (or replace) pixel data to the frame.
@ SCALE_CROP
Scale the clip until both height and width fill the canvas (cropping the overlap)
bool has_single_image
Determines if this file only contains a single image.
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
static Settings * Instance()
Create or get an instance of this logger singleton (invoke the class with this method)
std::string Json() const override
Get and Set JSON methods.
int GetSamplesPerFrame(openshot::Fraction fps, int sample_rate, int channels)
Calculate the # of samples per video frame (for the current frame number)
Exception for files that can not be found or opened.
void SetJson(const std::string value)
Load JSON string into this object.
@ SCALE_FIT
Scale the clip until either height or width fills the canvas (with no cropping)
std::shared_ptr< Frame > GetFrame(int64_t requested_frame)
std::string vcodec
The name of the video codec used to encode / decode the video stream.
Exception when a reader is closed, and a frame is requested.
int MAX_WIDTH
Maximum width for image data (useful for optimzing for a smaller preview or render)
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
double ToDouble()
Return this fraction as a double (i.e. 1/2 = 0.5)
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
@ SCALE_STRETCH
Scale the clip until both height and width fill the canvas (distort to fit)
std::string acodec
The name of the audio codec used to encode / decode the video stream.
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3)
int channels
The number of audio channels used in the audio stream.