OpenShot Library | libopenshot  0.2.5
ImageReader.h
Go to the documentation of this file.
1 /**
2  * @file
3  * @brief Header file for ImageReader 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_IMAGE_READER_H
32 #define OPENSHOT_IMAGE_READER_H
33 
34 // Require ImageMagick support
35 #ifdef USE_IMAGEMAGICK
36 
37 #include "ReaderBase.h"
38 
39 #include <cmath>
40 #include <ctime>
41 #include <iostream>
42 #include <omp.h>
43 #include <stdio.h>
44 #include <memory>
45 #include "CacheMemory.h"
46 #include "Exceptions.h"
47 #include "MagickUtilities.h"
48 
49 namespace openshot
50 {
51 
52  /**
53  * @brief This class uses the ImageMagick++ libraries, to open image files, and return
54  * openshot::Frame objects containing the image.
55  *
56  * @code
57  * // Create a reader for a video
58  * ImageReader r("MyAwesomeImage.jpeg");
59  * r.Open(); // Open the reader
60  *
61  * // Get frame number 1 from the video
62  * std::shared_ptr<Frame> f = r.GetFrame(1);
63  *
64  * // Now that we have an openshot::Frame object, lets have some fun!
65  * f->Display(); // Display the frame on the screen
66  *
67  * // Close the reader
68  * r.Close();
69  * @endcode
70  */
71  class ImageReader : public ReaderBase
72  {
73  private:
74  std::string path;
75  std::shared_ptr<Magick::Image> image;
76  bool is_open;
77 
78  public:
79 
80  /// Constructor for ImageReader. This automatically opens the media file and loads
81  /// frame 1, or it throws one of the following exceptions.
82  ImageReader(std::string path);
83 
84  /// Constructor for ImageReader. This only opens the media file to inspect its properties
85  /// if inspect_reader=true. When not inspecting the media file, it's much faster, and useful
86  /// when you are inflating the object using JSON after instantiating it.
87  ImageReader(std::string path, bool inspect_reader);
88 
89  /// Close File
90  void Close();
91 
92  /// Get the cache object used by this reader (always returns NULL for this object)
93  CacheMemory* GetCache() { return NULL; };
94 
95  /// Get an openshot::Frame object for a specific frame number of this reader. All numbers
96  /// return the same Frame, since they all share the same image data.
97  ///
98  /// @returns The requested frame (containing the image)
99  /// @param requested_frame The frame number that is requested.
100  std::shared_ptr<Frame> GetFrame(int64_t requested_frame);
101 
102  /// Determine if reader is open or closed
103  bool IsOpen() { return is_open; };
104 
105  /// Return the type name of the class
106  std::string Name() { return "ImageReader"; };
107 
108  /// Get and Set JSON methods
109  std::string Json() const override; ///< Generate JSON string of this object
110  void SetJson(const std::string value); ///< Load JSON string into this object
111  Json::Value JsonValue() const; ///< Generate Json::Value for this object
112  void SetJsonValue(const Json::Value root); ///< Load Json::Value into this object
113 
114  /// Open File - which is called by the constructor automatically
115  void Open();
116  };
117 
118 }
119 
120 #endif //USE_IMAGEMAGICK
121 #endif //OPENSHOT_IMAGE_READER_H
openshot
This namespace is the default namespace for all code in the openshot library.
Definition: AudioBufferSource.h:38
openshot::ImageReader::ImageReader
ImageReader(std::string path)
Definition: ImageReader.cpp:38
openshot::ImageReader::SetJsonValue
void SetJsonValue(const Json::Value root)
Load Json::Value into this object.
Definition: ImageReader.cpp:175
openshot::ImageReader::Name
std::string Name()
Return the type name of the class.
Definition: ImageReader.h:106
openshot::ImageReader::Json
std::string Json() const override
Get and Set JSON methods.
Definition: ImageReader.cpp:139
openshot::CacheMemory
This class is a memory-based cache manager for Frame objects.
Definition: CacheMemory.h:51
openshot::ImageReader
This class uses the ImageMagick++ libraries, to open image files, and return openshot::Frame objects ...
Definition: ImageReader.h:71
openshot::ImageReader::Open
void Open()
Open File - which is called by the constructor automatically.
Definition: ImageReader.cpp:55
openshot::ImageReader::SetJson
void SetJson(const std::string value)
Load JSON string into this object.
Definition: ImageReader.cpp:158
CacheMemory.h
Header file for CacheMemory class.
openshot::ImageReader::GetFrame
std::shared_ptr< Frame > GetFrame(int64_t requested_frame)
Definition: ImageReader.cpp:122
path
path
Definition: FFmpegWriter.cpp:1410
ReaderBase.h
Header file for ReaderBase class.
openshot::ImageReader::GetCache
CacheMemory * GetCache()
Get the cache object used by this reader (always returns NULL for this object)
Definition: ImageReader.h:93
MagickUtilities.h
Header file for MagickUtilities (IM6/IM7 compatibility overlay)
openshot::ImageReader::JsonValue
Json::Value JsonValue() const
Generate Json::Value for this object.
Definition: ImageReader.cpp:146
openshot::ReaderBase
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:97
openshot::ImageReader::IsOpen
bool IsOpen()
Determine if reader is open or closed.
Definition: ImageReader.h:103
Exceptions.h
Header file for all Exception classes.
openshot::ImageReader::Close
void Close()
Close File.
Definition: ImageReader.cpp:108