rjpeg_load_jpeg_image - cleanup
This commit is contained in:
parent
fae5eb89df
commit
fc37ef5c7d
|
@ -2395,10 +2395,7 @@ static uint8_t *rjpeg_load_jpeg_image(rjpeg__jpeg *z, unsigned *out_x, unsigned
|
||||||
|
|
||||||
/* load a jpeg image from whichever source, but leave in YCbCr format */
|
/* load a jpeg image from whichever source, but leave in YCbCr format */
|
||||||
if (!rjpeg__decode_jpeg_image(z))
|
if (!rjpeg__decode_jpeg_image(z))
|
||||||
{
|
goto error;
|
||||||
rjpeg__cleanup_jpeg(z);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* determine actual number of components to generate */
|
/* determine actual number of components to generate */
|
||||||
n = req_comp ? req_comp : z->s->img_n;
|
n = req_comp ? req_comp : z->s->img_n;
|
||||||
|
@ -2419,10 +2416,7 @@ static uint8_t *rjpeg_load_jpeg_image(rjpeg__jpeg *z, unsigned *out_x, unsigned
|
||||||
* with upsample factor of 4 */
|
* with upsample factor of 4 */
|
||||||
z->img_comp[k].linebuf = (uint8_t *) malloc(z->s->img_x + 3);
|
z->img_comp[k].linebuf = (uint8_t *) malloc(z->s->img_x + 3);
|
||||||
if (!z->img_comp[k].linebuf)
|
if (!z->img_comp[k].linebuf)
|
||||||
{
|
goto error;
|
||||||
rjpeg__cleanup_jpeg(z);
|
|
||||||
return rjpeg__errpuc("outofmem", "Out of memory");
|
|
||||||
}
|
|
||||||
|
|
||||||
r->hs = z->img_h_max / z->img_comp[k].h;
|
r->hs = z->img_h_max / z->img_comp[k].h;
|
||||||
r->vs = z->img_v_max / z->img_comp[k].v;
|
r->vs = z->img_v_max / z->img_comp[k].v;
|
||||||
|
@ -2446,10 +2440,7 @@ static uint8_t *rjpeg_load_jpeg_image(rjpeg__jpeg *z, unsigned *out_x, unsigned
|
||||||
output = (uint8_t *) malloc(n * z->s->img_x * z->s->img_y + 1);
|
output = (uint8_t *) malloc(n * z->s->img_x * z->s->img_y + 1);
|
||||||
|
|
||||||
if (!output)
|
if (!output)
|
||||||
{
|
goto error;
|
||||||
rjpeg__cleanup_jpeg(z);
|
|
||||||
return rjpeg__errpuc("outofmem", "Out of memory");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* now go ahead and resample */
|
/* now go ahead and resample */
|
||||||
for (j=0; j < z->s->img_y; ++j)
|
for (j=0; j < z->s->img_y; ++j)
|
||||||
|
@ -2458,8 +2449,9 @@ static uint8_t *rjpeg_load_jpeg_image(rjpeg__jpeg *z, unsigned *out_x, unsigned
|
||||||
for (k=0; k < decode_n; ++k)
|
for (k=0; k < decode_n; ++k)
|
||||||
{
|
{
|
||||||
rjpeg__resample *r = &res_comp[k];
|
rjpeg__resample *r = &res_comp[k];
|
||||||
int y_bot = r->ystep >= (r->vs >> 1);
|
int y_bot = r->ystep >= (r->vs >> 1);
|
||||||
coutput[k] = r->resample(z->img_comp[k].linebuf,
|
|
||||||
|
coutput[k] = r->resample(z->img_comp[k].linebuf,
|
||||||
y_bot ? r->line1 : r->line0,
|
y_bot ? r->line1 : r->line0,
|
||||||
y_bot ? r->line0 : r->line1,
|
y_bot ? r->line0 : r->line1,
|
||||||
r->w_lores, r->hs);
|
r->w_lores, r->hs);
|
||||||
|
@ -2505,6 +2497,12 @@ static uint8_t *rjpeg_load_jpeg_image(rjpeg__jpeg *z, unsigned *out_x, unsigned
|
||||||
if (comp)
|
if (comp)
|
||||||
*comp = z->s->img_n; /* report original components, not output */
|
*comp = z->s->img_n; /* report original components, not output */
|
||||||
return output;
|
return output;
|
||||||
|
|
||||||
|
error:
|
||||||
|
if (output)
|
||||||
|
free(output);
|
||||||
|
rjpeg__cleanup_jpeg(z);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static unsigned char *rjpeg__jpeg_load(rjpeg__context *s, unsigned *x, unsigned *y, int *comp, int req_comp)
|
static unsigned char *rjpeg__jpeg_load(rjpeg__context *s, unsigned *x, unsigned *y, int *comp, int req_comp)
|
||||||
|
|
Loading…
Reference in New Issue