Skip to content
This repository was archived by the owner on Jul 26, 2025. It is now read-only.

Commit f1832a3

Browse files
authored
fix: 16-bit PNG encoding (#445)
rename bitDepth to depth
1 parent 6e2b57c commit f1832a3

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

src/save/__tests__/encodePng.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,12 @@ test('should encode what it decoded', () => {
88
const imgDup = decode(encodePng(img));
99
expect(imgDup).toMatchImage(img);
1010
});
11+
12+
test('should encode a 16bits image correctly', () => {
13+
const img = testUtils.load('formats/tif/grey16.tif');
14+
expect(img.size).toBe(2700);
15+
expect(img.bitDepth).toBe(16);
16+
const imgDup = decode(encodePng(img));
17+
expect(imgDup.bitDepth).toBe(16);
18+
expect(imgDup).toMatchImage(img);
19+
});

src/save/encodePng.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,12 @@ export function encodePng(
1414
image: Image,
1515
options?: EncodePngOptions,
1616
): Uint8Array {
17-
return encode(image.getRawImage(), options);
17+
const { bitDepth: depth, ...other } = image.getRawImage();
18+
return encode(
19+
{
20+
depth,
21+
...other,
22+
},
23+
options,
24+
);
1825
}
28 Bytes
Loading

0 commit comments

Comments
 (0)