(x, y, width, height)
| 47 | this.colors = dictionary.clut; |
| 48 | } |
| 49 | begin(x, y, width, height) { |
| 50 | let rowBytes = this.pixelsToBytes(width); |
| 51 | |
| 52 | this.file.length = 0; |
| 53 | this.file.position = 0; |
| 54 | |
| 55 | if (32 == this.depth) { |
| 56 | this.file.write("BM"); // imageFileType |
| 57 | this.write32((rowBytes * height) + 0x38); // fileSize |
| 58 | this.write16(0); // reserved1 |
| 59 | this.write16(0); // reserved2 |
| 60 | this.write32(0x36); // imageDataOffset |
| 61 | |
| 62 | this.write32(0x28); // biSize |
| 63 | this.write32(width); // biWidth |
| 64 | this.write32(-height); // biHeight (negative, because we write top-to-bottom) |
| 65 | |
| 66 | this.write16(1); // biPlanes |
| 67 | this.write16(32); // biBitCount |
| 68 | this.write32(0); // biCompression |
| 69 | this.write32((rowBytes * height) + 2); // biSizeImage |
| 70 | this.write32(0x0b12); // biXPelsPerMeter |
| 71 | this.write32(0x0b12); // biYPelsPerMeter |
| 72 | this.write32(0); // biClrUsed |
| 73 | this.write32(0); // biClrImportant |
| 74 | } |
| 75 | else if (16 == this.depth) { |
| 76 | if (width % 2) |
| 77 | throw new Error("width must be multiple of 2"); |
| 78 | |
| 79 | // 0x46 byte header |
| 80 | this.file.write("BM"); // imageFileType |
| 81 | this.write32((rowBytes * height) + 0x46); // fileSize |
| 82 | // Moddable-specific: 'mE' in reserved1 signals big-endian RGB565 pixels |
| 83 | if (Bitmap.RGB565BE == this.pixelFormat) |
| 84 | this.write16(0x456D); // 'mE' (little-endian: 'm' then 'E') |
| 85 | else |
| 86 | this.write16(0); // reserved1 |
| 87 | this.write16(0); // reserved2 |
| 88 | this.write32(0x46); // imageDataOffset |
| 89 | |
| 90 | this.write32(0x38); // biSize |
| 91 | this.write32(width); // biWidth |
| 92 | this.write32(-height); // biHeight (negative, because we write top-to-bottom) |
| 93 | this.write16(1); // biPlanes |
| 94 | this.write16(16); // biBitCount |
| 95 | this.write32(3); // biCompression (3 == 565 pixels (see mask below), 0 == 555 pixels) |
| 96 | this.write32((rowBytes * height) + 2); // biSizeImage |
| 97 | this.write32(0x0b12); // biXPelsPerMeter |
| 98 | this.write32(0x0b12); // biYPelsPerMeter |
| 99 | this.write32(0); // biClrUsed |
| 100 | this.write32(0); // biClrImportant |
| 101 | |
| 102 | if (Bitmap.ARGB4444 == this.pixelFormat) |
| 103 | this.file.write(0x00, 0x0F, 0x00, 0x00, 0xF0, 0x00, 0x00, 0x00, 0x0F, 0x00, 0x00, 0x00, 0x00, 0xF0, 0x00, 0x00); // masks for RGBA444 pixels |
| 104 | else |
| 105 | this.file.write(0x00, 0xF8, 0x00, 0x00, 0xE0, 0x07, 0x00, 0x00, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00); // masks for 565 pixels |
| 106 | } |
nothing calls this directly
no test coverage detected