Browse Source

no idea, had some changes

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

23
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")

5
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;
};
}

8
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})

18
wavelet/jcmp.cpp

@ -23,10 +23,15 @@ static image compress(std::vector<double> const & img0, uint16_t width, double t
assert(width == height);
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 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<double> 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<double> 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;