Skip to content

Commit

Permalink
Rounding error causing crash and skewed image xLightsSequencer#5208
Browse files Browse the repository at this point in the history
  • Loading branch information
derwin12 committed Feb 18, 2025
1 parent 5a54b39 commit a88af55
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 2 additions & 0 deletions xLights/effects/VideoEffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ void VideoEffect::Render(RenderBuffer &buffer, std::string filename,
ispc::VideoData rdata;
rdata.width = _videoreader->GetWidth() - xoffset - xtail;
rdata.height = _videoreader->GetHeight() - yoffset - ytail;
rdata.buffer_width = buffer.BufferWi;
rdata.buffer_height = buffer.BufferHt;
rdata.ytail = ytail;
rdata.xtail = xtail;
rdata.yoffset = yoffset;
Expand Down
15 changes: 7 additions & 8 deletions xLights/effects/ispc/VideoFunctions.ispc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
export struct VideoData {
uint16 width;
uint16 height;
uint16 buffer_width;
uint16 buffer_height;
int16 yoffset;
int16 xoffset;
int16 ytail;
Expand All @@ -19,20 +21,17 @@ export struct VideoData {
};

export void VideoEffectProcess(const uniform VideoData &data,
uniform int startIdx, uniform int endIdx,
uniform uint8<4> result[])
uniform int startIdx, uniform int endIdx,
uniform uint8<4> result[])
{
uniform float width = data.width;
uniform float rszw = 1.0 / width;
uniform float height = data.height;
uniform int ch = data.ch;


foreach (index = startIdx...endIdx) {
float fidx = index;
float y = (floor)(fidx * rszw + 0.00001);
float x = fidx - (y * width);
int newIndex = x + data.startx + ((y + data.starty) * width);
float y = (floor)(fidx / data.buffer_width);
float x = fidx - (y * data.buffer_width);
int newIndex = x + data.startx + ((y + data.starty) * data.buffer_width);

uint8* ptr = data.image + (data.image_height - 1 - y - data.yoffset) * (data.image_width * ch) + (data.xoffset * ch) + (x * ch);
uint8<4> c;
Expand Down
3 changes: 3 additions & 0 deletions xLights/effects/ispc/VideoFunctions.ispc.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
//
// effects\\ispc\\VideoFunctions.ispc.h
// (Header automatically generated by the ispc compiler.)
// DO NOT EDIT THIS FILE.
//
Expand Down Expand Up @@ -51,6 +52,8 @@ struct uint8_t4 { uint8_t v[4]; } __attribute__ ((aligned(4)));
struct VideoData {
uint16_t width;
uint16_t height;
uint16_t buffer_width;
uint16_t buffer_height;
int16_t yoffset;
int16_t xoffset;
int16_t ytail;
Expand Down

0 comments on commit a88af55

Please sign in to comment.