Various hacks.
authorCarl Hetherington <cth@carlh.net>
Thu, 10 Mar 2016 17:12:22 +0000 (17:12 +0000)
committerCarl Hetherington <cth@carlh.net>
Mon, 21 Mar 2016 16:41:16 +0000 (16:41 +0000)
run/poznan
src/lib/poznan_encoder.cc
src/lib/poznan_encoder.h
test/poznan.cc
test/wscript

index d4e798f70695697608800843d46de2b265a14f08..22557b77d64f0e8eef4d775153c4145e01acd9d9 100755 (executable)
@@ -1,16 +1,17 @@
 #!/bin/bash
 
-export LD_LIBRARY_PATH=build/src/lib:poznan:$LD_LIBRARY_PATH
+export LD_LIBRARY_PATH=build/src/lib:$LD_LIBRARY_PATH
 export DCPOMATIC_LINUX_SHARE_PREFIX=`pwd`
 if [ "$1" == "--debug" ]; then
     shift;
     gdb --args build/test/poznan $*
 elif [ "$1" == "--valgrind" ]; then
     shift;
-    valgrind --tool="memcheck" --leak-check=full build/test/poznan $*
+    valgrind --tool="memcheck" build/test/poznan $*
 else
     build/test/poznan $*
 fi
 
-#j2k_dump -i poznan.j2k > poznan.dump
-#diff -u good.dump poznan.dump
+j2k_dump -i openjpeg.j2k > openjpeg.dump
+j2k_dump -i poznan.j2k > poznan.dump
+diff -u openjpeg.dump poznan.dump
index fa968010b776482c5c5d5185ddc18f1a7b1e32d2..9a172c4bb8419e3a7e2e0e920520502a44458d0a 100644 (file)
 #include <dcp/data.h>
 #include <dlfcn.h>
 #include <thrust/system/cuda/error.h>
+#include <cfloat>
 
 #include "i18n.h"
 
 using std::string;
 using std::cout;
+using std::min;
+using std::max;
 using boost::shared_ptr;
 using dcp::Data;
 
@@ -55,6 +58,7 @@ PoznanEncoder::PoznanEncoder ()
        _encode_codestream = (void (*)(type_buffer *, type_image *)) dlsym (tier2, "encode_codestream");
        _cuda_h_allocate_mem = (void (*)(void **, uint64_t)) dlsym (misc, "cuda_h_allocate_mem");
        _cuda_memcpy_htd = (void (*)(void *, void *, uint64_t)) dlsym (misc, "cuda_memcpy_htd");
+       _cuda_memcpy_dth = (void (*)(void *, void *, uint64_t)) dlsym (misc, "cuda_memcpy_dth");
        _cuda_h_free = (void (*)(void *)) dlsym (misc, "cuda_h_free");
 
        if (
@@ -158,20 +162,47 @@ PoznanEncoder::do_encode (shared_ptr<const dcp::OpenJPEGImage> input)
        for (int i = 0; i < 3; ++i) {
                type_tile_comp* c = &tile->tile_comp[i];
                c->tile_comp_no = i;
-               std::cout << "Tile comp " << i << ": " << c->width << "x" << c->height << "\n";
                int const pixels = c->width * c->height;
                _cuda_h_allocate_mem ((void **) &c->img_data, pixels * sizeof (type_data));
                for (int j = 0; j < pixels; ++j) {
                        c->img_data[j] = float (input->data(i)[j]);
-                       //c->img_data[j] = input->data(i)[j];
                }
                _cuda_memcpy_htd (c->img_data, c->img_data_d, pixels * sizeof (type_data));
                _cuda_h_free (c->img_data);
        }
 
+       for (int i = 0; i < 3; ++i) {
+               type_tile_comp* c = &tile->tile_comp[i];
+               int const pixels = c->width * c->height;
+               float* data = new float[pixels];
+               _cuda_memcpy_dth (c->img_data_d, data, pixels * sizeof (type_data));
+               float yuv_min = FLT_MAX;
+               float yuv_max = -FLT_MAX;
+               for (int j = 0; j < pixels; ++j) {
+                       yuv_min = min (yuv_min, data[j]);
+                       yuv_max = max (yuv_max, data[j]);
+               }
+               delete[] data;
+               printf("RGB component %d range %f to %f\n", i, yuv_min, yuv_max);
+       }
+
        _color_coder_lossy (img);
 
-       std::cout << "Tile " << tile->width << "x" << tile->height << "\n";
+       for (int i = 0; i < 3; ++i) {
+               type_tile_comp* c = &tile->tile_comp[i];
+               int const pixels = c->width * c->height;
+               float* data = new float[pixels];
+               _cuda_memcpy_dth (c->img_data_d, data, pixels * sizeof (type_data));
+               float yuv_min = FLT_MAX;
+               float yuv_max = -FLT_MAX;
+               for (int j = 0; j < pixels; ++j) {
+                       yuv_min = min (yuv_min, data[j]);
+                       yuv_max = max (yuv_max, data[j]);
+               }
+               delete[] data;
+               printf("YCbCr component %d range %f to %f\n", i, yuv_min, yuv_max);
+       }
+
        _fwt (tile);
        _quantize_tile (tile);
        _encode_tile (tile);
@@ -183,8 +214,7 @@ PoznanEncoder::do_encode (shared_ptr<const dcp::OpenJPEGImage> input)
                throw EncodeError ("CUDA error");
        }
 
