From 2abf3de6656b2ad1c1956a4124fbd04729bed48b Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 28 Mar 2024 16:42:56 +0900 Subject: [PATCH] Vulkan compute: minor refactoring --- src/blue_noise.cpp | 16 ++++++++++------ src/blue_noise.hpp | 2 +- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/blue_noise.cpp b/src/blue_noise.cpp index 85a8bf2..618a24d 100644 --- a/src/blue_noise.cpp +++ b/src/blue_noise.cpp @@ -576,7 +576,7 @@ std::optional> dither::internal::vulkan_minmax( std::array minmax_desc_sets, VkBuffer max_in_buf, VkBuffer min_in_buf, VkBuffer max_out_buf, VkBuffer min_out_buf, VkBuffer state_buf, const int size, const float *const filter_mapped, - std::vector pbp) { + const std::vector &pbp) { // ensure minority pixel is "true" unsigned int count = 0; for (bool value : pbp) { @@ -584,17 +584,21 @@ std::optional> dither::internal::vulkan_minmax( ++count; } } + bool flip; if (count * 2 >= pbp.size()) { - // std::cout << "MINMAX flip\n"; // DEBUG - for (unsigned int i = 0; i < pbp.size(); ++i) { - pbp[i] = !pbp[i]; - } + flip = true; + } else { + flip = false; } std::vector fai(size); for (int i = 0; i < size; ++i) { fai[i].value = filter_mapped[i]; - fai[i].pbp = pbp[i] ? 1 : 0; + if (flip) { + fai[i].pbp = pbp[i] ? 0 : 1; + } else { + fai[i].pbp = pbp[i] ? 1 : 0; + } fai[i].idx = i; } diff --git a/src/blue_noise.hpp b/src/blue_noise.hpp index 43f9f44..0a9f896 100644 --- a/src/blue_noise.hpp +++ b/src/blue_noise.hpp @@ -162,7 +162,7 @@ std::optional> vulkan_minmax( std::array minmax_desc_sets, VkBuffer max_in_buf, VkBuffer min_in_buf, VkBuffer max_out_buf, VkBuffer min_out_buf, VkBuffer state_buf, const int size, const float *const filter_mapped, - std::vector pbp); + const std::vector &pbp); #endif