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

Function load_jpeg_image

include/stb/stb_image.h:3865–4026  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3863}
3864
3865static stbi_uc *load_jpeg_image(stbi__jpeg *z, int *out_x, int *out_y, int *comp, int req_comp)
3866{
3867 int n, decode_n, is_rgb;
3868 z->s->img_n = 0; // make stbi__cleanup_jpeg safe
3869
3870 // validate req_comp
3871 if (req_comp < 0 || req_comp > 4) return stbi__errpuc("bad req_comp", "Internal error");
3872
3873 // load a jpeg image from whichever source, but leave in YCbCr format
3874 if (!stbi__decode_jpeg_image(z)) { stbi__cleanup_jpeg(z); return NULL; }
3875
3876 // determine actual number of components to generate
3877 n = req_comp ? req_comp : z->s->img_n >= 3 ? 3 : 1;
3878
3879 is_rgb = z->s->img_n == 3 && (z->rgb == 3 || (z->app14_color_transform == 0 && !z->jfif));
3880
3881 if (z->s->img_n == 3 && n < 3 && !is_rgb)
3882 decode_n = 1;
3883 else
3884 decode_n = z->s->img_n;
3885
3886 // nothing to do if no components requested; check this now to avoid
3887 // accessing uninitialized coutput[0] later
3888 if (decode_n <= 0) { stbi__cleanup_jpeg(z); return NULL; }
3889
3890 // resample and color-convert
3891 {
3892 int k;
3893 unsigned int i,j;
3894 stbi_uc *output;
3895 stbi_uc *coutput[4] = { NULL, NULL, NULL, NULL };
3896
3897 stbi__resample res_comp[4];
3898
3899 for (k=0; k < decode_n; ++k) {
3900 stbi__resample *r = &res_comp[k];
3901
3902 // allocate line buffer big enough for upsampling off the edges
3903 // with upsample factor of 4
3904 z->img_comp[k].linebuf = (stbi_uc *) stbi__malloc(z->s->img_x + 3);
3905 if (!z->img_comp[k].linebuf) { stbi__cleanup_jpeg(z); return stbi__errpuc("outofmem", "Out of memory"); }
3906
3907 r->hs = z->img_h_max / z->img_comp[k].h;
3908 r->vs = z->img_v_max / z->img_comp[k].v;
3909 r->ystep = r->vs >> 1;
3910 r->w_lores = (z->s->img_x + r->hs-1) / r->hs;
3911 r->ypos = 0;
3912 r->line0 = r->line1 = z->img_comp[k].data;
3913
3914 if (r->hs == 1 && r->vs == 1) r->resample = resample_row_1;
3915 else if (r->hs == 1 && r->vs == 2) r->resample = stbi__resample_row_v_2;
3916 else if (r->hs == 2 && r->vs == 1) r->resample = stbi__resample_row_h_2;
3917 else if (r->hs == 2 && r->vs == 2) r->resample = z->resample_row_hv_2_kernel;
3918 else r->resample = stbi__resample_row_generic;
3919 }
3920
3921 // can't error after this so, this is safe
3922 output = (stbi_uc *) stbi__malloc_mad3(n, z->s->img_x, z->s->img_y, 1);

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