fix: rotate portrait renders to EPD-native byte layout
CI / test (push) Has been cancelled

The .bin file for portrait orientation was packed as 480-pixel rows ×
800 rows, but firmware streams blindly at 800×480 (the EPD's native
scan order). Both layouts hit the same 192000-byte total, so the size
guard in epd_draw_image_with_border passed and the row-stride mismatch
showed up on the panel as the photo tiling/repeating.

Renderer now rotates the cropped photo 90° CW before dithering when
orientation is portrait, so the packed bytes always match the EPD's
800-pixel scan order. Firmware stays orientation-unaware (per the
"ESP32 never transforms images" decision in webApp/CLAUDE.md). Preview
decoder rotates -90° on the way out so the in-browser frame preview
stays upright.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-06 14:06:41 -04:00
parent c2b208f103
commit 70d48f9b11
3 changed files with 36 additions and 5 deletions
+12 -3
View File
@@ -215,8 +215,9 @@ class DeviceApiController extends AbstractController
$this->renderBinToPng(
$binPath,
$pngPath,
$device->getModel()->width($device->getOrientation()),
$device->getModel()->height($device->getOrientation()),
$device->getModel()->nativeWidth(),
$device->getModel()->nativeHeight(),
$device->getOrientation(),
);
}
@@ -229,7 +230,7 @@ class DeviceApiController extends AbstractController
return $response;
}
private function renderBinToPng(string $binPath, string $pngPath, int $width, int $height): void
private function renderBinToPng(string $binPath, string $pngPath, int $width, int $height, Orientation $orientation): void
{
$bin = (string) file_get_contents($binPath);
$len = strlen($bin);
@@ -250,6 +251,14 @@ class DeviceApiController extends AbstractController
$im = new \Imagick();
$im->readImageBlob($ppm);
// The .bin is always laid out in EPD-native scan order. For portrait,
// the renderer pre-rotated the photo 90° CW; rotate -90° here so the
// browser-side preview shows the photo upright.
if ($orientation === Orientation::Portrait) {
$im->rotateImage(new \ImagickPixel('white'), -90);
}
$im->setImageFormat('png');
$im->writeImage($pngPath);
$im->destroy();