| 4858 | } |
| 4859 | |
| 4860 | static int stbi__create_png_image(stbi__png *a, stbi_uc *image_data, stbi__uint32 image_data_len, int out_n, int depth, int color, int interlaced) |
| 4861 | { |
| 4862 | int bytes = (depth == 16 ? 2 : 1); |
| 4863 | int out_bytes = out_n * bytes; |
| 4864 | stbi_uc *final; |
| 4865 | int p; |
| 4866 | if (!interlaced) |
| 4867 | return stbi__create_png_image_raw(a, image_data, image_data_len, out_n, a->s->img_x, a->s->img_y, depth, color); |
| 4868 | |
| 4869 | // de-interlacing |
| 4870 | final = (stbi_uc *) stbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0); |
| 4871 | if (!final) return stbi__err("outofmem", "Out of memory"); |
| 4872 | for (p=0; p < 7; ++p) { |
| 4873 | int xorig[] = { 0,4,0,2,0,1,0 }; |
| 4874 | int yorig[] = { 0,0,4,0,2,0,1 }; |
| 4875 | int xspc[] = { 8,8,4,4,2,2,1 }; |
| 4876 | int yspc[] = { 8,8,8,4,4,2,2 }; |
| 4877 | int i,j,x,y; |
| 4878 | // pass1_x[4] = 0, pass1_x[5] = 1, pass1_x[12] = 1 |
| 4879 | x = (a->s->img_x - xorig[p] + xspc[p]-1) / xspc[p]; |
| 4880 | y = (a->s->img_y - yorig[p] + yspc[p]-1) / yspc[p]; |
| 4881 | if (x && y) { |
| 4882 | stbi__uint32 img_len = ((((a->s->img_n * x * depth) + 7) >> 3) + 1) * y; |
| 4883 | if (!stbi__create_png_image_raw(a, image_data, image_data_len, out_n, x, y, depth, color)) { |
| 4884 | STBI_FREE(final); |
| 4885 | return 0; |
| 4886 | } |
| 4887 | for (j=0; j < y; ++j) { |
| 4888 | for (i=0; i < x; ++i) { |
| 4889 | int out_y = j*yspc[p]+yorig[p]; |
| 4890 | int out_x = i*xspc[p]+xorig[p]; |
| 4891 | memcpy(final + out_y*a->s->img_x*out_bytes + out_x*out_bytes, |
| 4892 | a->out + (j*x+i)*out_bytes, out_bytes); |
| 4893 | } |
| 4894 | } |
| 4895 | STBI_FREE(a->out); |
| 4896 | image_data += img_len; |
| 4897 | image_data_len -= img_len; |
| 4898 | } |
| 4899 | } |
| 4900 | a->out = final; |
| 4901 | |
| 4902 | return 1; |
| 4903 | } |
| 4904 | |
| 4905 | static int stbi__compute_transparency(stbi__png *z, stbi_uc tc[3], int out_n) |
| 4906 | { |
no test coverage detected