MCPcopy Index your code
hub / github.com/Moddable-OpenSource/moddable / run

Method run

tools/buildclut.js:75–108  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73 }
74
75 run() {
76 let parts = this.splitPath(this.inputPath);
77 parts.directory = this.outputPath;
78 parts.extension = ".cct";
79 let output = new FILE(this.joinPath(parts), "wb");
80
81 let photoshopCLUT = new Uint8Array(this.readFileBuffer(this.inputPath));
82
83 // 4:4:4 color table
84 for (let i = 0, c = 0; i < 16; i++, c += 3) {
85 output.writeByte((this.roundComponent(photoshopCLUT[c + 1]) & 0xF0) |
86 (this.roundComponent(photoshopCLUT[c + 2]) >> 4));
87 output.writeByte(this.roundComponent(photoshopCLUT[c + 0]) >> 4);
88 }
89
90 // inverse table from 4:4:4 to 16 CLUT
91 for (let r = 0; r < 16; r++) {
92 for (let g = 0; g < 16; g++) {
93 for (let b = 0; b < 16; b++) {
94 let nearest = this.findNearest(photoshopCLUT, r | (r << 4), g | (g << 4), b | (b << 4));
95 output.writeByte(nearest);
96 }
97 }
98 }
99
100 // 5:6:5 color table
101 for (let i = 0, c = 0; i < 16; i++, c += 3) {
102 let pixel = ((photoshopCLUT[c + 0] >> 3) << 11) | ((photoshopCLUT[c + 1] >> 2) << 5) | (photoshopCLUT[c + 2] >> 3);
103 output.writeByte(pixel & 0xFF);
104 output.writeByte(pixel >> 8);
105 }
106
107 output.close();
108 }
109
110 findNearest(clut, r, g, b) {
111 let bestDelta = 1000000;

Callers

nothing calls this directly

Calls 4

roundComponentMethod · 0.80
findNearestMethod · 0.80
closeMethod · 0.65
writeByteMethod · 0.45

Tested by

no test coverage detected