Skip to content

Commit

Permalink
Added support for monochrome (1 bit per pixel) format for use on ther…
Browse files Browse the repository at this point in the history
…mal printers
  • Loading branch information
yegor-pelykh committed Nov 26, 2022
1 parent b7a7be2 commit 40bfd2f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/formats/bmp-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export class BmpDecoder implements Decoder {
const row = this.input.readBytes(rowStride);
for (let x = 0; x < image.width; ) {
this.info.decodeRgba(row, (color) => {
return image.setPixel(x++, line, color);
return image.setPixelSafe(x++, line, color);
});
}
}
Expand Down
8 changes: 7 additions & 1 deletion src/formats/bmp/bmp-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,13 @@ export class BmpInfo implements DecodeInfo {

public decodeRgba(input: InputBuffer, pixel: (color: number) => void): void {
if (this._colorPalette !== undefined) {
if (this._bpp === 4) {
if (this._bpp === 1) {
const b = input.readByte().toString(2).padStart(8, '0');
for (let i = 0; i < 8; i++) {
pixel(this._colorPalette![parseInt(b[i])]);
}
return;
} else if (this._bpp === 4) {
const b = input.readByte();
const left = b >> 4;
const right = b & 0x0f;
Expand Down
Binary file added test/res/bmp/buck_1.bmp
Binary file not shown.

0 comments on commit 40bfd2f

Please sign in to comment.