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());
This class represents a clip (used to arrange readers on the timeline)
This class represents a fraction.
int num
Numerator for the fraction.
double ToDouble()
Return this fraction as a double (i.e. 1/2 = 0.5)
void Reduce()
Reduce this fraction (i.e. 640/480 = 4/3)
int den
Denominator for the fraction.
This class represents a single frame of video (i.e. image & audio data)
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.
Exception for invalid JSON.
void SetJson(const std::string value)
Load JSON string into this object.
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
void Open()
Open File - which is called by the constructor automatically.
std::string Json() const override
Get and Set JSON methods.
std::shared_ptr< Frame > GetFrame(int64_t requested_frame)
QtImageReader(std::string path)
Current max_size as calculated with Clip properties
openshot::ClipBase * parent
juce::CriticalSection getFrameCriticalSection
Section lock for multiple threads.
openshot::ReaderInfo info
Information about the current media file.
openshot::ClipBase * GetClip()
Parent clip object of this reader (which can be unparented and NULL)
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
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)
static Settings * Instance()
Create or get an instance of this logger singleton (invoke the class with this method)
int MAX_HEIGHT
Maximum height for image data (useful for optimzing for a smaller preview or render)
This namespace is the default namespace for all code in the openshot library.
@ SCALE_FIT
Scale the clip until either height or width fills the canvas (with no cropping)
@ SCALE_STRETCH
Scale the clip until both height and width fill the canvas (distort to fit)
@ SCALE_CROP
Scale the clip until both height and width fill the canvas (cropping the overlap)
const Json::Value stringToJson(const std::string value)
bool has_single_image
Determines if this file only contains a single image.
float duration
Length of time (in seconds)
int width
The width of the video (in pixesl)
int channels
The number of audio channels used in the audio stream.
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3)
int height
The height of the video (in pixels)
int64_t video_length
The number of frames in the video stream.
std::string acodec
The name of the audio codec used to encode / decode the video stream.
std::string vcodec
The name of the video codec used to encode / decode the video stream.
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square)
bool has_video
Determines if this file has a video stream.
bool has_audio
Determines if this file has an audio stream.
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
int64_t file_size
Size of file (in bytes)