| 66 | } |
| 67 | |
| 68 | run() { |
| 69 | let parts = this.splitPath(this.inputPath); |
| 70 | parts.directory = this.outputPath; |
| 71 | parts.extension = ".cs"; |
| 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.RGB565LE); |
| 76 | |
| 77 | let writer = new ColorCellOut; |
| 78 | writer.begin(0, 0, uncompressed.width, uncompressed.height); |
| 79 | |
| 80 | const cellHeight = 4; |
| 81 | let sourceLineBytes = ((Bitmap.depth(uncompressed.pixelFormat) * uncompressed.width) + 7) >> 3; |
| 82 | let destLineBytes = uncompressed.width * 2; |
| 83 | let destBuffer = (new Uint8Array(cellHeight * destLineBytes)).buffer; |
| 84 | for (let i = 0, offset = uncompressed.offset; i < uncompressed.height; i += cellHeight) { |
| 85 | let sourceLine = uncompressed.buffer.slice(offset + (i * sourceLineBytes), offset + ((i + cellHeight) * sourceLineBytes)); |
| 86 | convert.process(sourceLine, destBuffer); |
| 87 | writer.send(destBuffer); |
| 88 | } |
| 89 | |
| 90 | writer.end(); |
| 91 | |
| 92 | let compressed = writer.bitmap; |
| 93 | |
| 94 | // CommodettoStream header |
| 95 | const frameCount = 1; |
| 96 | const fps_numerator = 1; |
| 97 | const fps_denominator = 1; |
| 98 | const frameSize = compressed.buffer.byteLength; |
| 99 | |
| 100 | output.writeByte('c'.charCodeAt(0)); |
| 101 | output.writeByte('s'.charCodeAt(0)); |
| 102 | output.writeByte(Bitmap.RGB565LE); |
| 103 | output.writeByte(0); |
| 104 | output.writeByte(compressed.width & 0xFF); |
| 105 | output.writeByte(compressed.width >> 8); |
| 106 | output.writeByte(compressed.height & 0xFF); |
| 107 | output.writeByte(compressed.height >> 8); |
| 108 | output.writeByte(frameCount & 0xFF); |
| 109 | output.writeByte(frameCount >> 8); |
| 110 | output.writeByte(fps_numerator & 0xFF); |
| 111 | output.writeByte(fps_numerator >> 8); |
| 112 | output.writeByte(fps_denominator & 0xFF); |
| 113 | output.writeByte(fps_denominator >> 8); |
| 114 | |
| 115 | output.writeByte(frameSize & 255); |
| 116 | output.writeByte(frameSize >> 8); |
| 117 | output.writeBuffer(compressed.buffer); |
| 118 | |
| 119 | output.writeByte(0); // 0 size frame to end |
| 120 | output.writeByte(0); |
| 121 | |
| 122 | output.close(); |
| 123 | } |
| 124 | } |