2012-08-29 15:29:15 -05:00
|
|
|
/**
|
2013-09-09 23:32:16 -05:00
|
|
|
* @file
|
|
|
|
|
* @brief Header file for ImageReader class
|
2013-09-12 17:52:10 -05:00
|
|
|
* @author Jonathan Thomas <jonathan@openshot.org>
|
|
|
|
|
*
|
2019-06-09 08:31:04 -04:00
|
|
|
* @ref License
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/* LICENSE
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2019-06-11 06:48:32 -04:00
|
|
|
* Copyright (c) 2008-2019 OpenShot Studios, LLC
|
2014-03-29 18:49:22 -05:00
|
|
|
* <http://www.openshotstudios.com/>. This file is part of
|
|
|
|
|
* OpenShot Library (libopenshot), an open-source project dedicated to
|
|
|
|
|
* delivering high quality video editing and animation solutions to the
|
|
|
|
|
* world. For more information visit <http://www.openshot.org/>.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is free software: you can redistribute it
|
2014-07-11 16:52:14 -05:00
|
|
|
* and/or modify it under the terms of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* as published by the Free Software Foundation, either version 3 of the
|
|
|
|
|
* License, or (at your option) any later version.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-03-29 18:49:22 -05:00
|
|
|
* OpenShot Library (libopenshot) is distributed in the hope that it will be
|
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-07-11 16:52:14 -05:00
|
|
|
* GNU Lesser General Public License for more details.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
2014-07-11 16:52:14 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
2014-03-29 18:49:22 -05:00
|
|
|
* along with OpenShot Library. If not, see <http://www.gnu.org/licenses/>.
|
2012-08-29 15:29:15 -05:00
|
|
|
*/
|
|
|
|
|
|
2013-09-12 17:52:10 -05:00
|
|
|
#ifndef OPENSHOT_IMAGE_READER_H
|
|
|
|
|
#define OPENSHOT_IMAGE_READER_H
|
|
|
|
|
|
Add backwards-compatible Imagemagick 7 support (#252)
* Add ImageMagick 7 compatibility
A new header, `imclude/MagickUtilities.h`, is created to hold the
compatibility `#define`s.
The image-conversion code in `src/Frame.cpp` received the only
major changes — instead of doing the export by hand (and having
to account for changes in the underlying API), it uses the
`MagickCore::ExportImagePixels()` function which does basically
the same work, but accounts for all of the API changes for us.
The API of that function is _unchanged_ from IM6 to IM7.
TODO: `MagickCore::ExportImagePixels()` will return an `exception`
struct if it encounters any problems. Currently the code ignores
that, which it should not.
* Add ImageMagick 7 compatibility
A new header, `imclude/MagickUtilities.h`, is created to hold the
compatibility `#define`s.
The image-conversion code in `src/Frame.cpp` received the only
major changes — instead of doing the export by hand (and having
to account for changes in the underlying API), it uses the
`MagickCore::ExportImagePixels()` function which does basically
the same work, but accounts for all of the API changes for us.
The API of that function is _unchanged_ from IM6 to IM7.
TODO: `MagickCore::ExportImagePixels()` will return an `exception`
struct if it encounters any problems. Currently the code ignores
that, which it should not.
Thanks @ferdnyc
2019-06-21 01:07:49 -04:00
|
|
|
// Require ImageMagick support
|
|
|
|
|
#ifdef USE_IMAGEMAGICK
|
|
|
|
|
|
2013-09-08 16:40:57 -05:00
|
|
|
#include "ReaderBase.h"
|
2012-08-29 15:29:15 -05:00
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
#include <ctime>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
#include <omp.h>
|
|
|
|
|
#include <stdio.h>
|
2017-08-20 17:37:39 -05:00
|
|
|
#include <memory>
|
2016-08-31 23:57:06 -05:00
|
|
|
#include "CacheMemory.h"
|
2012-08-29 15:29:15 -05:00
|
|
|
#include "Exceptions.h"
|
Add backwards-compatible Imagemagick 7 support (#252)
* Add ImageMagick 7 compatibility
A new header, `imclude/MagickUtilities.h`, is created to hold the
compatibility `#define`s.
The image-conversion code in `src/Frame.cpp` received the only
major changes — instead of doing the export by hand (and having
to account for changes in the underlying API), it uses the
`MagickCore::ExportImagePixels()` function which does basically
the same work, but accounts for all of the API changes for us.
The API of that function is _unchanged_ from IM6 to IM7.
TODO: `MagickCore::ExportImagePixels()` will return an `exception`
struct if it encounters any problems. Currently the code ignores
that, which it should not.
* Add ImageMagick 7 compatibility
A new header, `imclude/MagickUtilities.h`, is created to hold the
compatibility `#define`s.
The image-conversion code in `src/Frame.cpp` received the only
major changes — instead of doing the export by hand (and having
to account for changes in the underlying API), it uses the
`MagickCore::ExportImagePixels()` function which does basically
the same work, but accounts for all of the API changes for us.
The API of that function is _unchanged_ from IM6 to IM7.
TODO: `MagickCore::ExportImagePixels()` will return an `exception`
struct if it encounters any problems. Currently the code ignores
that, which it should not.
Thanks @ferdnyc
2019-06-21 01:07:49 -04:00
|
|
|
#include "MagickUtilities.h"
|
2012-08-29 15:29:15 -05:00
|
|
|
|
|
|
|
|
namespace openshot
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
2013-09-09 23:32:16 -05:00
|
|
|
* @brief This class uses the ImageMagick++ libraries, to open image files, and return
|
2012-08-29 15:29:15 -05:00
|
|
|
* openshot::Frame objects containing the image.
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
|
|
|
|
* @code
|
|
|
|
|
* // Create a reader for a video
|
|
|
|
|
* ImageReader r("MyAwesomeImage.jpeg");
|
|
|
|
|
* r.Open(); // Open the reader
|
|
|
|
|
*
|
|
|
|
|
* // Get frame number 1 from the video
|
2017-08-20 17:37:39 -05:00
|
|
|
* std::shared_ptr<Frame> f = r.GetFrame(1);
|
2013-09-12 17:52:10 -05:00
|
|
|
*
|
|
|
|
|
* // Now that we have an openshot::Frame object, lets have some fun!
|
|
|
|
|
* f->Display(); // Display the frame on the screen
|
|
|
|
|
*
|
|
|
|
|
* // Close the reader
|
|
|
|
|
* r.Close();
|
|
|
|
|
* @endcode
|
2012-08-29 15:29:15 -05:00
|
|
|
*/
|
2013-09-08 16:40:57 -05:00
|
|
|
class ImageReader : public ReaderBase
|
2012-08-29 15:29:15 -05:00
|
|
|
{
|
|
|
|
|
private:
|
2019-08-04 23:02:36 -04:00
|
|
|
std::string path;
|
2017-08-20 17:37:39 -05:00
|
|
|
std::shared_ptr<Magick::Image> image;
|
2012-10-09 01:45:34 -05:00
|
|
|
bool is_open;
|
2012-08-29 15:29:15 -05:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
|
|
/// Constructor for ImageReader. This automatically opens the media file and loads
|
|
|
|
|
/// frame 1, or it throws one of the following exceptions.
|
2019-08-04 23:02:36 -04:00
|
|
|
ImageReader(std::string path);
|
2012-08-29 15:29:15 -05:00
|
|
|
|
2019-03-14 09:26:56 -07:00
|
|
|
/// Constructor for ImageReader. This only opens the media file to inspect its properties
|
2016-09-16 17:43:26 -05:00
|
|
|
/// if inspect_reader=true. When not inspecting the media file, it's much faster, and useful
|
|
|
|
|
/// when you are inflating the object using JSON after instantiating it.
|
2019-08-04 23:02:36 -04:00
|
|
|
ImageReader(std::string path, bool inspect_reader);
|
2016-09-16 17:43:26 -05:00
|
|
|
|
2012-08-29 15:29:15 -05:00
|
|
|
/// Close File
|
2020-04-15 21:45:04 -04:00
|
|
|
void Close() override;
|
2012-08-29 15:29:15 -05:00
|
|
|
|
2015-06-01 00:20:14 -07:00
|
|
|
/// Get the cache object used by this reader (always returns NULL for this object)
|
2020-04-15 21:45:04 -04:00
|
|
|
CacheMemory* GetCache() override { return NULL; };
|
2015-06-01 00:20:14 -07:00
|
|
|
|
2012-08-29 15:29:15 -05:00
|
|
|
/// Get an openshot::Frame object for a specific frame number of this reader. All numbers
|
|
|
|
|
/// return the same Frame, since they all share the same image data.
|
|
|
|
|
///
|
|
|
|
|
/// @returns The requested frame (containing the image)
|
2013-09-12 17:52:10 -05:00
|
|
|
/// @param requested_frame The frame number that is requested.
|
2020-04-15 21:45:04 -04:00
|
|
|
std::shared_ptr<Frame> GetFrame(int64_t requested_frame) override;
|
2012-10-08 16:22:18 -05:00
|
|
|
|
2013-12-18 21:55:43 -06:00
|
|
|
/// Determine if reader is open or closed
|
2020-04-15 21:45:04 -04:00
|
|
|
bool IsOpen() override { return is_open; };
|
2013-12-18 21:55:43 -06:00
|
|
|
|
2016-01-05 01:59:50 -06:00
|
|
|
/// Return the type name of the class
|
2020-04-15 21:45:04 -04:00
|
|
|
std::string Name() override { return "ImageReader"; };
|
2016-01-05 01:59:50 -06:00
|
|
|
|
2013-12-07 16:52:09 -06:00
|
|
|
/// Get and Set JSON methods
|
2019-12-27 08:51:51 -05:00
|
|
|
std::string Json() const override; ///< Generate JSON string of this object
|
2020-04-15 21:45:04 -04:00
|
|
|
void SetJson(const std::string value) override; ///< Load JSON string into this object
|
|
|
|
|
Json::Value JsonValue() const override; ///< Generate Json::Value for this object
|
|
|
|
|
void SetJsonValue(const Json::Value root) override; ///< Load Json::Value into this object
|
2013-12-07 16:52:09 -06:00
|
|
|
|
2012-10-08 16:22:18 -05:00
|
|
|
/// Open File - which is called by the constructor automatically
|
2020-04-15 21:45:04 -04:00
|
|
|
void Open() override;
|
2012-08-29 15:29:15 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
Add backwards-compatible Imagemagick 7 support (#252)
* Add ImageMagick 7 compatibility
A new header, `imclude/MagickUtilities.h`, is created to hold the
compatibility `#define`s.
The image-conversion code in `src/Frame.cpp` received the only
major changes — instead of doing the export by hand (and having
to account for changes in the underlying API), it uses the
`MagickCore::ExportImagePixels()` function which does basically
the same work, but accounts for all of the API changes for us.
The API of that function is _unchanged_ from IM6 to IM7.
TODO: `MagickCore::ExportImagePixels()` will return an `exception`
struct if it encounters any problems. Currently the code ignores
that, which it should not.
* Add ImageMagick 7 compatibility
A new header, `imclude/MagickUtilities.h`, is created to hold the
compatibility `#define`s.
The image-conversion code in `src/Frame.cpp` received the only
major changes — instead of doing the export by hand (and having
to account for changes in the underlying API), it uses the
`MagickCore::ExportImagePixels()` function which does basically
the same work, but accounts for all of the API changes for us.
The API of that function is _unchanged_ from IM6 to IM7.
TODO: `MagickCore::ExportImagePixels()` will return an `exception`
struct if it encounters any problems. Currently the code ignores
that, which it should not.
Thanks @ferdnyc
2019-06-21 01:07:49 -04:00
|
|
|
#endif //USE_IMAGEMAGICK
|
|
|
|
|
#endif //OPENSHOT_IMAGE_READER_H
|