Various hacks.
authorCarl Hetherington <cth@carlh.net>
Thu, 2 Jul 2015 10:06:56 +0000 (11:06 +0100)
committerCarl Hetherington <cth@carlh.net>
Mon, 21 Mar 2016 16:41:13 +0000 (16:41 +0000)
run/poznan
src/lib/poznan_encoder.cc
src/lib/poznan_encoder.h
src/lib/wscript
test/poznan.cc
test/wscript
wscript

index 7c472711b1d65ea5d525e664245ac254addb638a..d4e798f70695697608800843d46de2b265a14f08 100755 (executable)
@@ -12,3 +12,5 @@ else
     build/test/poznan $*
 fi
 
+#j2k_dump -i poznan.j2k > poznan.dump
+#diff -u good.dump poznan.dump
index 937566e8105312c871a0588a41c7899a537b668b..22da60abd7a20b9bf3129f4f37534116740cdc46 100644 (file)
@@ -24,6 +24,7 @@
 #include <poznan/tier2/markers.h>
 #include <dcp/openjpeg_image.h>
 #include <dlfcn.h>
+#include <thrust/system/cuda/error.h>
 
 #include "i18n.h"
 
@@ -143,31 +144,32 @@ PoznanEncoder::do_encode (shared_ptr<const dcp::OpenJPEGImage> input)
        img->use_part2_mct = _param.param_use_part2_mct;
        img->mct_compression_method = _param.param_mct_compression_method;
 
-       img->coding_style = CODING_STYLE;
+       img->coding_style = CODING_STYLE_PRECINCTS_DEFINED;
        img->prog_order = COMP_POS_RES_LY_PROG;
        img->num_layers = NUM_LAYERS;
 
        _set_coding_parameters (img, &_param);
        _init_tiles (&img, &_param);
 
-       _color_coder_lossy (img);
-
        type_tile* tile = &(img->tile[0]);
 
        /* XXX: it's a shame about this int -> float conversion */
        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]) / 4095;
+                       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);
        }
 
+       _color_coder_lossy (img);
+
        std::cout << "Tile " << tile->width << "x" << tile->height << "\n";
        _fwt (tile);
        _quantize_tile (tile);
@@ -176,21 +178,14 @@ PoznanEncoder::do_encode (shared_ptr<const dcp::OpenJPEGImage> input)
        type_buffer buffer;
        _init_buffer (&buffer);
        _encode_codestream (&buffer, img);
+       if (cudaGetLastError () != cudaSuccess) {
+               throw EncodeError ("CUDA error");
+       }
 
        std::cout << img->num_tiles << " tiles.\n";
        std::cout << "got " << buffer.bytes_count << " bytes.\n";
        Data encoded (buffer.data, buffer.bytes_count);
 
-       /* XXX! */
-       static int shit = 0;
-       {
-               string name = raw_convert<string> (shit);
-               FILE* f = fopen (name.c_str(), "wb");
-               fwrite (buffer.data, 1, buffer.bytes_count, f);
-               fclose (f);
-               ++shit;
-       }
-
        free (buffer.data);
        delete img;
 
index 2184e49ff3d3728a04db181acebb8e1f773a4523..91413493c136371563b825330606fc54607af308 100644 (file)
@@ -58,4 +58,5 @@ private:
        void (*_cuda_h_allocate_mem) (void **, uint64_t);
        void (*_cuda_memcpy_htd) (void *, void *, uint64_t);
        void (*_cuda_h_free) (void *);
+       void (*_check_cuda_error) (char const *);
 };
index 7f7d63e5a0261fc8f1e3086271e312e22c3da7ba..46b6f2627e2bd79e65318f666c2bca7965fd6a85 100644 (file)
@@ -157,7 +157,7 @@ def build(bld):
                  AVCODEC AVUTIL AVFORMAT AVFILTER SWSCALE
                  BOOST_FILESYSTEM BOOST_THREAD BOOST_DATETIME BOOST_SIGNALS2 BOOST_REGEX
                  SNDFILE SAMPLERATE POSTPROC TIFF MAGICK SSH DCP CXML GLIB LZMA XML++
