Skip to content

Commit

Permalink
fix: Support array sample format (#51)
Browse files Browse the repository at this point in the history
A floating point image that was saved from PhotoShop sets "SampleFormat" to [3, 3, 3].
  • Loading branch information
chubei-urus authored Apr 8, 2024
1 parent de5d521 commit 42d778b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
Binary file added img/array-sample-format.tif
Binary file not shown.
8 changes: 8 additions & 0 deletions src/__tests__/decode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ const files: TiffFile[] = [
components: 1,
alpha: false,
},
{
name: 'array-sample-format.tif',
width: 2,
height: 2,
bitsPerSample: 32,
components: 3,
alpha: false,
},
];
const cases = files.map(
(file) => [file.name, file, readImage(file.name)] as const,
Expand Down
3 changes: 2 additions & 1 deletion src/tiffIfd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ export default class TiffIfd extends Ifd {
return this.get('Predictor') || 1;
}
public get sampleFormat(): number {
return this.get('SampleFormat') || 1;
const data = alwaysArray(this.get('SampleFormat') || 1);
return data[0];
}
public get sMinSampleValue(): number {
return this.get('SMinSampleValue') || this.minSampleValue;
Expand Down

0 comments on commit 42d778b

Please sign in to comment.