Browse Source

no idea, had some changes

master
Joshua Moerman 4 years ago
parent
commit
fe611907ea
  1. 9
      CMakeLists.txt
  2. 5
      include/png.hpp
  3. 8
      wavelet/CMakeLists.txt
  4. 14
      wavelet/jcmp.cpp

9
CMakeLists.txt

@ -4,16 +4,20 @@ project(compress)
include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/include/") include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/include/")
set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11") set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} "-std=c++11")
option(EnableBSP "Building with BSP" OFF)
option(MultiCoreBSP "Building with Multi Core BSP" ON) option(MultiCoreBSP "Building with Multi Core BSP" ON)
if(MultiCoreBSP) if(EnableBSP)
if(MultiCoreBSP)
# setup for my mac # setup for my mac
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
set(libs mcbsp m pthread) set(libs mcbsp m pthread)
add_definitions( -DUSE_MCBSP ) add_definitions( -DUSE_MCBSP )
include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/contrib/mcbsp") include_directories(SYSTEM "${PROJECT_SOURCE_DIR}/contrib/mcbsp")
else() add_subdirectory("contrib/mcbsp")
else()
# setup for cartesius # setup for cartesius
set(libs bsponmpi m) set(libs bsponmpi m)
endif()
endif() endif()
find_package(Boost REQUIRED COMPONENTS program_options filesystem system) find_package(Boost REQUIRED COMPONENTS program_options filesystem system)
@ -21,4 +25,3 @@ include_directories(SYSTEM ${Boost_INCLUDE_DIRS})
set(libs ${libs} ${Boost_LIBRARIES}) set(libs ${libs} ${Boost_LIBRARIES})
add_subdirectory("wavelet") add_subdirectory("wavelet")
add_subdirectory("contrib/mcbsp")

5
include/png.hpp

@ -129,7 +129,7 @@ namespace png{
throw std::runtime_error("Interalced PNG's are not supported"); throw std::runtime_error("Interalced PNG's are not supported");
height = png_get_image_height(png_ptr, info_ptr); 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 bit_depth = png_get_bit_depth(png_ptr, info_ptr);
auto channels = png_get_channels(png_ptr, info_ptr); auto channels = png_get_channels(png_ptr, info_ptr);
@ -171,7 +171,7 @@ namespace png{
return valid; return valid;
} }
uint32_t get_width() const { return row.size(); } uint32_t get_width() const { return width; }
uint32_t get_height() const { return height; } uint32_t get_height() const { return height; }
private: private:
@ -184,6 +184,7 @@ namespace png{
uint32_t stride; uint32_t stride;
uint32_t x; uint32_t x;
uint32_t y; uint32_t y;
uint32_t width;
uint32_t height; uint32_t height;
}; };
} }

8
wavelet/CMakeLists.txt

@ -1,5 +1,9 @@
file(GLOB sources *.cpp) if(EnableBSP)
file(GLOB headers *.hpp) file(GLOB sources *.cpp)
file(GLOB headers *.hpp)
else()
set(sources jcmp.cpp jcmp_image_test.cpp)
endif()
find_package(PNG REQUIRED) find_package(PNG REQUIRED)
include_directories(SYSTEM ${PNG_INCLUDE_DIRS}) include_directories(SYSTEM ${PNG_INCLUDE_DIRS})

14
wavelet/jcmp.cpp

@ -23,10 +23,15 @@ static image compress(std::vector<double> const & img0, uint16_t width, double t
assert(width == height); assert(width == height);
std::vector<double> img(img0.size(), 0); std::vector<double> img(img0.size(), 0);
std::vector<double> weights(img0.size(), 0);
for(uint16_t y = 0; y < height; y++){ for(uint16_t y = 0; y < height; y++){
for(uint16_t x = 0; x < width; x++) { for(uint16_t x = 0; x < width; x++) {
img[remap::to_hilbert(width, x, y)] = img0[x + y*width]; 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<double> const & img0, uint16_t width, double t
double min_abs = 10000.0; double min_abs = 10000.0;
double max_abs = 0.0; double max_abs = 0.0;
for(auto& el : img){ for(size_t i = 0; i < img.size(); ++i){
auto absel = std::abs(el); auto & el = img[i];
if(absel > threshold) { const auto w = weights[i];
const auto absel = std::abs(el);
if(absel > w*threshold) {
min_abs = std::min(min_abs, absel); min_abs = std::min(min_abs, absel);
max_abs = std::max(max_abs, absel); max_abs = std::max(max_abs, absel);
} else { } else {
@ -172,6 +179,7 @@ int main(int argc, char* argv[]){
auto width = image.get_width(); auto width = image.get_width();
auto height = image.get_height(); auto height = image.get_height();
std::cout << field("size") << width << "x" << height << std::endl;
// read into vector // read into vector
std::vector<double> image_vec; std::vector<double> image_vec;