// Copyright (c) the JPEG XL Project Authors. All rights reserved. // // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file.
// These templates are not found via ADL. using hwy::HWY_NAMESPACE::Or; using hwy::HWY_NAMESPACE::ShiftRight; using hwy::HWY_NAMESPACE::Vec;
using D = HWY_CAPPED(float, kBlockDim); using DI = hwy::HWY_NAMESPACE::Rebind<int, D>; using DI8 = hwy::HWY_NAMESPACE::Repartition<uint8_t, D>;
// Converts one vector's worth of random bits to floats in [1, 2). // NOTE: as the convolution kernel sums to 0, it doesn't matter if inputs are in // [0, 1) or in [1, 2). void BitsToFloat(const uint32_t* JXL_RESTRICT random_bits, float* JXL_RESTRICT floats) { const HWY_FULL(float) df; const HWY_FULL(uint32_t) du;
// May exceed the vector size, hence we have two loops over x below.
constexpr size_t kFloatsPerBatch =
Xorshift128Plus::N * sizeof(uint64_t) / sizeof(float);
HWY_ALIGN uint64_t batch[Xorshift128Plus::N] = {};
const HWY_FULL(float) df; const size_t N = Lanes(df);
for (size_t y = 0; y < ysize; ++y) { float* JXL_RESTRICT row = rect.Row(noise, y);
size_t x = 0; // Only entire batches (avoids exceeding the image padding). for (; x + kFloatsPerBatch < xsize; x += kFloatsPerBatch) {
rng->Fill(batch); for (size_t i = 0; i < kFloatsPerBatch; i += Lanes(df)) {
BitsToFloat(reinterpret_cast<const uint32_t*>(batch) + i, row + x + i);
}
}
// Any remaining pixels, rounded up to vectors (safe due to padding).
rng->Fill(batch);
size_t batch_pos = 0; // < kFloatsPerBatch for (; x < xsize; x += N) {
BitsToFloat(reinterpret_cast<const uint32_t*>(batch) + batch_pos,
row + x);
batch_pos += N;
}
}
} void Random3Planes(size_t visible_frame_index, size_t nonvisible_frame_index,
size_t x0, size_t y0, const std::pair<ImageF*, Rect>& plane0, const std::pair<ImageF*, Rect>& plane1, const std::pair<ImageF*, Rect>& plane2) {
HWY_ALIGN Xorshift128Plus rng(visible_frame_index, nonvisible_frame_index, x0,
y0);
RandomImage(&rng, plane0.second, plane0.first);
RandomImage(&rng, plane1.second, plane1.first);
RandomImage(&rng, plane2.second, plane2.first);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.