forked from old/legacy-imlib2
tillman's png interlacing support patch! yum!
SVN revision: 8261
This commit is contained in:
parent
f5df18e3b7
commit
18affb5b71
|
@ -252,7 +252,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
||||||
int pl = 0;
|
int pl = 0;
|
||||||
char pper = 0;
|
char pper = 0;
|
||||||
ImlibImageTag *tag;
|
ImlibImageTag *tag;
|
||||||
int quality = 75, compression = 3;
|
int quality = 75, compression = 3, num_passes = 1, pass;
|
||||||
|
|
||||||
f = fopen(im->real_file, "wb");
|
f = fopen(im->real_file, "wb");
|
||||||
if (!f)
|
if (!f)
|
||||||
|
@ -277,11 +277,21 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
||||||
png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr);
|
png_destroy_info_struct(png_ptr, (png_infopp) & info_ptr);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* check whether we should use interlacing */
|
||||||
|
if ((tag = __imlib_GetTag(im, "interlacing")) && tag->val)
|
||||||
|
{
|
||||||
|
#ifdef PNG_WRITE_INTERLACING_SUPPORTED
|
||||||
|
png_ptr->interlaced = PNG_INTERLACE_ADAM7;
|
||||||
|
num_passes = png_set_interlace_handling(png_ptr);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
png_init_io(png_ptr, f);
|
png_init_io(png_ptr, f);
|
||||||
if (im->flags & F_HAS_ALPHA)
|
if (im->flags & F_HAS_ALPHA)
|
||||||
{
|
{
|
||||||
png_set_IHDR(png_ptr, info_ptr, im->w, im->h, 8,
|
png_set_IHDR(png_ptr, info_ptr, im->w, im->h, 8,
|
||||||
PNG_COLOR_TYPE_RGB_ALPHA, PNG_INTERLACE_NONE,
|
PNG_COLOR_TYPE_RGB_ALPHA, png_ptr->interlaced,
|
||||||
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE);
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
png_set_swap_alpha(png_ptr);
|
png_set_swap_alpha(png_ptr);
|
||||||
|
@ -292,7 +302,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
png_set_IHDR(png_ptr, info_ptr, im->w, im->h, 8, PNG_COLOR_TYPE_RGB,
|
png_set_IHDR(png_ptr, info_ptr, im->w, im->h, 8, PNG_COLOR_TYPE_RGB,
|
||||||
PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE,
|
png_ptr->interlaced, PNG_COMPRESSION_TYPE_BASE,
|
||||||
PNG_FILTER_TYPE_BASE);
|
PNG_FILTER_TYPE_BASE);
|
||||||
data = malloc(im->w * 3 * sizeof(char));
|
data = malloc(im->w * 3 * sizeof(char));
|
||||||
}
|
}
|
||||||
|
@ -339,7 +349,10 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
||||||
png_set_shift(png_ptr, &sig_bit);
|
png_set_shift(png_ptr, &sig_bit);
|
||||||
png_set_packing(png_ptr);
|
png_set_packing(png_ptr);
|
||||||
|
|
||||||
|
for (pass = 0; pass < num_passes; pass++)
|
||||||
|
{
|
||||||
ptr = im->data;
|
ptr = im->data;
|
||||||
|
|
||||||
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)
|
||||||
|
@ -360,7 +373,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
||||||
char per;
|
char per;
|
||||||
int l;
|
int l;
|
||||||
|
|
||||||
per = (char)((100 * y) / im->h);
|
per = 100 * (pass + y / (float) im->h) / num_passes;
|
||||||
if ((per - pper) >= progress_granularity)
|
if ((per - pper) >= progress_granularity)
|
||||||
{
|
{
|
||||||
l = y - pl;
|
l = y - pl;
|
||||||
|
@ -382,6 +395,7 @@ save(ImlibImage * im, ImlibProgressFunction progress, char progress_granularity)
|
||||||
}
|
}
|
||||||
ptr += im->w;
|
ptr += im->w;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (data)
|
if (data)
|
||||||
free(data);
|
free(data);
|
||||||
png_write_end(png_ptr, info_ptr);
|
png_write_end(png_ptr, info_ptr);
|
||||||
|
|
Loading…
Reference in New Issue