float LocalFrameBuffer::endFrame(const float errorThreshold) { if (hasVarianceBuffer) { // process regions first, but don't process newly split regions again int regions = errorThreshold > 0.f ? errorRegion.size() : 0; for (int i = 0; i < regions; i++) { box2i& region = errorRegion[i]; float err = 0.f; float maxErr = 0.0f; for (int y = region.lower.y; y < region.upper.y; y++) for (int x = region.lower.x; x < region.upper.x; x++) { int idx = y * tilesx + x; err += tileErrorBuffer[idx]; maxErr = std::max(maxErr, tileErrorBuffer[idx]); } // set all tiles of this region to local max error to enforce their refinement as a group for (int y = region.lower.y; y < region.upper.y; y++) for (int x = region.lower.x; x < region.upper.x; x++) { int idx = y * tilesx + x; tileErrorBuffer[idx] = maxErr; } vec2i size = region.size(); int area = reduce_mul(size); err /= area; // avg if (err < 4.f*errorThreshold) { // split region? if (area <= 2) { // would just contain single tile after split: remove regions--; errorRegion[i] = errorRegion[regions]; errorRegion[regions]= errorRegion.back(); errorRegion.pop_back(); i--; continue; } vec2i split = region.lower + size / 2; // TODO: find split with equal variance errorRegion.push_back(region); // region reference might become invalid if (size.x > size.y) { errorRegion[i].upper.x = split.x; errorRegion.back().lower.x = split.x; } else { errorRegion[i].upper.y = split.y; errorRegion.back().lower.y = split.y; } } } float maxErr = 0.0f; for (int i = 0; i < tiles; i++) maxErr = std::max(maxErr, tileErrorBuffer[i]); return maxErr; } else return inf; }
void fe25519_mul(fe25519 *r, const fe25519 *x, const fe25519 *y) { int i,j; crypto_uint32 t[63]; for(i=0;i<63;i++)t[i] = 0; for(i=0;i<32;i++) for(j=0;j<32;j++) t[i+j] += x->v[i] * y->v[j]; for(i=32;i<63;i++) r->v[i-32] = t[i-32] + times38(t[i]); r->v[31] = t[31]; /* result now in r[0]...r[31] */ reduce_mul(r); }