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
|
|
|
|
|
*/
|
|
|
|
|
|
2021-10-16 01:26:26 -04:00
|
|
|
// Copyright (c) 2008-2019 OpenShot Studios, LLC
|
|
|
|
|
//
|
|
|
|
|
// SPDX-License-Identifier: LGPL-3.0-or-later
|
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
|
|
|
|
|
|
2017-08-20 17:37:39 -05:00
|
|
|
#include <memory>
|
2021-11-02 09:12:23 -04:00
|
|
|
#include <string>
|
2021-01-26 10:52:04 -05:00
|
|
|
|
2021-11-02 09:12:23 -04:00
|
|
|
#include "ReaderBase.h"
|
|
|
|
|
#include "Json.h"
|
|
|
|
|
|
|
|
|
|
// Forward decls
|
|
|
|
|
namespace Magick {
|
|
|
|
|
class Image;
|
|
|
|
|
}
|
|
|
|
|
namespace openshot {
|
|
|
|
|
class CacheBase;
|
|
|
|
|
class Frame;
|
|
|
|
|
}
|
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:
|
2020-10-17 05:56:02 -04:00
|
|
|
/// @brief Constructor for ImageReader.
|
|
|
|
|
///
|
|
|
|
|
/// Opens the media file to inspect its properties and loads frame 1,
|
|
|
|
|
/// iff inspect_reader == true (the default). Pass a false value in
|
|
|
|
|
/// the optional parameter to defer this initial Open()/Close() cycle.
|
|
|
|
|
///
|
|
|
|
|
/// When not inspecting the media file, it's much faster, and useful
|
|
|
|
|
/// when you are inflating the object using JSON after instantiation.
|
|
|
|
|
ImageReader(const std::string& path, bool inspect_reader=true);
|
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-11-27 00:38:04 -05:00
|
|
|
CacheBase* 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
|
|
|
|
2021-03-07 11:23:59 -05: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
|