Skip to content

Enhancement: Align payload to pixel boundaries in sendFrame for custom formats #3

@travisbreaks

Description

@travisbreaks

Nice library! The zero-copy buffer design is solid.

The Idea

In `sendFrame()`, the packetization loop uses `MAX_PAYLOAD_LENGTH` (1440) as the chunk size. This works perfectly for RGB (1440/3 = 480 pixels) and RGBW (1440/4 = 360 pixels).

But for custom `bytesPerPixel` values (say 5 for RGBWW or unusual formats), the payload could split mid-pixel. A receiver that processes pixels sequentially would get a partial pixel at the end of one packet and the remainder at the start of the next.

Suggested Fix

Round down to the nearest pixel boundary:

int maxPayloadForFormat = (DdpProtocol.MAX_PAYLOAD_LENGTH / bytesPerPixel) * bytesPerPixel;
int payloadLength = Math.min(remainingBytes, maxPayloadForFormat);

Not a problem for the standard RGB/RGBW use cases, but makes the generic `sendFrame()` method more robust.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions