jimp-dev / jimp-dev/bmp-ts

Alpha pixels are set to zero on all opaque pixel formats

Open
#31 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
18
Forks
7
PR merge metrics
No merged PRs in 30d

Description

For whatever reason, this library gets handling alpha all wrong.

The output `data` buffer seems to store the pixel data as RGBA or ABGR:
https://github.com/jimp-dev/bmp-ts/blob/2521cce93dbc770380940483af1a546bc42d0ed6/src/decoder.ts#L60-L63

However seems like all code that handles opaque pixel formats sets the alpha channel to zero which wasn't the behavior I expected and requires anyone trying to use this library to check whether the input BMP file has an alpha channel and handle it accordingly in their code. The alpha channel of any opaque pixels should be set to `255`.

https://github.com/jimp-dev/bmp-ts/blob/2521cce93dbc770380940483af1a546bc42d0ed6/src/decoder.ts#L438-L452

The documentation is also a bit unclear, endianess is pretty confusing when it comes to handling pixels, and since the library by default always decodes the image data to XBGR (because one might expect it's the same as input BMP), I think that the `toRGBA` option documentation should be clarified, "reverses the pixel byte order from ABGR to RGBA making it compatible with other libraries like pngjs"

Additionally said option is completely ignored if you pass in a palettized image.

https://github.com/jimp-dev/bmp-ts/blob/2521cce93dbc770380940483af1a546bc42d0ed6/src/decoder.ts#L326-L329

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.