IMPORTANT: This function is in critical rendering path and is called for every pixel. Please keep it as simple and efficient as possible.
| 324 | // IMPORTANT: This function is in critical rendering path and is called for every pixel. Please keep it as simple and |
| 325 | // efficient as possible. |
| 326 | void GfxRenderer::drawPixel(const int x, const int y, const bool state) const { |
| 327 | int phyX = 0; |
| 328 | int phyY = 0; |
| 329 | |
| 330 | // Note: this call should be inlined for better performance |
| 331 | rotateCoordinates(orientation, x, y, &phyX, &phyY, panelWidth, panelHeight); |
| 332 | |
| 333 | // Bounds checking against runtime panel dimensions |
| 334 | if (phyX < 0 || phyX >= panelWidth || phyY < 0 || phyY >= panelHeight) { |
| 335 | LOG_ERR("GFX", "!! Outside range (%d, %d) -> (%d, %d)", x, y, phyX, phyY); |
| 336 | return; |
| 337 | } |
| 338 | |
| 339 | // Tiled grayscale: redirect writes to the strip scratch and clip to the |
| 340 | // current band. Single predictable branch on the hot per-pixel path. |
| 341 | uint8_t* target = frameBuffer; |
| 342 | uint32_t rowY = static_cast<uint32_t>(phyY); |
| 343 | if (_stripActive) { |
| 344 | if (phyY < _stripY0 || phyY >= _stripY0 + _stripRows) { |
| 345 | return; // pixel outside the band currently being rendered |
| 346 | } |
| 347 | target = _stripBuf; |
| 348 | rowY = static_cast<uint32_t>(phyY - _stripY0); |
| 349 | } |
| 350 | |
| 351 | // Calculate byte position and bit position |
| 352 | const uint32_t byteIndex = rowY * panelWidthBytes + (phyX / 8); |
| 353 | const uint8_t bitPosition = 7 - (phyX % 8); // MSB first |
| 354 | |
| 355 | if (state) { |
| 356 | target[byteIndex] &= ~(1 << bitPosition); // Clear bit |
| 357 | } else { |
| 358 | target[byteIndex] |= 1 << bitPosition; // Set bit |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | int GfxRenderer::getTextWidth(const int fontId, const char* text, const EpdFontFamily::Style style, |
| 363 | const BidiUtils::BidiBaseDir baseDir) const { |
no test coverage detected