@4bitlabs/hercmono.drv 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/hercules-dithers.ts","../src/phosphors.ts","../src/hercmono-filter.ts"],"mappings":";;KAmJY;;;;;;;;;;;;;;;KCjGA;;;UCpCK;;EAEf,WAAW;;EAEX,YAAY;;;;;;cAUD,iBACX,UAAS,oBACR"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/hercules-dithers.ts","../src/phosphors.ts","../src/hercmono-filter.ts"],"mappings":";;KAmJY;;;;;;;;;;;;;;;KCjGA;;;UCpCK;;EAEf,WAAW;;EAEX,YAAY;;;;;;cAWD,iBACX,UAAS,oBACR"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { screenFilter } from "@4bitlabs/blend-filters";
2
- import { boxBlur } from "@4bitlabs/blur-filters";
2
+ import { boxBlur, hBoxBlur } from "@4bitlabs/blur-filters";
3
3
  import { asRGBA, createImageData, padImageFilter } from "@4bitlabs/image";
4
4
  import { nearestNeighbor } from "@4bitlabs/resize-filters";
5
5
  import { toUint32 } from "@4bitlabs/color-space/srgb";
@@ -40,7 +40,7 @@ const phosphorSample = (mid, range, intensity = 1) => {
40
40
  const Phosphors = {
41
41
  P1: [
42
42
  toUint32(toSRGB(phosphorSample(525, [490, 580]))),
43
- toUint32(toSRGB(wavelengthI(525, .125))),
43
+ toUint32(toSRGB(wavelengthI(525, .25))),
44
44
  4278190080
45
45
  ],
46
46
  P2: [
@@ -50,7 +50,7 @@ const Phosphors = {
50
50
  ],
51
51
  P3: [
52
52
  toUint32(toSRGB(phosphorSample(602, [504, 700]))),
53
- toUint32(toSRGB(wavelengthI(602, .125))),
53
+ toUint32(toSRGB(wavelengthI(602, .25))),
54
54
  4278190080
55
55
  ],
56
56
  P4: [
@@ -71,7 +71,8 @@ const hercPad = padImageFilter([
71
71
  40,
72
72
  42
73
73
  ], { backgroundColor: 4278190080 });
74
- const blur = boxBlur(5);
74
+ const blur = boxBlur(2);
75
+ const hBlur = hBoxBlur(16);
75
76
  const hercMonoFilter = (options = {}) => {
76
77
  const { phosphors = "P1", patterns = "pq2" } = options;
77
78
  const patternSet = DitherPresets[patterns];
@@ -89,7 +90,7 @@ const hercMonoFilter = (options = {}) => {
89
90
  outRGBA[idx] = set ? on : off;
90
91
  glowRGBA[idx] = set ? glow : off;
91
92
  }
92
- return screenFilter(hercPad(pixelsImg), blur(hercPad(glowImg)));
93
+ return screenFilter(hercPad(pixelsImg), hBlur(blur(hercPad(glowImg))));
93
94
  };
94
95
  };
95
96
  //#endregion
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/hercules-dithers.ts","../src/phosphors.ts","../src/hercmono-filter.ts"],"sourcesContent":["const d63b31d4b60aea159d7bb667995632d6fcd184e8 = Uint8Array.of(\n /** pattern 0 */\n 0b00000000,\n 0b00000000,\n 0b00000000,\n 0b00000000,\n 0b00000000,\n 0b00000000,\n 0b00000000,\n 0b00000000,\n /** pattern 1 */\n 0b0000000,\n 0b0000001,\n 0b0000000,\n 0b0000100,\n 0b0000000,\n 0b0000000,\n 0b0000000,\n 0b0010000,\n /** pattern 2 */\n 0b00001000,\n 0b00000001,\n 0b00100000,\n 0b00000100,\n 0b01000000,\n 0b00000010,\n 0b00010000,\n 0b10000000,\n /** pattern 3 */\n 0b00000000,\n 0b01010101,\n 0b00000000,\n 0b01010101,\n 0b00000000,\n 0b01010101,\n 0b00000000,\n 0b01010101,\n /** pattern 4 */\n 0b01000100,\n 0b00010001,\n 0b01000100,\n 0b00010001,\n 0b01000100,\n 0b00010001,\n 0b01000100,\n 0b00010001,\n /** pattern 5 */\n 0b00000000,\n 0b00010001,\n 0b00000000,\n 0b00010001,\n 0b00000000,\n 0b00010001,\n 0b00000000,\n 0b00010001,\n /** pattern 6 */\n 0b00010001,\n 0b00100010,\n 0b01000100,\n 0b10001000,\n 0b00010001,\n 0b00100010,\n 0b01000100,\n 0b10001000,\n /** pattern 7 */\n 0b01010101,\n 0b10101010,\n 0b01010101,\n 0b10101010,\n 0b01010101,\n 0b10101010,\n 0b01010101,\n 0b10101010,\n /** pattern 8 */\n 0b00000000,\n 0b01000100,\n 0b00000000,\n 0b00010001,\n 0b00000000,\n 0b01000100,\n 0b00000000,\n 0b00010001,\n /** pattern 9 */\n 0b11111111,\n 0b10101111,\n 0b11111111,\n 0b11111010,\n 0b11111111,\n 0b10101111,\n 0b11111111,\n 0b11111010,\n /** pattern A */\n 0b01010101,\n 0b10111011,\n 0b10101010,\n 0b11101110,\n 0b01010101,\n 0b10111011,\n 0b10101010,\n 0b11101110,\n /** pattern B */\n 0b11110111,\n 0b11111110,\n 0b11011111,\n 0b11111011,\n 0b10111111,\n 0b11111101,\n 0b11101111,\n 0b01111111,\n /** pattern C */\n 0b11111111,\n 0b01010101,\n 0b11111111,\n 0b01010101,\n 0b11111111,\n 0b01010101,\n 0b11111111,\n 0b01010101,\n /** pattern D */\n 0b11011101,\n 0b11101110,\n 0b01110111,\n 0b10111011,\n 0b11011101,\n 0b11101110,\n 0b01110111,\n 0b10111011,\n /** pattern E */\n 0b11111011,\n 0b11111110,\n 0b11011111,\n 0b11110111,\n 0b01111111,\n 0b11011111,\n 0b11111101,\n 0b01111111,\n /** pattern F */\n 0b11111111,\n 0b11111111,\n 0b11111111,\n 0b11111111,\n 0b11111111,\n 0b11111111,\n 0b11111111,\n 0b11111111,\n);\n\nexport type DitherPreset = 'astro-chicken' | 'pq2' | 'hoyle' | 'cbquest-demo';\n\nexport const DitherPresets: { [key in DitherPreset]: Uint8Array } = {\n 'astro-chicken': d63b31d4b60aea159d7bb667995632d6fcd184e8,\n hoyle: d63b31d4b60aea159d7bb667995632d6fcd184e8,\n pq2: d63b31d4b60aea159d7bb667995632d6fcd184e8,\n 'cbquest-demo': d63b31d4b60aea159d7bb667995632d6fcd184e8,\n};\n","import { toUint32 } from '@4bitlabs/color-space/srgb';\nimport { toSRGB, type XYZTuple, create, mix } from '@4bitlabs/color-space/xyz';\nimport { wavelengthI } from '@4bitlabs/wavelength/xyz';\n\nexport const lerp = (a: number, b: number, t: number): number =>\n a * (1 - t) + b * t;\n\nconst loplerp = (mid: number, [min, max]: [number, number], value: number) => {\n return value >= 0 ? lerp(mid, max, value) : lerp(mid, min, -value);\n};\n\nconst gaussian = (x: number, w: number = 1 / 2) => Math.exp(-((x / w) ** 2));\n\nconst phosphorSample = (\n mid: number,\n range: [number, number],\n intensity = 1,\n): XYZTuple => {\n const steps = 32;\n const color = create(0, 0, 0);\n const tmp = create(0, 0, 0);\n\n for (let i = -steps; i <= steps; i++) {\n const x = i / steps;\n const v = loplerp(mid, range, x);\n wavelengthI(v, intensity * gaussian(x), tmp);\n color[1] += tmp[1];\n color[2] += tmp[2];\n color[3] += tmp[3];\n }\n\n color[1] /= steps;\n color[2] /= steps;\n color[3] /= steps;\n\n return color;\n};\n\n/**\n * The supported standard phosphor types for monochrome CRT rendering.\n *\n * - `\"P1\"` - 525nm, green phosphor. A common phosphor type found in computer monitors of the era.\n * - `\"P2\"` - 543nm, blue-green phosphor. Mostly used in oscilloscopes.\n * - `\"P3\"` - 602nm, amber phosphor. A common phosphor type found in computer monitors of the era.\n * - `\"P4\"` - 565, 540nm, \"white\" phosphor. A common phosphor type found in computer monitors and TV CRTs.\n * - `\"P6\"` - 565, 460nm, \"white\" phosphor. A common phosphor type found in computer monitors and TV CRTs.\n *\n * @see {@link https://en.wikipedia.org/wiki/Phosphor}\n * @see {@link https://www.labguysworld.com/crt_phosphor_research.pdf}\n */\nexport type PhosphorTypes = 'P1' | 'P2' | 'P3' | 'P4' | 'P6';\nexport type PhosphorColors = [on: number, glow: number, off: number];\n\nexport const Phosphors: { [key in PhosphorTypes]: PhosphorColors } = {\n P1: [\n toUint32(toSRGB(phosphorSample(525, [490, 580]))),\n toUint32(toSRGB(wavelengthI(525, 0.125))),\n 0xff000000,\n ],\n P2: [\n toUint32(toSRGB(phosphorSample(534, [450, 640]))),\n toUint32(toSRGB(wavelengthI(534, 0.125))),\n 0xff000000,\n ],\n P3: [\n toUint32(toSRGB(phosphorSample(602, [504, 700]))),\n toUint32(toSRGB(wavelengthI(602, 0.125))),\n 0xff000000,\n ],\n P4: [\n toUint32(\n toSRGB(\n mix(\n phosphorSample(565, [390, 663], 1),\n phosphorSample(435, [390, 663], 1),\n 1 / 2,\n ),\n ),\n ),\n toUint32(\n toSRGB(\n mix(\n phosphorSample(565, [390, 663], 1 / 2),\n phosphorSample(435, [390, 663], 1 / 2),\n 2 / 3,\n ),\n ),\n ),\n 0xff000000,\n ],\n P6: [\n toUint32(\n toSRGB(\n mix(\n phosphorSample(563, [416, 695], 1),\n phosphorSample(460, [416, 695], 1),\n 1 / 3,\n ),\n ),\n ),\n toUint32(\n toSRGB(\n mix(\n phosphorSample(563, [416, 695], 1),\n phosphorSample(460, [416, 695], 1),\n 0.5,\n ),\n ),\n ),\n 0xff000000,\n ],\n};\n","import { screenFilter } from '@4bitlabs/blend-filters';\nimport { boxBlur } from '@4bitlabs/blur-filters';\nimport {\n type PaletteFilter,\n type IndexedPixelData,\n asRGBA,\n createImageData,\n padImageFilter,\n} from '@4bitlabs/image';\nimport { nearestNeighbor } from '@4bitlabs/resize-filters';\n\nimport { type DitherPreset, DitherPresets } from './hercules-dithers.js';\nimport { Phosphors, type PhosphorTypes } from './phosphors.js';\n\nexport interface HercMonoOptions {\n /** Selected dither patterns. @defaultValue `\"pq2\"` */\n patterns?: DitherPreset;\n /** Selected phosphor type. @defaultValue `\"P1\"` */\n phosphors?: PhosphorTypes;\n}\n\nconst hercPad = padImageFilter([57, 40, 42], { backgroundColor: 0xff000000 });\nconst blur = boxBlur(5);\n\n/**\n * @param options.patterns\n * @param options.phosphors\n */\nexport const hercMonoFilter = (\n options: HercMonoOptions = {},\n): PaletteFilter => {\n const { phosphors = 'P1', patterns = 'pq2' } = options;\n const patternSet = DitherPresets[patterns];\n const [on, glow, off] = Phosphors[phosphors];\n\n return (source: IndexedPixelData) => {\n const resize = nearestNeighbor([2, 1.5]);\n const resized = resize(source);\n const pixelsImg = createImageData(resized.width, resized.height);\n const glowImg = createImageData(resized.width, resized.height);\n const outRGBA = asRGBA(pixelsImg);\n const glowRGBA = asRGBA(glowImg);\n\n for (let y = 0; y < resized.height; y++)\n for (let x = 0; x < resized.width; x++) {\n const idx = x + y * resized.width;\n const patternIdx = resized.pixels[idx];\n const set = patternSet[patternIdx * 8 + (y % 8)] & (1 << (7 - (x % 8)));\n outRGBA[idx] = set ? on : off;\n glowRGBA[idx] = set ? glow : off;\n }\n\n return screenFilter(hercPad(pixelsImg), blur(hercPad(glowImg)));\n };\n};\n"],"mappings":";;;;;;;;AAAA,MAAM,2CAA2C,WAAW,GAE1D,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GAEA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,IAEA,GACA,GACA,IACA,GACA,IACA,GACA,IACA,KAEA,GACA,IACA,GACA,IACA,GACA,IACA,GACA,IAEA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IAEA,GACA,IACA,GACA,IACA,GACA,IACA,GACA,IAEA,IACA,IACA,IACA,KACA,IACA,IACA,IACA,KAEA,IACA,KACA,IACA,KACA,IACA,KACA,IACA,KAEA,GACA,IACA,GACA,IACA,GACA,IACA,GACA,IAEA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KAEA,IACA,KACA,KACA,KACA,IACA,KACA,KACA,KAEA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KAEA,KACA,IACA,KACA,IACA,KACA,IACA,KACA,IAEA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KAEA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KAEA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,GACF;AAIA,MAAa,gBAAuD;CAClE,iBAAiB;CACjB,OAAO;CACP,KAAK;CACL,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aAAa,QAAQ,OAAO;GAClC,MAAM,MAAM,WAAW,aAAa,IAAK,IAAI,KAAO,KAAM,IAAK,IAAI;GACnE,QAAQ,OAAO,MAAM,KAAK;GAC1B,SAAS,OAAO,MAAM,OAAO;EAC/B;EAEF,OAAO,aAAa,QAAQ,SAAS,GAAG,KAAK,QAAQ,OAAO,CAAC,CAAC;CAChE;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/hercules-dithers.ts","../src/phosphors.ts","../src/hercmono-filter.ts"],"sourcesContent":["const d63b31d4b60aea159d7bb667995632d6fcd184e8 = Uint8Array.of(\n /** pattern 0 */\n 0b00000000,\n 0b00000000,\n 0b00000000,\n 0b00000000,\n 0b00000000,\n 0b00000000,\n 0b00000000,\n 0b00000000,\n /** pattern 1 */\n 0b0000000,\n 0b0000001,\n 0b0000000,\n 0b0000100,\n 0b0000000,\n 0b0000000,\n 0b0000000,\n 0b0010000,\n /** pattern 2 */\n 0b00001000,\n 0b00000001,\n 0b00100000,\n 0b00000100,\n 0b01000000,\n 0b00000010,\n 0b00010000,\n 0b10000000,\n /** pattern 3 */\n 0b00000000,\n 0b01010101,\n 0b00000000,\n 0b01010101,\n 0b00000000,\n 0b01010101,\n 0b00000000,\n 0b01010101,\n /** pattern 4 */\n 0b01000100,\n 0b00010001,\n 0b01000100,\n 0b00010001,\n 0b01000100,\n 0b00010001,\n 0b01000100,\n 0b00010001,\n /** pattern 5 */\n 0b00000000,\n 0b00010001,\n 0b00000000,\n 0b00010001,\n 0b00000000,\n 0b00010001,\n 0b00000000,\n 0b00010001,\n /** pattern 6 */\n 0b00010001,\n 0b00100010,\n 0b01000100,\n 0b10001000,\n 0b00010001,\n 0b00100010,\n 0b01000100,\n 0b10001000,\n /** pattern 7 */\n 0b01010101,\n 0b10101010,\n 0b01010101,\n 0b10101010,\n 0b01010101,\n 0b10101010,\n 0b01010101,\n 0b10101010,\n /** pattern 8 */\n 0b00000000,\n 0b01000100,\n 0b00000000,\n 0b00010001,\n 0b00000000,\n 0b01000100,\n 0b00000000,\n 0b00010001,\n /** pattern 9 */\n 0b11111111,\n 0b10101111,\n 0b11111111,\n 0b11111010,\n 0b11111111,\n 0b10101111,\n 0b11111111,\n 0b11111010,\n /** pattern A */\n 0b01010101,\n 0b10111011,\n 0b10101010,\n 0b11101110,\n 0b01010101,\n 0b10111011,\n 0b10101010,\n 0b11101110,\n /** pattern B */\n 0b11110111,\n 0b11111110,\n 0b11011111,\n 0b11111011,\n 0b10111111,\n 0b11111101,\n 0b11101111,\n 0b01111111,\n /** pattern C */\n 0b11111111,\n 0b01010101,\n 0b11111111,\n 0b01010101,\n 0b11111111,\n 0b01010101,\n 0b11111111,\n 0b01010101,\n /** pattern D */\n 0b11011101,\n 0b11101110,\n 0b01110111,\n 0b10111011,\n 0b11011101,\n 0b11101110,\n 0b01110111,\n 0b10111011,\n /** pattern E */\n 0b11111011,\n 0b11111110,\n 0b11011111,\n 0b11110111,\n 0b01111111,\n 0b11011111,\n 0b11111101,\n 0b01111111,\n /** pattern F */\n 0b11111111,\n 0b11111111,\n 0b11111111,\n 0b11111111,\n 0b11111111,\n 0b11111111,\n 0b11111111,\n 0b11111111,\n);\n\nexport type DitherPreset = 'astro-chicken' | 'pq2' | 'hoyle' | 'cbquest-demo';\n\nexport const DitherPresets: { [key in DitherPreset]: Uint8Array } = {\n 'astro-chicken': d63b31d4b60aea159d7bb667995632d6fcd184e8,\n hoyle: d63b31d4b60aea159d7bb667995632d6fcd184e8,\n pq2: d63b31d4b60aea159d7bb667995632d6fcd184e8,\n 'cbquest-demo': d63b31d4b60aea159d7bb667995632d6fcd184e8,\n};\n","import { toUint32 } from '@4bitlabs/color-space/srgb';\nimport { toSRGB, type XYZTuple, create, mix } from '@4bitlabs/color-space/xyz';\nimport { wavelengthI } from '@4bitlabs/wavelength/xyz';\n\nexport const lerp = (a: number, b: number, t: number): number =>\n a * (1 - t) + b * t;\n\nconst loplerp = (mid: number, [min, max]: [number, number], value: number) => {\n return value >= 0 ? lerp(mid, max, value) : lerp(mid, min, -value);\n};\n\nconst gaussian = (x: number, w: number = 1 / 2) => Math.exp(-((x / w) ** 2));\n\nconst phosphorSample = (\n mid: number,\n range: [number, number],\n intensity = 1,\n): XYZTuple => {\n const steps = 32;\n const color = create(0, 0, 0);\n const tmp = create(0, 0, 0);\n\n for (let i = -steps; i <= steps; i++) {\n const x = i / steps;\n const v = loplerp(mid, range, x);\n wavelengthI(v, intensity * gaussian(x), tmp);\n color[1] += tmp[1];\n color[2] += tmp[2];\n color[3] += tmp[3];\n }\n\n color[1] /= steps;\n color[2] /= steps;\n color[3] /= steps;\n\n return color;\n};\n\n/**\n * The supported standard phosphor types for monochrome CRT rendering.\n *\n * - `\"P1\"` - 525nm, green phosphor. A common phosphor type found in computer monitors of the era.\n * - `\"P2\"` - 543nm, blue-green phosphor. Mostly used in oscilloscopes.\n * - `\"P3\"` - 602nm, amber phosphor. A common phosphor type found in computer monitors of the era.\n * - `\"P4\"` - 565, 540nm, \"white\" phosphor. A common phosphor type found in computer monitors and TV CRTs.\n * - `\"P6\"` - 565, 460nm, \"white\" phosphor. A common phosphor type found in computer monitors and TV CRTs.\n *\n * @see {@link https://en.wikipedia.org/wiki/Phosphor}\n * @see {@link https://www.labguysworld.com/crt_phosphor_research.pdf}\n */\nexport type PhosphorTypes = 'P1' | 'P2' | 'P3' | 'P4' | 'P6';\nexport type PhosphorColors = [on: number, glow: number, off: number];\n\nexport const Phosphors: { [key in PhosphorTypes]: PhosphorColors } = {\n P1: [\n toUint32(toSRGB(phosphorSample(525, [490, 580]))),\n toUint32(toSRGB(wavelengthI(525, 0.25))),\n 0xff000000,\n ],\n P2: [\n toUint32(toSRGB(phosphorSample(534, [450, 640]))),\n toUint32(toSRGB(wavelengthI(534, 0.125))),\n 0xff000000,\n ],\n P3: [\n toUint32(toSRGB(phosphorSample(602, [504, 700]))),\n toUint32(toSRGB(wavelengthI(602, 0.25))),\n 0xff000000,\n ],\n P4: [\n toUint32(\n toSRGB(\n mix(\n phosphorSample(565, [390, 663], 1),\n phosphorSample(435, [390, 663], 1),\n 1 / 2,\n ),\n ),\n ),\n toUint32(\n toSRGB(\n mix(\n phosphorSample(565, [390, 663], 1 / 2),\n phosphorSample(435, [390, 663], 1 / 2),\n 2 / 3,\n ),\n ),\n ),\n 0xff000000,\n ],\n P6: [\n toUint32(\n toSRGB(\n mix(\n phosphorSample(563, [416, 695], 1),\n phosphorSample(460, [416, 695], 1),\n 1 / 3,\n ),\n ),\n ),\n toUint32(\n toSRGB(\n mix(\n phosphorSample(563, [416, 695], 1),\n phosphorSample(460, [416, 695], 1),\n 0.5,\n ),\n ),\n ),\n 0xff000000,\n ],\n};\n","import { screenFilter } from '@4bitlabs/blend-filters';\nimport { boxBlur, hBoxBlur } from '@4bitlabs/blur-filters';\nimport {\n type PaletteFilter,\n type IndexedPixelData,\n asRGBA,\n createImageData,\n padImageFilter,\n} from '@4bitlabs/image';\nimport { nearestNeighbor } from '@4bitlabs/resize-filters';\n\nimport { type DitherPreset, DitherPresets } from './hercules-dithers.js';\nimport { Phosphors, type PhosphorTypes } from './phosphors.js';\n\nexport interface HercMonoOptions {\n /** Selected dither patterns. @defaultValue `\"pq2\"` */\n patterns?: DitherPreset;\n /** Selected phosphor type. @defaultValue `\"P1\"` */\n phosphors?: PhosphorTypes;\n}\n\nconst hercPad = padImageFilter([57, 40, 42], { backgroundColor: 0xff000000 });\nconst blur = boxBlur(2);\nconst hBlur = hBoxBlur(16);\n\n/**\n * @param options.patterns\n * @param options.phosphors\n */\nexport const hercMonoFilter = (\n options: HercMonoOptions = {},\n): PaletteFilter => {\n const { phosphors = 'P1', patterns = 'pq2' } = options;\n const patternSet = DitherPresets[patterns];\n const [on, glow, off] = Phosphors[phosphors];\n\n return (source: IndexedPixelData) => {\n const resize = nearestNeighbor([2, 1.5]);\n const resized = resize(source);\n const pixelsImg = createImageData(resized.width, resized.height);\n const glowImg = createImageData(resized.width, resized.height);\n const outRGBA = asRGBA(pixelsImg);\n const glowRGBA = asRGBA(glowImg);\n\n for (let y = 0; y < resized.height; y++)\n for (let x = 0; x < resized.width; x++) {\n const idx = x + y * resized.width;\n const patternIdx = resized.pixels[idx];\n const set = patternSet[patternIdx * 8 + (y % 8)] & (1 << (7 - (x % 8)));\n outRGBA[idx] = set ? on : off;\n glowRGBA[idx] = set ? glow : off;\n }\n\n return screenFilter(hercPad(pixelsImg), hBlur(blur(hercPad(glowImg))));\n };\n};\n"],"mappings":";;;;;;;;AAAA,MAAM,2CAA2C,WAAW,GAE1D,GACA,GACA,GACA,GACA,GACA,GACA,GACA,GAEA,GACA,GACA,GACA,GACA,GACA,GACA,GACA,IAEA,GACA,GACA,IACA,GACA,IACA,GACA,IACA,KAEA,GACA,IACA,GACA,IACA,GACA,IACA,GACA,IAEA,IACA,IACA,IACA,IACA,IACA,IACA,IACA,IAEA,GACA,IACA,GACA,IACA,GACA,IACA,GACA,IAEA,IACA,IACA,IACA,KACA,IACA,IACA,IACA,KAEA,IACA,KACA,IACA,KACA,IACA,KACA,IACA,KAEA,GACA,IACA,GACA,IACA,GACA,IACA,GACA,IAEA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KAEA,IACA,KACA,KACA,KACA,IACA,KACA,KACA,KAEA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KAEA,KACA,IACA,KACA,IACA,KACA,IACA,KACA,IAEA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KAEA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KAEA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,GACF;AAIA,MAAa,gBAAuD;CAClE,iBAAiB;CACjB,OAAO;CACP,KAAK;CACL,gBAAgB;AAClB;;;ACtJA,MAAa,QAAQ,GAAW,GAAW,MACzC,KAAK,IAAI,KAAK,IAAI;AAEpB,MAAM,WAAW,KAAa,CAAC,KAAK,MAAwB,UAAkB;CAC5E,OAAO,SAAS,IAAI,KAAK,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,KAAK,C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AAQ,SAAS,GAAG,MAAM,KAAK,QAAQ,OAAO,CAAC,CAAC,CAAC;CACvE;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@4bitlabs/hercmono.drv",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "A render filter for @4bitlabs/sci0-renderer generated PIC resources to replicate HERCMONO.DRV",
5
5
  "keywords": [
6
6
  "hercmono.drv"
@@ -36,10 +36,10 @@
36
36
  "@4bitlabs/color-space": "^3.1.0",
37
37
  "@4bitlabs/image": "^6.0.0",
38
38
  "@4bitlabs/resize-filters": "^2.1.0",
39
- "@4bitlabs/wavelength": "^0.1.1"
39
+ "@4bitlabs/wavelength": "^0.1.2"
40
40
  },
41
41
  "publishConfig": {
42
42
  "access": "public"
43
43
  },
44
- "gitHead": "9ba547796c3422364a963c87d452d6f1fb4a4713"
44
+ "gitHead": "95216b48523c5d0c9a8907f2ac8f137af83a9152"
45
45
  }