| 35 | } |
| 36 | |
| 37 | function encode(image: Bitmap, options: EncodeOptions = {}) { |
| 38 | scan( |
| 39 | { bitmap: image }, |
| 40 | 0, |
| 41 | 0, |
| 42 | image.width, |
| 43 | image.height, |
| 44 | function (_, __, index) { |
| 45 | const red = image.data[index + 0]!; |
| 46 | const green = image.data[index + 1]!; |
| 47 | const blue = image.data[index + 2]!; |
| 48 | const alpha = image.data[index + 3]!; |
| 49 | |
| 50 | image.data[index + 0] = alpha; |
| 51 | image.data[index + 1] = blue; |
| 52 | image.data[index + 2] = green; |
| 53 | image.data[index + 3] = red; |
| 54 | } |
| 55 | ); |
| 56 | |
| 57 | return BMP.encode({ ...image, ...options }).data; |
| 58 | } |
| 59 | |
| 60 | function decode(data: Buffer, options?: DecodeBmpOptions) { |
| 61 | const result = BMP.decode(data, options); |