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

Method run

tools/rle4encode.js:68–106  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

66 }
67
68 run() {
69 let parts = this.splitPath(this.inputPath);
70 parts.directory = this.outputPath;
71 parts.extension = ".bm4";
72 let output = new FILE(this.joinPath(parts), "wb");
73
74 let uncompressed = parseBMP(this.readFileBuffer(this.inputPath));
75 let convert = new Converter(uncompressed.pixelFormat, Bitmap.Gray16);
76
77 let writer = new RLE4Out({width: uncompressed.width, height: uncompressed.height, pixelFormat: Bitmap.Gray16});
78 writer.begin(0, 0, uncompressed.width, uncompressed.height);
79
80 let sourceLineBytes = ((Bitmap.depth(uncompressed.pixelFormat) * uncompressed.width) + 7) >> 3;
81 let destLineBytes = ((4 * uncompressed.width) + 7) >> 3;
82 let destLine = (new Uint8Array(destLineBytes)).buffer;
83 for (let i = 0, offset = uncompressed.offset; i < uncompressed.height; i++) {
84 let sourceLine = uncompressed.buffer.slice(offset + (i * sourceLineBytes), offset + ((i + 1) * sourceLineBytes));
85 convert.process(sourceLine, destLine);
86 writer.send(destLine);
87 }
88
89 writer.end();
90
91 let compressed = writer.bitmap;
92
93 // header: 'md', version, Commodetto pixel format, width and height (big endian)
94 output.writeByte('m'.charCodeAt(0));
95 output.writeByte('d'.charCodeAt(0));
96 output.writeByte(0);
97 output.writeByte(compressed.pixelFormat);
98 output.writeByte(compressed.width >> 8);
99 output.writeByte(compressed.width & 0xFF);
100 output.writeByte(compressed.height >> 8);
101 output.writeByte(compressed.height & 0xFF);
102
103 output.writeBuffer(compressed.buffer);
104
105 output.close();
106 }
107}

Callers

nothing calls this directly

Calls 9

beginMethod · 0.95
sendMethod · 0.95
endMethod · 0.95
sliceMethod · 0.65
closeMethod · 0.65
depthMethod · 0.45
processMethod · 0.45
writeByteMethod · 0.45
writeBufferMethod · 0.45

Tested by

no test coverage detected