- using namespace MagickCore;
- Magick::Image* image = new Magick::Image (content->path(0).string());
- _video_size = dcp::Size (image->columns(), image->rows());
- delete image;
+ auto path = content->path(0);
+ if (valid_j2k_file (path)) {
+ auto size = boost::filesystem::file_size (path);
+ dcp::File f(path, "rb");
+ if (!f) {
+ throw FileError ("Could not open file for reading", path);
+ }
+ std::vector<uint8_t> buffer(size);
+ f.checked_read(buffer.data(), size);
+ f.close();
+ try {
+ _video_size = dcp::decompress_j2k(buffer.data(), size, 0)->size();
+ } catch (dcp::ReadError& e) {
+ throw DecodeError (String::compose (_("Could not decode JPEG2000 file %1 (%2)"), path, e.what ()));
+ }
+ } else {
+ FFmpegImageProxy proxy(content->path(0));
+ _video_size = proxy.image(Image::Alignment::COMPACT).image->size();
+ }