在單色 LCD 上面利用 PWM 產生灰階的效果

Hacker News 上看到「Grayscale on 1-bit LCDs (2022) (zephray.me)」這篇,原文在「Grayscale on 1-bit LCDs」這篇,講在單色的 LCD (黑白的 LCD) 上利用 PWM 的方式來模擬出灰階的效果。

文章蠻有趣的,可以看到他一直在 tune,想辦法做出更多階的灰階效果:

不過其實更有趣的事情是在 Hacker News 的留言裡面,有人起手式就放大招:

My father Bryce Bayer studied this question fifty years ago at Eastman Kodak; his approach is known as ordered dithering:

https://en.wikipedia.org/wiki/Ordered_dithering

One is effectively posterizing a grayscale image, and his primary goal was to reduce artifacts drawing unwanted attention to the borders between poster levels.

With improvements in hardware other approaches to dithering took over. The last time I saw my father's pattern was on a DEC box logo. He moved to the color group at Kodak, and designed the "Bayer filter" used in digital cameras.

不只是提到大名鼎鼎的 Bryce Bayer,開頭直接就 "My father Bryce Bayer ..."。

搜了一下 syzygies 這個用戶名稱,看起來像是 Bryce Bayer 的兒子 Dave Bayer (維基百科也有條目:Dave Bayer)。

在 command line 下生出全灰的圖片

因為需要一張 1920x1080 全灰色的圖片,翻了一下 DuckDuckGo 找到這篇:「Linux create Image pixel by pixel in command line」。

裡面抓重點,主要的想法是 PPM 格式 (可以參考「Netpbm」這個條目),然後找到「PPM Format Specification」這份文件。

主要就是用 P3 模式下去產生檔案:

repeat 2073600 echo '127 127 127' >> grey.ppm

然後開頭的地方修一下,加上 P3、長寬資訊以及最大的值:

P3
1920 1080
255

接著就用 ImageMagick 轉檔:

convert grey.ppm grey.png

然後用 viewer 看一下,確認沒問題就收工了...