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,49 +349,53 @@ 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);
|
||||||
|
|
||||||
ptr = im->data;
|
for (pass = 0; pass < num_passes; pass++)
|
||||||
for (y = 0; y < im->h; y++)
|
|
||||||
{
|
{
|
||||||
if (im->flags & F_HAS_ALPHA)
|
ptr = im->data;
|
||||||
row_ptr = (png_bytep) ptr;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (j = 0, x = 0; x < im->w; x++)
|
|
||||||
{
|
|
||||||
data[j++] = (ptr[x] >> 16) & 0xff;
|
|
||||||
data[j++] = (ptr[x] >> 8) & 0xff;
|
|
||||||
data[j++] = (ptr[x]) & 0xff;
|
|
||||||
}
|
|
||||||
row_ptr = (png_bytep) data;
|
|
||||||
}
|
|
||||||
png_write_rows(png_ptr, &row_ptr, 1);
|
|
||||||
if (progress)
|
|
||||||
{
|
|
||||||
char per;
|
|
||||||
int l;
|
|
||||||
|
|
||||||
per = (char)((100 * y) / im->h);
|
for (y = 0; y < im->h; y++)
|
||||||
if ((per - pper) >= progress_granularity)
|
{
|
||||||
{
|
if (im->flags & F_HAS_ALPHA)
|
||||||
l = y - pl;
|
row_ptr = (png_bytep) ptr;
|
||||||
if (!progress(im, per, 0, (y - l), im->w, l))
|
else
|
||||||
{
|
{
|
||||||
if (data)
|
for (j = 0, x = 0; x < im->w; x++)
|
||||||
free(data);
|
{
|
||||||
png_write_end(png_ptr, info_ptr);
|
data[j++] = (ptr[x] >> 16) & 0xff;
|
||||||
png_destroy_write_struct(&png_ptr,
|
data[j++] = (ptr[x] >> 8) & 0xff;
|
||||||
(png_infopp) & info_ptr);
|
data[j++] = (ptr[x]) & 0xff;
|
||||||
png_destroy_info_struct(png_ptr,
|
}
|
||||||
(png_infopp) & info_ptr);
|
row_ptr = (png_bytep) data;
|
||||||
fclose(f);
|
}
|
||||||
return 2;
|
png_write_rows(png_ptr, &row_ptr, 1);
|
||||||
}
|
if (progress)
|
||||||
pper = per;
|
{
|
||||||
pl = y;
|
char per;
|
||||||
}
|
int l;
|
||||||
}
|
|
||||||
ptr += im->w;
|
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))
|
||||||
|
{
|
||||||
|
if (data)
|
||||||
|
free(data);
|
||||||
|
png_write_end(png_ptr, info_ptr);
|
||||||
|
png_destroy_write_struct(&png_ptr,
|
||||||
|
(png_infopp) & info_ptr);
|
||||||
|
png_destroy_info_struct(png_ptr,
|
||||||
|
(png_infopp) & info_ptr);
|
||||||
|
fclose(f);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
pper = per;
|
||||||
|
pl = y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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