Skip to content

Commit

Permalink
Merge pull request #56 from jet2jet/feature/fix_icon_item_image_size
Browse files Browse the repository at this point in the history
Fix icon item image size to ignore biImageSize when biCompression is BI_RGB
  • Loading branch information
jet2jet committed Oct 8, 2024
1 parent 8a65a6d commit 09a07d4
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 09a07d4

Please sign in to comment.