MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / stbi__create_png_image

Function stbi__create_png_image

lite/example/cpp_example/mge/cv/stb_image.h:5321–5369  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5319}
5320
5321static int stbi__create_png_image(
5322 stbi__png* a, stbi_uc* image_data, stbi__uint32 image_data_len, int out_n,
5323 int depth, int color, int interlaced) {
5324 int bytes = (depth == 16 ? 2 : 1);
5325 int out_bytes = out_n * bytes;
5326 stbi_uc* final;
5327 int p;
5328 if (!interlaced)
5329 return stbi__create_png_image_raw(
5330 a, image_data, image_data_len, out_n, a->s->img_x, a->s->img_y, depth,
5331 color);
5332
5333 // de-interlacing
5334 final = (stbi_uc*)stbi__malloc_mad3(a->s->img_x, a->s->img_y, out_bytes, 0);
5335 if (!final)
5336 return stbi__err("outofmem", "Out of memory");
5337 for (p = 0; p < 7; ++p) {
5338 int xorig[] = {0, 4, 0, 2, 0, 1, 0};
5339 int yorig[] = {0, 0, 4, 0, 2, 0, 1};
5340 int xspc[] = {8, 8, 4, 4, 2, 2, 1};
5341 int yspc[] = {8, 8, 8, 4, 4, 2, 2};
5342 int i, j, x, y;
5343 // pass1_x[4] = 0, pass1_x[5] = 1, pass1_x[12] = 1
5344 x = (a->s->img_x - xorig[p] + xspc[p] - 1) / xspc[p];
5345 y = (a->s->img_y - yorig[p] + yspc[p] - 1) / yspc[p];
5346 if (x && y) {
5347 stbi__uint32 img_len = ((((a->s->img_n * x * depth) + 7) >> 3) + 1) * y;
5348 if (!stbi__create_png_image_raw(
5349 a, image_data, image_data_len, out_n, x, y, depth, color)) {
5350 STBI_FREE(final);
5351 return 0;
5352 }
5353 for (j = 0; j < y; ++j) {
5354 for (i = 0; i < x; ++i) {
5355 int out_y = j * yspc[p] + yorig[p];
5356 int out_x = i * xspc[p] + xorig[p];
5357 memcpy(final + out_y * a->s->img_x * out_bytes + out_x * out_bytes,
5358 a->out + (j * x + i) * out_bytes, out_bytes);
5359 }
5360 }
5361 STBI_FREE(a->out);
5362 image_data += img_len;
5363 image_data_len -= img_len;
5364 }
5365 }
5366 a->out = final;
5367
5368 return 1;
5369}
5370
5371static int stbi__compute_transparency(stbi__png* z, stbi_uc tc[3], int out_n) {
5372 stbi__context* s = z->s;

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