* scribo/scribo/io/xml/internal/full_xml_visitor.hh,
* scribo/scribo/io/xml/load.hh: Here.
---
scribo/ChangeLog | 7 ++++
scribo/scribo/io/xml/internal/full_xml_visitor.hh | 34 ++++++++++++++------
scribo/scribo/io/xml/load.hh | 12 +++++--
3 files changed, 39 insertions(+), 14 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index da0d095..52da198 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,12 @@
2011-03-03 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Compress image data in XML output.
+
+ * scribo/scribo/io/xml/internal/full_xml_visitor.hh,
+ * scribo/scribo/io/xml/load.hh: Here.
+
+2011-03-03 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Small fixes in Scribo.
* scribo/convert/from_base64.hh: Remove guards HAVE_QT.
diff --git a/scribo/scribo/io/xml/internal/full_xml_visitor.hh
b/scribo/scribo/io/xml/internal/full_xml_visitor.hh
index 9c5bd1d..2b09b3a 100644
--- a/scribo/scribo/io/xml/internal/full_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/full_xml_visitor.hh
@@ -31,6 +31,9 @@
/// XML serializer Visitor.
# include <fstream>
+
+# include <QByteArray>
+
# include <scribo/core/internal/doc_xml_serializer.hh>
# include <scribo/core/document.hh>
# include <scribo/core/component_set.hh>
@@ -40,11 +43,12 @@
# include <scribo/core/line_links.hh>
# include <scribo/core/line_info.hh>
-# include <scribo/convert/to_base64.hh>
-
# include <scribo/io/xml/internal/print_box_coords.hh>
# include <scribo/io/xml/internal/print_page_preambule.hh>
+// Compression level 0-9. 9 is the best but is slow.
+// 5 seems to be a good compromise.
+# define COMPRESSION_LEVEL 5
namespace scribo
{
@@ -273,15 +277,20 @@ namespace scribo
<< "\" width=\"" << lbl.domain().width() <<
"\">"
<< "<![CDATA[";
- util::array<unsigned char> lbl64;
- convert::to_base64(lbl, lbl64);
- output.write((const char *)lbl64.std_vector().data(),
- lbl64.nelements());
+ // FIXME: Try to avoid that!
+ border::resize(lbl, 0);
+ QByteArray lbl64((const char *)lbl.buffer(),
+ lbl.nelements() * sizeof(mln_value(L)));
+ lbl64 = qCompress(lbl64, COMPRESSION_LEVEL);
+ lbl64 = lbl64.toBase64();
+
+ output.write(lbl64.data(), lbl64.size());
output << "]]></labeled_image>" << std::endl;
}
// Save separators image
+ if (comp_set.has_separators())
{
const mln_ch_value(L,bool)& seps = comp_set.separators();
output << "<separators_image "
@@ -289,10 +298,13 @@ namespace scribo
<< "\" width=\"" << seps.domain().width() <<
"\">"
<< "<![CDATA[";
- util::array<unsigned char> seps64;
- convert::to_base64(seps, seps64);
- output.write((const char *)seps64.std_vector().data(),
- seps64.nelements());
+ border::resize(seps, 0);
+ QByteArray seps64((const char *)seps.buffer(),
+ seps.nelements() * sizeof(bool));
+ seps64 = qCompress(seps64, COMPRESSION_LEVEL);
+ seps64 = seps64.toBase64();
+
+ output.write(seps64.data(), seps64.size());
output << "]]></separators_image>" << std::endl;
}
@@ -453,4 +465,6 @@ namespace scribo
} // end of namespace scribo
+# undef COMPRESSION_LEVEL
+
#endif // SCRIBO_IO_XML_INTERNAL_FULL_XML_VISITOR_HH
diff --git a/scribo/scribo/io/xml/load.hh b/scribo/scribo/io/xml/load.hh
index e0f4548..8042c75 100644
--- a/scribo/scribo/io/xml/load.hh
+++ b/scribo/scribo/io/xml/load.hh
@@ -50,8 +50,6 @@
# include <scribo/core/line_set.hh>
# include <scribo/core/line_info.hh>
-# include <scribo/convert/from_base64.hh>
-
namespace scribo
{
@@ -405,13 +403,19 @@ namespace scribo
{
case LabeledImage:
{
- scribo::convert::from_base64(ch, comp_set_data->ima_);
+ QByteArray data = ch.toAscii();
+ data = QByteArray::fromBase64(data);
+ data = qUncompress(data);
+ memcpy((char *) comp_set_data->ima_.buffer(), data.data(), data.size());
}
break;
case SeparatorsImage:
{
- scribo::convert::from_base64(ch, comp_set_data->separators_);
+ QByteArray data = ch.toAscii();
+ data = QByteArray::fromBase64(data);
+ data = qUncompress(data);
+ memcpy((char *) comp_set_data->separators_.buffer(), data.data(), data.size());
}
break;
--
1.5.6.5
Show replies by date