From de1b0cc2aca7ac99c930ee841dbf6cdb54e0509d Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Wed, 1 Dec 2021 18:13:21 +0900 Subject: [PATCH] Minor fix regarding blue-noise-offsets --- src/image.cc | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/image.cc b/src/image.cc index 284abf0..247bff2 100644 --- a/src/image.cc +++ b/src/image.cc @@ -50,6 +50,7 @@ Image::Image() is_dithered_grayscale_(false), is_dithered_color_(false), is_preserving_blue_noise_offsets_(true) { + std::srand(std::time(nullptr)); GenerateBlueNoiseOffsets(); } @@ -91,6 +92,7 @@ Image::Image(const std::string &filename) return; } + std::srand(std::time(nullptr)); GenerateBlueNoiseOffsets(); } @@ -696,10 +698,6 @@ std::unique_ptr Image::ToColorDitheredWithBlueNoise(Image *blue_noise) { if (!opencl_handle->HasBuffer(color_kernel_name, kBufferBlueNoiseOffsetsName)) { - if (!is_preserving_blue_noise_offsets_) { - GenerateBlueNoiseOffsets(); - } - if (!opencl_handle->CreateKernelBuffer( color_kernel_name, CL_MEM_READ_ONLY, sizeof(unsigned int) * blue_noise_offsets_.size(), nullptr, @@ -713,6 +711,10 @@ std::unique_ptr Image::ToColorDitheredWithBlueNoise(Image *blue_noise) { } } + if (!is_preserving_blue_noise_offsets_) { + GenerateBlueNoiseOffsets(); + } + if (!opencl_handle->SetKernelBufferData( color_kernel_name, kBufferBlueNoiseOffsetsName, blue_noise_offsets_.size() * sizeof(unsigned int), @@ -1413,12 +1415,11 @@ const std::string &Image::GetColorKernelName() { } void Image::GenerateBlueNoiseOffsets() { - std::srand(std::time(nullptr)); - while (DuplicateBlueNoiseOffsetExists()) { + do { for (unsigned int i = 0; i < blue_noise_offsets_.size(); ++i) { blue_noise_offsets_.at(i) = rand() % kBlueNoiseOffsetMax; } - } + } while (DuplicateBlueNoiseOffsetExists()); } bool Image::DuplicateBlueNoiseOffsetExists() const {