rows function
Fast whole-sky row shader over local rows y0d..y1d.
Implementation
void rows(
Painter p,
EffectMeta meta,
double y0d,
double y1d,
void Function(double y, RowBuffer r) fn,
) {
final box = boxOf(meta);
final w = box.w;
final rBuf = _rowBuffer..ensureWidth(w);
final y0 = math.max(box.y0, y0d.floor());
final y1 = math.min(box.y1 - 1, y1d.ceil());
if (y0 > y1) return;
final rot = p.sn != 0.0;
final q = rot ? clip(p, meta) : null;
final cBuf = p.frame.color;
final lBuf = p.frame.light;
final stride = p.w;
final fade = p.fade;
final lk = p.lightK * fade;
final fx = p.fx.toDouble();
for (var y = y0; y <= y1; y++) {
rBuf.c.fillRange(0, w, 0);
rBuf.k.fillRange(0, w, 0.0);
rBuf.a.fillRange(0, w, 1.0);
rBuf.b.fillRange(0, w, 0);
fn(y + 0.5, rBuf);
if (rot) {
for (var i = 0; i < w; i++) {
if (rBuf.c[i] != 0) {
if (rBuf.b[i] != 0) {
q!.blend(box.x0 + i, y, rBuf.c[i], rBuf.a[i]);
} else {
q!.dot(box.x0 + i, y, rBuf.c[i], rBuf.a[i]);
}
}
if (rBuf.k[i] > 0.0) {
q!.light(box.x0 + i, y, rBuf.l[i] != 0 ? rBuf.l[i] : rBuf.c[i], rBuf.k[i]);
}
}
continue;
}
final sy = (p.ty + y + 0.5).floor();
final ry = sy - p.oy;
if (ry < 0 || ry >= p.h) continue;
final row = ry * stride;
final by = (sy & 3) << 2;
var sxf = p.tx + (box.x0 + 0.5) * fx;
for (var i = 0; i < w; i++, sxf += fx) {
final c = rBuf.c[i];
final kk = rBuf.k[i];
if (c == 0 && !(kk > 0.0)) continue;
final sx = sxf.floor();
final rx = sx - p.ox;
if (rx < 0 || rx >= stride) continue;
final j = row + rx;
if (c != 0) {
final a = rBuf.a[i] * fade;
if (rBuf.b[i] != 0) {
if (a > 0.004) {
final d = cBuf[j];
final da = (d >>> 24) / 255.0;
final oa = a + da * (1.0 - a);
final k = a / oa;
final m = 1.0 - k;
final r = ((c & 255) * k + (d & 255) * m).toInt() & 255;
final g = (((c >>> 8) & 255) * k + ((d >>> 8) & 255) * m).toInt() & 255;
final bl = (((c >>> 16) & 255) * k + ((d >>> 16) & 255) * m).toInt() & 255;
final outA = (oa * 255.0).toInt() & 255;
cBuf[j] = ((outA << 24) | (bl << 16) | (g << 8) | r) & 0xffffffff;
}
} else if (a >= 1.0 || a > _bayerThresholds[by | (sx & 3)]) {
cBuf[j] = c;
}
}
if (kk > 0.0) {
final k = kk * lk;
if (k > 0.004) {
final lc = rBuf.l[i] != 0 ? rBuf.l[i] : c;
final d = lBuf[j];
final r = math.min(255, ((d & 255) + (lc & 255) * k).toInt());
final g = math.min(255, (((d >>> 8) & 255) + ((lc >>> 8) & 255) * k).toInt());
final bl = math.min(255, (((d >>> 16) & 255) + ((lc >>> 16) & 255) * k).toInt());
lBuf[j] = ((255 << 24) | (bl << 16) | (g << 8) | r) & 0xffffffff;
}
}
}
}
}