28 #include "../include/QtImageReader.h"
29 #include "../include/Settings.h"
30 #include "../include/Clip.h"
31 #include "../include/CacheMemory.h"
32 #include <QtCore/QString>
33 #include <QtGui/QImage>
34 #include <QtGui/QPainter>
42 using namespace openshot;
67 image = std::shared_ptr<QImage>(
new QImage());
73 if (path.find(
".svg") != std::string::npos ||
74 path.find(
".svgz") != std::string::npos) {
76 ResvgRenderer renderer(QString::fromStdString(path));
77 if (!renderer.isValid()) {
81 image = std::shared_ptr<QImage>(
new QImage(renderer.defaultSize(), QImage::Format_RGBA8888));
82 image->fill(Qt::transparent);
84 QPainter p(image.get());
91 success = image->load(QString::fromStdString(path));
93 image = std::shared_ptr<QImage>(
new QImage(image->convertToFormat(QImage::Format_RGBA8888)));
97 success = image->load(QString::fromStdString(path));
99 image = std::shared_ptr<QImage>(
new QImage(image->convertToFormat(QImage::Format_RGBA8888)));
104 throw InvalidFile(
"File could not be opened.", path);
160 throw ReaderClosed(
"The Image is closed. Call Open() before calling this method.", path);
183 max_width = max(
float(max_width), max_width * max_scale_x);
184 max_height = max(
float(max_height), max_height * max_scale_y);
190 QSize width_size(max_width * max_scale_x,
193 max_height * max_scale_y);
195 if (width_size.width() >= max_width && width_size.height() >= max_height) {
196 max_width = max(max_width, width_size.width());
197 max_height = max(max_height, width_size.height());
200 max_width = max(max_width, height_size.width());
201 max_height = max(max_height, height_size.height());
212 if (!cached_image || (cached_image && cached_image->width() != max_width || cached_image->height() != max_height)) {
218 if (path.find(
".svg") != std::string::npos ||
219 path.find(
".svgz") != std::string::npos) {
220 ResvgRenderer renderer(QString::fromStdString(path));
221 if (renderer.isValid()) {
223 cached_image = std::shared_ptr<QImage>(
new QImage(QSize(max_width, max_height), QImage::Format_RGBA8888));
224 cached_image->fill(Qt::transparent);
226 QPainter p(cached_image.get());
233 cached_image = std::shared_ptr<QImage>(
new QImage(image->scaled(max_width, max_height, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
234 cached_image = std::shared_ptr<QImage>(
new QImage(cached_image->convertToFormat(QImage::Format_RGBA8888)));
239 cached_image = std::shared_ptr<QImage>(
new QImage(image->scaled(max_width, max_height, Qt::KeepAspectRatio, Qt::SmoothTransformation)));
240 cached_image = std::shared_ptr<QImage>(
new QImage(cached_image->convertToFormat(QImage::Format_RGBA8888)));
248 image_frame->AddImage(cached_image);
266 root[
"type"] =
"QtImageReader";
279 bool success = reader.parse( value, root );
282 throw InvalidJSON(
"JSON could not be parsed (or is invalid)",
"");
292 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)",
"");
303 if (!root[
"path"].isNull())
304 path = root[
"path"].asString();
Point GetMaxPoint()
Get max point (by Y coordinate)
Json::Value JsonValue()
Generate Json::JsonValue for this object.
int MAX_HEIGHT
Maximum height for image data (useful for optimzing for a smaller preview or render) ...
int num
Numerator for the fraction.
Keyframe scale_y
Curve representing the vertical scaling in percent (0 to 1)
CriticalSection getFrameCriticalSection
Section lock for multiple threads.
void Open()
Open File - which is called by the constructor automatically.
QtImageReader(string path)
int width
The width of the video (in pixesl)
This class represents a single frame of video (i.e. image & audio data)
float duration
Length of time (in seconds)
void SetJsonValue(Json::Value root)
Load Json::JsonValue into this object.
string acodec
The name of the audio codec used to encode / decode the video stream.
Scale the clip until both height and width fill the canvas (cropping the overlap) ...
void SetJson(string value)
Load JSON string into this object.
Exception when a reader is closed, and a frame is requested.
bool has_video
Determines if this file has a video stream.
Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3) ...
int64_t file_size
Size of file (in bytes)
bool has_audio
Determines if this file has an audio stream.
This class represents a clip (used to arrange readers on the timeline)
double Y
The Y value of the coordinate (usually representing the value of the property being animated) ...
int MAX_WIDTH
Maximum width for image data (useful for optimzing for a smaller preview or render) ...
int64_t video_length
The number of frames in the video stream.
ScaleType scale
The scale determines how a clip should be resized to fit it's parent.
int height
The height of the video (in pixels)
Exception for files that can not be found or opened.
ClipBase * GetClip()
Parent clip object of this reader (which can be unparented and NULL)
This class represents a fraction.
string Json()
Get and Set JSON methods.
bool has_single_image
Determines if this file only contains a single image.
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
virtual void SetJsonValue(Json::Value root)=0
Load Json::JsonValue into this object.
Scale the clip until both height and width fill the canvas (distort to fit)
ReaderInfo info
Information about the current media file.
Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) ...
Coordinate co
This is the primary coordinate.
Exception for invalid JSON.
Keyframe scale_x
Curve representing the horizontal scaling in percent (0 to 1)
std::shared_ptr< Frame > GetFrame(int64_t requested_frame)
static Settings * Instance()
Create or get an instance of this logger singleton (invoke the class with this method) ...
string vcodec
The name of the video codec used to encode / decode the video stream.
int den
Denominator for the fraction.
int channels
The number of audio channels used in the audio stream.
Scale the clip until either height or width fills the canvas (with no cropping)
int GetSamplesPerFrame(Fraction fps, int sample_rate, int channels)
Calculate the # of samples per video frame (for the current frame number)
double ToDouble()
Return this fraction as a double (i.e. 1/2 = 0.5)
int sample_rate
The number of audio samples per second (44100 is a common sample rate)