37 #include <QtCore/QString> 38 #include <QtGui/QImage> 39 #include <QtGui/QPainter> 40 #include <QtGui/QIcon> 41 #include <QtGui/QImageReader> 71 QSize default_svg_size;
74 if (path.toLower().endsWith(
".svg") || path.toLower().endsWith(
".svgz")) {
75 default_svg_size = load_svg_path(path);
76 if (!default_svg_size.isEmpty()) {
85 image = std::make_shared<QImage>();
86 QImageReader imgReader( path );
87 imgReader.setAutoTransform(
true );
88 loaded = imgReader.read(image.get());
93 throw InvalidFile(
"File could not be opened.", path.toStdString());
100 #if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) 107 if (!default_svg_size.isEmpty()) {
166 throw ReaderClosed(
"The Image is closed. Call Open() before calling this method.", path.toStdString());
172 QSize current_max_size = calculate_max_size();
175 if (!cached_image || (max_size.width() != current_max_size.width() || max_size.height() != current_max_size.height())) {
177 if (path.toLower().endsWith(
".svg") || path.toLower().endsWith(
".svgz")) {
183 cached_image = std::make_shared<QImage>(image->scaled(
184 current_max_size.width(), current_max_size.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
187 max_size.setWidth(current_max_size.width());
188 max_size.setHeight(current_max_size.height());
192 auto image_frame = std::make_shared<Frame>(
193 requested_frame, cached_image->width(), cached_image->height(),
"#000000",
198 image_frame->AddImage(cached_image);
205 QSize QtImageReader::calculate_max_size() {
209 if (max_width == 0 || max_height == 0) {
226 max_width = std::max(
float(max_width), max_width * max_scale_x);
227 max_height = std::max(
float(max_height), max_height * max_scale_y);
233 QSize width_size(max_width * max_scale_x,
236 max_height * max_scale_y);
238 if (width_size.width() >= max_width && width_size.height() >= max_height) {
239 max_width = std::max(max_width, width_size.width());
240 max_height = std::max(max_height, width_size.height());
242 max_width = std::max(max_width, height_size.width());
243 max_height = std::max(max_height, height_size.height());
249 float preview_ratio = 1.0;
256 max_width =
info.
width * max_scale_x * preview_ratio;
257 max_height =
info.
height * max_scale_y * preview_ratio;
262 return QSize(max_width, max_height);
266 QSize QtImageReader::load_svg_path(QString) {
268 QSize default_size(0,0);
271 QSize current_max_size = calculate_max_size();
275 ResvgRenderer renderer(path);
276 if (renderer.isValid()) {
278 default_size.setWidth(renderer.defaultSize().width());
279 default_size.setHeight(renderer.defaultSize().height());
282 QSize svg_size(default_size.width(), default_size.height());
283 svg_size.scale(current_max_size.width(), current_max_size.height(), Qt::KeepAspectRatio);
286 image = std::make_shared<QImage>(svg_size, QImage::Format_RGBA8888_Premultiplied);
287 image->fill(Qt::transparent);
288 QPainter p(image.get());
297 image = std::make_shared<QImage>();
298 loaded = image->load(path);
302 default_size.setWidth(image->width());
303 default_size.setHeight(image->height());
305 if (image->width() < current_max_size.width() || image->height() < current_max_size.height()) {
307 QSize svg_size = image->size().scaled(current_max_size.width(), current_max_size.height(), Qt::KeepAspectRatio);
308 if (QCoreApplication::instance()) {
311 image = std::make_shared<QImage>(QIcon(path).pixmap(svg_size).toImage());
314 image = std::make_shared<QImage>(image->scaled(
315 svg_size.width(), svg_size.height(), Qt::KeepAspectRatio, Qt::SmoothTransformation));
336 root[
"type"] =
"QtImageReader";
337 root[
"path"] = path.toStdString();
353 catch (
const std::exception& e)
356 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
367 if (!root[
"path"].isNull())
368 path = QString::fromStdString(root[
"path"].asString());
int num
Numerator for the fraction.
Point GetMaxPoint() const
Get max point (by Y coordinate)
std::string Json() const override
Generate JSON string of this object.
int width
The width of the video (in pixesl)
int preview_width
Optional preview width of timeline image. If your preview window is smaller than the timeline...
float duration
Length of time (in seconds)
void Close() override
Close File.
double ToDouble() const
Return this fraction as a double (i.e. 1/2 = 0.5)
void Open() override
Open File - which is called by the constructor automatically.
Scale the clip until both height and width fill the canvas (cropping the overlap) ...
openshot::Keyframe scale_x
Curve representing the horizontal scaling in percent (0 to 1)
const Json::Value stringToJson(const std::string value)
openshot::Keyframe scale_y
Curve representing the vertical scaling in percent (0 to 1)
Exception when a reader is closed, and a frame is requested.
bool has_video
Determines if this file has a video stream.
Header file for CacheMemory class.
int64_t file_size
Size of file (in bytes)
Header file for Timeline class.
void SetJson(const std::string value) override
Load JSON string into this object.
int GetSamplesPerFrame(openshot::Fraction fps, int sample_rate, int channels)
Calculate the # of samples per video frame (for the current frame number)
Header file for all Exception classes.
bool has_audio
Determines if this file has an audio stream.
virtual Json::Value JsonValue() const =0
Generate Json::Value for this object.
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) ...
int64_t video_length
The number of frames in the video stream.
int height
The height of the video (in pixels)
openshot::Fraction video_timebase
The video timebase determines how long each frame stays on the screen.
Exception for files that can not be found or opened.
Header file for Clip class.
This class represents a fraction.
juce::CriticalSection getFrameCriticalSection
Section lock for multiple threads.
bool has_single_image
Determines if this file only contains a single image.
QtImageReader(std::string path, bool inspect_reader=true)
Constructor for QtImageReader.
Header file for global Settings class.
Scale the clip until both height and width fill the canvas (distort to fit)
virtual void SetJsonValue(const Json::Value root)=0
Load Json::Value into this object.
openshot::ClipBase * ParentClip()
Parent clip object of this reader (which can be unparented and NULL)
openshot::ReaderInfo info
Information about the current media file.
std::string vcodec
The name of the video codec used to encode / decode the video stream.
This namespace is the default namespace for all code in the openshot library.
Coordinate co
This is the primary coordinate.
Exception for invalid JSON.
openshot::Fraction display_ratio
The ratio of width to height of the video stream (i.e. 640x480 has a ratio of 4/3) ...
openshot::ScaleType scale
The scale determines how a clip should be resized to fit its parent.
Header file for QtImageReader class.
openshot::TimelineBase * ParentTimeline()
Get the associated Timeline pointer (if any)
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) ...
int preview_height
Optional preview width of timeline image. If your preview window is smaller than the timeline...
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
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)
openshot::Fraction fps
Frames per second, as a fraction (i.e. 24/1 = 24 fps)
std::string acodec
The name of the audio codec used to encode / decode the video stream.
Json::Value JsonValue() const override
Generate Json::Value for this object.
int sample_rate
The number of audio samples per second (44100 is a common sample rate)
std::shared_ptr< Frame > GetFrame(int64_t requested_frame) override
This class represents a timeline.