Commit 9691d68b authored by plgruener's avatar plgruener

PNG output; change type of vec to unsigned char

parent 04c2808d
......@@ -10,9 +10,12 @@ if(OPENMP_FOUND)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
endif()
find_package(PNG REQUIRED)
include_directories(${PNG_INCLUDE_DIR})
find_package(Boost REQUIRED COMPONENTS program_options)
target_include_directories(dynamicsystems PRIVATE ${Boost_INCLUDE_DIR})
target_link_libraries(dynamicsystems PRIVATE ${Boost_LIBRARIES})
target_link_libraries(dynamicsystems PRIVATE ${PNG_LIBRARY} ${Boost_LIBRARIES})
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel")
if (WIN32)
......
......@@ -10,6 +10,8 @@
#include <boost/program_options.hpp>
#include <png.h>
#include "colormaps.hpp"
#include "compute.hpp"
......@@ -116,8 +118,8 @@ int main(int argc, char* argv[]) {
// Initialization pixel values and color vectors
aligned_vector<float> result(alpha_num_params * beta_num_params);
aligned_vector<int> colors(alpha_num_params * beta_num_params);
aligned_vector<int> colors_rgb(3 * alpha_num_params * beta_num_params);
aligned_vector<unsigned char> colors(alpha_num_params * beta_num_params);
aligned_vector<unsigned char> colors_rgb(3 * alpha_num_params * beta_num_params);
auto time_start = std::chrono::system_clock::now();
......@@ -156,13 +158,13 @@ int main(int argc, char* argv[]) {
colors_rgb[3 * i + 1] = 255;
colors_rgb[3 * i + 2] = 255;
} else {
colors[i] = (int)254 * result[i] / threshold;
colors[i] = floor(254 * result[i] / threshold);
// RGB color gradient: viridis from matplotlib
int idx = floor(255 * result[i] / threshold);
int r = floor(255 * viridis[idx][0]);
int g = floor(255 * viridis[idx][1]);
int b = floor(255 * viridis[idx][2]);
unsigned char r = floor(255 * viridis[idx][0]);
unsigned char g = floor(255 * viridis[idx][1]);
unsigned char b = floor(255 * viridis[idx][2]);
colors_rgb[3 * i] = r; // red
colors_rgb[3 * i + 1] = g; // green
......@@ -189,5 +191,32 @@ int main(int argc, char* argv[]) {
// das geht theoretisch auch mit dem ganzen Array, aber praktisch nicht?!
ostrm_rgb << static_cast<char>(colors_rgb[i]);
}
// write to libpng
png_image img;
memset(&img, 0, sizeof(img));
img.version = PNG_IMAGE_VERSION;
img.opaque = NULL;
img.width = alpha_num_params;
img.height = beta_num_params;
img.format = PNG_FORMAT_RGB;
img.flags = 0;
img.colormap_entries = 0;
// set to negative for bottom-up image
const int row_stride = alpha_num_params * 3;
png_bytep buffer = colors_rgb.data();
png_image_write_to_file(&img, "picture_rgb.png", false, buffer, row_stride, NULL);
if (PNG_IMAGE_FAILED(img)) {
std::cerr << img.message << std::endl;
return -1;
} else {
if (img.warning_or_error != 0) {
std::cerr << img.message << std::endl;
}
}
std::cout << "png written" << std::endl;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment