| 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 | } |