Switch to CMake, try to fix grayscale blue-noise
This commit is contained in:
parent
c5364f2ebc
commit
a8f0ec788a
5 changed files with 49 additions and 36 deletions
2
.clangd
Normal file
2
.clangd
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
CompileFlags:
|
||||||
|
Add: [-std=c++17]
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -4,3 +4,4 @@ Dithering
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
|
|
||||||
.cache/
|
.cache/
|
||||||
|
build*/
|
||||||
|
|
29
CMakeLists.txt
Normal file
29
CMakeLists.txt
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
cmake_minimum_required(VERSION 3.9)
|
||||||
|
project(Dithering)
|
||||||
|
|
||||||
|
set(Dithering_SOURCES
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/blue_noise.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/image.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/main.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG")
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -O0 -g")
|
||||||
|
|
||||||
|
if(NOT DEFINED CMAKE_BUILD_TYPE OR NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE "Debug")
|
||||||
|
message("Set build type to Debug by default")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
find_package(OpenCL REQUIRED)
|
||||||
|
|
||||||
|
add_executable(Dithering ${Dithering_SOURCES})
|
||||||
|
target_compile_features(Dithering PUBLIC cxx_std_17)
|
||||||
|
target_include_directories(Dithering PUBLIC
|
||||||
|
Threads::Threads
|
||||||
|
${OpenCL_INCLUDE_DIRS})
|
||||||
|
target_link_libraries(Dithering PUBLIC
|
||||||
|
Threads::Threads
|
||||||
|
${OpenCL_LIBRARIES})
|
25
Makefile
25
Makefile
|
@ -1,25 +0,0 @@
|
||||||
|
|
||||||
COMMON_FLAGS=-Wall -Wextra -Wpedantic -std=c++17
|
|
||||||
LINKER_FLAGS=-lpthread -lOpenCL
|
|
||||||
ifdef DEBUG
|
|
||||||
CPPFLAGS=${COMMON_FLAGS} -g -O0
|
|
||||||
else
|
|
||||||
CPPFLAGS=${COMMON_FLAGS} -O3 -DNDEBUG
|
|
||||||
endif
|
|
||||||
|
|
||||||
SOURCES= \
|
|
||||||
src/main.cpp \
|
|
||||||
src/blue_noise.cpp \
|
|
||||||
src/image.cpp
|
|
||||||
OBJECTS=${subst .cpp,.o,${SOURCES}}
|
|
||||||
|
|
||||||
all: Dithering
|
|
||||||
|
|
||||||
Dithering: ${OBJECTS}
|
|
||||||
${CXX} ${CPPFLAGS} ${LINKER_FLAGS} -o Dithering $^
|
|
||||||
|
|
||||||
.PHONY:
|
|
||||||
|
|
||||||
clean:
|
|
||||||
rm -f Dithering
|
|
||||||
rm -f ${OBJECTS}
|
|
|
@ -113,10 +113,8 @@ image::Bl dither::blue_noise_grayscale(int width, int height, int threads) {
|
||||||
int filter_size = (width + height) / 2;
|
int filter_size = (width + height) / 2;
|
||||||
std::vector<float> precomputed(internal::precompute_gaussian(filter_size));
|
std::vector<float> precomputed(internal::precompute_gaussian(filter_size));
|
||||||
|
|
||||||
int min, max;
|
int min, max, min2, max2;
|
||||||
float tempPixel;
|
float tempPixel;
|
||||||
int prevmin = -1;
|
|
||||||
int prevmax = -1;
|
|
||||||
while(true) {
|
while(true) {
|
||||||
printf("Iteration %d\n", iterations);
|
printf("Iteration %d\n", iterations);
|
||||||
|
|
||||||
|
@ -126,17 +124,25 @@ image::Bl dither::blue_noise_grayscale(int width, int height, int threads) {
|
||||||
&precomputed, threads);
|
&precomputed, threads);
|
||||||
|
|
||||||
std::tie(min, max) = internal::filter_minmax(filter_out);
|
std::tie(min, max) = internal::filter_minmax(filter_out);
|
||||||
printf("min == %4d, max == %4d\n", min, max);
|
printf("min == %4d, max == %4d", min, max);
|
||||||
tempPixel = image[max];
|
tempPixel = image[max];
|
||||||
image[max] = image[min];
|
image[max] = 0.0F;
|
||||||
image[min] = tempPixel;
|
|
||||||
if(prevmin >= 0 && prevmax >= 0
|
internal::compute_filter_grayscale(image,
|
||||||
&& (utility::dist(min, prevmin, width) < 1.5F
|
width, height, count,
|
||||||
|| utility::dist(max, prevmax, width) < 1.5F)) {
|
filter_size, filter_out,
|
||||||
|
&precomputed, threads);
|
||||||
|
|
||||||
|
std::tie(min2, max2) = internal::filter_minmax(filter_out);
|
||||||
|
printf(", min2 == %4d, max2 == %4d\n", min2, max2);
|
||||||
|
|
||||||
|
if(utility::dist(min, min2, width) < 1.5F) {
|
||||||
|
image[max] = image[min2];
|
||||||
|
image[min2] = tempPixel;
|
||||||
|
} else {
|
||||||
|
image[max] = tempPixel;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
prevmin = min;
|
|
||||||
prevmax = max;
|
|
||||||
|
|
||||||
//#ifndef NDEBUG
|
//#ifndef NDEBUG
|
||||||
if(iterations % 20 == 0) {
|
if(iterations % 20 == 0) {
|
||||||
|
|
Loading…
Reference in a new issue