[gimp] plug-ins - compress the PNG comment when over a given size.
- From: Jehan Pagès <jehanp src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] plug-ins - compress the PNG comment when over a given size.
- Date: Thu, 12 Sep 2013 00:58:46 +0000 (UTC)
commit d38f209e2ff5294764ec4882ecab1d66a00e3008
Author: Jehan <jehan girinstud io>
Date: Thu Sep 12 12:52:09 2013 +1200
plug-ins - compress the PNG comment when over a given size.
plug-ins/common/file-png.c | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
---
diff --git a/plug-ins/common/file-png.c b/plug-ins/common/file-png.c
index 223f69d..13d7ccb 100644
--- a/plug-ins/common/file-png.c
+++ b/plug-ins/common/file-png.c
@@ -1558,6 +1558,12 @@ save_image (const gchar *filename,
}
#endif
+#ifdef PNG_zTXt_SUPPORTED
+/* Small texts are not worth compressing and will be even bigger if compressed.
+ Empirical length limit of a text being worth compressing. */
+#define COMPRESSION_WORTHY_LENGTH 200
+#endif
+
if (pngvals.comment)
{
GimpParasite *parasite;
@@ -1595,7 +1601,12 @@ save_image (const gchar *filename,
text[0].text = g_strdup (comment);
text[0].itxt_length = strlen (text[0].text);
+#ifdef PNG_zTXt_SUPPORTED
+ text[0].compression = strlen (text[0].text) > COMPRESSION_WORTHY_LENGTH ?
+ PNG_ITXT_COMPRESSION_zTXt : PNG_ITXT_COMPRESSION_NONE;
+#else
text[0].compression = PNG_ITXT_COMPRESSION_NONE;
+#endif /* PNG_zTXt_SUPPORTED */
}
else
/* The comment is ISO-8859-1 compatible, so we use tEXt
@@ -1617,7 +1628,13 @@ save_image (const gchar *filename,
NULL);
#endif
+#ifdef PNG_zTXt_SUPPORTED
+ text[0].compression = strlen (text[0].text) > COMPRESSION_WORTHY_LENGTH ?
+ PNG_TEXT_COMPRESSION_zTXt : PNG_TEXT_COMPRESSION_NONE;
+#else
text[0].compression = PNG_TEXT_COMPRESSION_NONE;
+#endif /* PNG_zTXt_SUPPORTED */
+
text[0].text_length = text_length;
}
@@ -1633,6 +1650,10 @@ save_image (const gchar *filename,
}
}
+#ifdef PNG_zTXt_SUPPORTED
+#undef COMPRESSION_WORTHY_LENGTH
+#endif
+
if (text)
png_set_text (pp, info, text, 1);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]