Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

8-bit PNG #62

@Artoria2e5

Description

@Artoria2e5

目前繪圖所用顏色基本只有一種(加上 Anti-Alias 得到的 Alpha),應該可以考慮將 PNG 轉為 256 索引顏色(8-bit)模式(這麼多灰階很夠用了)。測試將楷體 biangpngquant 轉為 256 索引色(8-bit),檔案大小由 6403 位元組減少至 4967 位元組(77.6% 原大小);轉為 64 索引色(4-bit),檔案大小為 3516 位元組(54.9%)。

要實作的話,StackOverflow 上已有前人經驗

其中 ImageTypeSpecifier.createIndexed 基本上是應該傳入幾個這樣的陣列:

byte[] 紅表 = new byte[256],
       綠表 = new byte[256],
       藍表 = new byte[256],
       透表 = new byte[256];

// 現時都是使用黑色
byte  =  =  = 0x00;

// 只須考慮透明,因此紅綠藍三表各值同色
Array.fill(紅表, );
Array.fill(綠表, );
Array.fill(藍表, ); 

// 256 階色,區別全在透明
// 注意若要製作均勻 64 階,應使用 (byte) (i * (255.0 / 63.0) + 0.5)。
for (int i = 0; i < 256; i++)
    透表[i] = (byte) i;

return ImageTypeSpecifier.createIndexed(紅表, 綠表, 藍表, 透表, 8, DataBuffer.TYPE_BYTE);

之後 PNGMetadata 感覺是直接用之前建立的 ImageTypeSpecifierinitialize 一下就好,總之先寫下來有空去做吧。


pngquant 處理的結果如下所示。如果看得出區別的話,應該都是在字邊緣處。

64
biang-fs4
256
biang-fs8
原始
biang

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions