| 4954 | } |
| 4955 | |
| 4956 | static int stbi__expand_png_palette(stbi__png *a, stbi_uc *palette, int len, int pal_img_n) |
| 4957 | { |
| 4958 | stbi__uint32 i, pixel_count = a->s->img_x * a->s->img_y; |
| 4959 | stbi_uc *p, *temp_out, *orig = a->out; |
| 4960 | |
| 4961 | p = (stbi_uc *) stbi__malloc_mad2(pixel_count, pal_img_n, 0); |
| 4962 | if (p == NULL) return stbi__err("outofmem", "Out of memory"); |
| 4963 | |
| 4964 | // between here and free(out) below, exitting would leak |
| 4965 | temp_out = p; |
| 4966 | |
| 4967 | if (pal_img_n == 3) { |
| 4968 | for (i=0; i < pixel_count; ++i) { |
| 4969 | int n = orig[i]*4; |
| 4970 | p[0] = palette[n ]; |
| 4971 | p[1] = palette[n+1]; |
| 4972 | p[2] = palette[n+2]; |
| 4973 | p += 3; |
| 4974 | } |
| 4975 | } else { |
| 4976 | for (i=0; i < pixel_count; ++i) { |
| 4977 | int n = orig[i]*4; |
| 4978 | p[0] = palette[n ]; |
| 4979 | p[1] = palette[n+1]; |
| 4980 | p[2] = palette[n+2]; |
| 4981 | p[3] = palette[n+3]; |
| 4982 | p += 4; |
| 4983 | } |
| 4984 | } |
| 4985 | STBI_FREE(a->out); |
| 4986 | a->out = temp_out; |
| 4987 | |
| 4988 | STBI_NOTUSED(len); |
| 4989 | |
| 4990 | return 1; |
| 4991 | } |
| 4992 | |
| 4993 | static int stbi__unpremultiply_on_load_global = 0; |
| 4994 | static int stbi__de_iphone_flag_global = 0; |
no test coverage detected