summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2014-11-23 01:48:55 +0000
committerCarl Hetherington <cth@carlh.net>2014-11-23 12:47:36 +0000
commit80fafad9c11e0cd8cf9d6ce17deb83be6f680f2d (patch)
treead1b5f69d9863a86ecbf2c46ae0b7916ce60be09 /src/lib
parent2f51e117cbaf36b9e0ccb02c338b316fc8e26b9a (diff)
First cut at J2K import.
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/image_decoder.cc11
-rw-r--r--src/lib/image_examiner.cc28
-rw-r--r--src/lib/j2k_image_proxy.cc8
-rw-r--r--src/lib/j2k_image_proxy.h1
-rw-r--r--src/lib/util.cc8
-rw-r--r--src/lib/util.h1
6 files changed, 50 insertions, 7 deletions
diff --git a/src/lib/image_decoder.cc b/src/lib/image_decoder.cc
index 53ef7bae7..f11d37756 100644
--- a/src/lib/image_decoder.cc
+++ b/src/lib/image_decoder.cc
@@ -24,6 +24,7 @@
#include "image_decoder.h"
#include "image.h"
#include "magick_image_proxy.h"
+#include "j2k_image_proxy.h"
#include "film.h"
#include "exceptions.h"
@@ -49,7 +50,15 @@ ImageDecoder::pass ()
if (!_image_content->still() || !_image) {
/* Either we need an image or we are using moving images, so load one */
- _image.reset (new MagickImageProxy (_image_content->path (_image_content->still() ? 0 : _video_position)));
+ boost::filesystem::path path = _image_content->path (_image_content->still() ? 0 : _video_position);
+ if (valid_j2k_file (path)) {
+ /* We can't extract image size from a JPEG2000 codestream without decoding it,
+ so pass in the image content's size here.
+ */
+ _image.reset (new J2KImageProxy (path, _image_content->video_size ()));
+ } else {
+ _image.reset (new MagickImageProxy (path));
+ }
}
video (_image, _video_position);
diff --git a/src/lib/image_examiner.cc b/src/lib/image_examiner.cc
index 75ccb6a3e..ef9c13c5a 100644
--- a/src/lib/image_examiner.cc
+++ b/src/lib/image_examiner.cc
@@ -17,14 +17,16 @@
*/
-#include <iostream>
-#include <Magick++.h>
#include "image_content.h"
#include "image_examiner.h"
#include "film.h"
#include "job.h"
#include "exceptions.h"
#include "config.h"
+#include "cross.h"
+#include <dcp/xyz_frame.h>
+#include <Magick++.h>
+#include <iostream>
#include "i18n.h"
@@ -39,10 +41,24 @@ ImageExaminer::ImageExaminer (shared_ptr<const Film> film, shared_ptr<const Imag
{
#ifdef DCPOMATIC_IMAGE_MAGICK
using namespace MagickCore;
-#endif
- Magick::Image* image = new Magick::Image (content->path(0).string());
- _video_size = dcp::Size (image->columns(), image->rows());
- delete image;
+#endif
+ boost::filesystem::path path = content->path(0).string ();
+ if (valid_j2k_file (path)) {
+ boost::uintmax_t size = boost::filesystem::file_size (path);
+ uint8_t* buffer = new uint8_t[size];
+ FILE* f = fopen_boost (path, "r");
+ if (!f) {
+ throw FileError ("Could not open file for reading", path);
+ }
+ fread (buffer, 1, size, f);
+ fclose (f);
+ _video_size = dcp::decompress_j2k (buffer, size, 0)->size ();
+ delete[] buffer;
+ } else {
+ Magick::Image* image = new Magick::Image (content->path(0).string());
+ _video_size = dcp::Size (image->columns(), image->rows());
+ delete image;
+ }
if (content->still ()) {
_video_length = ContentTime::from_seconds (Config::instance()->default_still_length());
diff --git a/src/lib/j2k_image_proxy.cc b/src/lib/j2k_image_proxy.cc
index 1fe854cd1..9312a7763 100644
--- a/src/lib/j2k_image_proxy.cc
+++ b/src/lib/j2k_image_proxy.cc
@@ -31,6 +31,14 @@
using std::string;
using boost::shared_ptr;
+/** Construct a J2KImageProxy from a JPEG2000 file */
+J2KImageProxy::J2KImageProxy (boost::filesystem::path path, dcp::Size size)
+ : _mono (new dcp::MonoPictureFrame (path))
+ , _size (size)
+{
+
+}
+
J2KImageProxy::J2KImageProxy (shared_ptr<const dcp::MonoPictureFrame> frame, dcp::Size size)
: _mono (frame)
, _size (size)
diff --git a/src/lib/j2k_image_proxy.h b/src/lib/j2k_image_proxy.h
index c931e5644..299180f50 100644
--- a/src/lib/j2k_image_proxy.h
+++ b/src/lib/j2k_image_proxy.h
@@ -25,6 +25,7 @@ class EncodedData;
class J2KImageProxy : public ImageProxy
{
public:
+ J2KImageProxy (boost::filesystem::path path, dcp::Size);
J2KImageProxy (boost::shared_ptr<const dcp::MonoPictureFrame> frame, dcp::Size);
J2KImageProxy (boost::shared_ptr<const dcp::StereoPictureFrame> frame, dcp::Size, dcp::Eye);
J2KImageProxy (boost::shared_ptr<cxml::Node> xml, boost::shared_ptr<Socket> socket);
diff --git a/src/lib/util.cc b/src/lib/util.cc
index 2b7df86bf..ec8b0f7a5 100644
--- a/src/lib/util.cc
+++ b/src/lib/util.cc
@@ -797,6 +797,14 @@ valid_image_file (boost::filesystem::path f)
return (ext == ".tif" || ext == ".tiff" || ext == ".jpg" || ext == ".jpeg" || ext == ".png" || ext == ".bmp" || ext == ".tga" || ext == ".dpx");
}
+bool
+valid_j2k_file (boost::filesystem::path f)
+{
+ string ext = f.extension().string();
+ transform (ext.begin(), ext.end(), ext.begin(), ::tolower);
+ return (ext == ".j2k" || ext == ".j2c");
+}
+
string
tidy_for_filename (string f)
{
diff --git a/src/lib/util.h b/src/lib/util.h
index c06f51ca3..886e2a61c 100644
--- a/src/lib/util.h
+++ b/src/lib/util.h
@@ -63,6 +63,7 @@ extern std::string md5_digest (std::vector<boost::filesystem::path>, boost::shar
extern void ensure_ui_thread ();
extern std::string audio_channel_name (int);
extern bool valid_image_file (boost::filesystem::path);
+extern bool valid_j2k_file (boost::filesystem::path);
#ifdef DCPOMATIC_WINDOWS
extern boost::filesystem::path mo_path ();
#endif