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

Function load_jpeg_image

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

Source from the content-addressed store, hash-verified

4171}
4172
4173static stbi_uc* load_jpeg_image(
4174 stbi__jpeg* z, int* out_x, int* out_y, int* comp, int req_comp) {
4175 int n, decode_n, is_rgb;
4176 z->s->img_n = 0; // make stbi__cleanup_jpeg safe
4177
4178 // validate req_comp
4179 if (req_comp < 0 || req_comp > 4)
4180 return stbi__errpuc("bad req_comp", "Internal error");
4181
4182 // load a jpeg image from whichever source, but leave in YCbCr format
4183 if (!stbi__decode_jpeg_image(z)) {
4184 stbi__cleanup_jpeg(z);
4185 return NULL;
4186 }
4187
4188 // determine actual number of components to generate
4189 n = req_comp ? req_comp : z->s->img_n >= 3 ? 3 : 1;
4190
4191 is_rgb = z->s->img_n == 3 &&
4192 (z->rgb == 3 || (z->app14_color_transform == 0 && !z->jfif));
4193
4194 if (z->s->img_n == 3 && n < 3 && !is_rgb)
4195 decode_n = 1;
4196 else
4197 decode_n = z->s->img_n;
4198
4199 // nothing to do if no components requested; check this now to avoid
4200 // accessing uninitialized coutput[0] later
4201 if (decode_n <= 0) {
4202 stbi__cleanup_jpeg(z);
4203 return NULL;
4204 }
4205
4206 // resample and color-convert
4207 {
4208 int k;
4209 unsigned int i, j;
4210 stbi_uc* output;
4211 stbi_uc* coutput[4] = {NULL, NULL, NULL, NULL};
4212
4213 stbi__resample res_comp[4];
4214
4215 for (k = 0; k < decode_n; ++k) {
4216 stbi__resample* r = &res_comp[k];
4217
4218 // allocate line buffer big enough for upsampling off the edges
4219 // with upsample factor of 4
4220 z->img_comp[k].linebuf = (stbi_uc*)stbi__malloc(z->s->img_x + 3);
4221 if (!z->img_comp[k].linebuf) {
4222 stbi__cleanup_jpeg(z);
4223 return stbi__errpuc("outofmem", "Out of memory");
4224 }
4225
4226 r->hs = z->img_h_max / z->img_comp[k].h;
4227 r->vs = z->img_v_max / z->img_comp[k].v;
4228 r->ystep = r->vs >> 1;
4229 r->w_lores = (z->s->img_x + r->hs - 1) / r->hs;
4230 r->ypos = 0;

Callers 1

stbi__jpeg_loadFunction · 0.85

Calls 6

stbi__decode_jpeg_imageFunction · 0.85
stbi__cleanup_jpegFunction · 0.85
stbi__mallocFunction · 0.85
stbi__malloc_mad3Function · 0.85
stbi__blinn_8x8Function · 0.85
stbi__compute_yFunction · 0.85

Tested by

no test coverage detected