Don't save transparent information on full-opaque .png files (fix #1572)

This commit is contained in:
David Capello 2017-09-26 11:59:55 -03:00
parent af3cc1d3c0
commit 33507fd097

View File

@ -446,6 +446,7 @@ bool PngFormat::onSave(FileOp* fop)
mask_entry = fop->document()->sprite()->transparentColor();
}
bool all_opaque = true;
int num_trans = pal_size;
png_bytep trans = (png_bytep)png_malloc(png_ptr, num_trans);
@ -453,9 +454,13 @@ bool PngFormat::onSave(FileOp* fop)
int alpha = 255;
fop->sequenceGetAlpha(c, &alpha);
trans[c] = (c == mask_entry ? 0: alpha);
if (alpha < 255)
all_opaque = false;
}
png_set_tRNS(png_ptr, info_ptr, trans, num_trans, NULL);
if (!all_opaque || mask_entry >= 0)
png_set_tRNS(png_ptr, info_ptr, trans, num_trans, nullptr);
png_free(png_ptr, trans);
}