-       std::cout << img->num_tiles << " tiles.\n";
-       std::cout << "got " << buffer.bytes_count << " bytes.\n";
+       cout << "Output " << buffer.bytes_count << " bytes.\n";
        Data encoded (buffer.data, buffer.bytes_count);
 
        free (buffer.data);
index 6cdc5f0740ed85eb22c40dbb43b9c683d99d85ff..3cb94ed66306183f9455d2f7a833d23be53cd50a 100644 (file)
@@ -57,6 +57,7 @@ private:
        void (*_encode_codestream) (type_buffer *, type_image *);
        void (*_cuda_h_allocate_mem) (void **, uint64_t);
        void (*_cuda_memcpy_htd) (void *, void *, uint64_t);
+       void (*_cuda_memcpy_dth) (void *, void *, uint64_t);
        void (*_cuda_h_free) (void *);
        void (*_check_cuda_error) (char const *);
 };
index 713ff0f93c5c97f4c2def27b5e611bb853336443..9e43aba2a31fede61d356344dba89be0429287cd 100644 (file)
@@ -3,6 +3,7 @@
 #include "lib/image.h"
 #include "lib/colour_conversion.h"
 #include "lib/config.h"
+#include "lib/magick_image_proxy.h"
 #include <dcp/rgb_xyz.h>
 
 using std::vector;
@@ -10,17 +11,10 @@ using std::cout;
 using boost::shared_ptr;
 using dcp::Data;
 
-int main ()
+static
+void
+colour_bars (shared_ptr<Image> rgb)
 {
-       JPEG2000Encoder::setup_encoders ();
-
-       shared_ptr<JPEG2000Encoder> openjpeg = JPEG2000Encoder::from_id ("openjpeg");
-       shared_ptr<JPEG2000Encoder> poznan = JPEG2000Encoder::from_id ("poznan");
-
-       shared_ptr<Image> rgb (new Image (AV_PIX_FMT_RGB48LE, dcp::Size (1998, 1080), false));
-
-       cout << rgb->stride()[0] << "\n";
-
        int const line_size = rgb->stride()[0] / 2;
        int const width = rgb->size().width;
        int const height = rgb->size().height;
@@ -50,6 +44,43 @@ int main ()
                        p[y * line_size + x * 3 + 2] = 65535;
                }
        }
+}
+
+int main ()
+{
+       JPEG2000Encoder::setup_encoders ();
+
+       shared_ptr<JPEG2000Encoder> openjpeg = JPEG2000Encoder::from_id ("openjpeg");
+       shared_ptr<JPEG2000Encoder> poznan = JPEG2000Encoder::from_id ("poznan");
+
+       bool const testcard = false;
+
+       shared_ptr<Image> rgb;
+       if (testcard) {
+               rgb.reset (new Image (AV_PIX_FMT_RGB48LE, dcp::Size (1998, 1080), false));
+               colour_bars (rgb);
+       } else {
+               shared_ptr<MagickImageProxy> mip (new MagickImageProxy ("../dcpomatic-test-private/frame.tiff"));
+               shared_ptr<Image> raw = mip->image();
+               rgb.reset (new Image (AV_PIX_FMT_RGB48LE, raw->size(), false));
+               for (int y = 0; y < raw->size().height; ++y) {
+                       uint8_t const * p = raw->data()[0] + y * raw->stride()[0];
+                       uint8_t* q = rgb->data()[0] + y * rgb->stride()[0];
+                       if (y == 0) {
+                               for (int x = 0; x < 16; ++x) {
+                                       cout << ((int)p[x * 3]) << " " << ((int)p[x * 3 + 1]) << " " << ((int)p[x * 2]) << "\n";
+                               }
+                       }
+                       for (int x = 0; x < raw->size().width; ++x) {
+                               *q++ = 0;
+                               *q++ = *p++;
+                               *q++ = 0;
+                               *q++ = *p++;
+                               *q++ = 0;
+                               *q++ = *p++;
+                       }
+               }
+       }
 
        shared_ptr<const dcp::OpenJPEGImage> xyz = dcp::rgb_to_xyz (rgb->data()[0], rgb->size(), rgb->stride()[0], ColourConversion::rec709_to_xyz ());
        openjpeg->encode (xyz, 100000000, 24, RESOLUTION_2K, false).write ("openjpeg.j2k");
index fe4a7dfaf51def1f3a4cdd7e5af3dd458f0c3f95..f88b006e0e908d5982b2b6a8a14e20e3aca86e7a 100644 (file)
@@ -102,7 +102,7 @@ def build(bld):
 
     obj = bld(features='cxx cxxprogram')
     obj.name = 'poznan'
-    obj.uselib = 'DCP CUDA'
+    obj.uselib = 'DCP CUDA MAGICK BOOST_FILESYSTEM SNDFILE'
     obj.use = 'libdcpomatic2'
     obj.source = "poznan.cc"
     obj.target = 'poznan'