--- /dev/null
+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})
+++ /dev/null
-
-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}
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);
&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) {