JPG loader: Refactor

This commit is contained in:
Kim Woelders 2018-07-21 19:37:24 +02:00
parent 5051ef9249
commit 1c095fd9be
1 changed files with 43 additions and 68 deletions

View File

@ -104,88 +104,63 @@ load(ImlibImage * im, ImlibProgressFunction progress,
count = 0; count = 0;
prevy = 0; prevy = 0;
if (cinfo.output_components > 1)
{
for (i = 0; i < cinfo.rec_outbuf_height; i++)
line[i] = data + (i * w * cinfo.output_components);
for (l = 0; l < h; l += cinfo.rec_outbuf_height)
{
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
scans = cinfo.rec_outbuf_height;
if ((h - l) < scans)
scans = h - l;
ptr = data;
for (y = 0; y < scans; y++)
{
for (x = 0; x < w; x++)
{
*ptr2 = (0xff000000) | ((ptr[0]) << 16) |
((ptr[1]) << 8) | (ptr[2]);
ptr += cinfo.output_components;
ptr2++;
}
}
if (progress)
{
int per;
per = (l * 100) / h; for (i = 0; i < cinfo.rec_outbuf_height; i++)
if (((per - count) >= progress_granularity) line[i] = data + (i * w * cinfo.output_components);
|| ((h - l) <= cinfo.rec_outbuf_height))
{ for (l = 0; l < h; l += cinfo.rec_outbuf_height)
count = per;
if (!progress
(im, per, 0, prevy, w, scans + l - prevy))
{
rc = 2;
goto done;
}
prevy = l + scans;
}
}
}
}
else if (cinfo.output_components == 1)
{ {
for (i = 0; i < cinfo.rec_outbuf_height; i++) jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height);
line[i] = data + (i * w); scans = cinfo.rec_outbuf_height;
for (l = 0; l < h; l += cinfo.rec_outbuf_height) if ((h - l) < scans)
scans = h - l;
ptr = data;
for (y = 0; y < scans; y++)
{ {
jpeg_read_scanlines(&cinfo, line, cinfo.rec_outbuf_height); switch (cinfo.out_color_space)
scans = cinfo.rec_outbuf_height;
if ((h - l) < scans)
scans = h - l;
ptr = data;
for (y = 0; y < scans; y++)
{ {
default:
free(data);
goto quit_error;
case JCS_GRAYSCALE:
for (x = 0; x < w; x++) for (x = 0; x < w; x++)
{ {
*ptr2 = (0xff000000) | ((ptr[0]) << 16) | *ptr2 = PIXEL_ARGB(0xff, ptr[0], ptr[0], ptr[0]);
((ptr[0]) << 8) | (ptr[0]);
ptr++; ptr++;
ptr2++; ptr2++;
} }
} break;
if (progress) case JCS_RGB:
{ case JCS_CMYK:
int per; for (x = 0; x < w; x++)
per = (l * 100) / h;
if (((per - count) >= progress_granularity)
|| ((h - l) <= cinfo.rec_outbuf_height))
{ {
count = per; *ptr2 = PIXEL_ARGB(0xff, ptr[0], ptr[1], ptr[2]);
if (!progress ptr += cinfo.output_components;
(im, per, 0, prevy, w, l + scans - prevy)) ptr2++;
{
rc = 2;
goto done;
}
prevy = l + scans;
} }
break;
}
}
if (progress)
{
int per;
per = (l * 100) / h;
if (((per - count) >= progress_granularity)
|| ((h - l) <= cinfo.rec_outbuf_height))
{
count = per;
if (!progress(im, per, 0, prevy, w, scans + l - prevy))
{
rc = 2;
goto done;
}
prevy = l + scans;
} }
} }
} }
done: done:
jpeg_finish_decompress(&cinfo); jpeg_finish_decompress(&cinfo);
free(data); free(data);