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());
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);
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();
295 Json::CharReaderBuilder rbuilder;
296 Json::CharReader* reader(rbuilder.newCharReader());
299 bool success = reader->parse( value.c_str(),
300 value.c_str() + value.size(), &root, &errors );
305 throw InvalidJSON(
"JSON could not be parsed (or is invalid)");
312 catch (
const std::exception& e)
315 throw InvalidJSON(
"JSON is invalid (missing keys or invalid data types)");
326 if (!root[
"path"].isNull())
327 path = QString::fromStdString(root[
"path"].asString());
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.
void Open()
Open File - which is called by the constructor automatically.
Point GetMaxPoint() const
Get max point (by Y coordinate)
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 SetJson(std::string value)
Load JSON string into this object.
void SetJsonValue(Json::Value root)
Load Json::JsonValue into this object.
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)
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.
int64_t file_size
Size of file (in bytes)
int GetSamplesPerFrame(openshot::Fraction fps, int sample_rate, int channels)
Calculate the # of samples per video frame (for the current frame number)
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.
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.
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.
virtual Json::Value JsonValue()=0
Generate Json::JsonValue for this object.
QtImageReader(std::string path)
Current max_size as calculated with Clip properties
openshot::ClipBase * parent
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)
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.
openshot::ClipBase * GetClip()
Parent clip object of this reader (which can be unparented and NULL)
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.
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) ...
openshot::Fraction pixel_ratio
The pixel ratio of the video stream as a fraction (i.e. some pixels are not square) ...
std::string Json()
Get and Set JSON methods.
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.
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)