Skip to content

Commit

Permalink
Fix icon item image size to ignore biImageSize when biCompression is …
Browse files Browse the repository at this point in the history
…BI_RGB
  • Loading branch information
jet2jet committed Oct 8, 2024
1 parent 2b80e09 commit 695e9ac
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/main/data/IconItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,17 @@ export default class IconItem {
// round up to 4 bytes (32 bit)
const widthBytes = roundUp(bi.bitCount * Math.abs(bi.width), 32) / 8;
const absActualHeight = Math.abs(bi.height) / 2;
const size = sizeImage || widthBytes * absActualHeight;
// sizeImage may be weird if compression is 0 (BI_RGB), so
// we calculate actual bitmap size from width and height
const size =
bi.compression !== 0 && sizeImage !== 0
? sizeImage
: widthBytes * absActualHeight;
if (size + offset > totalSize) {
throw new Error(
`Unexpected bitmap data in icon: bitmap size ${size} is larger than ${totalSize} - ${offset}`
);
}
this._pixels = allocatePartialBinary(view, offset, size);
offset += size;
const maskSize = calcMaskSize(bi.width, absActualHeight);
Expand Down

0 comments on commit 695e9ac

Please sign in to comment.