Hack.
authorCarl Hetherington <cth@carlh.net>
Wed, 1 Aug 2012 14:47:12 +0000 (15:47 +0100)
committerCarl Hetherington <cth@carlh.net>
Wed, 1 Aug 2012 14:47:12 +0000 (15:47 +0100)
src/picture_asset.cc
src/picture_asset.h
src/wscript
wscript

index e35dcc62cac972da596047459957e42645bc7401..969a5523f0872c0e83a25a90a243f2eca17360eb 100644 (file)
@@ -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;
+}
index cccea0f33dfaf527f4bcc8e62809e27de04d3456..3980794a13f741d8168c494d063efc6b3512aa85 100644 (file)
@@ -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;
index 6c4f483e26552a95f13072f422d298f135ee5c6e..8caae703ae22d7a90815592de0d69f251d9ebe64 100644 (file)
@@ -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 c619dbb25a115610fab269b520b01f115c1e9a89..30974ac7172ec8e878dd55718e023f73f7e46d2a 100644 (file)
--- 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: