OpenShot Library | libopenshot 0.2.7
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
47#include "MagickUtilities.h"
48
49namespace openshot
50{
51 // Forward decls
52 class CacheBase;
53
54 /**
55 * @brief This class uses the ImageMagick++ libraries, to open image files, and return
56 * openshot::Frame objects containing the image.
57 *
58 * @code
59 * // Create a reader for a video
60 * ImageReader r("MyAwesomeImage.jpeg");
61 * r.Open(); // Open the reader
62 *
63 * // Get frame number 1 from the video
64 * std::shared_ptr<Frame> f = r.GetFrame(1);
65 *
66 * // Now that we have an openshot::Frame object, lets have some fun!
67 * f->Display(); // Display the frame on the screen
68 *
69 * // Close the reader
70 * r.Close();
71 * @endcode
72 */
73 class ImageReader : public ReaderBase
74 {
75 private:
76 std::string path;
77 std::shared_ptr<Magick::Image> image;
78 bool is_open;
79
80 public:
81 /// @brief Constructor for ImageReader.
82 ///
83 /// Opens the media file to inspect its properties and loads frame 1,
84 /// iff inspect_reader == true (the default). Pass a false value in
85 /// the optional parameter to defer this initial Open()/Close() cycle.
86 ///
87 /// When not inspecting the media file, it's much faster, and useful
88 /// when you are inflating the object using JSON after instantiation.
89 ImageReader(const std::string& path, bool inspect_reader=true);
90
91 /// Close File
92 void Close() override;
93
94 /// Get the cache object used by this reader (always returns NULL for this object)
95 CacheBase* GetCache() override { return NULL; };
96
97 /// Get an openshot::Frame object for a specific frame number of this reader. All numbers
98 /// return the same Frame, since they all share the same image data.
99 ///
100 /// @returns The requested frame (containing the image)
101 /// @param requested_frame The frame number that is requested.
102 std::shared_ptr<Frame> GetFrame(int64_t requested_frame) override;
103
104 /// Determine if reader is open or closed
105 bool IsOpen() override { return is_open; };
106
107 /// Return the type name of the class
108 std::string Name() override { return "ImageReader"; };
109
110 // Get and Set JSON methods
111 std::string Json() const override; ///< Generate JSON string of this object
112 void SetJson(const std::string value) override; ///< Load JSON string into this object
113 Json::Value JsonValue() const override; ///< Generate Json::Value for this object
114 void SetJsonValue(const Json::Value root) override; ///< Load Json::Value into this object
115
116 /// Open File - which is called by the constructor automatically
117 void Open() override;
118 };
119
120}
121
122#endif //USE_IMAGEMAGICK
123#endif //OPENSHOT_IMAGE_READER_H
Header file for CacheMemory class.
Header file for MagickUtilities (IM6/IM7 compatibility overlay)
Header file for ReaderBase class.
All cache managers in libopenshot are based on this CacheBase class.
Definition: CacheBase.h:49
This class uses the ImageMagick++ libraries, to open image files, and return openshot::Frame objects ...
Definition: ImageReader.h:74
bool IsOpen() override
Determine if reader is open or closed.
Definition: ImageReader.h:105
void Open() override
Open File - which is called by the constructor automatically.
Definition: ImageReader.cpp:49
std::shared_ptr< Frame > GetFrame(int64_t requested_frame) override
ImageReader(const std::string &path, bool inspect_reader=true)
Constructor for ImageReader.
Definition: ImageReader.cpp:39
std::string Name() override
Return the type name of the class.
Definition: ImageReader.h:108
void SetJson(const std::string value) override
Load JSON string into this object.
void SetJsonValue(const Json::Value root) override
Load Json::Value into this object.
Json::Value JsonValue() const override
Generate Json::Value for this object.
CacheBase * GetCache() override
Get the cache object used by this reader (always returns NULL for this object)
Definition: ImageReader.h:95
std::string Json() const override
Generate JSON string of this object.
void Close() override
Close File.
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