-                 CURL ZIP FONTCONFIG PANGOMM CAIROMM XMLSEC SUB ICU PATCHED_FFMPEG
+                 CURL ZIP FONTCONFIG PANGOMM CAIROMM XMLSEC SUB ICU PATCHED_FFMPEG CUDA
                  """
 
     if bld.env.TARGET_OSX:
index d96dcae1b8270f8db989f1a6cec25df91c1c360a..fe18667d10c2f89400c35b6223e4ad69f31e110e 100644 (file)
@@ -28,20 +28,21 @@ int main ()
 
        for (int x = 666; x < 1332; ++x) {
                for (int y = 0; y < 1080; ++y) {
-                       rgb->data()[0][y * line_size + x * 3] = 255;
-                       rgb->data()[0][y * line_size + x * 3 + 1] = 0;
+                       rgb->data()[0][y * line_size + x * 3] = 0;
+                       rgb->data()[0][y * line_size + x * 3 + 1] = 255;
                        rgb->data()[0][y * line_size + x * 3 + 2] = 0;
                }
        }
 
        for (int x = 1332; x < 1998; ++x) {
                for (int y = 0; y < 1080; ++y) {
-                       rgb->data()[0][y * line_size + x * 3] = 255;
+                       rgb->data()[0][y * line_size + x * 3] = 0;
                        rgb->data()[0][y * line_size + x * 3 + 1] = 0;
-                       rgb->data()[0][y * line_size + x * 3 + 2] = 0;
+                       rgb->data()[0][y * line_size + x * 3 + 2] = 255;
                }
        }
 
        shared_ptr<const dcp::OpenJPEGImage> xyz = dcp::rgb_to_xyz (rgb->data()[0], rgb->size(), rgb->stride()[0], ColourConversion::rec709_to_xyz ());
        Data j2k = encoder->encode (xyz, 100000000, 24, RESOLUTION_2K, false);
+       j2k.write ("poznan.j2k");
 }
index b424ed22cd73364b12110c3300da7bb87136f08b..fe4a7dfaf51def1f3a4cdd7e5af3dd458f0c3f95 100644 (file)
@@ -31,7 +31,7 @@ def build(bld):
     obj = bld(features='cxx cxxprogram')
     obj.name   = 'unit-tests'
     obj.uselib =  'BOOST_TEST BOOST_THREAD BOOST_FILESYSTEM BOOST_DATETIME SNDFILE SAMPLERATE DCP FONTCONFIG CAIROMM PANGOMM XMLPP '
-    obj.uselib += 'AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE POSTPROC CXML MAGICK SUB GLIB CURL SSH XMLSEC BOOST_REGEX ICU '
+    obj.uselib += 'AVFORMAT AVFILTER AVCODEC AVUTIL SWSCALE POSTPROC CXML MAGICK SUB GLIB CURL SSH XMLSEC BOOST_REGEX ICU CUDA '
     if bld.env.TARGET_WINDOWS:
         obj.uselib += 'WINSOCK2'
     obj.use    = 'libdcpomatic2'
@@ -102,7 +102,7 @@ def build(bld):
 
     obj = bld(features='cxx cxxprogram')
     obj.name = 'poznan'
-    obj.uselib = 'DCP'
+    obj.uselib = 'DCP CUDA'
     obj.use = 'libdcpomatic2'
     obj.source = "poznan.cc"
     obj.target = 'poznan'
diff --git a/wscript b/wscript
index 98b1363684b73230256a2760a44ed44226f7000c..4fd019bf32dc2798a044f39988992eb0876e2880 100644 (file)
--- a/wscript
+++ b/wscript
@@ -267,6 +267,9 @@ def configure(conf):
     else:
         conf.env.LIB_XMLSEC = ['xmlsec1-openssl', 'xmlsec1']
 
+    # XXX
+    conf.env.LIB_CUDA = ['cudart']
+
     # FFmpeg
     if conf.options.static_ffmpeg:
         names = ['avformat', 'avfilter', 'avcodec', 'avutil', 'swscale', 'postproc']