feat: Implement GRB color order for WledClient

This commit is contained in:
Tobias J. Endres 2025-08-16 05:16:08 +02:00
parent 60bcfb043d
commit d81fe64cc1
3 changed files with 18 additions and 6 deletions

Binary file not shown.

View File

@ -17,6 +17,7 @@ This document captures key insights, challenges, and solutions encountered durin
## 3. Robustness of Image Processing to Input Variations
* **Challenge:** The `HyperionProcessor` initially produced dark, almost black LED colors when tested with `frames/frame_000.png`. This led to initial concerns about the `BlackBorderDetector` or `getAverageColor` logic.
* **Solution:** Visual inspection of `frame_000.png` revealed it was indeed mostly black. This confirmed that the `HyperionProcessor` was functioning correctly based on its input. The subsequent live testing with `grabberconfigurator` (showing the scaled screen) confirmed the entire capture pipeline was working.
* **Lesson:** Always validate input data. An unexpected output might not indicate a bug in the processing logic but rather an issue with the input data itself. Using real-world or representative input is critical for accurate testing.
@ -51,4 +52,12 @@ This document captures key insights, challenges, and solutions encountered durin
* **Solution:** Disabling the interfering KWin script immediately resolved the issues, allowing the `grabberconfigurator` to display correct and vibrant LED colors.
* **Lesson:** When debugging screen capture or visual processing issues, always consider external factors like display server configurations, window managers, and overlay applications. These can silently alter the input data, leading to misleading debugging results within the application itself.
[Commit: e31f154] - feat: Implement and verify HyperionProcessor with live visualization
## 9. WLED Integration and Testing
* **Challenge:** Integrating the `WledClient` into `grabberconfigurator` and verifying direct WLED communication.
* **Solution:** Added `WledClient` instance, command-line options for WLED address/port, and called `setLedsColor` with calculated LED colors. This sets up the pipeline for sending data directly to the WLED device.
* **Lesson:** Modular design allows for easy integration of different components. The `grabberconfigurator` now serves as a complete testbed for the entire Ambilight pipeline, from screen capture to WLED output.
[Commit: e31f154] - feat: Implement and verify HyperionProcessor with live visualization
[Commit: 478828b] - docs: Add lesson learned about KWin script interference
[Commit: 60bcfb0] - feat: Integrate WledClient into grabberconfigurator for direct WLED communication

View File

@ -62,8 +62,9 @@ void WledClient::sendImage(const QImage &image)
int y = pixelIndex / rgbImage.width();
QRgb pixel = rgbImage.pixel(x, y);
datagram.append(qRed(pixel));
// Swap R and G for GRB order
datagram.append(qGreen(pixel));
datagram.append(qRed(pixel));
datagram.append(qBlue(pixel));
}
@ -104,8 +105,9 @@ void WledClient::setLedsColor(const QVector<QColor> &colors, int timeout)
for (int j = 0; j < currentLedsInPacket; ++j) {
const QColor &color = colors.at(i + j);
datagram.append(color.red());
// Swap R and G for GRB order
datagram.append(color.green());
datagram.append(color.red());
datagram.append(color.blue());
}
@ -128,7 +130,7 @@ void WledClient::flashLeds(int startIndex, int count, QColor color)
// Max UDP payload size (approx 508 bytes for safe transmission)
// 4 bytes for DDP header, so 504 bytes for LED data
const int MAX_LED_DATA_PER_PACKET = 504; // 504 bytes / 3 bytes per LED = 168 LEDs
const int MAX_LED_DATA_PER_PACKET = 504; // 504 bytes / 3 bytes per LED (RGB)
int ledsPerPacket = MAX_LED_DATA_PER_PACKET / 3; // 3 bytes per LED (RGB)
for (int i = 0; i < count; i += ledsPerPacket) {
@ -148,8 +150,9 @@ void WledClient::flashLeds(int startIndex, int count, QColor color)
int currentLedsInPacket = qMin(ledsPerPacket, count - i);
for (int j = 0; j < currentLedsInPacket; ++j) {
datagram.append(color.red());
// Swap R and G for GRB order
datagram.append(color.green());
datagram.append(color.red());
datagram.append(color.blue());
}
@ -164,4 +167,4 @@ void WledClient::flashLeds(int startIndex, int count, QColor color)
qWarning() << "WledClient: Sent fewer bytes than expected for flashLeds. Expected:" << datagram.size() << "Sent:" << bytesSent;
}
}
}
}