]> git.seodisparate.com - blue_noise_generation/commitdiff
Switch to CMake, try to fix grayscale blue-noise
authorStephen Seo <seo.disparate@gmail.com>
Wed, 6 Oct 2021 10:54:07 +0000 (19:54 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 6 Oct 2021 10:54:07 +0000 (19:54 +0900)
.clangd [new file with mode: 0644]
.gitignore
CMakeLists.txt [new file with mode: 0644]
Makefile [deleted file]
src/blue_noise.cpp

diff --git a/.clangd b/.clangd
new file mode 100644 (file)
index 0000000..43f14d4
--- /dev/null
+++ b/.clangd
@@ -0,0 +1,2 @@
+CompileFlags:
+    Add: [-std=c++17]
index 2551958e5ee310450c0e246a192f6d5b49169c1a..414513bb90a1208b280437b4aa18ca5730bc0e5e 100644 (file)
@@ -4,3 +4,4 @@ Dithering
 compile_commands.json
 
 .cache/
+build*/
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644 (file)
index 0000000..4d18424
--- /dev/null
@@ -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})
diff --git a/Makefile b/Makefile
deleted file mode 100644 (file)
index d4e60a1..0000000
--- a/Makefile
+++ /dev/null
@@ -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}
index bb30f31365f6fad75c0d1cd504c952ed25af87f0..fd901628ddcbec6bf382ed07e9aeed0e090aeb5e 100644 (file)
@@ -113,10 +113,8 @@ image::Bl dither::blue_noise_grayscale(int width, int height, int threads) {
     int filter_size = (width + height) / 2;
     std::vector<float> precomputed(internal::precompute_gaussian(filter_size));
 
-    int min, max;
+    int min, max, min2, max2;
     float tempPixel;
-    int prevmin = -1;
-    int prevmax = -1;
     while(true) {
         printf("Iteration %d\n", iterations);
 
@@ -126,17 +124,25 @@ image::Bl dither::blue_noise_grayscale(int width, int height, int threads) {
                                            &precomputed, threads);
 
         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];
-        image[max] = image[min];
-        image[min] = tempPixel;
-        if(prevmin >= 0 && prevmax >= 0
-                && (utility::dist(min, prevmin, width) < 1.5F
-                    || utility::dist(max, prevmax, width) < 1.5F)) {
+        image[max] = 0.0F;
+
+        internal::compute_filter_grayscale(image,
+                                           width, height, count,
+                                           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;
         }
-        prevmin = min;
-        prevmax = max;
 
 //#ifndef NDEBUG
         if(iterations % 20 == 0) {