MCPcopy Create free account
hub / github.com/ARM-software/ComputeLibrary / stbi__create_png_image

Function stbi__create_png_image

include/stb/stb_image.h:4861–4904  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

stbi__parse_png_fileFunction · 0.85

Calls 3

stbi__malloc_mad3Function · 0.85
stbi__errFunction · 0.85

Tested by

no test coverage detected