forked from old/legacy-imlib2
Savers: Simplify progress handling
This commit is contained in:
parent
0f5b4fb10a
commit
10e21579fa
|
@ -86,8 +86,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
int rc;
|
||||
FILE *f;
|
||||
DATA32 *ptr;
|
||||
int y, pl = 0, alpha = 0;
|
||||
char pper = 0;
|
||||
int y, alpha = 0;
|
||||
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
DATA32 *buf = (DATA32 *) malloc(im->w * 4);
|
||||
|
@ -120,23 +119,11 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
fwrite(ptr, im->w, 4, f);
|
||||
#endif
|
||||
ptr += im->w;
|
||||
if (progress)
|
||||
{
|
||||
char per;
|
||||
int l;
|
||||
|
||||
per = (char)((100 * y) / im->h);
|
||||
if (((per - pper) >= progress_granularity) || (y == (im->h - 1)))
|
||||
{
|
||||
l = y - pl;
|
||||
if (!progress(im, per, 0, (y - l), im->w, l))
|
||||
{
|
||||
rc = LOAD_BREAK;
|
||||
goto quit;
|
||||
}
|
||||
pper = per;
|
||||
pl = y;
|
||||
}
|
||||
if (im->lc && __imlib_LoadProgressRows(im, y, 1))
|
||||
{
|
||||
rc = LOAD_BREAK;
|
||||
goto quit;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -141,11 +141,12 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
}
|
||||
if (fwrite(row, sizeof(uint16_t), rowlen, f) != rowlen)
|
||||
goto quit;
|
||||
}
|
||||
|
||||
if (progress)
|
||||
{
|
||||
progress(im, 100, 0, 0, im->w, im->h);
|
||||
if (im->lc && __imlib_LoadProgressRows(im, i, 1))
|
||||
{
|
||||
rc = LOAD_BREAK;
|
||||
goto quit;
|
||||
}
|
||||
}
|
||||
|
||||
rc = LOAD_SUCCESS;
|
||||
|
|
|
@ -196,8 +196,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
JSAMPROW *jbuf;
|
||||
int y, quality, compression;
|
||||
ImlibImageTag *tag;
|
||||
int i, j, pl;
|
||||
char pper;
|
||||
int i, j;
|
||||
|
||||
/* allocate a small buffer to convert image data */
|
||||
buf = malloc(im->w * 3 * sizeof(DATA8));
|
||||
|
@ -251,16 +250,13 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
quality = 100;
|
||||
|
||||
/* set up jepg compression parameters */
|
||||
y = 0;
|
||||
pl = 0;
|
||||
pper = 0;
|
||||
jpeg_set_defaults(&cinfo);
|
||||
jpeg_set_quality(&cinfo, quality, TRUE);
|
||||
jpeg_start_compress(&cinfo, TRUE);
|
||||
/* get the start pointer */
|
||||
ptr = im->data;
|
||||
/* go one scanline at a time... and save */
|
||||
while (cinfo.next_scanline < cinfo.image_height)
|
||||
for (y = 0; cinfo.next_scanline < cinfo.image_height; y++)
|
||||
{
|
||||
/* convcert scaline from ARGB to RGB packed */
|
||||
for (j = 0, i = 0; i < im->w; i++)
|
||||
|
@ -274,24 +270,11 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
/* write scanline */
|
||||
jbuf = (JSAMPROW *) (&buf);
|
||||
jpeg_write_scanlines(&cinfo, jbuf, 1);
|
||||
y++;
|
||||
if (progress)
|
||||
{
|
||||
char per;
|
||||
int l;
|
||||
|
||||
per = (char)((100 * y) / im->h);
|
||||
if (((per - pper) >= progress_granularity) || (y == (im->h - 1)))
|
||||
{
|
||||
l = y - pl;
|
||||
if (!progress(im, per, 0, (y - l), im->w, l))
|
||||
{
|
||||
rc = LOAD_BREAK;
|
||||
goto quit;
|
||||
}
|
||||
pper = per;
|
||||
pl = y;
|
||||
}
|
||||
if (im->lc && __imlib_LoadProgressRows(im, y, 1))
|
||||
{
|
||||
rc = LOAD_BREAK;
|
||||
goto quit;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -202,7 +202,8 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
png_bytep row_ptr, data;
|
||||
png_color_8 sig_bit;
|
||||
ImlibImageTag *tag;
|
||||
int quality = 75, compression = 3, num_passes = 1, pass;
|
||||
int quality = 75, compression = 3;
|
||||
int pass, n_passes = 1;
|
||||
|
||||
f = fopen(im->real_file, "wb");
|
||||
if (!f)
|
||||
|
@ -295,13 +296,16 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
png_set_packing(png_ptr);
|
||||
|
||||
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||
num_passes = png_set_interlace_handling(png_ptr);
|
||||
n_passes = png_set_interlace_handling(png_ptr);
|
||||
#endif
|
||||
|
||||
for (pass = 0; pass < num_passes; pass++)
|
||||
for (pass = 0; pass < n_passes; pass++)
|
||||
{
|
||||
ptr = im->data;
|
||||
|
||||
if (im->lc)
|
||||
__imlib_LoadProgressSetPass(im, pass, n_passes);
|
||||
|
||||
for (y = 0; y < im->h; y++)
|
||||
{
|
||||
if (im->flags & F_HAS_ALPHA)
|
||||
|
@ -320,24 +324,12 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
}
|
||||
png_write_rows(png_ptr, &row_ptr, 1);
|
||||
|
||||
if (progress)
|
||||
if (im->lc && __imlib_LoadProgressRows(im, y, 1))
|
||||
{
|
||||
char per;
|
||||
int l, pl = 0, pper = 0;
|
||||
|
||||
per = 100 * (pass + y / (float)im->h) / num_passes;
|
||||
if ((per - pper) >= progress_granularity)
|
||||
{
|
||||
l = y - pl;
|
||||
if (!progress(im, per, 0, (y - l), im->w, l))
|
||||
{
|
||||
rc = LOAD_BREAK;
|
||||
goto quit;
|
||||
}
|
||||
pper = per;
|
||||
pl = y;
|
||||
}
|
||||
rc = LOAD_BREAK;
|
||||
goto quit;
|
||||
}
|
||||
|
||||
ptr += im->w;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,6 @@
|
|||
#include "loader_common.h"
|
||||
#include <ctype.h>
|
||||
|
||||
static int
|
||||
do_progress(ImlibImage * im, ImlibProgressFunction progress,
|
||||
char progress_granularity, char *pper, int *py, int y)
|
||||
{
|
||||
int rc = 0;
|
||||
int per;
|
||||
|
||||
per = (100 * (y + 1)) / im->h;
|
||||
if (per == 100 || per >= *pper + progress_granularity)
|
||||
{
|
||||
rc = !progress(im, per, 0, *py, im->w, y + 1 - *py);
|
||||
*py = y + 1;
|
||||
*pper += progress_granularity;
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
char
|
||||
load(ImlibImage * im, ImlibProgressFunction progress,
|
||||
char progress_granularity, char load_data)
|
||||
|
@ -409,8 +391,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
FILE *f;
|
||||
DATA8 *buf, *bptr;
|
||||
DATA32 *ptr;
|
||||
int x, y, pl = 0;
|
||||
char pper = 0;
|
||||
int x, y;
|
||||
|
||||
f = fopen(im->real_file, "wb");
|
||||
if (!f)
|
||||
|
@ -444,8 +425,8 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
bptr += 4;
|
||||
}
|
||||
fwrite(buf, im->w * 4, 1, f);
|
||||
if (progress &&
|
||||
do_progress(im, progress, progress_granularity, &pper, &pl, y))
|
||||
|
||||
if (im->lc && __imlib_LoadProgressRows(im, y, 1))
|
||||
goto quit_progress;
|
||||
}
|
||||
}
|
||||
|
@ -466,8 +447,8 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
bptr += 3;
|
||||
}
|
||||
fwrite(buf, im->w * 3, 1, f);
|
||||
if (progress &&
|
||||
do_progress(im, progress, progress_granularity, &pper, &pl, y))
|
||||
|
||||
if (im->lc && __imlib_LoadProgressRows(im, y, 1))
|
||||
goto quit_progress;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,8 +69,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
FILE *f;
|
||||
DATA32 *dataptr;
|
||||
unsigned char *buf, *bufptr;
|
||||
int y, pl = 0;
|
||||
char pper = 0;
|
||||
int y;
|
||||
tga_header header;
|
||||
|
||||
f = fopen(im->real_file, "wb");
|
||||
|
@ -132,23 +131,10 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
} /* end for (each pixel in row) */
|
||||
|
||||
/* report progress every row */
|
||||
if (progress)
|
||||
if (im->lc && __imlib_LoadProgressRows(im, y, 1))
|
||||
{
|
||||
char per;
|
||||
int l;
|
||||
|
||||
per = (char)((100 * y) / im->h);
|
||||
if (((per - pper) >= progress_granularity) || (y == (im->h - 1)))
|
||||
{
|
||||
l = y - pl;
|
||||
if (!progress(im, per, 0, (y - l), im->w, l))
|
||||
{
|
||||
rc = LOAD_BREAK;
|
||||
goto quit;
|
||||
}
|
||||
pper = per;
|
||||
pl = y;
|
||||
}
|
||||
rc = LOAD_BREAK;
|
||||
goto quit;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -383,8 +383,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
int x, y;
|
||||
uint8 r, g, b, a = 0;
|
||||
int has_alpha = IMAGE_HAS_ALPHA(im);
|
||||
int i = 0, pl = 0;
|
||||
char pper = 0;
|
||||
int i;
|
||||
|
||||
/* By default uses patent-free use COMPRESSION_DEFLATE,
|
||||
* another lossless compression technique */
|
||||
|
@ -497,19 +496,10 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
|||
if (!TIFFWriteScanline(tif, buf, y, 0))
|
||||
goto quit;
|
||||
|
||||
if (progress)
|
||||
if (im->lc && __imlib_LoadProgressRows(im, y, 1))
|
||||
{
|
||||
char per;
|
||||
int l;
|
||||
|
||||
per = (char)((100 * y) / im->h);
|
||||
if ((per - pper) >= progress_granularity)
|
||||
{
|
||||
l = y - pl;
|
||||
(*progress) (im, per, 0, (y - l), im->w, l);
|
||||
pper = per;
|
||||
pl = y;
|
||||
}
|
||||
rc = LOAD_BREAK;
|
||||
goto quit;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue