OpenShot Library | libopenshot  0.1.2
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  * @section LICENSE
7  *
8  * Copyright (c) 2008-2014 OpenShot Studios, LLC
9  * <http://www.openshotstudios.com/>. This file is part of
10  * OpenShot Library (libopenshot), an open-source project dedicated to
11  * delivering high quality video editing and animation solutions to the
12  * world. For more information visit <http://www.openshot.org/>.
13  *
14  * OpenShot Library (libopenshot) is free software: you can redistribute it
15  * and/or modify it under the terms of the GNU Lesser General Public License
16  * as published by the Free Software Foundation, either version 3 of the
17  * License, or (at your option) any later version.
18  *
19  * OpenShot Library (libopenshot) is distributed in the hope that it will be
20  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public License
25  * along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
26  */
27 
28 #ifndef OPENSHOT_IMAGE_READER_H
29 #define OPENSHOT_IMAGE_READER_H
30 
31 #include "ReaderBase.h"
32 
33 #include <cmath>
34 #include <ctime>
35 #include <iostream>
36 #include <omp.h>
37 #include <stdio.h>
38 #include <tr1/memory>
39 #include "Magick++.h"
40 #include "Cache.h"
41 #include "Exceptions.h"
42 
43 using namespace std;
44 
45 namespace openshot
46 {
47 
48  /**
49  * @brief This class uses the ImageMagick++ libraries, to open image files, and return
50  * openshot::Frame objects containing the image.
51  *
52  * @code
53  * // Create a reader for a video
54  * ImageReader r("MyAwesomeImage.jpeg");
55  * r.Open(); // Open the reader
56  *
57  * // Get frame number 1 from the video
58  * tr1::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  */
67  class ImageReader : public ReaderBase
68  {
69  private:
70  string path;
71  tr1::shared_ptr<Magick::Image> image;
72  bool is_open;
73 
74  public:
75 
76  /// Constructor for ImageReader. This automatically opens the media file and loads
77  /// frame 1, or it throws one of the following exceptions.
78  ImageReader(string path) throw(InvalidFile);
79 
80  /// Close File
81  void Close();
82 
83  /// Get the cache object used by this reader (always returns NULL for this object)
84  Cache* GetCache() { return NULL; };
85 
86  /// Get an openshot::Frame object for a specific frame number of this reader. All numbers
87  /// return the same Frame, since they all share the same image data.
88  ///
89  /// @returns The requested frame (containing the image)
90  /// @param requested_frame The frame number that is requested.
91  tr1::shared_ptr<Frame> GetFrame(long int requested_frame) throw(ReaderClosed);
92 
93  /// Determine if reader is open or closed
94  bool IsOpen() { return is_open; };
95 
96  /// Return the type name of the class
97  string Name() { return "ImageReader"; };
98 
99  /// Get and Set JSON methods
100  string Json(); ///< Generate JSON string of this object
101  void SetJson(string value) throw(InvalidJSON); ///< Load JSON string into this object
102  Json::Value JsonValue(); ///< Generate Json::JsonValue for this object
103  void SetJsonValue(Json::Value root) throw(InvalidFile); ///< Load Json::JsonValue into this object
104 
105  /// Open File - which is called by the constructor automatically
106  void Open() throw(InvalidFile);
107  };
108 
109 }
110 
111 #endif
bool IsOpen()
Determine if reader is open or closed.
Definition: ImageReader.h:94
Header file for ReaderBase class.
This abstract class is the base class, used by all readers in libopenshot.
Definition: ReaderBase.h:95
Exception when a reader is closed, and a frame is requested.
Definition: Exceptions.h:234
This class uses the ImageMagick++ libraries, to open image files, and return openshot::Frame objects ...
Definition: ImageReader.h:67
Header file for all Exception classes.
Exception for files that can not be found or opened.
Definition: Exceptions.h:132
Header file for Cache class.
This class is a cache manager for Frame objects.
Definition: Cache.h:55
Cache * GetCache()
Get the cache object used by this reader (always returns NULL for this object)
Definition: ImageReader.h:84
This namespace is the default namespace for all code in the openshot library.
Exception for invalid JSON.
Definition: Exceptions.h:152
string Name()
Return the type name of the class.
Definition: ImageReader.h:97