forked from Blendman974/faceclaw
Add a notification-icons database (from Pebble) for iOS
This commit is contained in:
1 parent
f47d82b871
commit
35a4ae7064
20 files changed
+1236
-102
No files matched your search
@@ -0,0 +1,28 @@
|
||||
import { GrayImage } from "./image";
|
||||
import { decodeBase64 } from "../util/base64";
|
||||
import { PEBBLE_ICON_DATA, PEBBLE_ICON_SIZE, type PebbleIconName } from "./pebble-icons-data";
|
||||
|
||||
export { PEBBLE_ICON_SIZE, type PebbleIconName };
|
||||
|
||||
// 2-bit codes in pebble-icons-data.ts -> coverage.
|
||||
const LEVELS = [0, 128, 255, 255];
|
||||
|
||||
const cache = new Map<PebbleIconName, GrayImage>();
|
||||
|
||||
/**
|
||||
* One of the bundled Pebble notification icons (see pebble-icons-data.ts and
|
||||
* scripts/generate-pebble-icons.cjs), as a PEBBLE_ICON_SIZE square coverage
|
||||
* bitmap. Decoded once and shared: clone it before drawing on it.
|
||||
*/
|
||||
export function pebbleIcon(name: PebbleIconName): GrayImage {
|
||||
let icon = cache.get(name);
|
||||
if (!icon) {
|
||||
const bytes = decodeBase64(PEBBLE_ICON_DATA[name]);
|
||||
icon = new GrayImage(PEBBLE_ICON_SIZE, PEBBLE_ICON_SIZE, 0);
|
||||
for (let i = 0; i < icon.pixels.length; i++) {
|
||||
icon.pixels[i] = LEVELS[(bytes[i >> 2]! >> (6 - 2 * (i & 3))) & 3]!;
|
||||
}
|
||||
cache.set(name, icon);
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
Reference in new issue
Block a user