OpenShot Library | libopenshot  0.2.5
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 #include "Exceptions.h"
41 #include "ReaderBase.h"
42 
43 namespace openshot
44 {
45 
46  /**
47  * @brief This class uses the Qt library, to open image files, and return
48  * openshot::Frame objects containing the image.
49  *
50  * @code
51  * // Create a reader for a video
52  * QtImageReader r("MyAwesomeImage.jpeg");
53  * r.Open(); // Open the reader
54  *
55  * // Get frame number 1 from the video
56  * std::shared_ptr<Frame> f = r.GetFrame(1);
57  *
58  * // Now that we have an openshot::Frame object, lets have some fun!
59  * f->Display(); // Display the frame on the screen
60  *
61  * // Close the reader
62  * r.Close();
63  * @endcode
64  */
65  class QtImageReader : public ReaderBase
66  {
67  private:
68  QString path;
69  std::shared_ptr<QImage> image; ///> Original image (full quality)
70  std::shared_ptr<QImage> cached_image; ///> Scaled for performance
71  bool is_open; ///> Is Reader opened
72  QSize max_size; ///> Current max_size as calculated with Clip properties
73 
74  public:
75 
76  /// Constructor for QtImageReader. This automatically opens the media file and loads
77  /// frame 1, or it throws one of the following exceptions.
78  QtImageReader(std::string path);
79 
80  /// Constructor for QtImageReader. This only opens the media file to inspect its properties
81  /// if inspect_reader=true. When not inspecting the media file, it's much faster, and useful
82  /// when you are inflating the object using JSON after instantiating it.
83  QtImageReader(std::string path, bool inspect_reader);
84 
85  virtual ~QtImageReader();
86 
87  /// Close File
88  void Close();
89 
90  /// Get the cache object used by this reader (always returns NULL for this object)
91  CacheMemory* GetCache() { return NULL; };
92 
93  /// Get an openshot::Frame object for a specific frame number of this reader. All numbers
94  /// return the same Frame, since they all share the same image data.
95  ///
96  /// @returns The requested frame (containing the image)
97  /// @param requested_frame The frame number that is requested.
98  std::shared_ptr<Frame> GetFrame(int64_t requested_frame);
99 
100  /// Determine if reader is open or closed
101  bool IsOpen() { return is_open; };
102 
103  /// Return the type name of the class
104  std::string Name() { return "QtImageReader"; };
105 
106  /// Get and Set JSON methods
107  std::string Json() const override; ///< Generate JSON string of this object
108  void SetJson(const std::string value); ///< Load JSON string into this object
109  Json::Value JsonValue() const override; ///< Generate Json::Value for this object
110  void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
111 
112  /// Open File - which is called by the constructor automatically
113  void Open();
114  };
115 
116 }
117 
118 #endif
openshot::QtImageReader::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: QtImageReader.cpp:308
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: AudioBufferSource.h:39
openshot::QtImageReader::QtImageReader
QtImageReader(std::string path)
Current max_size as calculated with Clip properties
Definition: QtImageReader.cpp:47
openshot::QtImageReader::Name
std::string Name()
Return the type name of the class.
Definition: QtImageReader.h:104
openshot::QtImageReader::JsonValue
Json::Value JsonValue() const override
Generate Json::Value for this object.
Definition: QtImageReader.cpp:279
openshot::QtImageReader
This class uses the Qt library, to open image files, and return openshot::Frame objects containing th...
Definition: QtImageReader.h:66
openshot::QtImageReader::Open
void Open()
Open File - which is called by the constructor automatically.
Definition: QtImageReader.cpp:68
openshot::CacheMemory
This class is a memory-based cache manager for Frame objects.
Definition: CacheMemory.h:51
openshot::QtImageReader::Json
std::string Json() const override
Get and Set JSON methods.
Definition: QtImageReader.cpp:272
openshot::QtImageReader::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition: QtImageReader.cpp:291
openshot::QtImageReader::GetFrame
std::shared_ptr< Frame > GetFrame(int64_t requested_frame)
Definition: QtImageReader.cpp:164
ReaderBase.h
Header file for ReaderBase class.
openshot::QtImageReader::Close
void Close()
Close File.
Definition: QtImageReader.cpp:147
openshot::ReaderBase
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:98
openshot::QtImageReader::IsOpen
bool IsOpen()
Determine if reader is open or closed.
Definition: QtImageReader.h:101
openshot::QtImageReader::GetCache
CacheMemory * GetCache()
Get the cache object used by this reader (always returns NULL for this object)
Definition: QtImageReader.h:91
openshot::QtImageReader::~QtImageReader
virtual ~QtImageReader()
Definition: QtImageReader.cpp:63
Exceptions.h
Header file for all Exception classes.