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