Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduced render time for bars by 60-80%, by caching IsSpatial #5026

Merged
merged 1 commit into from
Dec 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions xLights/effects/BarsEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,24 @@ void BarsEffect::Render(Effect* effect, const SettingsMap& SettingsMap, RenderBu
}
color = hsv;
}

const bool isSpatialColor = buffer.palette.IsSpatial(colorIdx); // Cache the spatial color check, as it's expensive to do for every pixel

switch (direction) {
case 1:
// down
for (int x = 0; x < buffer.BufferWi; ++x) {
GetSpatialColor(color, colorIdx, (float)x / (float)buffer.BufferWi, (float)(n % barHt) / (float)barHt, buffer, gradient, highlightColor, highlight, show3D, barHt, n, pct, color2);
if (isSpatialColor)
GetSpatialColor(color, colorIdx, (float)x / (float)buffer.BufferWi, (float)(n % barHt) / (float)barHt, buffer, gradient, highlightColor, highlight, show3D, barHt, n, pct, color2);
buffer.SetPixel(x, y, color);
}
break;
case 2:
// expand
if (y <= newCenter) {
for (int x = 0; x < buffer.BufferWi; ++x) {
GetSpatialColor(color, colorIdx, (float)x / (float)buffer.BufferWi, (float)(n % barHt) / (float)barHt, buffer, gradient, highlightColor, highlight, show3D, barHt, n, pct, color2);
if (isSpatialColor)
GetSpatialColor(color, colorIdx, (float)x / (float)buffer.BufferWi, (float)(n % barHt) / (float)barHt, buffer, gradient, highlightColor, highlight, show3D, barHt, n, pct, color2);
buffer.SetPixel(x, y, color);
buffer.SetPixel(x, newCenter + (newCenter - y), color);
}
Expand All @@ -236,7 +241,8 @@ void BarsEffect::Render(Effect* effect, const SettingsMap& SettingsMap, RenderBu
// compress
if (y >= newCenter) {
for (int x = 0; x < buffer.BufferWi; ++x) {
GetSpatialColor(color, colorIdx, (float)x / (float)buffer.BufferWi, (float)(n % barHt) / (float)barHt, buffer, gradient, highlightColor, highlight, show3D, barHt, n, pct, color2);
if (isSpatialColor)
GetSpatialColor(color, colorIdx, (float)x / (float)buffer.BufferWi, (float)(n % barHt) / (float)barHt, buffer, gradient, highlightColor, highlight, show3D, barHt, n, pct, color2);
buffer.SetPixel(x, y, color);
buffer.SetPixel(x, newCenter + (newCenter - y), color);
}
Expand All @@ -245,7 +251,8 @@ void BarsEffect::Render(Effect* effect, const SettingsMap& SettingsMap, RenderBu
default:
// up
for (int x = 0; x < buffer.BufferWi; ++x) {
GetSpatialColor(color, colorIdx, (float)x / (float)buffer.BufferWi, 1.0 - (float)(n % barHt) / (float)barHt, buffer, gradient, highlightColor, highlight, show3D, barHt, n, pct, color2);
if (isSpatialColor)
GetSpatialColor(color, colorIdx, (float)x / (float)buffer.BufferWi, 1.0 - (float)(n % barHt) / (float)barHt, buffer, gradient, highlightColor, highlight, show3D, barHt, n, pct, color2);
buffer.SetPixel(x, buffer.BufferHt - y - 1, color);
}
break;
Expand Down Expand Up @@ -357,19 +364,24 @@ void BarsEffect::Render(Effect* effect, const SettingsMap& SettingsMap, RenderBu
hsv.value *= double(barWi - n % barWi - 1) / barWi;
color = hsv;
}

const bool isSpatialColor = buffer.palette.IsSpatial(colorIdx); // Cache the spatial color check, as it's expensive to do for every pixel

switch (direction) {
case 5:
// right
for (int y = 0; y < buffer.BufferHt; ++y) {
GetSpatialColor(color, colorIdx, 1.0 - pct, (double)y / (double)buffer.BufferHt, buffer, gradient, highlightColor, highlight, show3D, barWi, n, pct, color2);
if (isSpatialColor)
GetSpatialColor(color, colorIdx, 1.0 - pct, (double)y / (double)buffer.BufferHt, buffer, gradient, highlightColor, highlight, show3D, barWi, n, pct, color2);
buffer.SetPixel(buffer.BufferWi - x - 1, y, color);
}
break;
case 6:
// H-expand
if (x <= newCenter) {
for (int y = 0; y < buffer.BufferHt; ++y) {
GetSpatialColor(color, colorIdx, pct, (double)y / (double)buffer.BufferHt, buffer, gradient, highlightColor, highlight, show3D, barWi, n, pct, color2);
if (isSpatialColor)
GetSpatialColor(color, colorIdx, pct, (double)y / (double)buffer.BufferHt, buffer, gradient, highlightColor, highlight, show3D, barWi, n, pct, color2);
buffer.SetPixel(x, y, color);
buffer.SetPixel(newCenter + (newCenter - x), y, color);
}
Expand All @@ -379,7 +391,8 @@ void BarsEffect::Render(Effect* effect, const SettingsMap& SettingsMap, RenderBu
// H-compress
if (x >= newCenter) {
for (int y = 0; y < buffer.BufferHt; ++y) {
GetSpatialColor(color, colorIdx, pct, (double)y / (double)buffer.BufferHt, buffer, gradient, highlightColor, highlight, show3D, barWi, n, pct, color2);
if (isSpatialColor)
GetSpatialColor(color, colorIdx, pct, (double)y / (double)buffer.BufferHt, buffer, gradient, highlightColor, highlight, show3D, barWi, n, pct, color2);
buffer.SetPixel(x, y, color);
buffer.SetPixel(newCenter + (newCenter - x), y, color);
}
Expand All @@ -388,7 +401,8 @@ void BarsEffect::Render(Effect* effect, const SettingsMap& SettingsMap, RenderBu
default:
// left
for (int y = 0; y < buffer.BufferHt; ++y) {
GetSpatialColor(color, colorIdx, pct, (double)y / (double)buffer.BufferHt, buffer, gradient, highlightColor, highlight, show3D, barWi, n, pct, color2);
if (isSpatialColor)
GetSpatialColor(color, colorIdx, pct, (double)y / (double)buffer.BufferHt, buffer, gradient, highlightColor, highlight, show3D, barWi, n, pct, color2);
buffer.SetPixel(x, y, color);
}
break;
Expand Down
Loading