summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2012-08-01 15:47:12 +0100
committerCarl Hetherington <cth@carlh.net>2012-08-01 15:47:12 +0100
commit2def26f93946953149baadee2a9c5b59f6ab32cf (patch)
treebd223d8df921bb74ce11dc7cf96f969d8cb80972
parentfb128e6dc3b951c9d12ffb00b110714d3acfa5fd (diff)
Hack.
-rw-r--r--src/picture_asset.cc55
-rw-r--r--src/picture_asset.h2
-rw-r--r--src/wscript2
-rw-r--r--wscript9
4 files changed, 67 insertions, 1 deletions
diff --git a/src/picture_asset.cc b/src/picture_asset.cc
index e35dcc62..969a5523 100644
--- a/src/picture_asset.cc
+++ b/src/picture_asset.cc
@@ -27,6 +27,7 @@
#include <sstream>
#include <boost/filesystem.hpp>
#include <boost/lexical_cast.hpp>
+#include <openjpeg.h>
#include "AS_DCP.h"
#include "KM_fileio.h"
#include "picture_asset.h"
@@ -208,17 +209,71 @@ PictureAsset::equals (shared_ptr<const Asset> other, EqualityFlags flags) const
throw DCPReadError ("could not read video frame");
}
+ bool j2k_same = true;
+
if (buffer_A.Size() != buffer_B.Size()) {
notes.push_back ("sizes of video data for frame " + lexical_cast<string>(i) + " differ");
+ j2k_same = false;
continue;
}
if (memcmp (buffer_A.RoData(), buffer_B.RoData(), buffer_A.Size()) != 0) {
notes.push_back ("J2K data for frame " + lexical_cast<string>(i) + " differ");
+ j2k_same = false;
continue;
}
+
+ if (!j2k_same) {
+ /* Decompress the images to bitmaps */
+ opj_image_t* image_A = decompress_j2k (const_cast<uint8_t*> (buffer_A.RoData()), buffer_A.Size ());
+ opj_image_t* image_B = decompress_j2k (const_cast<uint8_t*> (buffer_B.RoData()), buffer_B.Size ());
+
+ /* Compare them */
+
+ if (image_A->numcomps != image_B->numcomps) {
+ notes.push_back ("image component counts for frame " + lexical_cast<string>(i) + " differ");
+ }
+
+ for (int c = 0; c < image_A->numcomps; ++c) {
+ if (image_A->comps[c].w != image_B->comps[c].w || image_A->comps[c].h != image_B->comps[c].h) {
+ notes.push_back ("image sizes for frame " + lexical_cast<string>(i) + " differ");
+ }
+
+ cout << "comp " << c << " of " << image_A->numcomps << "\n";
+ cout << "bpp " << image_A->comps[c].bpp << "\n";
+
+ for (int x = 0; x < image_A->comps[c].w; ++x) {
+ for (int y = 0; y < image_A->comps[c].h; ++y) {
+
+ }
+ }
+ }
+
+
+ opj_image_destroy (image_A);
+ opj_image_destroy (image_B);
+ }
}
}
return notes;
}
+
+opj_image_t *
+PictureAsset::decompress_j2k (uint8_t* data, int64_t size) const
+{
+ opj_dinfo_t* decoder = opj_create_decompress (CODEC_J2K);
+ opj_dparameters_t parameters;
+ opj_set_default_decoder_parameters (&parameters);
+ opj_setup_decoder (decoder, &parameters);
+ opj_cio_t* cio = opj_cio_open ((opj_common_ptr) decoder, data, size);
+ opj_image_t* image = opj_decode (decoder, cio);
+ if (!image) {
+ opj_destroy_decompress (decoder);
+ opj_cio_close (cio);
+ throw DCPReadError ("could not decode JPEG2000 codestream");
+ }
+
+ opj_cio_close (cio);
+ return image;
+}
diff --git a/src/picture_asset.h b/src/picture_asset.h
index cccea0f3..3980794a 100644
--- a/src/picture_asset.h
+++ b/src/picture_asset.h
@@ -21,6 +21,7 @@
* @brief An asset made up of JPEG2000 files
*/
+#include <openjpeg.h>
#include "asset.h"
namespace libdcp
@@ -86,6 +87,7 @@ public:
private:
std::string path_from_list (int f, std::vector<std::string> const & files) const;
void construct (sigc::slot<std::string, int>);
+ opj_image_t* decompress_j2k (uint8_t* data, int64_t size) const;
/** picture width in pixels */
int _width;
diff --git a/src/wscript b/src/wscript
index 6c4f483e..8caae703 100644
--- a/src/wscript
+++ b/src/wscript
@@ -3,7 +3,7 @@ def build(bld):
obj.name = 'libdcp'
obj.target = 'dcp'
obj.export_includes = ['.']
- obj.uselib = 'BOOST_FILESYSTEM OPENSSL SIGC++ LIBXML++'
+ obj.uselib = 'BOOST_FILESYSTEM OPENSSL SIGC++ LIBXML++ OPENJPEG'
obj.use = 'libkumu-libdcp libasdcp-libdcp'
obj.source = """
asset.cc
diff --git a/wscript b/wscript
index c619dbb2..30974ac7 100644
--- a/wscript
+++ b/wscript
@@ -23,6 +23,15 @@ def configure(conf):
conf.check_cfg(package = 'sigc++-2.0', args = '--cflags --libs', uselib_store = 'SIGC++', mandatory = True)
conf.check_cfg(package = 'libxml++-2.6', args = '--cflags --libs', uselib_store = 'LIBXML++', mandatory = True)
+ conf.check_cc(fragment = """
+ #include <stdio.h>\n
+ #include <openjpeg.h>\n
+ int main () {\n
+ void* p = (void *) opj_image_create;\n
+ return 0;\n
+ }
+ """, msg = 'Checking for library openjpeg', lib = 'openjpeg', uselib_store = 'OPENJPEG')
+
if conf.options.target_windows:
boost_lib_suffix = '-mt'
else: