Minor fix regarding blue-noise-offsets
This commit is contained in:
parent
6e27c41f43
commit
de1b0cc2ac
1 changed files with 8 additions and 7 deletions
15
src/image.cc
15
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> 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> 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 {
|
||||
|
|
Loading…
Reference in a new issue