From fe611907ea65dbec9129ffda878189a087b71c8d Mon Sep 17 00:00:00 2001 From: Joshua Moerman Date: Wed, 21 Apr 2021 14:18:43 +0200 Subject: [PATCH] no idea, had some changes --- CMakeLists.txt | 23 +++++++++++++---------- include/png.hpp | 5 +++-- wavelet/CMakeLists.txt | 8 ++++++-- wavelet/jcmp.cpp | 18 +++++++++++++----- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a4f9297..4393035 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,16 +4,20 @@ project(compress) include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/include/") set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11") +option(EnableBSP "Building with BSP" OFF) option(MultiCoreBSP "Building with Multi Core BSP" ON) -if(MultiCoreBSP) - # setup for my mac - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") - set(libs mcbsp m pthread) - add_definitions( -DUSE_MCBSP ) - include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/contrib/mcbsp") -else() - # setup for cartesius - set(libs bsponmpi m) +if(EnableBSP) + if(MultiCoreBSP) + # setup for my mac + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + set(libs mcbsp m pthread) + add_definitions( -DUSE_MCBSP ) + include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/contrib/mcbsp") + add_subdirectory("contrib/mcbsp") + else() + # setup for cartesius + set(libs bsponmpi m) + endif() endif() find_package(Boost REQUIRED COMPONENTS program_options filesystem system) @@ -21,4 +25,3 @@ include_directories(SYSTEM ${Boost_INCLUDE_DIRS}) set(libs ${libs} ${Boost_LIBRARIES}) add_subdirectory("wavelet") -add_subdirectory("contrib/mcbsp") diff --git a/include/png.hpp b/include/png.hpp index 2afbe6a..00a0fd0 100644 --- a/include/png.hpp +++ b/include/png.hpp @@ -129,7 +129,7 @@ namespace png{ throw std::runtime_error("Interalced PNG's are not supported"); height = png_get_image_height(png_ptr, info_ptr); - auto width = png_get_image_width(png_ptr, info_ptr); + width = png_get_image_width(png_ptr, info_ptr); auto bit_depth = png_get_bit_depth(png_ptr, info_ptr); auto channels = png_get_channels(png_ptr, info_ptr); @@ -171,7 +171,7 @@ namespace png{ return valid; } - uint32_t get_width() const { return row.size(); } + uint32_t get_width() const { return width; } uint32_t get_height() const { return height; } private: @@ -184,6 +184,7 @@ namespace png{ uint32_t stride; uint32_t x; uint32_t y; + uint32_t width; uint32_t height; }; } diff --git a/wavelet/CMakeLists.txt b/wavelet/CMakeLists.txt index 7509a83..f966803 100644 --- a/wavelet/CMakeLists.txt +++ b/wavelet/CMakeLists.txt @@ -1,5 +1,9 @@ -file(GLOB sources *.cpp) -file(GLOB headers *.hpp) +if(EnableBSP) + file(GLOB sources *.cpp) + file(GLOB headers *.hpp) +else() + set(sources jcmp.cpp jcmp_image_test.cpp) +endif() find_package(PNG REQUIRED) include_directories(SYSTEM ${PNG_INCLUDE_DIRS}) diff --git a/wavelet/jcmp.cpp b/wavelet/jcmp.cpp index 4305995..8938e81 100644 --- a/wavelet/jcmp.cpp +++ b/wavelet/jcmp.cpp @@ -23,10 +23,15 @@ static image compress(std::vector const & img0, uint16_t width, double t assert(width == height); std::vector img(img0.size(), 0); + std::vector weights(img0.size(), 0); for(uint16_t y = 0; y < height; y++){ for(uint16_t x = 0; x < width; x++) { img[remap::to_hilbert(width, x, y)] = img0[x + y*width]; + + const double xx = (x + 0.5 - 2120) / double(width); + const double yy = (y + 0.5 - 1624) / double(height); + weights[remap::to_hilbert(width, x, y)] = xx*xx + yy*yy; } } @@ -47,9 +52,11 @@ static image compress(std::vector const & img0, uint16_t width, double t double min_abs = 10000.0; double max_abs = 0.0; - for(auto& el : img){ - auto absel = std::abs(el); - if(absel > threshold) { + for(size_t i = 0; i < img.size(); ++i){ + auto & el = img[i]; + const auto w = weights[i]; + const auto absel = std::abs(el); + if(absel > w*threshold) { min_abs = std::min(min_abs, absel); max_abs = std::max(max_abs, absel); } else { @@ -172,11 +179,12 @@ int main(int argc, char* argv[]){ auto width = image.get_width(); auto height = image.get_height(); + std::cout << field("size") << width << "x" << height << std::endl; // read into vector std::vector image_vec; - image_vec.reserve(width * height); - for(unsigned char c = 0; image >> c;) image_vec.push_back(c/255.0); + image_vec.reserve(width * height); + for(unsigned char c = 0; image >> c;) image_vec.push_back(c/255.0); // compress and decompress to see how we lost information unsigned int nzeros = 0;