Hacks. attic/gpu
authorCarl Hetherington <cth@carlh.net>
Sun, 17 Apr 2016 17:26:44 +0000 (18:26 +0100)
committerCarl Hetherington <cth@carlh.net>
Sun, 17 Apr 2016 17:26:44 +0000 (18:26 +0100)
NOTES
run/poznan
src/lib/poznan_encoder.cc

diff --git a/NOTES b/NOTES
index 96385a1874fb118b30497178f70fcde5381af5d3..f01dc5731188cd738b5eadef868e9aba0efa164b 100644 (file)
--- a/NOTES
+++ b/NOTES
@@ -1,3 +1,5 @@
 Run hacks/setup_cuda
 run/poznan tries to convert a RGB test pattern to J2K with the Poznan encoder.
 
+j2k_to_image -i poznan.j2k -o poznan.png -r 4 gives a clean image; compare with
+enc_dwt_after.bmp and the result is the same size as the first DWT-ed image.
\ No newline at end of file
index 22557b77d64f0e8eef4d775153c4145e01acd9d9..29baaad457dd49d06e9d36e4f4b586c28b76472a 100755 (executable)
@@ -12,6 +12,13 @@ else
     build/test/poznan $*
 fi
 
+rm *.png
 j2k_dump -i openjpeg.j2k > openjpeg.dump
+j2k_to_image -i openjpeg.j2k -o openjpeg.png
 j2k_dump -i poznan.j2k > poznan.dump
+j2k_to_image -i poznan.j2k -o poznan.png
+j2k_to_image -i poznan.j2k -o poznan1.png -r 1
+j2k_to_image -i poznan.j2k -o poznan2.png -r 2
+j2k_to_image -i poznan.j2k -o poznan3.png -r 3
+j2k_to_image -i poznan.j2k -o poznan4.png -r 4
 diff -u openjpeg.dump poznan.dump
index 9a172c4bb8419e3a7e2e0e920520502a44458d0a..a336a27481537fcfa533ebb130cc45f554bbdf8c 100644 (file)
@@ -168,7 +168,7 @@ PoznanEncoder::do_encode (shared_ptr<const dcp::OpenJPEGImage> input)
                        c->img_data[j] = float (input->data(i)[j]);
                }
                _cuda_memcpy_htd (c->img_data, c->img_data_d, pixels * sizeof (type_data));
-               _cuda_h_free (c->img_data);
+//             _cuda_h_free (c->img_data);
        }
 
        for (int i = 0; i < 3; ++i) {
@@ -176,14 +176,14 @@ PoznanEncoder::do_encode (shared_ptr<const dcp::OpenJPEGImage> input)
                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;
+               float rgb_min = FLT_MAX;
+               float rgb_max = -FLT_MAX;
                for (int j = 0; j < pixels; ++j) {
-                       yuv_min = min (yuv_min, data[j]);
-                       yuv_max = max (yuv_max, data[j]);
+                       rgb_min = min (rgb_min, data[j]);
+                       rgb_max = max (rgb_max, data[j]);
                }
                delete[] data;
-               printf("RGB component %d range %f to %f\n", i, yuv_min, yuv_max);
+               printf("RGB component %d range %f to %f\n", i, rgb_min, rgb_max);
        }
 
        _color_coder_lossy (img);
@@ -191,20 +191,71 @@ PoznanEncoder::do_encode (shared_ptr<const dcp::OpenJPEGImage> input)
        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));
+               _cuda_memcpy_dth (c->img_data_d, c->img_data, pixels * sizeof (type_data));
+               for (int j = 0; j < pixels; ++j) {
+                       c->img_data[j] = 0;
+               }
+               _cuda_memcpy_htd (c->img_data, c->img_data_d, 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]);
+                       yuv_min = min (yuv_min, c->img_data[j]);
+                       yuv_max = max (yuv_max, c->img_data[j]);
                }
-               delete[] data;
+//             delete[] data;
                printf("YCbCr component %d range %f to %f\n", i, yuv_min, yuv_max);
        }
 
        _fwt (tile);
        _quantize_tile (tile);
+
+       int checked = 0;
+
+       for (int i = 0; i < 3; ++i) {
+               type_tile_comp* comp = &tile->tile_comp[i];
+               for (int j = 0; j < comp->num_rlvls; ++j) {
+                       type_res_lvl* lvl = &comp->res_lvls[j];
+                       for (int k = 0; k < lvl->num_subbands; ++k) {
+                               type_subband* sb = &lvl->subbands[k];
+
+                               printf("copying subband %d of %d; %d cblks of %d by %d\n", k, lvl->num_subbands, sb->num_cblks, comp->cblk_w, comp->cblk_h);
+                               int32_t* data;
+                               _cuda_h_allocate_mem ((void **) &data, sb->num_cblks * comp->cblk_w * comp->cblk_h * sizeof(int32_t));
+                               _cuda_memcpy_dth (data, sb->cblks_data_d, sb->num_cblks * comp->cblk_w * comp->cblk_h * sizeof(int32_t));
+                               for (int l = 0; l < (sb->num_cblks * comp->cblk_w * comp->cblk_h); ++l) {
+                                       if (data[l] != 0) {
+                                               printf("AWOOGA: %d\n", data[l]);
+                                       }
+                                       data[l] = 0;
+                                       ++checked;
+                               }
+                               _cuda_memcpy_htd (sb->cblks_data_d, data, sb->num_cblks * comp->cblk_w * comp->cblk_h * sizeof(int32_t));
+                               _cuda_h_free (data);
+
+#if 0
+                               for (int l = 0; l < sb->num_cblks; ++l) {
+                                       type_codeblock* cb = &sb->cblks[l];
+                                       int32_t* data_h;
+                                       _cuda_h_allocate_mem ((void **) &data_h, cb->width * cb->height * sizeof (int32_t));
+                                       _cuda_memcpy_dth (data_h, cb->data_d, cb->width * cb->height * sizeof (int32_t));
+                                       for (int m = 0; m < cb->width * cb->height; ++m) {
+                                               if (data_h[m] != 0) {
+                                                       printf("AWOOGA: %d\n", data_h[m]);
+                                               }
+                                               data_h[m] = 0xf0f0f0f0;
+                                               ++checked;
+                                       }
+                                       _cuda_memcpy_htd (cb->data_d, data_h, cb->width * cb->height * sizeof (int32_t));
+                                       _cuda_h_free (data_h);
+                               }
+#endif
+                       }
+               }
+       }
+
+       printf ("checked %d\n", checked);
+
+       /* T1 encoder */
        _encode_tile (tile);
 
        type_buffer buffer;