mirror of https://github.com/nothings/stb.git
stbi__bmp_load() might not return correct Channel
Struct stbi__bmp_data in stbi__bmp_load() does not have initialize code for the: mr,mg,mb,ma, all_a as the code does in the beginning of " stbi__bmp_load()" function. When I tried to load 24bit BMP image, the number of channels returned was 4. Image displayed wrongly. When I done the same on the old stb_image (v1.33) image displayed correctly. On that code, the channel number returned was: 3. After debugging, I found out that difference was in the use of the named struct. The values of the parameters above were not initialized for the 24bit BMP when calling "stbi__bmp_parse_header()" function. Proposed solution: I added an init() function to the struct, and called it just before we initialized the "info.all_a" in "stbi__bmp_load()" function. Since the "stbi__bmp_parse_header()" is called only from stbi__bmp_load(), I think my suggestion is safe.pull/243/head
parent
955dfe991b
commit
56392668cb
|
@ -4603,6 +4603,11 @@ typedef struct
|
||||||
{
|
{
|
||||||
int bpp, offset, hsz;
|
int bpp, offset, hsz;
|
||||||
unsigned int mr,mg,mb,ma, all_a;
|
unsigned int mr,mg,mb,ma, all_a;
|
||||||
|
// added by snagar.dev - missing initialization. Fix the channel value for 24bit BMP files
|
||||||
|
void init()
|
||||||
|
{
|
||||||
|
mr = mg = mb = ma = all_a = 0;
|
||||||
|
}
|
||||||
} stbi__bmp_data;
|
} stbi__bmp_data;
|
||||||
|
|
||||||
static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info)
|
static void *stbi__bmp_parse_header(stbi__context *s, stbi__bmp_data *info)
|
||||||
|
@ -4699,6 +4704,7 @@ static stbi_uc *stbi__bmp_load(stbi__context *s, int *x, int *y, int *comp, int
|
||||||
int flip_vertically, pad, target;
|
int flip_vertically, pad, target;
|
||||||
stbi__bmp_data info;
|
stbi__bmp_data info;
|
||||||
|
|
||||||
|
info.init(); // added by saar
|
||||||
info.all_a = 255;
|
info.all_a = 255;
|
||||||
if (stbi__bmp_parse_header(s, &info) == NULL)
|
if (stbi__bmp_parse_header(s, &info) == NULL)
|
||||||
return NULL; // error code already set
|
return NULL; // error code already set
|
||||||
|
|
Loading…
Reference in New Issue