(data: Uint8Array, width: number, height: number)
| 71 | color0 > color1 => interpolation, else => average |
| 72 | */ |
| 73 | static bc1(data: Uint8Array, width: number, height: number): Uint8Array { |
| 74 | const rgba = new Uint8Array(4 * width * height); |
| 75 | const colorPalette = new Uint8Array(16); |
| 76 | let offset = 0; |
| 77 | |
| 78 | for (let y = 0; y < height; y += 4) { |
| 79 | for (let x = 0; x < width; x += 4) { |
| 80 | const color0 = ImageDecoder.readUInt16LE(data, offset); |
| 81 | const color1 = ImageDecoder.readUInt16LE(data, offset + 2); |
| 82 | let colorBits = ImageDecoder.readUInt32LE(data, offset + 4); |
| 83 | offset += 8; |
| 84 | |
| 85 | let [c0r, c0g, c0b] = ImageDecoder.decode565(color0); |
| 86 | let [c1r, c1g, c1b] = ImageDecoder.decode565(color1); |
| 87 | |
| 88 | if (color0 > color1) { |
| 89 | colorPalette[0] = c0r; colorPalette[1] = c0g; colorPalette[2] = c0b; |
| 90 | colorPalette[4] = c1r; colorPalette[5] = c1g; colorPalette[6] = c1b; |
| 91 | colorPalette[8] = (2 * c0r + c1r) / 3; |
| 92 | colorPalette[9] = (2 * c0g + c1g) / 3; |
| 93 | colorPalette[10] = (2 * c0b + c1b) / 3; |
| 94 | colorPalette[12] = (c0r + 2 * c1r) / 3; |
| 95 | colorPalette[13] = (c0g + 2 * c1g) / 3; |
| 96 | colorPalette[14] = (c0b + 2 * c1b) / 3; |
| 97 | } |
| 98 | else { |
| 99 | colorPalette[0] = c0r; colorPalette[1] = c0g; colorPalette[2] = c0b; |
| 100 | colorPalette[4] = c1r; colorPalette[5] = c1g; colorPalette[6] = c1b; |
| 101 | colorPalette[8] = (c0r + c1r) >> 1; |
| 102 | colorPalette[9] = (c0g + c1g) >> 1; |
| 103 | colorPalette[10] = (c0b + c1b) >> 1; |
| 104 | colorPalette[12] = 0; colorPalette[13] = 0; colorPalette[14] = 0; |
| 105 | } |
| 106 | |
| 107 | const baseIndex = (y * width + x) * 4; |
| 108 | for (let k = 0; k < 16; k++) { |
| 109 | const colorIdx = colorBits & 0x3; |
| 110 | colorBits >>>= 2; |
| 111 | |
| 112 | const j = k >> 2; |
| 113 | const i = k & 3; |
| 114 | const idx = baseIndex + ((j * width + i) << 2); |
| 115 | |
| 116 | rgba[idx + 0] = colorPalette[colorIdx * 4]; |
| 117 | rgba[idx + 1] = colorPalette[colorIdx * 4 + 1]; |
| 118 | rgba[idx + 2] = colorPalette[colorIdx * 4 + 2]; |
| 119 | |
| 120 | if (color0 <= color1 && colorIdx === 3) { |
| 121 | rgba[idx + 3] = 0; |
| 122 | } |
| 123 | else { |
| 124 | rgba[idx + 3] = 255; |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | return rgba; |
no test coverage detected