Browse Source

stb_image: Account for tRNS chunk in non-paletted images.

So we report channels_in_file correctly.

Fixes #329.
Fabian Giesen 8 years ago
parent
commit
0fbbda56fa
1 changed files with 3 additions and 0 deletions
  1. 3 0
      stb_image.h

+ 3 - 0
stb_image.h

@@ -4822,6 +4822,9 @@ static int stbi__parse_png_file(stbi__png *z, int scan, int req_comp)
                if (req_comp >= 3) s->img_out_n = req_comp;
                if (req_comp >= 3) s->img_out_n = req_comp;
                if (!stbi__expand_png_palette(z, palette, pal_len, s->img_out_n))
                if (!stbi__expand_png_palette(z, palette, pal_len, s->img_out_n))
                   return 0;
                   return 0;
+            } else if (has_trans) {
+               // non-paletted image with tRNS -> source image has (constant) alpha
+               ++s->img_n;
             }
             }
             STBI_FREE(z->expanded); z->expanded = NULL;
             STBI_FREE(z->expanded); z->expanded = NULL;
             return 1;
             return 1;