OpenShot Library | libopenshot 0.2.7
QtImageReader.h
Go to the documentation of this file.
1/**
2 * @file
3 * @brief Header file for QtImageReader class
4 * @author Jonathan Thomas <jonathan@openshot.org>
5 *
6 * @ref License
7 */
8
9/* LICENSE
10 *
11 * Copyright (c) 2008-2019 OpenShot Studios, LLC
12 * <http://www.openshotstudios.com/>. This file is part of
13 * OpenShot Library (libopenshot), an open-source project dedicated to
14 * delivering high quality video editing and animation solutions to the
15 * world. For more information visit <http://www.openshot.org/>.
16 *
17 * OpenShot Library (libopenshot) is free software: you can redistribute it
18 * and/or modify it under the terms of the GNU Lesser General Public License
19 * as published by the Free Software Foundation, either version 3 of the
20 * License, or (at your option) any later version.
21 *
22 * OpenShot Library (libopenshot) is distributed in the hope that it will be
23 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU Lesser General Public License for more details.
26 *
27 * You should have received a copy of the GNU Lesser General Public License
28 * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
29 */
30
31#ifndef OPENSHOT_QIMAGE_READER_H
32#define OPENSHOT_QIMAGE_READER_H
33
34#include <cmath>
35#include <ctime>
36#include <iostream>
37#include <omp.h>
38#include <stdio.h>
39#include <memory>
40
41#include "ReaderBase.h"
42
43namespace openshot
44{
45 // Forward decl
46 class CacheBase;
47
48 /**
49 * @brief This class uses the Qt library, to open image files, and return
50 * openshot::Frame objects containing the image.
51 *
52 * @code
53 * // Create a reader for a video
54 * QtImageReader r("MyAwesomeImage.jpeg");
55 * r.Open(); // Open the reader
56 *
57 * // Get frame number 1 from the video
58 * std::shared_ptr<Frame> f = r.GetFrame(1);
59 *
60 * // Now that we have an openshot::Frame object, lets have some fun!
61 * f->Display(); // Display the frame on the screen
62 *
63 * // Close the reader
64 * r.Close();
65 * @endcode
66 */
68 {
69 private:
70 QString path;
71 std::shared_ptr<QImage> image; ///> Original image (full quality)
72 std::shared_ptr<QImage> cached_image; ///> Scaled for performance
73 bool is_open; ///> Is Reader opened
74 QSize max_size; ///> Current max_size as calculated with Clip properties
75
76 /// Load an SVG file with Resvg or fallback with Qt
77 ///
78 /// @returns Success as a boolean
79 /// @param path The file path of the SVG file
80 QSize load_svg_path(QString path);
81
82 /// Calculate the max_size QSize, based on parent timeline and parent clip settings
83 QSize calculate_max_size();
84
85 public:
86 /// @brief Constructor for QtImageReader.
87 ///
88 /// Opens the media file to inspect its properties and loads frame 1,
89 /// iff inspect_reader == true (the default). Pass a false value in
90 /// the optional parameter to defer this initial Open()/Close() cycle.
91 ///
92 /// When not inspecting the media file, it's much faster, and useful
93 /// when you are inflating the object using JSON after instantiation.
94 QtImageReader(std::string path, bool inspect_reader=true);
95
96 virtual ~QtImageReader();
97
98 /// Close File
99 void Close() override;
100
101 /// Get the cache object used by this reader (always returns NULL for this object)
102 CacheBase* GetCache() override { return NULL; };
103
104 /// Get an openshot::Frame object for a specific frame number of this reader. All numbers
105 /// return the same Frame, since they all share the same image data.
106 ///
107 /// @returns The requested frame (containing the image)
108 /// @param requested_frame The frame number that is requested.
109 std::shared_ptr<Frame> GetFrame(int64_t requested_frame) override;
110
111 /// Determine if reader is open or closed
112 bool IsOpen() override { return is_open; };
113
114 /// Return the type name of the class
115 std::string Name() override { return "QtImageReader"; };
116
117 // Get and Set JSON methods
118 std::string Json() const override; ///< Generate JSON string of this object
119 void SetJson(const std::string value) override; ///< Load JSON string into this object
120 Json::Value JsonValue() const override; ///< Generate Json::Value for this object
121 void SetJsonValue(const Json::Value root) override; ///< Load Json::Value into this object
122
123 /// Open File - which is called by the constructor automatically
124 void Open() override;
125 };
126
127}
128
129#endif
Header file for ReaderBase class.
All cache managers in libopenshot are based on this CacheBase class.
Definition: CacheBase.h:49
This class uses the Qt library, to open image files, and return openshot::Frame objects containing th...
Definition: QtImageReader.h:68
std::string Name() override
Return the type name of the class.
Json::Value JsonValue() const override
Generate Json::Value for this object.
QtImageReader(std::string path, bool inspect_reader=true)
Constructor for QtImageReader.
CacheBase * GetCache() override
Get the cache object used by this reader (always returns NULL for this object)
std::string Json() const override
Generate JSON string of this object.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
void Open() override
Open File - which is called by the constructor automatically.
void SetJson(const std::string value) override
Load JSON string into this object.
bool IsOpen() override
Determine if reader is open or closed.
void Close() override
Close File.
std::shared_ptr< Frame > GetFrame(int64_t requested_frame) override
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:98
This namespace is the default namespace for all code in the openshot library.
Definition: Compressor.h:47