Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
last-svn-commit-792-g446d792 scribo/io/xml/internal/extended_page_xml_visitor.hh: Save separators data.
by Guillaume Lazzara 29 Mar '11
by Guillaume Lazzara 29 Mar '11
29 Mar '11
---
scribo/ChangeLog | 5 +++++
.../io/xml/internal/extended_page_xml_visitor.hh | 4 ++++
2 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 3f17098..9e63c2a 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,10 @@
2011-03-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * scribo/io/xml/internal/extended_page_xml_visitor.hh: Save
+ separators data.
+
+2011-03-04 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* scribo/io/xml/internal/full_xml_visitor.hh: Do not copy image
data.
diff --git a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
index 4da0755..f573d88 100644
--- a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
@@ -113,6 +113,10 @@ namespace scribo
if (doc.has_elements())
doc.elements().accept(*this);
+ // line seraparators
+ if (doc.has_line_seps())
+ doc.line_seps_comps().accept(*this);
+
// Whitespace seraparators
if (doc.has_whitespace_seps())
doc.whitespace_seps_comps().accept(*this);
--
1.5.6.5
1
0
* demo/viewer/main.cc: Add more includes.
* demo/viewer/viewer.cc: Add debug output.
---
scribo/ChangeLog | 8 ++++++++
scribo/demo/viewer/main.cc | 5 ++++-
scribo/demo/viewer/viewer.cc | 8 +++++++-
3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 9e63c2a..358201c 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,11 @@
+2011-03-11 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Small fixes in viewer.
+
+ * demo/viewer/main.cc: Add more includes.
+
+ * demo/viewer/viewer.cc: Add debug output.
+
2011-03-04 Guillaume Lazzara <z(a)lrde.epita.fr>
* scribo/io/xml/internal/extended_page_xml_visitor.hh: Save
diff --git a/scribo/demo/viewer/main.cc b/scribo/demo/viewer/main.cc
index 6d1cb18..069d5e9 100644
--- a/scribo/demo/viewer/main.cc
+++ b/scribo/demo/viewer/main.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -23,6 +24,8 @@
#include <mln/math/pi.hh>
#include <mln/io/magick/load.hh>
#include <scribo/make/debug_filename.hh>
+#include <mln/debug/filename.hh>
+#include <mln/literal/white.hh>
int main(int argc, char** argv)
{
diff --git a/scribo/demo/viewer/viewer.cc b/scribo/demo/viewer/viewer.cc
index f34b3e7..173cb3b 100644
--- a/scribo/demo/viewer/viewer.cc
+++ b/scribo/demo/viewer/viewer.cc
@@ -372,7 +372,10 @@ Viewer::add_text(QDomNode line)
coords = coords.nextSibling();
if (coords.isNull())
+ {
+ qDebug() << "Warning : textline without coordinates...";
return;
+ }
QDomNode point = coords.firstChild();
@@ -393,7 +396,7 @@ Viewer::add_text(QDomNode line)
point = point.nextSibling();
}
- QString text = line.toElement().attribute("text", "none");
+ QString text = line.toElement().attribute("text", "");
QFont font("Times");
font.setPixelSize(a_height + d_height);
QGraphicsTextItem* text_item = scene_->addText(text, font);
@@ -417,7 +420,10 @@ Viewer::add_region(QDomNode father, QString attr_id)
coords = coords.nextSibling();
if (coords.isNull())
+ {
+ qDebug() << "Warning : add_region - region without coordinates";
return;
+ }
QDomNode point = coords.firstChild();
QVector<QPoint> points;
--
1.5.6.5
1
0
* scribo/convert/from_base64.hh,
* scribo/io/xml/save.hh: Here.
---
scribo/ChangeLog | 7 +++++++
scribo/scribo/convert/from_base64.hh | 12 ++++++++++++
scribo/scribo/io/xml/save.hh | 13 ++++++++++++-
3 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 358201c..32a53f7 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,12 @@
2011-03-11 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add HAVE_QT guards.
+
+ * scribo/convert/from_base64.hh,
+ * scribo/io/xml/save.hh: Here.
+
+2011-03-11 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Small fixes in viewer.
* demo/viewer/main.cc: Add more includes.
diff --git a/scribo/scribo/convert/from_base64.hh b/scribo/scribo/convert/from_base64.hh
index 5eeeb53..753883d 100644
--- a/scribo/scribo/convert/from_base64.hh
+++ b/scribo/scribo/convert/from_base64.hh
@@ -63,6 +63,10 @@
#include <cstdio>
#include <cstdlib>
+# ifdef HAVE_QT
+# include <QString>
+# endif // ! HAVE_QT
+
# include <mln/border/resize.hh>
# include <mln/core/image/image2d.hh>
# include <mln/util/array.hh>
@@ -82,9 +86,13 @@ namespace scribo
Image<I>& output);
+# ifdef HAVE_QT
+
template <typename I>
void from_base64(const QString& data64, Image<I>& output_);
+# endif // ! HAVE_QT
+
# ifndef MLN_INCLUDE_ONLY
@@ -187,6 +195,8 @@ namespace scribo
}
+# ifdef HAVE_QT
+
template <typename I>
void
from_base64(const QString& data64, Image<I>& output_)
@@ -199,6 +209,8 @@ namespace scribo
trace::exiting("scribo::convert::to_base64");
}
+# endif // ! HAVE_QT
+
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/scribo/io/xml/save.hh b/scribo/scribo/io/xml/save.hh
index 7428e5d..54afa79 100644
--- a/scribo/scribo/io/xml/save.hh
+++ b/scribo/scribo/io/xml/save.hh
@@ -39,7 +39,10 @@
# include <scribo/core/document.hh>
-# include <scribo/io/xml/internal/full_xml_visitor.hh>
+# ifdef HAVE_QT
+# include <scribo/io/xml/internal/full_xml_visitor.hh>
+# endif // ! HAVE_QT
+
# include <scribo/io/xml/internal/extended_page_xml_visitor.hh>
# include <scribo/io/xml/internal/page_xml_visitor.hh>
@@ -66,7 +69,11 @@ namespace scribo
{
Page,
PageExtended,
+
+# ifdef HAVE_QT
Full
+# endif // ! HAVE_QT
+
//Hocr
};
@@ -100,12 +107,14 @@ namespace scribo
doc.accept(f);
}
+# ifdef HAVE_QT
template <typename L>
void save_full(const document<L>& doc, std::ofstream& output)
{
scribo::io::xml::internal::full_xml_visitor f(output);
doc.accept(f);
}
+# endif // ! HAVE_QT
} // end of namespace scribo::io::xml::internal
@@ -143,9 +152,11 @@ namespace scribo
internal::save_page_extended(doc, output);
break;
+# ifdef HAVE_QT
case Full:
internal::save_full(doc, output);
break;
+# endif // ! HAVE_QT
default:
trace::warning("scribo::io::xml::save - Invalid XML format! Skip saving...");
--
1.5.6.5
1
0
* src/primitive/extract/Makefile.am,
* src/primitive/remove/Makefile.am: Add new targets.
* src/primitive/extract/separators_nonvisible.cc,
* src/primitive/remove/separators.cc: New.
---
scribo/ChangeLog | 10 ++++++++++
scribo/src/primitive/extract/Makefile.am | 2 ++
.../extract/separators_nonvisible.cc} | 19 ++++++++++---------
scribo/src/primitive/{ => remove}/Makefile.am | 11 ++++++-----
.../negate.cc => primitive/remove/separators.cc} | 20 ++++++++++++--------
5 files changed, 40 insertions(+), 22 deletions(-)
copy scribo/src/{misc/negate.cc => primitive/extract/separators_nonvisible.cc} (79%)
copy scribo/src/primitive/{ => remove}/Makefile.am (82%)
copy scribo/src/{misc/negate.cc => primitive/remove/separators.cc} (76%)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index fd4b155..3d23191 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,15 @@
2011-02-17 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add new tools in Scribo.
+
+ * src/primitive/extract/Makefile.am,
+ * src/primitive/remove/Makefile.am: Add new targets.
+
+ * src/primitive/extract/separators_nonvisible.cc,
+ * src/primitive/remove/separators.cc: New.
+
+2011-02-17 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Small fixes in Scribo.
* scribo/core/macros.hh: Update comments.
diff --git a/scribo/src/primitive/extract/Makefile.am b/scribo/src/primitive/extract/Makefile.am
index a46cd68..22d6bfd 100644
--- a/scribo/src/primitive/extract/Makefile.am
+++ b/scribo/src/primitive/extract/Makefile.am
@@ -22,6 +22,7 @@ noinst_PROGRAMS = \
discontinued_lines \
discontinued_vlines \
discontinued_hlines \
+ separators_nonvisible \
thick_vlines \
thick_hlines \
lines_pattern
@@ -29,6 +30,7 @@ noinst_PROGRAMS = \
discontinued_lines_SOURCES = discontinued_lines.cc
discontinued_vlines_SOURCES = discontinued_vlines.cc
discontinued_hlines_SOURCES = discontinued_hlines.cc
+separators_nonvisible_SOURCES = separators_nonvisible.cc
thick_vlines_SOURCES = thick_vlines.cc
thick_hlines_SOURCES = thick_hlines.cc
lines_pattern_SOURCES = lines_pattern.cc
diff --git a/scribo/src/misc/negate.cc b/scribo/src/primitive/extract/separators_nonvisible.cc
similarity index 79%
copy from scribo/src/misc/negate.cc
copy to scribo/src/primitive/extract/separators_nonvisible.cc
index da6fad6..82d4787 100644
--- a/scribo/src/misc/negate.cc
+++ b/scribo/src/primitive/extract/separators_nonvisible.cc
@@ -1,5 +1,4 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -25,35 +24,37 @@
// executable file might be covered by the GNU General Public License.
#include <mln/core/image/image2d.hh>
-#include <mln/logical/not.hh>
#include <mln/io/pbm/all.hh>
+#include <mln/data/convert.hh>
+#include <scribo/primitive/extract/separators_nonvisible2.hh>
#include <scribo/debug/usage.hh>
-
const char *args_desc[][2] =
{
{ "input.pbm", "A binary image." },
+ { "output.pbm", "Output image." },
{0, 0}
};
int main(int argc, char *argv[])
{
- mln::trace::entering("main");
using namespace mln;
+ using namespace scribo;
if (argc != 3)
return scribo::debug::usage(argv,
- "Negate a binary image",
+ "Extract non visible separators (whitespaces)",
"input.pbm output.pbm",
args_desc);
+ trace::entering("main");
+
image2d<bool> input;
io::pbm::load(input, argv[1]);
- io::pbm::save(logical::not_(input), argv[2]);
-
- mln::trace::exiting("main");
+ io::pbm::save(primitive::extract::separators_nonvisible(input), argv[2]);
+ trace::exiting("main");
}
diff --git a/scribo/src/primitive/Makefile.am b/scribo/src/primitive/remove/Makefile.am
similarity index 82%
copy from scribo/src/primitive/Makefile.am
copy to scribo/src/primitive/remove/Makefile.am
index 7e46a66..a673886 100644
--- a/scribo/src/primitive/Makefile.am
+++ b/scribo/src/primitive/remove/Makefile.am
@@ -1,4 +1,4 @@
-# Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE).
+# Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE).
#
# This file is part of Olena.
#
@@ -16,7 +16,8 @@
include $(top_srcdir)/scribo/scribo.mk
-SUBDIRS = \
- extract \
- find \
- group
+
+noinst_PROGRAMS = \
+ separators
+
+separators_SOURCES = separators.cc
diff --git a/scribo/src/misc/negate.cc b/scribo/src/primitive/remove/separators.cc
similarity index 76%
copy from scribo/src/misc/negate.cc
copy to scribo/src/primitive/remove/separators.cc
index da6fad6..46e977f 100644
--- a/scribo/src/misc/negate.cc
+++ b/scribo/src/primitive/remove/separators.cc
@@ -1,5 +1,4 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -25,35 +24,40 @@
// executable file might be covered by the GNU General Public License.
#include <mln/core/image/image2d.hh>
-#include <mln/logical/not.hh>
#include <mln/io/pbm/all.hh>
+#include <mln/data/convert.hh>
+#include <scribo/primitive/extract/separators.hh>
+#include <scribo/primitive/remove/separators.hh>
#include <scribo/debug/usage.hh>
-
const char *args_desc[][2] =
{
{ "input.pbm", "A binary image." },
+ { "output.pbm", "Output image." },
{0, 0}
};
int main(int argc, char *argv[])
{
- mln::trace::entering("main");
using namespace mln;
+ using namespace scribo;
if (argc != 3)
return scribo::debug::usage(argv,
- "Negate a binary image",
+ "Remove visible separators",
"input.pbm output.pbm",
args_desc);
+ trace::entering("main");
+
image2d<bool> input;
io::pbm::load(input, argv[1]);
- io::pbm::save(logical::not_(input), argv[2]);
+ image2d<bool> seps = primitive::extract::separators(input, 81);
- mln::trace::exiting("main");
+ io::pbm::save(primitive::remove::separators(input, seps), argv[2]);
+ trace::exiting("main");
}
--
1.5.6.5
1
0
last-svn-commit-776-g4a86f5d configure.ac: scribo/src/primitive/remove.
by Guillaume Lazzara 29 Mar '11
by Guillaume Lazzara 29 Mar '11
29 Mar '11
---
ChangeLog | 4 ++++
configure.ac | 1 +
2 files changed, 5 insertions(+), 0 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 9fedefa..30f8b74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2011-02-17 Guillaume Lazzara <z(a)lrde.epita.fr>
+ * configure.ac: scribo/src/primitive/remove.
+
+2011-02-17 Guillaume Lazzara <z(a)lrde.epita.fr>
+
* configure.ac: configure scribo/tests/convert.
2011-03-14 Thierry GERAUD <thierry.geraud(a)lrde.epita.fr>
diff --git a/configure.ac b/configure.ac
index e30f010..44f359b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -332,6 +332,7 @@ AC_CONFIG_FILES([
scribo/src/primitive/extract/Makefile
scribo/src/primitive/find/Makefile
scribo/src/primitive/group/Makefile
+ scribo/src/primitive/remove/Makefile
scribo/src/table/Makefile
scribo/src/text/Makefile
scribo/src/toolchain/Makefile
--
1.5.6.5
1
0
last-svn-commit-777-g09da3ef Set component type during component extraction.
by Guillaume Lazzara 29 Mar '11
by Guillaume Lazzara 29 Mar '11
29 Mar '11
* scribo/core/component_info.hh,
* scribo/core/component_set.hh,
* scribo/core/document.hh,
* scribo/core/tag/component.hh,
* scribo/primitive/extract/components.hh,
* scribo/primitive/identify.hh: Explicitly set component type to
Separator when extracting separator components.
---
scribo/ChangeLog | 12 ++++++
scribo/scribo/core/component_info.hh | 8 ++-
scribo/scribo/core/component_set.hh | 50 ++++++++++++++++---------
scribo/scribo/core/document.hh | 6 ++-
scribo/scribo/core/tag/component.hh | 20 ++++++---
scribo/scribo/primitive/extract/components.hh | 18 ++++++---
scribo/scribo/primitive/identify.hh | 2 +-
7 files changed, 79 insertions(+), 37 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 3d23191..63e3fee 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,15 @@
+2011-03-01 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Set component type during component extraction.
+
+ * scribo/core/component_info.hh,
+ * scribo/core/component_set.hh,
+ * scribo/core/document.hh,
+ * scribo/core/tag/component.hh,
+ * scribo/primitive/extract/components.hh,
+ * scribo/primitive/identify.hh: Explicitly set component type to
+ Separator when extracting separator components.
+
2011-02-17 Guillaume Lazzara <z(a)lrde.epita.fr>
Add new tools in Scribo.
diff --git a/scribo/scribo/core/component_info.hh b/scribo/scribo/core/component_info.hh
index 1b03318..6fc73f8 100644
--- a/scribo/scribo/core/component_info.hh
+++ b/scribo/scribo/core/component_info.hh
@@ -53,7 +53,8 @@ namespace scribo
component_info(const component_id_t& id,
const mln::box2d& bbox,
const mln::point2d& mass_center,
- unsigned card);
+ unsigned card,
+ component::Type type = component::Undefined);
component_id_t id() const;
const mln::box2d& bbox() const;
@@ -101,9 +102,10 @@ namespace scribo
component_info::component_info(const component_id_t& id,
const mln::box2d& bbox,
const mln::point2d& mass_center,
- unsigned card)
+ unsigned card,
+ component::Type type)
: id_(id), bbox_(bbox), mass_center_(mass_center), card_(card),
- tag_(component::None), type_(component::Undefined)
+ tag_(component::None), type_(type)
{
}
diff --git a/scribo/scribo/core/component_set.hh b/scribo/scribo/core/component_set.hh
index 7ddcf16..442e8d6 100644
--- a/scribo/scribo/core/component_set.hh
+++ b/scribo/scribo/core/component_set.hh
@@ -86,16 +86,20 @@ namespace scribo
component_set_data();
component_set_data(const L& ima, const mln_value(L)& ncomps);
component_set_data(const L& ima, const mln_value(L)& ncomps,
- const mln::util::array<pair_accu_t>& attribs);
+ const mln::util::array<pair_accu_t>& attribs,
+ component::Type type = component::Undefined);
component_set_data(const L& ima, const mln_value(L)& ncomps,
- const mln::util::array<pair_data_t>& attribs);
+ const mln::util::array<pair_data_t>& attribs,
+ component::Type type = component::Undefined);
component_set_data(const L& ima, const mln_value(L)& ncomps,
const mln::util::array<scribo::component_info>& infos);
- void fill_infos(const mln::util::array<pair_accu_t>& attribs);
+ void fill_infos(const mln::util::array<pair_accu_t>& attribs,
+ component::Type type = component::Undefined);
- void fill_infos(const mln::util::array<pair_data_t>& attribs);
+ void fill_infos(const mln::util::array<pair_data_t>& attribs,
+ component::Type type = component::Undefined);
// Useful while constructing incrementaly (XML loading).
void soft_init(const mln_value(L) ncomps);
@@ -141,10 +145,12 @@ namespace scribo
/// Constructor from an image \p ima, the number of labels \p ncomps and
/// attributes values (bounding box and mass center).
component_set(const L& ima, const mln_value(L)& ncomps,
- const mln::util::array<pair_accu_t>& attribs);
+ const mln::util::array<pair_accu_t>& attribs,
+ component::Type type = component::Undefined);
component_set(const L& ima, const mln_value(L)& ncomps,
- const mln::util::array<pair_data_t>& attribs);
+ const mln::util::array<pair_data_t>& attribs,
+ component::Type type = component::Undefined);
/// @}
/// Return the component count.
@@ -284,26 +290,28 @@ namespace scribo
inline
component_set_data<L>::component_set_data(const L& ima,
const mln_value(L)& ncomps,
- const mln::util::array<pair_accu_t>& attribs)
+ const mln::util::array<pair_accu_t>& attribs,
+ component::Type type)
: ima_(ima), ncomps_(ncomps)
{
initialize(separators_, ima); // FIXME: do we really want that?
mln::data::fill(separators_, false);
- fill_infos(attribs);
+ fill_infos(attribs, type);
}
template <typename L>
inline
component_set_data<L>::component_set_data(const L& ima,
const mln_value(L)& ncomps,
- const mln::util::array<pair_data_t>& attribs)
+ const mln::util::array<pair_data_t>& attribs,
+ component::Type type)
: ima_(ima), ncomps_(ncomps)
{
initialize(separators_, ima); // FIXME: do we really want that?
mln::data::fill(separators_, false);
- fill_infos(attribs);
+ fill_infos(attribs, type);
}
template <typename L>
@@ -321,7 +329,8 @@ namespace scribo
template <typename L>
inline
void
- component_set_data<L>::fill_infos(const mln::util::array<pair_accu_t>& attribs)
+ component_set_data<L>::fill_infos(const mln::util::array<pair_accu_t>& attribs,
+ component::Type type)
{
typedef mln_site(L) P;
@@ -331,7 +340,8 @@ namespace scribo
for_all_comp_data(i, attribs)
{
component_info info(i, attribs[i].first(),
- attribs[i].second(), attribs[i].second_accu().nsites());
+ attribs[i].second(), attribs[i].second_accu().nsites(),
+ type);
infos_.append(info);
}
}
@@ -339,7 +349,8 @@ namespace scribo
template <typename L>
inline
void
- component_set_data<L>::fill_infos(const mln::util::array<pair_data_t>& attribs)
+ component_set_data<L>::fill_infos(const mln::util::array<pair_data_t>& attribs,
+ component::Type type)
{
typedef mln_site(L) P;
@@ -349,7 +360,8 @@ namespace scribo
for_all_comp_data(i, attribs)
{
component_info info(i, attribs[i].first,
- attribs[i].second.first, attribs[i].second.second);
+ attribs[i].second.first, attribs[i].second.second,
+ type);
infos_.append(info);
}
}
@@ -397,9 +409,10 @@ namespace scribo
template <typename L>
inline
component_set<L>::component_set(const L& ima, const mln_value(L)& ncomps,
- const mln::util::array<pair_accu_t>& attribs)
+ const mln::util::array<pair_accu_t>& attribs,
+ component::Type type)
{
- data_ = new internal::component_set_data<L>(ima, ncomps, attribs);
+ data_ = new internal::component_set_data<L>(ima, ncomps, attribs, type);
}
@@ -407,9 +420,10 @@ namespace scribo
inline
component_set<L>::component_set(const L& ima, const mln_value(L)& ncomps,
- const mln::util::array<pair_data_t>& attribs)
+ const mln::util::array<pair_data_t>& attribs,
+ component::Type type)
{
- data_ = new internal::component_set_data<L>(ima, ncomps, attribs);
+ data_ = new internal::component_set_data<L>(ima, ncomps, attribs, type);
}
diff --git a/scribo/scribo/core/document.hh b/scribo/scribo/core/document.hh
index e5ac825..ef0869e 100644
--- a/scribo/scribo/core/document.hh
+++ b/scribo/scribo/core/document.hh
@@ -297,7 +297,8 @@ namespace scribo
mln_value(L) ncomps;
whitespace_seps_comps_ = primitive::extract::components(whitespace_seps,
- mln::c8(), ncomps);
+ mln::c8(), ncomps,
+ component::WhitespaceSeparator);
}
@@ -333,7 +334,8 @@ namespace scribo
mln_value(L) ncomps;
line_seps_comps_ = primitive::extract::components(line_seps,
- mln::c8(), ncomps);
+ mln::c8(), ncomps,
+ component::LineSeparator);
}
diff --git a/scribo/scribo/core/tag/component.hh b/scribo/scribo/core/tag/component.hh
index 10b86a6..7cd2ede 100644
--- a/scribo/scribo/core/tag/component.hh
+++ b/scribo/scribo/core/tag/component.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -55,7 +55,8 @@ namespace scribo
{
Undefined = 0,
Character,
- Separator,
+ LineSeparator,
+ WhitespaceSeparator,
Noise,
Punctuation,
Image
@@ -116,8 +117,11 @@ namespace scribo
case Character:
str = "Character";
break;
- case Separator:
- str = "Separator";
+ case LineSeparator:
+ str = "LineSeparator";
+ break;
+ case WhitespaceSeparator:
+ str = "WhitespaceSeparator";
break;
case Noise:
str = "Noise";
@@ -139,8 +143,10 @@ namespace scribo
{
if (str == "Character")
return Character;
- else if (str == "Separator")
- return Separator;
+ else if (str == "LineSeparator")
+ return LineSeparator;
+ else if (str == "WhitespaceSeparator")
+ return WhitespaceSeparator;
else if (str == "Noise")
return Noise;
else if (str == "Punctuation")
diff --git a/scribo/scribo/primitive/extract/components.hh b/scribo/scribo/primitive/extract/components.hh
index 4994d4b..849dd7b 100644
--- a/scribo/scribo/primitive/extract/components.hh
+++ b/scribo/scribo/primitive/extract/components.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -68,6 +69,7 @@ namespace scribo
/// and background to 'false'.
/// \param[in] nbh A neighborhood to be used for labeling.
/// \param[in,out] ncomponents Will store the numbers of components found.
+ /// \param[in] type The default component type set to components.
///
/// \return An image of labeled components.
//
@@ -75,7 +77,8 @@ namespace scribo
inline
component_set<mln_ch_value(I,V)>
components(const Image<I>& input,
- const Neighborhood<N>& nbh, V& ncomponents);
+ const Neighborhood<N>& nbh, V& ncomponents,
+ component::Type type = component::Undefined);
# ifndef MLN_INCLUDE_ONLY
@@ -88,7 +91,8 @@ namespace scribo
inline
void
components_tests(const Image<I>& input,
- const Neighborhood<N>& nbh, V& ncomponents)
+ const Neighborhood<N>& nbh, V& ncomponents,
+ component::Type type)
{
mlc_equal(mln_value(I),bool)::check();
// mlc_is_a(V, mln::value::Symbolic)::check();
@@ -97,6 +101,7 @@ namespace scribo
(void) input;
(void) nbh;
(void) ncomponents;
+ (void) type;
}
@@ -107,11 +112,12 @@ namespace scribo
inline
component_set<mln_ch_value(I,V)>
components(const Image<I>& input,
- const Neighborhood<N>& nbh, V& ncomponents)
+ const Neighborhood<N>& nbh, V& ncomponents,
+ component::Type type = component::Undefined)
{
trace::entering("scribo::components");
- internal::components_tests(input, nbh, ncomponents);
+ internal::components_tests(input, nbh, ncomponents, type);
typedef mln_ch_value(I,V) L;
typedef mln::accu::shape::bbox<mln_site(L)> bbox_accu_t;
@@ -129,7 +135,7 @@ namespace scribo
pair_accu_t());
component_set<L>
- output(results.first(), ncomponents, results.second().second());
+ output(results.first(), ncomponents, results.second().second(), type);
trace::exiting("scribo::components");
return output;
diff --git a/scribo/scribo/primitive/identify.hh b/scribo/scribo/primitive/identify.hh
index 81a7d16..1bed712 100644
--- a/scribo/scribo/primitive/identify.hh
+++ b/scribo/scribo/primitive/identify.hh
@@ -61,7 +61,7 @@ namespace scribo
std::swap(min, max);
if (max/min > 10)
- output(c).update_type(component::Separator);
+ output(c).update_type(component::LineSeparator);
}
mln::trace::exiting("scribo::primitive::identify");
--
1.5.6.5
1
0
29 Mar '11
* scribo/core/component_info.hh,
* scribo/core/component_set.hh,
* scribo/core/document.hh,
* scribo/core/line_info.hh,
* scribo/core/line_links.hh,
* scribo/core/object_groups.hh,
* scribo/core/object_links.hh,
* scribo/core/paragraph_set.hh: Make these classes serializable.
* scribo/core/concept/serializable.hh,
* scribo/core/concept/serialize_visitor.hh: New concepts.
* scribo/core/internal/doc_xml_serializer.hh: New. Base
implementation.
* scribo/io/xml/internal/extended_page_xml_visitor.hh,
* scribo/io/xml/internal/full_xml_visitor.hh,
* scribo/io/xml/internal/page_xml_visitor.hh: New. Visitors
producing different XML outputs.
* scribo/io/xml/internal/html_markups_replace.hh,
* scribo/io/xml/internal/print_box_coords.hh,
* scribo/io/xml/internal/print_page_preambule.hh: New. Tools for
XML output.
* scribo/io/xml/save.hh: Make use of visitors.
* scribo/toolchain/internal/content_in_doc_functor.hh: Set default
XML output type.
* src/content_in_doc.cc: Produce several XML output.
---
scribo/ChangeLog | 38 ++
scribo/demo/viewer/runner.cc | 5 +-
scribo/scribo/core/component_info.hh | 3 +-
scribo/scribo/core/component_set.hh | 7 +-
scribo/scribo/core/concept/serializable.hh | 64 +++
scribo/scribo/core/concept/serialize_visitor.hh | 49 +++
scribo/scribo/core/document.hh | 8 +-
scribo/scribo/core/internal/doc_xml_serializer.hh | 140 ++++++
scribo/scribo/core/line_info.hh | 21 +-
scribo/scribo/core/line_links.hh | 3 +-
scribo/scribo/core/object_groups.hh | 4 +-
scribo/scribo/core/object_links.hh | 8 +-
scribo/scribo/core/paragraph_set.hh | 4 +-
.../io/xml/internal/extended_page_xml_visitor.hh | 283 ++++++++++++
scribo/scribo/io/xml/internal/full_xml_visitor.hh | 456 ++++++++++++++++++++
.../scribo/io/xml/internal/html_markups_replace.hh | 97 +++++
scribo/scribo/io/xml/internal/page_xml_visitor.hh | 222 ++++++++++
scribo/scribo/io/xml/internal/print_box_coords.hh | 92 ++++
.../scribo/io/xml/internal/print_page_preambule.hh | 95 ++++
scribo/scribo/io/xml/save.hh | 388 +++--------------
.../toolchain/internal/content_in_doc_functor.hh | 9 +-
scribo/src/content_in_doc.cc | 4 +-
22 files changed, 1660 insertions(+), 340 deletions(-)
create mode 100644 scribo/scribo/core/concept/serializable.hh
create mode 100644 scribo/scribo/core/concept/serialize_visitor.hh
create mode 100644 scribo/scribo/core/internal/doc_xml_serializer.hh
create mode 100644 scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
create mode 100644 scribo/scribo/io/xml/internal/full_xml_visitor.hh
create mode 100644 scribo/scribo/io/xml/internal/html_markups_replace.hh
create mode 100644 scribo/scribo/io/xml/internal/page_xml_visitor.hh
create mode 100644 scribo/scribo/io/xml/internal/print_box_coords.hh
create mode 100644 scribo/scribo/io/xml/internal/print_page_preambule.hh
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 63e3fee..cf02d73 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,43 @@
2011-03-01 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Make XML output more flexible.
+
+ * scribo/core/component_info.hh,
+ * scribo/core/component_set.hh,
+ * scribo/core/document.hh,
+ * scribo/core/line_info.hh,
+ * scribo/core/line_links.hh,
+ * scribo/core/object_groups.hh,
+ * scribo/core/object_links.hh,
+ * scribo/core/paragraph_set.hh: Make these classes serializable.
+
+ * scribo/core/concept/serializable.hh,
+ * scribo/core/concept/serialize_visitor.hh: New concepts.
+
+ * scribo/core/internal/doc_xml_serializer.hh: New. Base
+ implementation.
+
+ * scribo/io/xml/internal/extended_page_xml_visitor.hh,
+ * scribo/io/xml/internal/full_xml_visitor.hh,
+ * scribo/io/xml/internal/page_xml_visitor.hh: New. Visitors
+ producing different XML outputs.
+
+ * scribo/io/xml/internal/html_markups_replace.hh,
+ * scribo/io/xml/internal/print_box_coords.hh,
+ * scribo/io/xml/internal/print_page_preambule.hh: New. Tools for
+ XML output.
+
+ * scribo/io/xml/save.hh: Make use of visitors.
+
+ * scribo/toolchain/internal/content_in_doc_functor.hh: Set default
+ XML output type.
+
+ * src/content_in_doc.cc: Produce several XML output.
+
+ * demo/viewer/runner.cc: Update call to io::xml::save.
+
+2011-03-01 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Set component type during component extraction.
* scribo/core/component_info.hh,
diff --git a/scribo/demo/viewer/runner.cc b/scribo/demo/viewer/runner.cc
index 86ff5dc..a3cc883 100644
--- a/scribo/demo/viewer/runner.cc
+++ b/scribo/demo/viewer/runner.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -156,7 +157,7 @@ void runner::process(const image2d<value::rgb8>& original_ima,
f.enable_whitespace_seps = (find_seps == defs::Whitespaces
|| find_seps == defs::LinesAndWhitespaces);
- f.allow_xml_extensions = true;
+ f.xml_format = scribo::io::xml::PageExtended;
f.save_doc_as_xml = true;
diff --git a/scribo/scribo/core/component_info.hh b/scribo/scribo/core/component_info.hh
index 6fc73f8..f825aee 100644
--- a/scribo/scribo/core/component_info.hh
+++ b/scribo/scribo/core/component_info.hh
@@ -36,6 +36,7 @@
# include <mln/core/alias/point2d.hh>
# include <mln/util/object_id.hh>
+# include <scribo/core/concept/serializable.hh>
# include <scribo/core/tag/component.hh>
# include <scribo/core/tag/line.hh>
@@ -44,7 +45,7 @@ namespace scribo
typedef mln::util::object_id<scribo::ComponentId, unsigned> component_id_t;
- class component_info
+ class component_info : public Serializable<component_info>
{
typedef mln::util::object_id<scribo::ComponentId, unsigned> component_id_t;
diff --git a/scribo/scribo/core/component_set.hh b/scribo/scribo/core/component_set.hh
index 442e8d6..a63ed6c 100644
--- a/scribo/scribo/core/component_set.hh
+++ b/scribo/scribo/core/component_set.hh
@@ -30,6 +30,10 @@
/// \file
///
/// \brief Definition of a component set.
+///
+/// \fixme component_set should always set a component type in order
+/// to be fully supported by visitors.
+
# include <mln/core/concept/site_set.hh>
# include <mln/core/concept/function.hh>
@@ -59,6 +63,7 @@
# include <scribo/core/macros.hh>
# include <scribo/core/component_info.hh>
+# include <scribo/core/concept/serializable.hh>
namespace scribo
@@ -115,7 +120,7 @@ namespace scribo
template <typename L>
- class component_set
+ class component_set : public Serializable<component_set<L> >
{
typedef mln::accu::shape::bbox<mln_site(L)> bbox_accu_t;
typedef mln::accu::center<mln_site(L)> center_accu_t;
diff --git a/scribo/scribo/core/concept/serializable.hh b/scribo/scribo/core/concept/serializable.hh
new file mode 100644
index 0000000..6e661a6
--- /dev/null
+++ b/scribo/scribo/core/concept/serializable.hh
@@ -0,0 +1,64 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_CORE_CONCEPT_SERIALIZABLE_HH
+# define SCRIBO_CORE_CONCEPT_SERIALIZABLE_HH
+
+/// \file
+///
+/// Concept for serializer visitors.
+
+# include <mln/core/concept/object.hh>
+# include <scribo/core/concept/serialize_visitor.hh>
+
+namespace scribo
+{
+
+ /// \brief Link functor concept.
+ template <typename E>
+ class Serializable : public mln::Object<E>
+ {
+ public:
+ template <typename E2>
+ void accept(const SerializeVisitor<E2>& visitor) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ template <typename E2>
+ void
+ Serializable<E>::accept(const SerializeVisitor<E2>& visitor) const
+ {
+ exact(visitor).visit(exact(*this));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of namespace scribo
+
+#endif // SCRIBO_CORE_CONCEPT_SERIALIZABLE_HH
diff --git a/scribo/scribo/core/concept/serialize_visitor.hh b/scribo/scribo/core/concept/serialize_visitor.hh
new file mode 100644
index 0000000..e5e598f
--- /dev/null
+++ b/scribo/scribo/core/concept/serialize_visitor.hh
@@ -0,0 +1,49 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_CORE_CONCEPT_SERIALIZE_VISITOR_HH
+# define SCRIBO_CORE_CONCEPT_SERIALIZE_VISITOR_HH
+
+/// \file
+///
+/// Concept for serializer visitors.
+
+# include <mln/core/concept/object.hh>
+
+namespace scribo
+{
+
+ /// \brief Link functor concept.
+ template <typename E>
+ class SerializeVisitor : public mln::Object<E>
+ {
+ public:
+ // void visit(..);
+ };
+
+
+} // end of namespace scribo
+
+#endif // SCRIBO_CORE_CONCEPT_SERIALIZE_VISITOR_HH
diff --git a/scribo/scribo/core/document.hh b/scribo/scribo/core/document.hh
index ef0869e..372f0a4 100644
--- a/scribo/scribo/core/document.hh
+++ b/scribo/scribo/core/document.hh
@@ -40,13 +40,15 @@
# include <scribo/core/line_set.hh>
# include <scribo/core/paragraph_set.hh>
+# include <scribo/core/concept/serializable.hh>
+
# include <scribo/primitive/extract/components.hh>
namespace scribo
{
template <typename L>
- struct document
+ struct document : public Serializable<document<L> >
{
public:
@@ -98,7 +100,7 @@ namespace scribo
private:
- const char *filename_;
+ std::string filename_;
mln::image2d<mln::value::rgb8> image_;
paragraph_set<L> parset_;
@@ -142,7 +144,7 @@ namespace scribo
const char *
document<L>::filename() const
{
- return filename_;
+ return filename_.c_str();
}
diff --git a/scribo/scribo/core/internal/doc_xml_serializer.hh b/scribo/scribo/core/internal/doc_xml_serializer.hh
new file mode 100644
index 0000000..b64c9d4
--- /dev/null
+++ b/scribo/scribo/core/internal/doc_xml_serializer.hh
@@ -0,0 +1,140 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_CORE_INTERNAL_DOC_XML_SERIALIZER_HH
+# define SCRIBO_CORE_INTERNAL_DOC_XML_SERIALIZER_HH
+
+/// \file
+///
+/// Concept for serializer visitors.
+
+# include <scribo/core/concept/serialize_visitor.hh>
+
+# include <scribo/core/document.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/core/component_info.hh>
+# include <scribo/core/paragraph_set.hh>
+# include <scribo/core/object_groups.hh>
+# include <scribo/core/object_links.hh>
+# include <scribo/core/line_links.hh>
+# include <scribo/core/line_info.hh>
+
+namespace scribo
+{
+
+ /// \brief Link functor concept.
+ template <typename E>
+ class doc_xml_serializer : public SerializeVisitor<E>
+ {
+ public:
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ template <typename L>
+ void visit(const line_links<L>& llinks) const;
+
+ template <typename L>
+ void visit(const object_groups<L>& groups) const;
+
+ template <typename L>
+ void visit(const object_links<L>& links) const;
+
+ template <typename L>
+ void visit(const component_set<L>& comp_set) const;
+
+ void visit(const component_info& info) const;
+
+ template <typename L>
+ void visit(const paragraph_set<L>& parset) const;
+
+ template <typename L>
+ void visit(const line_info<L>& line) const;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ template <typename L>
+ void
+ doc_xml_serializer<E>::visit(const document<L>& doc) const
+ {
+ }
+
+ template <typename E>
+ template <typename L>
+ void
+ doc_xml_serializer<E>::visit(const line_links<L>& llinks) const
+ {
+ }
+
+ template <typename E>
+ template <typename L>
+ void
+ doc_xml_serializer<E>::visit(const object_groups<L>& groups) const
+ {
+ }
+
+ template <typename E>
+ template <typename L>
+ void
+ doc_xml_serializer<E>::visit(const object_links<L>& links) const
+ {
+ }
+
+ template <typename E>
+ template <typename L>
+ void
+ doc_xml_serializer<E>::visit(const component_set<L>& comp_set) const
+ {
+ }
+
+ template <typename E>
+ void
+ doc_xml_serializer<E>::visit(const component_info& info) const
+ {
+ }
+
+ template <typename E>
+ template <typename L>
+ void
+ doc_xml_serializer<E>::visit(const paragraph_set<L>& parset) const
+ {
+ }
+
+ template <typename E>
+ template <typename L>
+ void
+ doc_xml_serializer<E>::visit(const line_info<L>& line) const
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+
+} // end of namespace scribo
+
+#endif // SCRIBO_CORE_INTERNAL_DOC_XML_SERIALIZER_HH
diff --git a/scribo/scribo/core/line_info.hh b/scribo/scribo/core/line_info.hh
index c82160a..33a1529 100644
--- a/scribo/scribo/core/line_info.hh
+++ b/scribo/scribo/core/line_info.hh
@@ -53,6 +53,11 @@
# include <scribo/core/line_set.hh>
# include <scribo/core/component_set.hh>
+# include <scribo/io/xml/internal/html_markups_replace.hh>
+
+# include <scribo/core/concept/serializable.hh>
+
+
namespace scribo
{
@@ -114,6 +119,7 @@ namespace scribo
bool indented_;
std::string text_;
+ std::string html_text_;
// Line set holding this element.
line_set<L> holder_;
@@ -125,7 +131,7 @@ namespace scribo
template <typename L>
- class line_info
+ class line_info : public Serializable<line_info<L> >
{
typedef internal::line_info_data<L> data_t;
typedef mln::util::object_id<scribo::ComponentId, unsigned> component_id_t;
@@ -198,6 +204,7 @@ namespace scribo
bool has_text() const;
const std::string& text() const;
+ const std::string& html_text() const;
void update_text(const std::string& str);
bool is_valid() const;
@@ -604,6 +611,7 @@ namespace scribo
return data_->indented_;
}
+
template <typename L>
bool
line_info<L>::has_text() const
@@ -611,6 +619,7 @@ namespace scribo
return !data_->text_.empty();
}
+
template <typename L>
const std::string&
line_info<L>::text() const
@@ -620,10 +629,19 @@ namespace scribo
template <typename L>
+ const std::string&
+ line_info<L>::html_text() const
+ {
+ return data_->html_text_;
+ }
+
+
+ template <typename L>
void
line_info<L>::update_text(const std::string& str)
{
data_->text_ = str;
+ data_->html_text_ = scribo::io::xml::internal::html_markups_replace(str);
}
@@ -987,6 +1005,7 @@ namespace scribo
<< ", indented=" << info.indented()
<< ", hidden=" << info.is_hidden()
<< ", text=" << info.text()
+ << ", html_text=" << info.html_text()
<< ")" << std::endl;
}
diff --git a/scribo/scribo/core/line_links.hh b/scribo/scribo/core/line_links.hh
index de62158..fdd09a5 100644
--- a/scribo/scribo/core/line_links.hh
+++ b/scribo/scribo/core/line_links.hh
@@ -34,6 +34,7 @@
# include <mln/util/array.hh>
# include <mln/util/tracked_ptr.hh>
+# include <scribo/core/concept/serializable.hh>
# include <scribo/core/line_set.hh>
@@ -69,7 +70,7 @@ namespace scribo
/// \brief Line group representation.
//
template <typename L>
- class line_links
+ class line_links : public Serializable<line_links<L> >
{
typedef internal::line_links_data<L> data_t;
diff --git a/scribo/scribo/core/object_groups.hh b/scribo/scribo/core/object_groups.hh
index 9d9fb25..bbfaf6e 100644
--- a/scribo/scribo/core/object_groups.hh
+++ b/scribo/scribo/core/object_groups.hh
@@ -36,6 +36,8 @@
# include <scribo/core/object_links.hh>
# include <scribo/core/component_set.hh>
+# include <scribo/core/concept/serializable.hh>
+
namespace scribo
{
@@ -69,7 +71,7 @@ namespace scribo
/// \brief Object group representation.
//
template <typename L>
- class object_groups
+ class object_groups : public Serializable<object_groups<L> >
{
typedef internal::object_groups_data<L> data_t;
diff --git a/scribo/scribo/core/object_links.hh b/scribo/scribo/core/object_links.hh
index af7dc38..2c2eea1 100644
--- a/scribo/scribo/core/object_links.hh
+++ b/scribo/scribo/core/object_links.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -37,6 +37,8 @@
# include <scribo/core/component_set.hh>
+# include <scribo/core/concept/serializable.hh>
+
namespace scribo
{
@@ -70,7 +72,7 @@ namespace scribo
/// \brief Object group representation.
//
template <typename L>
- class object_links
+ class object_links : public Serializable<object_links<L> >
{
typedef internal::object_links_data<L> data_t;
diff --git a/scribo/scribo/core/paragraph_set.hh b/scribo/scribo/core/paragraph_set.hh
index 6597189..5451069 100644
--- a/scribo/scribo/core/paragraph_set.hh
+++ b/scribo/scribo/core/paragraph_set.hh
@@ -33,6 +33,8 @@
# include <scribo/core/line_set.hh>
# include <scribo/core/paragraph_info.hh>
+# include <scribo/core/concept/serializable.hh>
+
namespace scribo
{
@@ -61,7 +63,7 @@ namespace scribo
*/
template <typename L>
- class paragraph_set
+ class paragraph_set : public Serializable<paragraph_set<L> >
{
public:
paragraph_set();
diff --git a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
new file mode 100644
index 0000000..5d8a672
--- /dev/null
+++ b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
@@ -0,0 +1,283 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_XML_INTERNAL_EXTENDED_PAGE_XML_VISITOR_HH
+# define SCRIBO_IO_XML_INTERNAL_EXTENDED_PAGE_XML_VISITOR_HH
+
+/// \file
+///
+/// Extended XML PAGE format serializer Visitor.
+
+# include <fstream>
+# include <scribo/core/internal/doc_xml_serializer.hh>
+# include <scribo/core/document.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/core/paragraph_set.hh>
+# include <scribo/core/object_groups.hh>
+# include <scribo/core/object_links.hh>
+# 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>
+
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace xml
+ {
+
+ namespace internal
+ {
+
+
+ class extended_page_xml_visitor : public doc_xml_serializer<extended_page_xml_visitor>
+ {
+ public:
+ // Constructor
+ extended_page_xml_visitor(std::ofstream& out);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ template <typename L>
+ void visit(const component_set<L>& comp_set) const;
+
+ void visit(const component_info& info) const;
+
+ template <typename L>
+ void visit(const paragraph_set<L>& parset) const;
+
+ template <typename L>
+ void visit(const line_info<L>& line) const;
+
+ private: // Attributes
+ std::ofstream& output;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ inline
+ extended_page_xml_visitor::extended_page_xml_visitor(std::ofstream& out)
+ : output(out)
+ {
+ }
+
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ extended_page_xml_visitor::visit(const document<L>& doc) const
+ {
+ // Preambule
+ print_PAGE_preambule(output, doc, false);
+
+ // Text
+ if (doc.has_text())
+ doc.paragraphs().accept(*this);
+
+
+ // Page elements (Pictures, ...)
+ if (doc.has_elements())
+ doc.elements().accept(*this);
+
+ // Whitespace seraparators
+ if (doc.has_whitespace_seps())
+ doc.whitespace_seps_comps().accept(*this);
+
+ output << " </page>" << std::endl;
+ output << "</pcGts>" << std::endl;
+
+ }
+
+ /// Component Set
+ //
+ template <typename L>
+ void
+ extended_page_xml_visitor::visit(const component_set<L>& comp_set) const
+ {
+ for_all_comps(c, comp_set)
+ if (comp_set(c).is_valid())
+ comp_set(c).accept(*this);
+ }
+
+
+ /// Component_info
+ //
+ inline
+ void
+ extended_page_xml_visitor::visit(const component_info& info) const
+ {
+ switch (info.type())
+ {
+ case component::WhitespaceSeparator:
+ {
+ output << " <whitespace_separator_region id=\"wss"
+ << info.id()
+ << "\">" << std::endl;
+
+ internal::print_box_coords(output, info.bbox(), " ");
+
+ output << " </whitespace_separator_region>" << std::endl;
+ break;
+ }
+
+ case component::LineSeparator:
+ {
+ output << " <separator_region id=\"sr" << info.id()
+ << "\" sep_orientation=\"0.000000\" "
+ << " sep_colour=\"Black\" "
+ << " sep_bgcolour=\"White\">" << std::endl;
+
+ internal::print_box_coords(output, info.bbox(), " ");
+
+ output << " </separator_region>" << std::endl;
+ break;
+ }
+
+
+ default:
+ case component::Image:
+ {
+ output << " <image_region id=\"ir" << info.id()
+ << "\" img_colour_type=\"24_Bit_Colour\""
+ << " img_orientation=\"0.000000\" "
+ << " img_emb_text=\"No\" "
+ << " img_bgcolour=\"White\">" << std::endl;
+
+ internal::print_box_coords(output, info.bbox(), " ");
+
+ output << " </image_region>" << std::endl;
+ break;
+ }
+ }
+ }
+
+
+ /// Paragraph Set
+ //
+ template <typename L>
+ void
+ extended_page_xml_visitor::visit(const paragraph_set<L>& parset) const
+ {
+ const line_set<L>& lines = parset.lines();
+
+ for_all_paragraphs(p, parset)
+ {
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ // FIXME: compute that information on the whole paragraph
+ // and use them here.
+ line_id_t fid = line_ids(0);
+ output << " <text_region id=\"" << p
+ << "\" txt_orientation=\"" << lines(fid).orientation()
+ << "\" txt_reading_orientation=\"" << lines(fid).reading_orientation()
+ << "\" txt_reading_direction=\"" << lines(fid).reading_direction()
+ << "\" txt_text_type=\"" << lines(fid).type()
+ << "\" txt_reverse_video=\"" << (lines(fid).reverse_video() ? "true" : "false")
+ << "\" txt_indented=\"" << (lines(fid).indented() ? "true" : "false")
+ << "\" kerning=\"" << lines(fid).char_space();
+
+ // EXTENSIONS - Not officially supported
+ output << "\" baseline=\"" << lines(fid).baseline()
+ << "\" meanline=\"" << lines(fid).meanline()
+ << "\" x_height=\"" << lines(fid).x_height()
+ << "\" d_height=\"" << lines(fid).d_height()
+ << "\" a_height=\"" << lines(fid).a_height()
+ << "\" char_width=\"" << lines(fid).char_width();
+ // End of EXTENSIONS
+ output << "\">"
+ << std::endl;
+
+ internal::print_box_coords(output, parset(p).bbox(), " ");
+
+ // EXTENSIONS - Not officially supported
+ for_all_paragraph_lines(lid, line_ids)
+ {
+ line_id_t l = line_ids(lid);
+ lines(l).accept(*this);
+ }
+ // End of EXTENSIONS
+
+ output << " </text_region>" << std::endl;
+ }
+ }
+
+
+ template <typename L>
+ void
+ extended_page_xml_visitor::visit(const line_info<L>& line) const
+ {
+ if (line.has_text())
+ {
+ output << " <line text=\"" << line.html_text() << "\" ";
+ }
+ else
+ output << " <line " << std::endl;
+
+ output << "id=\"" << line.id()
+ << "\" txt_orientation=\"" << line.orientation()
+ << "\" txt_reading_orientation=\"" << line.reading_orientation()
+ << "\" txt_reading_direction=\"" << line.reading_direction()
+ << "\" txt_text_type=\"" << line.type()
+ << "\" txt_reverse_video=\"" << (line.reverse_video() ? "true" : "false")
+ << "\" txt_indented=\"" << (line.indented() ? "true" : "false")
+ << "\" kerning=\"" << line.char_space()
+ << "\" baseline=\"" << line.baseline()
+ << "\" meanline=\"" << line.meanline()
+ << "\" x_height=\"" << line.x_height()
+ << "\" d_height=\"" << line.d_height()
+ << "\" a_height=\"" << line.a_height()
+ << "\" char_width=\"" << line.char_width()
+ << "\">" << std::endl;
+
+ internal::print_box_coords(output, line.bbox(), " ");
+
+ output << " </line>" << std::endl;
+ }
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::xml::internal
+
+ } // end of namespace scribo::io::xml
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_XML_INTERNAL_EXTENDED_PAGE_XML_VISITOR_HH
diff --git a/scribo/scribo/io/xml/internal/full_xml_visitor.hh b/scribo/scribo/io/xml/internal/full_xml_visitor.hh
new file mode 100644
index 0000000..9c5bd1d
--- /dev/null
+++ b/scribo/scribo/io/xml/internal/full_xml_visitor.hh
@@ -0,0 +1,456 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_XML_INTERNAL_FULL_XML_VISITOR_HH
+# define SCRIBO_IO_XML_INTERNAL_FULL_XML_VISITOR_HH
+
+/// \file
+///
+/// XML serializer Visitor.
+
+# include <fstream>
+# include <scribo/core/internal/doc_xml_serializer.hh>
+# include <scribo/core/document.hh>
+# include <scribo/core/component_set.hh>
+# include <scribo/core/paragraph_set.hh>
+# include <scribo/core/object_groups.hh>
+# include <scribo/core/object_links.hh>
+# 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>
+
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace xml
+ {
+
+ namespace internal
+ {
+
+
+ class full_xml_visitor : public doc_xml_serializer<full_xml_visitor>
+ {
+ public:
+ // Constructor
+ full_xml_visitor(std::ofstream& out);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ template <typename L>
+ void visit(const line_links<L>& llinks) const;
+
+ template <typename L>
+ void visit(const object_groups<L>& groups) const;
+
+ template <typename L>
+ void visit(const object_links<L>& links) const;
+
+ template <typename L>
+ void visit(const component_set<L>& comp_set) const;
+
+ void visit(const component_info& info) const;
+
+ template <typename L>
+ void visit(const paragraph_set<L>& parset) const;
+
+ template <typename L>
+ void visit(const line_info<L>& line) const;
+
+ private: // Attributes
+ std::ofstream& output;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ inline
+ full_xml_visitor::full_xml_visitor(std::ofstream& out)
+ : output(out)
+ {
+ }
+
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ full_xml_visitor::visit(const document<L>& doc) const
+ {
+ print_PAGE_preambule(output, doc, false);
+
+ // Text
+ if (doc.has_text())
+ {
+ const line_set<L>& lines = doc.lines();
+
+ // Save component/link/group information (Extension)
+ {
+ // Component set
+ lines.components().accept(*this);
+
+ // Object link
+ lines.links().accept(*this);
+
+ // Object group
+ lines.groups().accept(*this);
+ }
+ // End of EXTENSIONS
+
+ const paragraph_set<L>& parset = doc.paragraphs();
+
+ // Save paragraphs related information (Extension)
+ {
+ // General text information
+ output << " <text_data nlines=\"" << lines.nelements() << "\" "
+ << " nparagraphs=\"" << parset.nelements() << "\" />" << std::endl;
+
+ // line_links
+ parset.links().accept(*this);
+ }
+
+ // Paragraph and lines
+ parset.accept(*this);
+ }
+
+
+ // Page elements (Pictures, ...)
+ if (doc.has_elements())
+ {
+ const component_set<L>& elts = doc.elements();
+ for_all_comps(e, elts)
+ if (elts(e).is_valid())
+ elts(e).accept(*this);
+ }
+
+
+ // line seraparators
+ if (doc.has_line_seps())
+ {
+ const component_set<L>&
+ line_seps_comps = doc.line_seps_comps();
+
+ for_all_comps(c, line_seps_comps)
+ line_seps_comps(c).accept(*this);
+ }
+
+
+ // Whitespace seraparators
+ if (doc.has_whitespace_seps())
+ {
+ const component_set<L>&
+ whitespace_seps_comps = doc.whitespace_seps_comps();
+
+ for_all_comps(c, whitespace_seps_comps)
+ whitespace_seps_comps(c).accept(*this);
+ }
+
+ output << " </page>" << std::endl;
+ output << "</pcGts>" << std::endl;
+
+ }
+
+
+ /// Line Links
+ //
+ template <typename L>
+ void
+ full_xml_visitor::visit(const line_links<L>& llinks) const
+ {
+ output << " <line_links>" << std::endl;
+ for_all_links(l, llinks)
+ {
+ output << " <line_link"
+ << " from=\"" << l
+ << "\" to=\"" << llinks(l)
+ << "\"/>" << std::endl;
+ }
+ output << " </line_links>" << std::endl;
+ }
+
+
+ /// Object Groups
+ //
+ template <typename L>
+ void
+ full_xml_visitor::visit(const object_groups<L>& groups) const
+ {
+ output << " <object_groups>" << std::endl;
+ for_all_groups(g, groups)
+ {
+ output << " <group "
+ << " object_id=\"" << g
+ << "\" group_id=\"" << groups(g)
+ << "\"/>" << std::endl;
+ }
+ output << " </object_groups>" << std::endl;
+ }
+
+
+ /// Object Links
+ //
+ template <typename L>
+ void
+ full_xml_visitor::visit(const object_links<L>& links) const
+ {
+ output << " <object_links>" << std::endl;
+ for_all_links(l, links)
+ {
+ output << " <link"
+ << " from=\"" << l
+ << "\" to=\"" << links(l)
+ << "\"/>" << std::endl;
+ }
+ output << " </object_links>" << std::endl;
+ }
+
+
+ /// Component Set
+ //
+ template <typename L>
+ void
+ full_xml_visitor::visit(const component_set<L>& comp_set) const
+ {
+ output << " <component_set nelements=\"" << comp_set.nelements()
+ << "\">" << std::endl;
+ for_all_comps(c, comp_set)
+ {
+ output << " <component_info"
+ << " id=\"" << comp_set(c).id()
+ << "\" mass_center_x=\"" << comp_set(c).mass_center().col()
+ << "\" mass_center_y=\"" << comp_set(c).mass_center().row()
+ << "\" card=\"" << comp_set(c).card()
+ << "\" tag=\"" << comp_set(c).tag()
+ << "\" type=\"" << comp_set(c).type()
+ << "\" pmin_x=\"" << comp_set(c).bbox().pmin().col()
+ << "\" pmin_y=\"" << comp_set(c).bbox().pmin().row()
+ << "\" pmax_x=\"" << comp_set(c).bbox().pmax().col()
+ << "\" pmax_y=\"" << comp_set(c).bbox().pmax().row()
+ << "\"/>" << std::endl;
+ }
+
+
+ // Save labeled image
+ {
+ const L& lbl = comp_set.labeled_image();
+ output << "<labeled_image "
+ << " height=\"" << lbl.domain().height()
+ << "\" 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());
+
+ output << "]]></labeled_image>" << std::endl;
+ }
+
+ // Save separators image
+ {
+ const mln_ch_value(L,bool)& seps = comp_set.separators();
+ output << "<separators_image "
+ << " height=\"" << seps.domain().height()
+ << "\" 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());
+
+ output << "]]></separators_image>" << std::endl;
+ }
+
+ output << "</component_set>" << std::endl;
+ }
+
+
+ /// Component_info
+ //
+ inline
+ void
+ full_xml_visitor::visit(const component_info& info) const
+ {
+ switch (info.type())
+ {
+ case component::WhitespaceSeparator:
+ {
+ output << " <whitespace_separator_region id=\"wss"
+ << info.id()
+ << "\">" << std::endl;
+
+ internal::print_box_coords(output, info.bbox(), " ");
+
+ output << " </whitespace_separator_region>" << std::endl;
+ break;
+ }
+
+ case component::LineSeparator:
+ {
+ output << " <separator_region id=\"sr" << info.id()
+ << "\" sep_orientation=\"0.000000\" "
+ << " sep_colour=\"Black\" "
+ << " sep_bgcolour=\"White\">" << std::endl;
+
+ internal::print_box_coords(output, info.bbox(), " ");
+
+ output << " </separator_region>" << std::endl;
+ break;
+ }
+
+
+ default:
+ case component::Image:
+ {
+ output << " <image_region id=\"ir" << info.id()
+ << "\" img_colour_type=\"24_Bit_Colour\""
+ << " img_orientation=\"0.000000\" "
+ << " img_emb_text=\"No\" "
+ << " img_bgcolour=\"White\">" << std::endl;
+
+ internal::print_box_coords(output, info.bbox(), " ");
+
+ output << " </image_region>" << std::endl;
+ break;
+ }
+ }
+ }
+
+ /// Paragraph Set
+ //
+ template <typename L>
+ void
+ full_xml_visitor::visit(const paragraph_set<L>& parset) const
+ {
+ const line_set<L>& lines = parset.lines();
+
+ for_all_paragraphs(p, parset)
+ {
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ // FIXME: compute that information on the whole paragraph
+ // and use them here.
+ line_id_t fid = line_ids(0);
+ output << " <text_region id=\"" << p
+ << "\" txt_orientation=\"" << lines(fid).orientation()
+ << "\" txt_reading_orientation=\"" << lines(fid).reading_orientation()
+ << "\" txt_reading_direction=\"" << lines(fid).reading_direction()
+ << "\" txt_text_type=\"" << lines(fid).type()
+ << "\" txt_reverse_video=\"" << (lines(fid).reverse_video() ? "true" : "false")
+ << "\" txt_indented=\"" << (lines(fid).indented() ? "true" : "false")
+ << "\" kerning=\"" << lines(fid).char_space();
+
+ // EXTENSIONS - Not officially supported
+ output << "\" baseline=\"" << lines(fid).baseline()
+ << "\" meanline=\"" << lines(fid).meanline()
+ << "\" x_height=\"" << lines(fid).x_height()
+ << "\" d_height=\"" << lines(fid).d_height()
+ << "\" a_height=\"" << lines(fid).a_height()
+ << "\" char_width=\"" << lines(fid).char_width();
+ // End of EXTENSIONS
+ output << "\">"
+ << std::endl;
+
+ internal::print_box_coords(output, parset(p).bbox(), " ");
+
+
+ // EXTENSIONS - Not officially supported
+ for_all_paragraph_lines(lid, line_ids)
+ {
+ line_id_t l = line_ids(lid);
+
+ lines(l).accept(*this);
+ }
+
+ output << " </text_region>" << std::endl;
+ }
+ }
+
+
+ template <typename L>
+ void
+ full_xml_visitor::visit(const line_info<L>& line) const
+ {
+ if (line.has_text())
+ {
+ output << " <line text=\"" << line.html_text() << "\" ";
+ }
+ else
+ output << " <line " << std::endl;
+
+ output << "id=\"" << line.id()
+ << "\" txt_orientation=\"" << line.orientation()
+ << "\" txt_reading_orientation=\"" << line.reading_orientation()
+ << "\" txt_reading_direction=\"" << line.reading_direction()
+ << "\" txt_text_type=\"" << line.type()
+ << "\" txt_reverse_video=\"" << (line.reverse_video() ? "true" : "false")
+ << "\" txt_indented=\"" << (line.indented() ? "true" : "false")
+ << "\" kerning=\"" << line.char_space()
+ << "\" baseline=\"" << line.baseline()
+ << "\" meanline=\"" << line.meanline()
+ << "\" x_height=\"" << line.x_height()
+ << "\" d_height=\"" << line.d_height()
+ << "\" a_height=\"" << line.a_height()
+ << "\" char_width=\"" << line.char_width()
+ << "\">" << std::endl;
+
+ internal::print_box_coords(output, line.bbox(), " ");
+
+ output << " <compid_list>" << std::endl;
+
+ for_all_line_comps(c, line.components())
+ output << " <compid value=\""
+ << line.components()(c) << "\" />" << std::endl;
+
+ output << " </compid_list>" << std::endl;
+
+ output << " </line>" << std::endl;
+ }
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::xml::internal
+
+ } // end of namespace scribo::io::xml
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_XML_INTERNAL_FULL_XML_VISITOR_HH
diff --git a/scribo/scribo/io/xml/internal/html_markups_replace.hh b/scribo/scribo/io/xml/internal/html_markups_replace.hh
new file mode 100644
index 0000000..76f8107
--- /dev/null
+++ b/scribo/scribo/io/xml/internal/html_markups_replace.hh
@@ -0,0 +1,97 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_XML_INTERNAL_HTML_MARKUPS_REPLACE_HH
+# define SCRIBO_IO_XML_INTERNAL_HTML_MARKUPS_REPLACE_HH
+
+/// \file
+///
+/// \brief Replace HTML markups characters by their corresponding
+/// markups.
+
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace xml
+ {
+
+ namespace internal
+ {
+
+ /*! \brief Replace HTML markups characters by their corresponding
+ markups.
+ */
+ inline
+ std::string
+ html_markups_replace(std::string& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ static inline std::map<char, std::string> init_map()
+ {
+ std::map<char, std::string> html_map;
+ html_map['\"'] = """;
+ html_map['<'] = "<";
+ html_map['>'] = ">";
+ html_map['&'] = "&";
+ return html_map;
+ }
+
+
+ inline
+ std::string
+ html_markups_replace(const std::string& input)
+ {
+ static std::map<char, std::string> map = init_map();
+
+ std::string output = input;
+ for (unsigned i = 0; i < input.size(); ++i)
+ {
+ std::map<char, std::string>::iterator it = map.find(output.at(i));
+ if (it != map.end())
+ {
+ output.replace(i, 1, it->second);
+ i += it->second.size() - 1;
+ }
+ }
+ return output;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::xml::internal
+
+ } // end of namespace scribo::io::xml
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_IO_XML_INTERNAL_HTML_MARKUPS_REPLACE_HH
diff --git a/scribo/scribo/io/xml/internal/page_xml_visitor.hh b/scribo/scribo/io/xml/internal/page_xml_visitor.hh
new file mode 100644
index 0000000..52d8f12
--- /dev/null
+++ b/scribo/scribo/io/xml/internal/page_xml_visitor.hh
@@ -0,0 +1,222 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_XML_INTERNAL_PAGE_XML_VISITOR_HH
+# define SCRIBO_IO_XML_INTERNAL_PAGE_XML_VISITOR_HH
+
+/// \file
+///
+/// PAGE format XML serializer Visitor.
+
+# include <fstream>
+
+# include <scribo/core/internal/doc_xml_serializer.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>
+
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace xml
+ {
+
+ namespace internal
+ {
+
+ /*! \brief Save document information as XML.
+
+ We use a XML Schema part of the PAGE (Page Analysis and Ground
+ truth Elements) image representation framework.
+
+ This schema was used in the Page Segmentation COMPetition
+ (PSCOMP) for ICDAR 2009.
+
+ Its XSD file is located here:
+ http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16/pagecontent…
+
+ */
+ class page_xml_visitor : public doc_xml_serializer<page_xml_visitor>
+ {
+ public:
+ // Constructor
+ page_xml_visitor(std::ofstream& out);
+
+ // Visit overloads
+ template <typename L>
+ void visit(const document<L>& doc) const;
+
+ template <typename L>
+ void visit(const component_set<L>& comp_set) const;
+
+ void visit(const component_info& info) const;
+
+ template <typename L>
+ void visit(const paragraph_set<L>& parset) const;
+
+ private: // Attributes
+ std::ofstream& output;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ inline
+ page_xml_visitor::page_xml_visitor(std::ofstream& out)
+ : output(out)
+ {
+ }
+
+
+
+ /// Document
+ //
+ template <typename L>
+ void
+ page_xml_visitor::visit(const document<L>& doc) const
+ {
+ // Preambule
+ print_PAGE_preambule(output, doc, true);
+
+ // Text
+ if (doc.has_text())
+ doc.paragraphs().accept(*this);
+
+ // Page elements (Pictures, ...)
+ if (doc.has_elements())
+ doc.elements().accept(*this);
+
+ // line seraparators
+ if (doc.has_line_seps())
+ doc.line_seps_comps().accept(*this);
+
+ output << " </page>" << std::endl;
+ output << "</pcGts>" << std::endl;
+ }
+
+
+ /// Component Set
+ //
+ template <typename L>
+ void
+ page_xml_visitor::visit(const component_set<L>& comp_set) const
+ {
+ for_all_comps(c, comp_set)
+ if (comp_set(c).is_valid())
+ comp_set(c).accept(*this);
+ }
+
+
+ /// Component_info
+ //
+ inline
+ void
+ page_xml_visitor::visit(const component_info& info) const
+ {
+ switch (info.type())
+ {
+ case component::LineSeparator:
+ {
+ output << " <separator_region id=\"sr" << info.id()
+ << "\" sep_orientation=\"0.000000\" "
+ << " sep_colour=\"Black\" "
+ << " sep_bgcolour=\"White\">" << std::endl;
+
+ internal::print_box_coords(output, info.bbox(), " ");
+
+ output << " </separator_region>" << std::endl;
+ break;
+ }
+
+
+ default:
+ case component::Image:
+ {
+ output << " <image_region id=\"ir" << info.id()
+ << "\" img_colour_type=\"24_Bit_Colour\""
+ << " img_orientation=\"0.000000\" "
+ << " img_emb_text=\"No\" "
+ << " img_bgcolour=\"White\">" << std::endl;
+
+ internal::print_box_coords(output, info.bbox(), " ");
+
+ output << " </image_region>" << std::endl;
+ break;
+ }
+ }
+ }
+
+
+ /// Paragraph Set
+ //
+ template <typename L>
+ void
+ page_xml_visitor::visit(const paragraph_set<L>& parset) const
+ {
+ const line_set<L>& lines = parset.lines();
+
+ for_all_paragraphs(p, parset)
+ {
+ const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
+
+ // FIXME: compute that information on the whole paragraph
+ // and use them here.
+ line_id_t fid = line_ids(0);
+ output << " <text_region id=\"" << p
+ << "\" txt_orientation=\"" << lines(fid).orientation()
+ << "\" txt_reading_orientation=\"" << lines(fid).reading_orientation()
+ << "\" txt_reading_direction=\"" << lines(fid).reading_direction()
+ << "\" txt_text_type=\"" << lines(fid).type()
+ << "\" txt_reverse_video=\"" << (lines(fid).reverse_video() ? "true" : "false")
+ << "\" txt_indented=\"" << (lines(fid).indented() ? "true" : "false")
+ << "\" kerning=\"" << lines(fid).char_space()
+ << "\">"
+ << std::endl;
+
+ internal::print_box_coords(output, parset(p).bbox(), " ");
+
+ output << " </text_region>" << std::endl;
+ }
+ }
+
+
+#endif // MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::xml::internal
+
+ } // end of namespace scribo::io::xml
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // SCRIBO_IO_XML_INTERNAL_PAGE_XML_VISITOR_HH
diff --git a/scribo/scribo/io/xml/internal/print_box_coords.hh b/scribo/scribo/io/xml/internal/print_box_coords.hh
new file mode 100644
index 0000000..d3aeedf
--- /dev/null
+++ b/scribo/scribo/io/xml/internal/print_box_coords.hh
@@ -0,0 +1,92 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
+# define SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
+
+/// \file
+///
+/// \brief Prints box2d coordinates to XML data.
+
+# include <mln/core/alias/box2d.hh>
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace xml
+ {
+
+ namespace internal
+ {
+
+ /*! \brief Prints box2d coordinates to XML data.
+ */
+ void
+ print_box_coords(std::ofstream& ostr, const box2d& b,
+ const char *space);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ inline
+ void
+ print_box_coords(std::ofstream& ostr, const box2d& b,
+ const char *space)
+ {
+ std::string sc = space;
+ std::string sp = sc + " ";
+ ostr << sc << "<coords>" << std::endl
+ << sp << "<point x=\"" << b.pmin().col()
+ << "\" y=\"" << b.pmin().row() << "\"/>"
+ << std::endl
+ << sp << "<point x=\"" << b.pmax().col()
+ << "\" y=\"" << b.pmin().row() << "\"/>"
+ << std::endl
+ << sp << "<point x=\"" << b.pmax().col()
+ << "\" y=\"" << b.pmax().row() << "\"/>"
+ << std::endl
+ << sp << "<point x=\"" << b.pmin().col()
+ << "\" y=\"" << b.pmax().row() << "\"/>"
+ << std::endl
+ << sc << "</coords>" << std::endl;
+
+ }
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::xml::internal
+
+ } // end of namespace scribo::io::xml
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_IO_XML_INTERNAL_PRINT_BOX_COORDS_HH
diff --git a/scribo/scribo/io/xml/internal/print_page_preambule.hh b/scribo/scribo/io/xml/internal/print_page_preambule.hh
new file mode 100644
index 0000000..b5ae891
--- /dev/null
+++ b/scribo/scribo/io/xml/internal/print_page_preambule.hh
@@ -0,0 +1,95 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+#ifndef SCRIBO_IO_XML_INTERNAL_PRINT_PAGE_PREAMBULE_HH
+# define SCRIBO_IO_XML_INTERNAL_PRINT_PAGE_PREAMBULE_HH
+
+/// \file
+///
+/// \brief Print PAGE XML format preambule.
+
+# include <mln/core/alias/box2d.hh>
+
+namespace scribo
+{
+
+ namespace io
+ {
+
+ namespace xml
+ {
+
+ namespace internal
+ {
+
+ /// \brief Print PAGE XML format preambule.
+ template <typename L>
+ void print_PAGE_preambule(std::ofstream& output,
+ const document<L>& doc,
+ bool with_validation);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename L>
+ void print_PAGE_preambule(std::ofstream& output,
+ const document<L>& doc,
+ bool with_validation)
+ {
+ output << "<?xml version=\"1.0\"?>" << std::endl;
+
+ if (with_validation)
+ output << "<pcGts xmlns=\"http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16\" "
+ << "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "
+ << "xsi:schemaLocation=\"http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16 "
+ << "http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16/pagecontent…" "
+ << "pcGtsId=\"" << doc.filename() << "\">" << std::endl;
+ else
+ output << "<pcGts>" << std::endl;
+
+ output << " <pcMetadata>" << std::endl;
+ output << " <pcCreator>LRDE</pcCreator>" << std::endl;
+ output << " <pcCreated/>" << std::endl;
+ output << " <pcLastChange/>" << std::endl;
+ output << " <pcComments>Generated by Scribo from Olena.</pcComments>" << std::endl;
+ output << " </pcMetadata>" << std::endl;
+
+ output << " <page image_filename=\"" << doc.filename()
+ << "\" image_width=\"" << doc.width()
+ << "\" image_height=\"" << doc.height()
+ << "\">" << std::endl;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::io::xml::internal
+
+ } // end of namespace scribo::io::xml
+
+ } // end of namespace scribo::io
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_IO_XML_INTERNAL_PRINT_PAGE_PREAMBULE_HH
diff --git a/scribo/scribo/io/xml/save.hh b/scribo/scribo/io/xml/save.hh
index 7011e87..30579d0 100644
--- a/scribo/scribo/io/xml/save.hh
+++ b/scribo/scribo/io/xml/save.hh
@@ -38,7 +38,11 @@
# include <map>
# include <scribo/core/document.hh>
-# include <scribo/core/line_set.hh>
+
+# include <scribo/io/xml/internal/full_xml_visitor.hh>
+# include <scribo/io/xml/internal/extended_page_xml_visitor.hh>
+# include <scribo/io/xml/internal/page_xml_visitor.hh>
+
namespace scribo
{
@@ -49,360 +53,104 @@ namespace scribo
namespace xml
{
- /*! \brief Save document information as XML.
+ /*! \brief Supported XML formats
+
+ Page : PRima PAGE format. Used in ICDAR 2009.
- We use a XML Schema part of the PAGE (Page Analysis and Ground
- truth Elements) image representation framework.
+ PageExtended : Enriched PRima PAGE format with scribo data.
+
+ Full : Enriched PRima PAGE format with scribo data. This
+ format can be reloaded in Scribo.
+ */
+ enum Format
+ {
+ Page,
+ PageExtended,
+ Full
+ //Hocr
+ };
- This schema was used in the Page Segmentation COMPetition
- (PSCOMP) for ICDAR 2009.
- Its XSD file is located here:
- http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16/pagecontent…
+ /*! \brief Save document information as XML.
*/
template <typename L>
void
- save(const document<L>& doc,
- const std::string& output_name,
- bool allow_extensions);
+ save(const document<L>& doc, const std::string& output_name,
+ Format format);
# ifndef MLN_INCLUDE_ONLY
+
namespace internal
{
- inline
- std::string&
- html_markups_replace(std::string& input,
- std::map<char, std::string>& map)
- {
- for (unsigned i = 0; i < input.size(); ++i)
- {
- std::map<char, std::string>::iterator it = map.find(input.at(i));
- if (it != map.end())
- {
- input.replace(i, 1, it->second);
- i += it->second.size() - 1;
- }
- }
- return input;
- }
-
-
- inline
- void print_box_coords(std::ofstream& ostr, const box2d& b,
- const char *space)
+ template <typename L>
+ void save_page(const document<L>& doc, std::ofstream& output)
{
- std::string sc = space;
- std::string sp = sc + " ";
- ostr << sc << "<coords>" << std::endl
- << sp << "<point x=\"" << b.pmin().col()
- << "\" y=\"" << b.pmin().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmax().col()
- << "\" y=\"" << b.pmin().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmax().col()
- << "\" y=\"" << b.pmax().row() << "\"/>"
- << std::endl
- << sp << "<point x=\"" << b.pmin().col()
- << "\" y=\"" << b.pmax().row() << "\"/>"
- << std::endl
- << sc << "</coords>" << std::endl;
-
+ scribo::io::xml::internal::page_xml_visitor f(output);
+ doc.accept(f);
}
-
-
template <typename L>
- void
- save(const document<L>& doc,
- const std::string& output_name)
+ void save_page_extended(const document<L>& doc, std::ofstream& output)
{
- trace::entering("scribo::io::xml:save_text_lines");
-
- std::ofstream file(output_name.c_str());
- if (! file)
- {
- std::cerr << "error: cannot open file '" << doc.filename() << "'!";
- abort();
- }
-
- std::map<char, std::string> html_map;
- html_map['\"'] = """;
- html_map['<'] = "<";
- html_map['>'] = ">";
- html_map['&'] = "&";
-
- file << "<?xml version=\"1.0\"?>" << std::endl;
- file << "<pcGts xmlns=\"http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16 http://schema.primaresearch.org/PAGE/gts/pagecontent/2009-03-16/pagecontent…" pcGtsId=\"" << doc.filename() << "\">" << std::endl;
-
- file << " <pcMetadata>" << std::endl;
- file << " <pcCreator>LRDE</pcCreator>" << std::endl;
- file << " <pcCreated/>" << std::endl;
- file << " <pcLastChange/>" << std::endl;
- file << " <pcComments>Generated by Scribo from Olena.</pcComments>" << std::endl;
- file << " </pcMetadata>" << std::endl;
-
- file << " <page image_filename=\"" << doc.filename()
- << "\" image_width=\"" << doc.width()
- << "\" image_height=\"" << doc.height()
- << "\">" << std::endl;
-
- // Text
- if (doc.has_text())
- {
- const line_set<L>& lines = doc.lines();
- const paragraph_set<L>& parset = doc.paragraphs();
-
- for_all_paragraphs(p, parset)
- {
- const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
-
- // FIXME: compute that information on the whole paragraph
- // and use them here.
- line_id_t fid = line_ids(0);
- file << " <text_region id=\"" << p
- << "\" txt_orientation=\"" << lines(fid).orientation()
- << "\" txt_reading_orientation=\"" << lines(fid).reading_orientation()
- << "\" txt_reading_direction=\"" << lines(fid).reading_direction()
- << "\" txt_text_type=\"" << lines(fid).type()
- << "\" txt_reverse_video=\"" << (lines(fid).reverse_video() ? "true" : "false")
- << "\" txt_indented=\"" << (lines(fid).indented() ? "true" : "false")
- << "\" kerning=\"" << lines(fid).char_space()
- << "\">"
- << std::endl;
-
- internal::print_box_coords(file, parset(p).bbox(), " ");
-
- file << " </text_region>" << std::endl;
- }
- }
-
- // Page elements (Pictures, ...)
- if (doc.has_elements())
- {
- const component_set<L>& elts = doc.elements();
- for_all_comps(e, elts)
- if (elts(e).is_valid())
- {
- file << " <image_region id=\"ir" << elts(e).id()
- << "\" img_colour_type=\"24_Bit_Colour\""
- << " img_orientation=\"0.000000\" "
- << " img_emb_text=\"No\" "
- << " img_bgcolour=\"White\">" << std::endl;
-
- internal::print_box_coords(file, elts(e).bbox(), " ");
-
- file << " </image_region>" << std::endl;
- }
- }
-
-
- file << " </page>" << std::endl;
- file << "</pcGts>" << std::endl;
-
- trace::exiting("scribo::io::xml::save_text_lines");
+ scribo::io::xml::internal::extended_page_xml_visitor f(output);
+ doc.accept(f);
}
-
-
-
template <typename L>
- void
- save_extended(const document<L>& doc,
- const std::string& output_name)
+ void save_full(const document<L>& doc, std::ofstream& output)
{
- trace::entering("scribo::io::xml:save_text_lines");
-
- std::ofstream file(output_name.c_str());
- if (! file)
- {
- std::cerr << "error: cannot open file '" << doc.filename() << "'!";
- abort();
- }
-
- std::map<char, std::string> html_map;
- html_map['\"'] = """;
- html_map['<'] = "<";
- html_map['>'] = ">";
- html_map['&'] = "&";
-
- file << "<?xml version=\"1.0\"?>" << std::endl;
- file << "<pcGts>" << std::endl;
-
- file << " <pcMetadata>" << std::endl;
- file << " <pcCreator>LRDE</pcCreator>" << std::endl;
- file << " <pcCreated/>" << std::endl;
- file << " <pcLastChange/>" << std::endl;
- file << " <pcComments>Generated by Scribo from Olena.</pcComments>" << std::endl;
- file << " </pcMetadata>" << std::endl;
-
- file << " <page image_filename=\"" << doc.filename()
- << "\" image_width=\"" << doc.width()
- << "\" image_height=\"" << doc.height()
- << "\">" << std::endl;
-
- // Text
- if (doc.has_text())
- {
- const line_set<L>& lines = doc.lines();
- const paragraph_set<L>& parset = doc.paragraphs();
-
- for_all_paragraphs(p, parset)
- {
- const mln::util::array<line_id_t>& line_ids = parset(p).line_ids();
-
- // FIXME: compute that information on the whole paragraph
- // and use them here.
- line_id_t fid = line_ids(0);
- file << " <text_region id=\"" << p
- << "\" txt_orientation=\"" << lines(fid).orientation()
- << "\" txt_reading_orientation=\"" << lines(fid).reading_orientation()
- << "\" txt_reading_direction=\"" << lines(fid).reading_direction()
- << "\" txt_text_type=\"" << lines(fid).type()
- << "\" txt_reverse_video=\"" << (lines(fid).reverse_video() ? "true" : "false")
- << "\" txt_indented=\"" << (lines(fid).indented() ? "true" : "false")
- << "\" kerning=\"" << lines(fid).char_space();
-
- // EXTENSIONS - Not officially supported
- file << "\" baseline=\"" << lines(fid).baseline()
- << "\" meanline=\"" << lines(fid).meanline()
- << "\" x_height=\"" << lines(fid).x_height()
- << "\" d_height=\"" << lines(fid).d_height()
- << "\" a_height=\"" << lines(fid).a_height()
- << "\" char_width=\"" << lines(fid).char_width();
- // End of EXTENSIONS
- file << "\">"
- << std::endl;
-
- internal::print_box_coords(file, parset(p).bbox(), " ");
-
-
- // EXTENSIONS - Not officially supported
- for_all_paragraph_lines(lid, line_ids)
- {
- line_id_t l = line_ids(lid);
-
- if (lines(l).has_text())
- {
- std::string tmp = lines(l).text();
- tmp = internal::html_markups_replace(tmp, html_map);
-
- file << " <line text=\"" << tmp << "\" ";
- }
- else
- file << " <line " << std::endl;
-
- file << "id=\"" << lines(l).id()
- << "\" txt_orientation=\"" << lines(l).orientation()
- << "\" txt_reading_orientation=\"" << lines(l).reading_orientation()
- << "\" txt_reading_direction=\"" << lines(l).reading_direction()
- << "\" txt_text_type=\"" << lines(l).type()
- << "\" txt_reverse_video=\"" << (lines(l).reverse_video() ? "true" : "false")
- << "\" txt_indented=\"" << (lines(l).indented() ? "true" : "false")
- << "\" kerning=\"" << lines(l).char_space()
- << "\" baseline=\"" << lines(l).baseline()
- << "\" meanline=\"" << lines(l).meanline()
- << "\" x_height=\"" << lines(l).x_height()
- << "\" d_height=\"" << lines(l).d_height()
- << "\" a_height=\"" << lines(l).a_height()
- << "\" char_width=\"" << lines(l).char_width()
- << "\">" << std::endl;
-
- internal::print_box_coords(file, lines(l).bbox(), " ");
-
- file << " </line>" << std::endl;
- }
-
- file << " </text_region>" << std::endl;
- }
- }
- // End of EXTENSIONS
-
- // Page elements (Pictures, ...)
- if (doc.has_elements())
- {
- const component_set<L>& elts = doc.elements();
- for_all_comps(e, elts)
- if (elts(e).is_valid())
- {
- switch (elts(e).type())
- {
- case component::Separator:
- {
- file << " <separator_region id=\"sr" << elts(e).id()
- << "\" sep_orientation=\"0.000000\" "
- << " sep_colour=\"Black\" "
- << " sep_bgcolour=\"White\">" << std::endl;
-
- internal::print_box_coords(file, elts(e).bbox(), " ");
-
- file << " </separator_region>" << std::endl;
- break;
- break;
- }
-
- default:
- case component::Image:
- {
- file << " <image_region id=\"ir" << elts(e).id()
- << "\" img_colour_type=\"24_Bit_Colour\""
- << " img_orientation=\"0.000000\" "
- << " img_emb_text=\"No\" "
- << " img_bgcolour=\"White\">" << std::endl;
-
- internal::print_box_coords(file, elts(e).bbox(), " ");
-
- file << " </image_region>" << std::endl;
- break;
- }
- }
- }
- }
-
-
- // Whitespace seraparators
- if (doc.has_whitespace_seps())
- {
- const component_set<L>&
- whitespace_seps_comps = doc.whitespace_seps_comps();
-
- for_all_comps(c, whitespace_seps_comps)
- {
- file << " <whitespace_separator_region id=\"wss"
- << whitespace_seps_comps(c).id()
- << "\">" << std::endl;
-
- internal::print_box_coords(file, whitespace_seps_comps(c).bbox(), " ");
-
- file << " </whitespace_separator_region>" << std::endl;
- }
- }
-
- file << " </page>" << std::endl;
- file << "</pcGts>" << std::endl;
-
- trace::exiting("scribo::io::xml::save_text_lines");
+ scribo::io::xml::internal::full_xml_visitor f(output);
+ doc.accept(f);
}
} // end of namespace scribo::io::xml::internal
+
// FACADE
template <typename L>
void
save(const document<L>& doc,
const std::string& output_name,
- bool allow_extensions)
+ Format format)
{
- if (allow_extensions)
- internal::save_extended(doc, output_name);
- else
- internal::save(doc, output_name);
+ trace::entering("scribo::io::xml::save");
+
+ // Open file
+ std::ofstream output(output_name.c_str());
+ if (! output)
+ {
+ std::cerr << "scribo::io::xml::save - ERROR: cannot open file '"
+ << doc.filename() << "'!";
+ return;
+ }
+
+ // Choose saving method.
+ switch (format)
+ {
+ case Page:
+ internal::save_page(doc, output);
+ break;
+
+ case PageExtended:
+ internal::save_page_extended(doc, output);
+ break;
+
+ case Full:
+ internal::save_full(doc, output);
+ break;
+
+ default:
+ trace::warning("scribo::io::xml::save - Invalid XML format! Skip saving...");
+ }
+
+ output.close();
+ trace::exiting("scribo::io::xml::save");
}
diff --git a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
index 48098ba..dcbb4f7 100644
--- a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
+++ b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
@@ -36,7 +36,6 @@
# include <scribo/primitive/extract/non_text.hh>
# include <scribo/primitive/extract/components.hh>
-//# include <scribo/primitive/extract/vertical_separators.hh>
# include <scribo/primitive/extract/separators.hh>
# include <scribo/primitive/extract/separators_nonvisible.hh>
@@ -114,7 +113,7 @@ namespace scribo
bool enable_whitespace_seps;
bool enable_debug;
bool save_doc_as_xml;
- bool allow_xml_extensions;
+ scribo::io::xml::Format xml_format;
//============
// Parameters
@@ -139,7 +138,7 @@ namespace scribo
enable_whitespace_seps(true),
enable_debug(false),
save_doc_as_xml(false),
- allow_xml_extensions(true),
+ xml_format(scribo::io::xml::PageExtended),
ocr_language("eng"),
output_file("/tmp/foo.xml"),
doc(doc_filename)
@@ -189,7 +188,7 @@ namespace scribo
// Whitespace separators
on_new_progress_label("Find whitespace separators...");
- whitespaces = primitive::extract::separators_nonvisible(processed_image);
+ whitespaces = primitive::extract::separators_nonvisible(input_cleaned);
on_progress();
}
@@ -483,7 +482,7 @@ namespace scribo
{
on_new_progress_label("Saving results");
- scribo::io::xml::save(doc, output_file, allow_xml_extensions);
+ scribo::io::xml::save(doc, output_file, xml_format);
on_xml_saved();
on_progress();
diff --git a/scribo/src/content_in_doc.cc b/scribo/src/content_in_doc.cc
index 9748b28..d8d4e52 100644
--- a/scribo/src/content_in_doc.cc
+++ b/scribo/src/content_in_doc.cc
@@ -172,7 +172,9 @@ int main(int argc, char* argv[])
debug);
// Saving results
- scribo::io::xml::save(doc, argv[2], true);
+ scribo::io::xml::save(doc, argv[2], scribo::io::xml::PageExtended);
+ scribo::io::xml::save(doc, "page.xml", scribo::io::xml::Page);
+ scribo::io::xml::save(doc, "full.xml", scribo::io::xml::Full);
trace::exiting("main");
}
--
1.5.6.5
1
0
last-svn-commit-773-gb084bec Improve and cleanup whitespace separator detection.
by Guillaume Lazzara 29 Mar '11
by Guillaume Lazzara 29 Mar '11
29 Mar '11
* scribo/core/tag/anchor.hh: Add new anchors.
* scribo/filter/internal/alignment_angle.hh,
* scribo/primitive/link/internal/compute_anchor.hh: Support new
anchors.
* scribo/primitive/extract/separators_nonvisible.hh: Remove dead
code and comment debug code.
* scribo/toolchain/internal/content_in_doc_functor.hh: Detect
horizontal whitespace.
---
scribo/ChangeLog | 16 +
scribo/scribo/core/tag/anchor.hh | 5 +-
scribo/scribo/filter/internal/alignment_angle.hh | 144 +++--
.../primitive/extract/separators_nonvisible.hh | 673 +++++++++-----------
.../primitive/link/internal/compute_anchor.hh | 26 +-
.../toolchain/internal/content_in_doc_functor.hh | 13 +-
6 files changed, 447 insertions(+), 430 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index f03eb97..001e134 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,21 @@
2011-02-17 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Improve and cleanup whitespace separator detection.
+
+ * scribo/core/tag/anchor.hh: Add new anchors.
+
+ * scribo/filter/internal/alignment_angle.hh,
+ * scribo/primitive/link/internal/compute_anchor.hh: Support new
+ anchors.
+
+ * scribo/primitive/extract/separators_nonvisible.hh: Remove dead
+ code and comment debug code.
+
+ * scribo/toolchain/internal/content_in_doc_functor.hh: Detect
+ horizontal whitespace.
+
+2011-02-17 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add new conversion routines from string to tag.
* scribo/core/tag/component.hh,
diff --git a/scribo/scribo/core/tag/anchor.hh b/scribo/scribo/core/tag/anchor.hh
index 262a32d..bb6780c 100644
--- a/scribo/scribo/core/tag/anchor.hh
+++ b/scribo/scribo/core/tag/anchor.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2009, 2011 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of Olena.
//
@@ -43,9 +44,11 @@ namespace scribo
ActualRight,
Right,
TopLeft,
+ TopStrictLeft,
TopRight,
BottomLeft,
BottomRight,
+ BottomStrictRight,
Invalid
};
diff --git a/scribo/scribo/filter/internal/alignment_angle.hh b/scribo/scribo/filter/internal/alignment_angle.hh
index 5b88012..33855a8 100644
--- a/scribo/scribo/filter/internal/alignment_angle.hh
+++ b/scribo/scribo/filter/internal/alignment_angle.hh
@@ -1,4 +1,4 @@
-// Copyright (C) 2010 EPITA Research and Development Laboratory
+// Copyright (C) 2010, 2011 EPITA Research and Development Laboratory
// (LRDE)
//
// This file is part of Olena.
@@ -73,76 +73,98 @@ namespace scribo
unsigned current_object, unsigned nbh_object,
anchor::Type anchor)
{
- trace::entering("scribo::filter::internal::alignment_angle_rad");
+ trace::entering("scribo::filter::internal::alignment_angle");
mln_precondition(comps.is_valid());
- float dr, dc;
+ float dr, dc, result = 0;
if (nbh_object == current_object)
return 0;
- // Center
- if (anchor == anchor::Center)
+ switch(anchor)
{
- dr = math::abs(comps(current_object).bbox().pcenter().row()
- - comps(nbh_object).bbox().pcenter().row());
- dc = math::abs(comps(current_object).bbox().pcenter().col()
- - comps(nbh_object).bbox().pcenter().col());
-
- return std::atan(dr / dc);
- }
-
- // Top
- else if (anchor == anchor::Top)
- {
- dr = math::abs(comps(current_object).bbox().pmin().row()
- - comps(nbh_object).bbox().pmin().row());
- dc = math::abs(comps(current_object).bbox().pcenter().col()
- - comps(nbh_object).bbox().pcenter().col());
-
- return std::atan(dr / dc);
+ // Center
+ case anchor::Center:
+ {
+ dr = math::abs(comps(current_object).bbox().pcenter().row()
+ - comps(nbh_object).bbox().pcenter().row());
+ dc = math::abs(comps(current_object).bbox().pcenter().col()
+ - comps(nbh_object).bbox().pcenter().col());
+
+ result = std::atan(dr / dc);
+ }
+ break;
+
+ // Mass Center
+ case anchor::MassCenter:
+ {
+ dr = math::abs(comps(current_object).mass_center().row()
+ - comps(nbh_object).mass_center().row());
+ dc = math::abs(comps(current_object).mass_center().col()
+ - comps(nbh_object).mass_center().col());
+
+ result = std::atan(dr / dc);
+ }
+ break;
+
+ // Top
+ case anchor::TopStrictLeft:
+ case anchor::Top:
+ {
+ dr = math::abs(comps(current_object).bbox().pmin().row()
+ - comps(nbh_object).bbox().pmin().row());
+ dc = math::abs(comps(current_object).bbox().pcenter().col()
+ - comps(nbh_object).bbox().pcenter().col());
+
+ result = std::atan(dr / dc);
+ }
+ break;
+
+ // Bottom
+ case anchor::BottomStrictRight:
+ case anchor::Bottom:
+ {
+ dr = math::abs(comps(current_object).bbox().pmax().row()
+ - comps(nbh_object).bbox().pmax().row());
+ dc = math::abs(comps(current_object).bbox().pcenter().col()
+ - comps(nbh_object).bbox().pcenter().col());
+
+ result = std::atan(dr / dc);
+ }
+ break;
+
+ // Left
+ case anchor::Left:
+ {
+ dr = math::abs(comps(current_object).bbox().pcenter().row()
+ - comps(nbh_object).bbox().pcenter().row());
+ dc = math::abs(comps(current_object).bbox().pmin().col()
+ - comps(nbh_object).bbox().pmin().col());
+
+ result = std::atan(dc / dr);
+ }
+ break;
+
+ // Right
+ case anchor::Right:
+ {
+ dr = math::abs(comps(current_object).bbox().pcenter().row()
+ - comps(nbh_object).bbox().pcenter().row());
+ dc = math::abs(comps(current_object).bbox().pmax().col()
+ - comps(nbh_object).bbox().pmax().col());
+
+ result = std::atan(dc / dr);
+ }
+ break;
+
+ default:
+ trace::warning("scribo::filter::internal::alignment_angle,"
+ " Invalid anchor value... Aborting computation.");
}
- // Bottom
- else if (anchor == anchor::Bottom)
- {
- dr = math::abs(comps(current_object).bbox().pmax().row()
- - comps(nbh_object).bbox().pmax().row());
- dc = math::abs(comps(current_object).bbox().pcenter().col()
- - comps(nbh_object).bbox().pcenter().col());
-
- return std::atan(dr / dc);
- }
-
- // Left
- else if (anchor == anchor::Left)
- {
- dr = math::abs(comps(current_object).bbox().pcenter().row()
- - comps(nbh_object).bbox().pcenter().row());
- dc = math::abs(comps(current_object).bbox().pmin().col()
- - comps(nbh_object).bbox().pmin().col());
-
- return std::atan(dc / dr);
- }
-
- // Right
- else if (anchor == anchor::Right)
- {
- dr = math::abs(comps(current_object).bbox().pcenter().row()
- - comps(nbh_object).bbox().pcenter().row());
- dc = math::abs(comps(current_object).bbox().pmax().col()
- - comps(nbh_object).bbox().pmax().col());
-
- return std::atan(dc / dr);
- }
-
- else
- trace::warning("Invalid anchor value... Aborting computation.");
-
- trace::exiting("scribo::filter::internal::alignment_angle_rad");
- return 0;
-
+ trace::exiting("scribo::filter::internal::alignment_angle");
+ return result;
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/scribo/scribo/primitive/extract/separators_nonvisible.hh b/scribo/scribo/primitive/extract/separators_nonvisible.hh
index 81ebd64..4e31650 100644
--- a/scribo/scribo/primitive/extract/separators_nonvisible.hh
+++ b/scribo/scribo/primitive/extract/separators_nonvisible.hh
@@ -86,6 +86,8 @@
#include <scribo/preprocessing/denoise_fg.hh>
#include <scribo/preprocessing/rotate_90.hh>
+#include <scribo/primitive/link/internal/compute_anchor.hh>
+
#include <scribo/primitive/link/internal/dmax_default.hh>
#include <scribo/primitive/link/with_single_right_link_dmax_ratio.hh>
@@ -128,80 +130,6 @@ namespace scribo
namespace internal
{
- template <typename L>
- void filter_bad_groups(object_groups<L>& top_groups,
- object_groups<L>& bot_groups)
- {
- const component_set<L>& comps = top_groups.components();
- const L& lbl = comps.labeled_image();
-
- for_all_groups(c, top_groups)
- {
- box2d b = comps(c).bbox();
- b.enlarge(0, comps(c).bbox().height());
- b.crop_wrt(lbl.domain());
-
- typedef mln_value(L) V;
-
- const V* top_ptr = & lbl(b.pmin());
- const V* bot_ptr = & lbl(point2d(b.pmax().row(), b.pmin().col()));
-
- unsigned ntop = 0, nbot = 0;
- for (unsigned n = 0; n < b.width(); ++n)
- {
- if (*top_ptr)
- ++ntop;
- if (*bot_ptr)
- ++nbot;
- }
-
- if (ntop / b.width() > 0.50f)
- top_groups(c) = c;
-
- if (nbot / b.width() > 0.50f)
- bot_groups(c) = c;
- }
-
- }
-
-
- template <typename L>
- mln_site(L)
- my_anchors(const component_set<L>& comps,
- unsigned current_object,
- anchor::Type anchor)
- {
- mln_site(L) sp;// = comps(current_object).bbox().pcenter();
-
- unsigned h = comps(current_object).bbox().height();
-
- switch (anchor)
- {
- default:
- return sp;
-
-
- // Bounding box top center
- case anchor::Top: // FIXME: rename as TopLeft
- sp.col() = comps(current_object).bbox().pmin().col();
- sp.row() = comps(current_object).bbox().pmin().row()
- + math::min(2u, (h + 1) / 2 - 1);
- break;
-
-
- // Bounding box bottom center
- case anchor::Bottom: // FIXME: rename as BottomLeft
- sp.col() = comps(current_object).bbox().pmax().col();
- sp.row() = comps(current_object).bbox().pmax().row()
- - math::min(2u, (h + 1) / 2 - 1);
- break;
- }
-
- return sp;
- }
-
-
-
using namespace primitive::link::internal;
template <typename L, typename E>
@@ -225,12 +153,17 @@ namespace scribo
anchor::Horizontal,
dmax_default(dmax)),
anchor(anchor_),
- debug_(data::convert(value::rgb8(), input)),
- debug_angle_(data::convert(value::rgb8(), input)),
_debug_(debug)
{
+ (void) input; // FIXME : remove this argument
min_alpha_rad = (min_angle / 180.0f) * math::pi;
max_alpha_rad = (max_angle / 180.0f) * math::pi;
+
+ // if (_debug_)
+ // {
+ // debug_ = data::convert(value::rgb8(), input);
+ // debug_angle_ = data::convert(value::rgb8(), input);
+ // }
}
void compute_next_site_(P& p)
@@ -247,7 +180,8 @@ namespace scribo
mln_site(L)
start_point_(unsigned current_object, anchor::Type anchor)
{
- return my_anchors(this->components_, current_object, anchor);
+ return link::internal::compute_anchor(this->components_,
+ current_object, anchor);
}
@@ -303,27 +237,29 @@ namespace scribo
{
super_::validate_link_(current_object, start_point, p, anchor);
- if (_debug_)
- {
- mln_site(L)
- p1 = my_anchors(this->components_, current_object, anchor),
- p2 = my_anchors(this->components_, this->labeled_image_(p),
- anchor);
- mln::draw::line(debug_, p1, p2, literal::green);
-
-
- float
- angle = filter::internal::alignment_angle(this->components_,
- current_object,
- this->labeled_image_(p),
- anchor);
- angle = (angle * 180.0f) / math::pi;
- angle = angle * 20.0f + 1.0f;
- mln::draw::line(debug_angle_, p1, p2,
- value::rgb8(unsigned(angle),
- unsigned(angle),
- unsigned(angle)));
- }
+ // if (_debug_)
+ // {
+ // mln_site(L)
+ // p1 = link::internal::compute_anchor(this->components_,
+ // current_object, anchor),
+ // p2 = link::internal::compute_anchor(this->components_,
+ // this->labeled_image_(p),
+ // anchor);
+ // mln::draw::line(debug_, p1, p2, literal::green);
+
+
+ // float
+ // angle = filter::internal::alignment_angle(this->components_,
+ // current_object,
+ // this->labeled_image_(p),
+ // anchor);
+ // angle = (angle * 180.0f) / math::pi;
+ // angle = angle * 20.0f + 1.0f;
+ // mln::draw::line(debug_angle_, p1, p2,
+ // value::rgb8(unsigned(angle),
+ // unsigned(angle),
+ // unsigned(angle)));
+ // }
}
void invalidate_link_(unsigned current_object,
@@ -333,33 +269,36 @@ namespace scribo
{
super_::invalidate_link_(current_object, start_point, p, anchor);
- if (_debug_)
- {
- if (this->labeled_image_.domain().has(p) && this->labeled_image_(p) != 0)
- {
- mln_site(L)
- p1 = my_anchors(this->components_, current_object, anchor),
- p2 = my_anchors(this->components_, this->labeled_image_(p),
- anchor);
- if (this->labeled_image_.domain().has(p2) && norm::l1_distance(p1.to_vec(), p2.to_vec()) < 300)
- {
- mln::draw::line(debug_, p1, p2, literal::red);
- }
-
-
- float
- angle = filter::internal::alignment_angle(this->components_,
- current_object,
- this->labeled_image_(p),
- anchor);
- angle = (angle * 180.0f) / math::pi;
- angle = angle * 20.0f + 1.0f;
- mln::draw::line(debug_angle_, p1, p2,
- value::rgb8(unsigned(angle),
- unsigned(angle),
- unsigned(angle)));
- }
- }
+ // if (_debug_)
+ // {
+ // if (this->labeled_image_.domain().has(p) && this->labeled_image_(p) != 0)
+ // {
+ // mln_site(L)
+ // p1 = link::internal::compute_anchor(this->components_,
+ // current_object, anchor),
+ // p2 = link::internal::compute_anchor(this->components_,
+ // this->labeled_image_(p),
+ // anchor);
+ // if (this->labeled_image_.domain().has(p2)
+ // && norm::l1_distance(p1.to_vec(), p2.to_vec()) < 300)
+ // {
+ // mln::draw::line(debug_, p1, p2, literal::red);
+ // }
+
+
+ // float
+ // angle = filter::internal::alignment_angle(this->components_,
+ // current_object,
+ // this->labeled_image_(p),
+ // anchor);
+ // angle = (angle * 180.0f) / math::pi;
+ // angle = angle * 20.0f + 1.0f;
+ // mln::draw::line(debug_angle_, p1, p2,
+ // value::rgb8(unsigned(angle),
+ // unsigned(angle),
+ // unsigned(angle)));
+ // }
+ // }
}
@@ -368,8 +307,8 @@ namespace scribo
anchor::Type anchor;
- mln_ch_value(L, value::rgb8) debug_;
- mln_ch_value(L, value::rgb8) debug_angle_;
+ // mln_ch_value(L, value::rgb8) debug_;
+ // mln_ch_value(L, value::rgb8) debug_angle_;
bool _debug_;
};
@@ -392,7 +331,8 @@ namespace scribo
float max_angle,
anchor::Type anchor,
bool debug)
- : super_(input, components, dmax, min_angle, max_angle, anchor, debug)
+ : super_(input, components, dmax, min_angle,
+ max_angle, anchor, debug)
{
}
@@ -427,7 +367,8 @@ namespace scribo
float max_angle,
anchor::Type anchor,
bool debug)
- : super_(input, components, dmax, min_angle, max_angle, anchor, debug)
+ : super_(input, components, dmax, min_angle,
+ max_angle, anchor, debug)
{
}
@@ -455,6 +396,8 @@ namespace scribo
mln_concrete(I)
separators_nonvisible(const Image<I>& in_)
{
+ trace::entering("scribo::primitive::extract::separators_nonvisible");
+
const I& in = exact(in_);
mln_precondition(in.is_valid());
typedef mln_value(I) Vi;
@@ -469,42 +412,35 @@ namespace scribo
util::timer t;
util::timer gt;
- // Load (OK)
- t.start();
- float t_ = t;
- std::cout << "Image loaded - " << t_ << std::endl;
-
gt.start();
- // Remove horizontal lines.
- t.restart();
+ // // Remove horizontal lines.
+ // t.restart();
- mln_concrete(I) hlines = primitive::extract::lines_h_pattern(in, 50, 3);
- mln_concrete(I) input = primitive::remove::separators(in, hlines);
+ // mln_concrete(I) hlines = primitive::extract::lines_h_pattern(in, 50, 3);
+ // mln_concrete(I) input = primitive::remove::separators(in, hlines);
- t_ = t;
- std::cout << "Horizontal lines removed - " << t_ << std::endl;
+ // t_ = t;
+ // std::cout << "Horizontal lines removed - " << t_ << std::endl;
// Closing structural - Connect characters.
- t.restart();
+ t.start();
win::hline2d vl(17);
- mln_concrete(I) input_clo = morpho::closing::structural(input, vl);
+ mln_concrete(I) input_clo = morpho::closing::structural(in, vl);
-// input_clo = scribo::preprocessing::rotate_90(input_clo, true);
-
- t_ = t;
+ float t_ = t;
std::cout << "closing_structural - " << t_ << std::endl;
- if (_debug_)
- {
- // Restore input orientation.
- input = scribo::preprocessing::rotate_90(input, false);
+ // if (_debug_)
+ // {
+ // // Restore input orientation.
+ // input = scribo::preprocessing::rotate_90(input, false);
- io::pbm::save(input_clo, "input_clo.pbm");
- }
+ // io::pbm::save(input_clo, "input_clo.pbm");
+ // }
// Rotate (OK)
t.restart();
@@ -526,9 +462,9 @@ namespace scribo
t_ = t;
std::cout << "extract::components - " << t_ << std::endl;
- if (_debug_)
- io::pgm::save(data::convert(value::int_u8(), components.labeled_image()),
- "lbl.pgm");
+ // if (_debug_)
+ // io::pgm::save(data::convert(value::int_u8(), components.labeled_image()),
+ // "lbl.pgm");
unsigned dmax = 5;
@@ -543,39 +479,42 @@ namespace scribo
{
// Right
internal::single_right_dmax_ratio_aligned_functor<L>
- functor(input_clo, components, dmax, min_angle, max_angle, anchor::Top, _debug_);
-// top_right = primitive::link::impl::compute_fastest(functor, anchor::Top);
- top_right = primitive::link::compute(functor, anchor::Top);
+ functor(input_clo, components, dmax, min_angle, max_angle,
+ anchor::TopStrictLeft, _debug_);
+// top_right = primitive::link::impl::compute_fastest(functor, anchor::TopStrictLeft);
+ top_right = primitive::link::compute(functor, anchor::TopStrictLeft);
t.stop();
- if (_debug_)
- {
- io::ppm::save(functor.debug_, "right_top.ppm");
- io::ppm::save(functor.debug_angle_, "right_top_angle.ppm");
- }
+ // if (_debug_)
+ // {
+ // io::ppm::save(functor.debug_, "right_top.ppm");
+ // io::ppm::save(functor.debug_angle_, "right_top_angle.ppm");
+ // }
t.resume();
// Left
internal::single_left_dmax_ratio_aligned_functor<L>
- lfunctor(input_clo, components, dmax, min_angle, max_angle, anchor::Top, _debug_);
- top_left = primitive::link::compute(lfunctor, anchor::Top);
+ lfunctor(input_clo, components, dmax, min_angle, max_angle,
+ anchor::TopStrictLeft, _debug_);
+ top_left = primitive::link::compute(lfunctor, anchor::TopStrictLeft);
t.stop();
- if (_debug_)
- {
- io::ppm::save(lfunctor.debug_, "left_top.ppm");
- io::ppm::save(lfunctor.debug_angle_, "left_top_angle.ppm");
+ // if (_debug_)
+ // {
+ // io::ppm::save(lfunctor.debug_, "left_top.ppm");
+ // io::ppm::save(lfunctor.debug_angle_, "left_top_angle.ppm");
- mln_ch_value(I, value::rgb8) output = duplicate(functor.debug_);
- data::paste((lfunctor.debug_ | (pw::value(lfunctor.debug_) != pw::cst(literal::black))) | (pw::value(lfunctor.debug_) != pw::cst(literal::white)), output);
+ // mln_ch_value(I, value::rgb8) output = duplicate(functor.debug_);
+ // data::paste((lfunctor.debug_ | (pw::value(lfunctor.debug_) != pw::cst(literal::black)))
+ // | (pw::value(lfunctor.debug_) != pw::cst(literal::white)), output);
- io::ppm::save(output, "left_right_top.ppm");
- }
+ // io::ppm::save(output, "left_right_top.ppm");
+ // }
t.resume();
}
@@ -585,105 +524,53 @@ namespace scribo
{
// Right
internal::single_right_dmax_ratio_aligned_functor<L>
- functor(input_clo, components, dmax, min_angle, max_angle, anchor::Bottom, _debug_);
- bot_right = primitive::link::compute(functor, anchor::Bottom);
+ functor(input_clo, components, dmax, min_angle, max_angle,
+ anchor::BottomStrictRight, _debug_);
+ bot_right = primitive::link::compute(functor, anchor::BottomStrictRight);
t.stop();
- if (_debug_)
- {
- io::ppm::save(functor.debug_, "right_bot.ppm");
- io::ppm::save(functor.debug_angle_, "right_bot_angle.ppm");
- }
+ // if (_debug_)
+ // {
+ // io::ppm::save(functor.debug_, "right_bot.ppm");
+ // io::ppm::save(functor.debug_angle_, "right_bot_angle.ppm");
+ // }
t.resume();
// Left
internal::single_left_dmax_ratio_aligned_functor<L>
- lfunctor(input_clo, components, dmax, min_angle, max_angle, anchor::Bottom, _debug_);
- bot_left = primitive::link::compute(lfunctor, anchor::Bottom);
+ lfunctor(input_clo, components, dmax, min_angle, max_angle,
+ anchor::BottomStrictRight, _debug_);
+ bot_left = primitive::link::compute(lfunctor, anchor::BottomStrictRight);
t.stop();
- if (_debug_)
- {
- io::ppm::save(lfunctor.debug_, "left_bot.ppm");
- io::ppm::save(lfunctor.debug_angle_, "left_bot_angle.ppm");
- }
+ // if (_debug_)
+ // {
+ // io::ppm::save(lfunctor.debug_, "left_bot.ppm");
+ // io::ppm::save(lfunctor.debug_angle_, "left_bot_angle.ppm");
- if (_debug_)
- {
- mln_ch_value(I, value::rgb8) output = duplicate(functor.debug_);
- data::paste((lfunctor.debug_ | (pw::value(lfunctor.debug_) != pw::cst(literal::black))) | (pw::value(lfunctor.debug_) != pw::cst(literal::white)), output);
+ // mln_ch_value(I, value::rgb8) output = duplicate(functor.debug_);
+ // data::paste((lfunctor.debug_ | (pw::value(lfunctor.debug_) != pw::cst(literal::black)))
+ // | (pw::value(lfunctor.debug_) != pw::cst(literal::white)), output);
- io::ppm::save(output, "left_right_bot.ppm");
- }
+ // io::ppm::save(output, "left_right_bot.ppm");
+ // }
}
t_ = t;
std::cout << "links - " << t_ << std::endl;
-
+ // Merge links and build CC groups
t.restart();
- std::cout << "group - top" << std::endl;
object_groups<L>
top_groups = primitive::group::from_double_link_any(top_left, top_right);
- std::cout << "group - bot" << std::endl;
object_groups<L>
bot_groups = primitive::group::from_double_link_any(bot_left, bot_right);
t_ = t;
std::cout << "group - " << t_ << std::endl;
- t.restart();
- util::array<accu::shape::bbox<point2d> >
- btop_accu(top_groups.nelements()),
- bbot_accu(bot_groups.nelements());
-
-
- for_all_groups(c, top_groups)
- {
- btop_accu(top_groups(c)).take(components(c).bbox());
- bbot_accu(bot_groups(c)).take(components(c).bbox());
- }
- t_ = t;
- std::cout << "groups to group bboxes - " << t_ << std::endl;
-
-
-
- if (_debug_)
- {
-
- mln_ch_value(I, value::rgb8)
- wo_filtering = data::convert(value::rgb8(), input);
-
- for_all_comp_data(d, btop_accu)
- {
- if (btop_accu(d).is_valid())
- {
- mln::draw::line(wo_filtering,
- btop_accu(d).to_result().pmin(),
- point2d(btop_accu(d).to_result().pmin().row(),
- btop_accu(d).to_result().pmax().col()),
- literal::green);
-
- }
- }
-
- for_all_comp_data(d, bbot_accu)
- {
- if (bbot_accu(d).is_valid())
- {
- mln::draw::line(wo_filtering,
- point2d(bbot_accu(d).to_result().pmax().row(),
- bbot_accu(d).to_result().pmin().col()),
- bbot_accu(d).to_result().pmax(),
- literal::green);
- }
-
- }
- io::ppm::save(wo_filtering, "wo_filtering.ppm");
- }
-
-
+ // Filter CC groups
t.restart();
top_groups = filter::object_groups_small(top_groups, min_card);
bot_groups = filter::object_groups_small(bot_groups, min_card);
@@ -691,7 +578,7 @@ namespace scribo
std::cout << "small groups - " << t_ << std::endl;
-
+ // Compute group bboxes
t.restart();
util::array<accu::shape::bbox<point2d> >
top_accu(top_groups.nelements()),
@@ -708,78 +595,35 @@ namespace scribo
-
-
-
-
-
t.restart();
mln_concrete(I) separators;
initialize(separators, input_clo);
+
+ // FIXME: any way to fill border AND data at the same time?
data::fill(separators, false);
+ extension::fill(separators, false);
+
t_ = t;
std::cout << "Initialize separators image - " << t_ << std::endl;
- mln_ch_value(I, value::rgb8) both;
-
- if (_debug_)
- both = data::convert(value::rgb8(), input);
-
-
-
t.restart();
for_all_comp_data(d, top_accu)
{
- if (top_accu(d).is_valid() || btop_accu(d).is_valid())
+ if (top_accu(d).is_valid())
{
- if (top_accu(d).is_valid())
- {
- if (_debug_)
- mln::draw::line(both,
- top_accu(d).to_result().pmin(),
- point2d(top_accu(d).to_result().pmin().row(),
- top_accu(d).to_result().pmax().col()),
- literal::green);
-
- mln::draw::line(separators,
- top_accu(d).to_result().pmin(),
- point2d(top_accu(d).to_result().pmin().row(),
- top_accu(d).to_result().pmax().col()),
- true);
- }
- else
- if (_debug_ && btop_accu(d).is_valid())
- mln::draw::line(both,
- btop_accu(d).to_result().pmin(),
- point2d(btop_accu(d).to_result().pmin().row(),
- btop_accu(d).to_result().pmax().col()),
- literal::yellow);
-
+ mln::draw::line(separators,
+ top_accu(d).to_result().pmin(),
+ point2d(top_accu(d).to_result().pmin().row(),
+ top_accu(d).to_result().pmax().col()),
+ true);
}
- if (bot_accu(d).is_valid() || bbot_accu(d).is_valid())
+ if (bot_accu(d).is_valid())
{
- if (bot_accu(d).is_valid())
- {
- if (_debug_)
- mln::draw::line(both,
- point2d(bot_accu(d).to_result().pmax().row(),
- bot_accu(d).to_result().pmin().col()),
- bot_accu(d).to_result().pmax(),
- literal::green);
-
- mln::draw::line(separators,
- point2d(bot_accu(d).to_result().pmax().row(),
- bot_accu(d).to_result().pmin().col()),
- bot_accu(d).to_result().pmax(),
- true);
- }
- else
- if (_debug_ && bbot_accu(d).is_valid())
- mln::draw::line(both,
- point2d(bbot_accu(d).to_result().pmax().row(),
- bbot_accu(d).to_result().pmin().col()),
- bbot_accu(d).to_result().pmax(),
- literal::yellow);
+ mln::draw::line(separators,
+ point2d(bot_accu(d).to_result().pmax().row(),
+ bot_accu(d).to_result().pmin().col()),
+ bot_accu(d).to_result().pmax(),
+ true);
}
}
@@ -787,22 +631,112 @@ namespace scribo
std::cout << "Drawing output image - " << t_ << std::endl;
- if (_debug_)
- {
- io::ppm::save(both, "both.ppm");
- io::pbm::save(separators, "separators.pbm");
- }
+ // if (_debug_)
+ // {
+ // // Restore input orientation.
+ // mln_concrete(I) input = scribo::preprocessing::rotate_90(in, false);
+
+
+ // // Debug group bboxes (includes all bboxes before filtering)
+ // util::array<accu::shape::bbox<point2d> >
+ // btop_accu(top_groups.nelements()),
+ // bbot_accu(bot_groups.nelements());
+
+
+ // for_all_groups(c, top_groups)
+ // {
+ // btop_accu(top_groups(c)).take(components(c).bbox());
+ // bbot_accu(bot_groups(c)).take(components(c).bbox());
+ // }
+
+ // mln_ch_value(I, value::rgb8)
+ // wo_filtering = data::convert(value::rgb8(), input);
+
+ // for_all_comp_data(d, btop_accu)
+ // {
+ // if (btop_accu(d).is_valid())
+ // {
+ // mln::draw::line(wo_filtering,
+ // btop_accu(d).to_result().pmin(),
+ // point2d(btop_accu(d).to_result().pmin().row(),
+ // btop_accu(d).to_result().pmax().col()),
+ // literal::green);
+
+ // }
+ // }
+
+ // for_all_comp_data(d, bbot_accu)
+ // {
+ // if (bbot_accu(d).is_valid())
+ // {
+ // mln::draw::line(wo_filtering,
+ // point2d(bbot_accu(d).to_result().pmax().row(),
+ // bbot_accu(d).to_result().pmin().col()),
+ // bbot_accu(d).to_result().pmax(),
+ // literal::green);
+ // }
+
+ // }
+ // io::ppm::save(wo_filtering, "wo_filtering.ppm");
+
+ // mln_ch_value(I, value::rgb8) both = data::convert(value::rgb8(), input);
+
+ // for_all_comp_data(d, top_accu)
+ // {
+ // if (top_accu(d).is_valid() || btop_accu(d).is_valid())
+ // {
+ // if (top_accu(d).is_valid())
+ // {
+ // mln::draw::line(both,
+ // top_accu(d).to_result().pmin(),
+ // point2d(top_accu(d).to_result().pmin().row(),
+ // top_accu(d).to_result().pmax().col()),
+ // literal::green);
+ // }
+ // else
+ // if (btop_accu(d).is_valid())
+ // mln::draw::line(both,
+ // btop_accu(d).to_result().pmin(),
+ // point2d(btop_accu(d).to_result().pmin().row(),
+ // btop_accu(d).to_result().pmax().col()),
+ // literal::yellow);
+
+ // }
+ // if (bot_accu(d).is_valid() || bbot_accu(d).is_valid())
+ // {
+ // if (bot_accu(d).is_valid())
+ // {
+ // mln::draw::line(both,
+ // point2d(bot_accu(d).to_result().pmax().row(),
+ // bot_accu(d).to_result().pmin().col()),
+ // bot_accu(d).to_result().pmax(),
+ // literal::green);
+ // }
+ // else
+ // if (bbot_accu(d).is_valid())
+ // mln::draw::line(both,
+ // point2d(bbot_accu(d).to_result().pmax().row(),
+ // bbot_accu(d).to_result().pmin().col()),
+ // bbot_accu(d).to_result().pmax(),
+ // literal::yellow);
+ // }
+
+ // }
+
+ // io::ppm::save(both, "both.ppm");
+ // io::pbm::save(separators, "separators.pbm");
+ // }
// Hit or miss
{
- if (_debug_)
- {
- mln_concrete(I) input_with_seps = duplicate(input_clo);
- data::paste(separators | pw::value(separators), input_with_seps);
+ // if (_debug_)
+ // {
+ // mln_concrete(I) input_with_seps = duplicate(input_clo);
+ // data::paste(separators | pw::value(separators), input_with_seps);
- io::pbm::save(input_with_seps, "input_with_seps.pbm");
- }
+ // io::pbm::save(input_with_seps, "input_with_seps.pbm");
+ // }
t.restart();
unsigned length = 25;
@@ -819,11 +753,12 @@ namespace scribo
typedef mln_ch_value(I,unsigned) J;
J tmp = accu::transform_line(accu, input_clo, length, 1);
+
t_ = t;
std::cout << "* accu::transform_line - " << t_ << std::endl;
- if (_debug_)
- io::pgm::save(data::convert(value::int_u8(), tmp), "tmp.pgm");
+ // if (_debug_)
+ // io::pgm::save(data::convert(value::int_u8(), tmp), "tmp.pgm");
t.restart();
@@ -841,25 +776,53 @@ namespace scribo
unsigned invalid_ratio = unsigned(length * 0.30f);
- mln_piter(I) p(separators.domain());
- for_all(p)
- if (separators(p))
- {
- unsigned lbl = sep_lbl(p);
+ extension::adjust_fill(tmp, 21, 0);
+
+ value::int_u8 *sep_lbl_ptr = sep_lbl.buffer() + sep_lbl.index_of_point(sep_lbl.domain().pmin());
+ bool *separators_ptr = separators.buffer() + separators.index_of_point(separators.domain().pmin());
+ unsigned *tmp_ptr = tmp.buffer() + tmp.index_of_point(tmp.domain().pmin());;
+ int idx1 = tmp.delta_index(dp1);
+ int idx2 = tmp.delta_index(dp2);
+
+ unsigned nrows = separators.nrows();
+ unsigned ncols = separators.ncols();
- unsigned
- top_count = tmp(p + dp1),
- bot_count = tmp(p + dp2);
+ unsigned row_idx_sep_lbl = sep_lbl.delta_index(dpoint2d(+1, - ncols));
+ unsigned row_idx_separators = separators.delta_index(dpoint2d(+1, - ncols));
+ unsigned row_idx_tmp = tmp.delta_index(dpoint2d(+1, - ncols));
- // This site is wrapped between two lines of text so we don't
- // want it.
- if (top_count >= invalid_ratio + 1
- && bot_count >= invalid_ratio + 1)
+ for (unsigned row = 0; row < nrows; ++row)
+ {
+ for (unsigned col = 0; col < ncols; ++col)
+ {
+ if (*separators_ptr)
{
- relbl(lbl) = false;
+ unsigned lbl = *sep_lbl_ptr;
+
+ unsigned
+ top_count = *(tmp_ptr + idx1),
+ bot_count = *(tmp_ptr + idx2);
+
+ // This site is wrapped between two lines of text so we don't
+ // want it.
+ if (top_count >= invalid_ratio + 1
+ && bot_count >= invalid_ratio + 1)
+ {
+ relbl(lbl) = false;
+ }
}
+
+ ++tmp_ptr;
+ ++sep_lbl_ptr;
+ ++separators_ptr;
}
+ tmp_ptr += row_idx_tmp;
+ sep_lbl_ptr += row_idx_sep_lbl;
+ separators_ptr += row_idx_separators;
+ }
+
+
t_ = t;
std::cout << "* reading data - " << t_ << std::endl;
@@ -870,37 +833,35 @@ namespace scribo
mln_concrete(I) output = data::convert(bool(), sep_lbl);
- if (_debug_)
- {
- io::pbm::save(output, "separators_hom.pbm");
- io::pbm::save(separators, "separators_filtered.pbm");
- }
+ // if (_debug_)
+ // {
+ // io::pbm::save(output, "separators_hom.pbm");
+ // io::pbm::save(separators, "separators_filtered.pbm");
- t.restart();
- value::int_u16 ncomps;
- component_set<L> comps = primitive::extract::components(output, c8(), ncomps);
- mln_ch_value(I, value::rgb8) both;
+ // // value::int_u16 ncomps;
+ // // component_set<L> comps = primitive::extract::components(output, c8(), ncomps);
+ // // mln_ch_value(I, value::rgb8) both;
- both = data::convert(value::rgb8(), input);
+ // // both = data::convert(value::rgb8(), input);
- // Needed since the rotated image origin is (0,0). Rotation does
- // not preserve rotated coordinates.
- dpoint2d dp(input.domain().pcenter() - input_clo.domain().pcenter());
+ // // // Needed since the rotated image origin is (0,0).
+ // // dpoint2d dp(input.domain().pcenter() - input_clo.domain().pcenter());
+
+ // // for_all_comps(c, comps)
+ // // {
+ // // box2d b = geom::rotate(comps(c).bbox(), -90, input_clo.domain().pcenter());
+ // // mln::draw::line(both,
+ // // b.pmin() + dp,
+ // // b.pmax() + dp,
+ // // literal::green);
+ // // }
+ // }
- for_all_comps(c, comps)
- {
- box2d b = geom::rotate(comps(c).bbox(), -90, input_clo.domain().pcenter());
- mln::draw::line(both,
- b.pmin() + dp,
- b.pmax() + dp,
- literal::green);
- }
- t_ = t;
- std::cout << "Output image - " << t_ << std::endl;
gt.stop();
t_ = gt;
- std::cout << "Total time: " << t_ << std::endl;
+ std::cout << "Non visible separators: " << t_ << std::endl;
+ trace::exiting("scribo::primitive::extract::separators_nonvisible");
return scribo::preprocessing::rotate_90(output, true);
}
}
diff --git a/scribo/scribo/primitive/link/internal/compute_anchor.hh b/scribo/scribo/primitive/link/internal/compute_anchor.hh
index 1c52b91..c1a9106 100644
--- a/scribo/scribo/primitive/link/internal/compute_anchor.hh
+++ b/scribo/scribo/primitive/link/internal/compute_anchor.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -88,10 +88,8 @@ namespace scribo
{
typedef mln_site(L) P;
- unsigned h = components(current_object).bbox().pmax().row()
- - components(current_object).bbox().pmin().row();
- unsigned w = components(current_object).bbox().pmax().col()
- - components(current_object).bbox().pmin().col();
+ unsigned h = components(current_object).bbox().height();
+ unsigned w = components(current_object).bbox().width();
mln_site(L) sp = components(current_object).bbox().pcenter();
@@ -113,6 +111,22 @@ namespace scribo
break;
+ // Bounding box top left
+ case anchor::TopStrictLeft:
+ sp.col() = components(current_object).bbox().pmin().col();
+ sp.row() = components(current_object).bbox().pmin().row()
+ + math::min(2u, (h + 1) / 2 - 1);
+ break;
+
+
+ // Bounding box bottom right
+ case anchor::BottomStrictRight:
+ sp.col() = components(current_object).bbox().pmax().col();
+ sp.row() = components(current_object).bbox().pmax().row()
+ - math::min(2u, (h + 1) / 2 - 1);
+ break;
+
+
// Bounding box bottom center
case anchor::Bottom:
if (h < 30)
diff --git a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
index ed691e8..48098ba 100644
--- a/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
+++ b/scribo/scribo/toolchain/internal/content_in_doc_functor.hh
@@ -34,11 +34,11 @@
# include <scribo/core/line_set.hh>
# include <scribo/core/paragraph_set.hh>
-# include <scribo/primitive/extract/elements.hh>
+# include <scribo/primitive/extract/non_text.hh>
# include <scribo/primitive/extract/components.hh>
-# include <scribo/primitive/extract/vertical_separators.hh>
+//# include <scribo/primitive/extract/vertical_separators.hh>
+# include <scribo/primitive/extract/separators.hh>
# include <scribo/primitive/extract/separators_nonvisible.hh>
-# include <scribo/primitive/extract/elements.hh>
# include <scribo/primitive/identify.hh>
@@ -168,16 +168,17 @@ namespace scribo
input_cleaned = exact(processed_image);
if (enable_line_seps)
{
- on_new_progress_label("Find vertical separators...");
+ on_new_progress_label("Find vertical and horizontal separators...");
- // Vertical separators
- separators = primitive::extract::vertical_separators(processed_image, 81);
+ // Vertical and horizontal separators
+ separators = primitive::extract::separators(processed_image, 81);
on_progress();
on_new_progress_label("Remove separators...");
input_cleaned = primitive::remove::separators(processed_image, separators);
+ doc.set_line_separators(separators);
on_progress();
}
--
1.5.6.5
1
0
* scribo/core/macros.hh: Update comments.
* scribo/text/merging.hh: Add comments and fix line data swap.
* scribo/text/recognition.hh: Make use of is_textline.
* src/text_in_picture.cc: Initialize ImageMagick.
---
scribo/ChangeLog | 12 ++++++++++++
scribo/scribo/core/macros.hh | 7 +++----
scribo/scribo/text/merging.hh | 6 +++---
scribo/scribo/text/recognition.hh | 2 +-
4 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 001e134..fd4b155 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,5 +1,17 @@
2011-02-17 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Small fixes in Scribo.
+
+ * scribo/core/macros.hh: Update comments.
+
+ * scribo/text/merging.hh: Add comments and fix line data swap.
+
+ * scribo/text/recognition.hh: Make use of is_textline.
+
+ * src/text_in_picture.cc: Initialize ImageMagick.
+
+2011-02-17 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Improve and cleanup whitespace separator detection.
* scribo/core/tag/anchor.hh: Add new anchors.
diff --git a/scribo/scribo/core/macros.hh b/scribo/scribo/core/macros.hh
index 887539f..c6de1ff 100644
--- a/scribo/scribo/core/macros.hh
+++ b/scribo/scribo/core/macros.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-// (LRDE)
+// Copyright (C) 2009, 2010, 2011 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of Olena.
//
@@ -33,8 +33,6 @@
# define for_all_elements(E, S) \
for (unsigned E = 0; E < S.nelements(); ++E)
-
-// FIXME: we want to replace previous macros by these ones.
# define for_all_comps(C, S) \
for (unsigned C = 1; C <= S.nelements(); ++C)
@@ -56,6 +54,7 @@
# define for_all_line_comps(E, S) \
for_all_elements(E, S)
+// Internal use only.
# define for_all_lines_info(E, S) \
for_all_comp_data(E, S)
diff --git a/scribo/scribo/text/merging.hh b/scribo/scribo/text/merging.hh
index 3087465..f433e51 100644
--- a/scribo/scribo/text/merging.hh
+++ b/scribo/scribo/text/merging.hh
@@ -192,7 +192,7 @@ namespace scribo
{
// we transfer data from the largest item to the root one.
scribo::line_info<L> tmp = lines(l1);
- lines(l1) = lines(l2);
+ std::swap(lines(l1), lines(l2));
lines(l1).fast_merge(tmp);
// We must set manually the tag for lines(l2) since it is
@@ -504,8 +504,8 @@ namespace scribo
void
one_merge_pass(unsigned ith_pass,
const box2d& domain,
- std::vector<scribo::line_id_t>& v,
- scribo::line_set<L>& lines,
+ std::vector<scribo::line_id_t>& v, // Ids sorted by bbox size.
+ scribo::line_set<L>& lines, // Tagged Lines (looks_like_a_text_line?)
mln::util::array<unsigned>& parent)
{
image2d<unsigned> billboard(domain);
diff --git a/scribo/scribo/text/recognition.hh b/scribo/scribo/text/recognition.hh
index 59f269e..3a9742b 100644
--- a/scribo/scribo/text/recognition.hh
+++ b/scribo/scribo/text/recognition.hh
@@ -127,7 +127,7 @@ namespace scribo
/// Use text bboxes with Tesseract
for_all_lines(i, lines)
{
- if (! lines(i).is_valid() || lines(i).is_hidden() || lines(i).type() != line::Text)
+ if (! lines(i).is_textline())
continue;
mln_domain(I) box = lines(i).bbox();
--
1.5.6.5
1
0
29 Mar '11
* scribo/scribo/convert/from_base64.hh,
* scribo/scribo/convert/to_base64.hh: New routines.
* scribo/tests/Makefile.am,
* scribo/tests/convert/Makefile.am,
* scribo/tests/convert/base64.cc: New associated test.
---
scribo/ChangeLog | 11 ++
scribo/scribo/convert/from_base64.hh | 217 ++++++++++++++++++++++++++++
scribo/scribo/convert/to_base64.hh | 185 ++++++++++++++++++++++++
scribo/tests/Makefile.am | 1 +
scribo/tests/{core => convert}/Makefile.am | 8 +-
scribo/tests/convert/base64.cc | 89 ++++++++++++
6 files changed, 507 insertions(+), 4 deletions(-)
create mode 100644 scribo/scribo/convert/from_base64.hh
create mode 100644 scribo/scribo/convert/to_base64.hh
copy scribo/tests/{core => convert}/Makefile.am (84%)
create mode 100644 scribo/tests/convert/base64.cc
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index 1bd708a..7b409a2 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,14 @@
+2011-02-17 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Add Base64 conversion routines.
+
+ * scribo/scribo/convert/from_base64.hh,
+ * scribo/scribo/convert/to_base64.hh: New routines.
+
+ * scribo/tests/Makefile.am,
+ * scribo/tests/convert/Makefile.am,
+ * scribo/tests/convert/base64.cc: New associated test.
+
2011-02-05 Guillaume Lazzara <z(a)lrde.epita.fr>
Add support for whitespace separators visualization.
diff --git a/scribo/scribo/convert/from_base64.hh b/scribo/scribo/convert/from_base64.hh
new file mode 100644
index 0000000..8c14a0f
--- /dev/null
+++ b/scribo/scribo/convert/from_base64.hh
@@ -0,0 +1,217 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+
+
+#ifndef SCRIBO_CONVERT_FROM_BASE64_HH
+# define SCRIBO_CONVERT_FROM_BASE64_HH
+
+/*! \file
+
+ \brief Decode base64 raw data and convert it to an image.
+
+ Based on Bob Trower's code.
+ http://base64.sourceforge.net/b64.c
+
+ LICENCE: Copyright (c) 2001 Bob Trower, Trantor Standard Systems Inc.
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated
+ documentation files (the "Software"), to deal in the
+ Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute,
+ sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so,
+ subject to the following conditions:
+
+ The above copyright notice and this permission notice shall
+ be included in all copies or substantial portions of the
+ Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+#include <cstdio>
+#include <cstdlib>
+
+# include <mln/border/resize.hh>
+# include <mln/core/image/image2d.hh>
+# include <mln/util/array.hh>
+
+
+
+namespace scribo
+{
+
+ namespace convert
+ {
+
+ using namespace mln;
+
+ template <typename I>
+ void from_base64(const util::array<unsigned char>& data64,
+ Image<I>& output);
+
+
+# if defined HAVE_QT
+
+ template <typename I>
+ void from_base64(const QString& data64, Image<I>& output_);
+
+# endif // ! HAVE_QT
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ /*
+ ** Translation Table to decode
+ */
+ static const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefghijklmnopq";
+
+ /*
+ ** decodeblock
+ **
+ ** decode 4 '6-bit' characters into 3 8-bit binary bytes
+ */
+ inline
+ void
+ decodeblock(unsigned char in[4], unsigned char out[3])
+ {
+ out[ 0 ] = (unsigned char) (in[0] << 2 | in[1] >> 4);
+ out[ 1 ] = (unsigned char) (in[1] << 4 | in[2] >> 2);
+ out[ 2 ] = (unsigned char) (((in[2] << 6) & 0xc0) | in[3]);
+ }
+
+
+ template <typename V, typename I>
+ void
+ from_base64_(const V& data64, const unsigned length, Image<I>& output_)
+ {
+ trace::entering("scribo::convert::from_base64_");
+
+ mln_precondition(exact(output_).is_valid());
+ using namespace internal;
+
+ I& output = exact(output_);
+
+ unsigned char in[4], out[3], v;
+ int i, len;
+
+ border::resize(output, 0); // Make sure there is no border!
+
+ unsigned char *ptr = (unsigned char *)output.buffer();
+ unsigned char *end_ptr = (unsigned char *)(output.buffer() + output.nelements());
+
+ for (unsigned idx = 0; idx < length;)
+ {
+ for(len = 0, i = 0; i < 4 && idx < length; i++)
+ {
+ v = 0;
+ while(idx < length && v == 0)
+ {
+ v = (unsigned char) data64[idx++];
+ v = (unsigned char) ((v < 43 || v > 122) ? 0 : cd64[ v - 43 ]);
+ if(v)
+ {
+ v = (unsigned char) ((v == '$') ? 0 : v - 61);
+ }
+ }
+ if(idx < length)
+ {
+ len++;
+ if(v)
+ {
+ in[ i ] = (unsigned char) (v - 1);
+ }
+ }
+ else
+ {
+ in[i] = 0;
+ }
+ }
+ if(len)
+ {
+ decodeblock(in, out);
+ for(i = 0; i < len - 1 && ptr != end_ptr; i++)
+ {
+ *ptr++ = out[i];
+ }
+ }
+ }
+
+ trace::exiting("scribo::convert::to_base64_");
+ }
+
+
+ } // end of namespace scribo::convert::internal
+
+
+ template <typename I>
+ void
+ from_base64(const util::array<unsigned char>& data64, Image<I>& output_)
+ {
+ trace::entering("scribo::convert::from_base64");
+
+ internal::from_base64_(data64, data64.nelements(), output_);
+
+ trace::exiting("scribo::convert::to_base64");
+ }
+
+
+# if defined HAVE_QT
+
+ template <typename I>
+ void
+ from_base64(const QString& data64, Image<I>& output_)
+ {
+ trace::entering("scribo::convert::from_base64");
+
+ QByteArray data64_ = data64.toAscii();
+ internal::from_base64_(data64_.constData(), data64_.size(), output_);
+
+ trace::exiting("scribo::convert::to_base64");
+ }
+
+# endif // ! HAVE_QT
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace scribo::convert
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_CONVERT_FROM_BASE64_HH
diff --git a/scribo/scribo/convert/to_base64.hh b/scribo/scribo/convert/to_base64.hh
new file mode 100644
index 0000000..8df3ed2
--- /dev/null
+++ b/scribo/scribo/convert/to_base64.hh
@@ -0,0 +1,185 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE)
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+//
+// As a special exception, you may use this file as part of a free
+// software project without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to produce
+// an executable, this file does not by itself cause the resulting
+// executable to be covered by the GNU General Public License. This
+// exception does not however invalidate any other reasons why the
+// executable file might be covered by the GNU General Public License.
+
+
+
+#ifndef SCRIBO_CONVERT_TO_BASE64_HH
+# define SCRIBO_CONVERT_TO_BASE64_HH
+
+/*! \file
+
+ \brief Encode an image into base64 raw data.
+
+ Based on Bob Trower's code.
+ http://base64.sourceforge.net/b64.c
+
+ LICENCE: Copyright (c) 2001 Bob Trower, Trantor Standard Systems Inc.
+
+ Permission is hereby granted, free of charge, to any person
+ obtaining a copy of this software and associated
+ documentation files (the "Software"), to deal in the
+ Software without restriction, including without limitation
+ the rights to use, copy, modify, merge, publish, distribute,
+ sublicense, and/or sell copies of the Software, and to
+ permit persons to whom the Software is furnished to do so,
+ subject to the following conditions:
+
+ The above copyright notice and this permission notice shall
+ be included in all copies or substantial portions of the
+ Software.
+
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
+ KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
+ PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
+ OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+*/
+
+# include <cstdio>
+# include <cstdlib>
+
+# include <mln/border/resize.hh>
+# include <mln/core/image/image2d.hh>
+# include <mln/util/array.hh>
+
+
+# define B64_DEF_LINE_SIZE 72
+
+namespace scribo
+{
+
+ namespace convert
+ {
+
+ using namespace mln;
+
+
+ template <typename I>
+ void
+ to_base64(const Image<I>& input, util::array<unsigned char>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ namespace internal
+ {
+
+ /*
+ ** Translation Table as described in RFC1113
+ */
+ static const char cb64[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
+
+ /*
+ ** encodeblock
+ **
+ ** encode 3 8-bit binary bytes as 4 '6-bit' characters
+ */
+ inline
+ void
+ encodeblock(unsigned char in[3], unsigned char out[4], int len)
+ {
+ out[0] = cb64[ in[0] >> 2 ];
+ out[1] = cb64[ ((in[0] & 0x03) << 4) | ((in[1] & 0xf0) >> 4) ];
+ out[2] = (unsigned char) (len > 1 ? cb64[ ((in[1] & 0x0f) << 2) | ((in[2] & 0xc0) >> 6) ] : '=');
+ out[3] = (unsigned char) (len > 2 ? cb64[ in[2] & 0x3f ] : '=');
+ }
+
+ } // end of namespace scribo::convert::internal
+
+
+
+ template <typename I>
+ void
+ to_base64(const Image<I>& input_, util::array<unsigned char>& output)
+ {
+ trace::entering("scribo::convert::to_base64");
+
+ mln_precondition(exact(input_).is_valid());
+ using namespace internal;
+
+ const I& input = exact(input_);
+
+ unsigned char in[3], out[4];
+ int i, len, blocksout = 0;
+
+ // FIXME: Take border into account while moving pointer and
+ // remove that call.
+ border::resize(input, 0);
+
+ const unsigned char
+ *end_ptr = (unsigned char *) (input.buffer() + input.nelements()),
+ *ptr = (unsigned char *)input.buffer();
+
+ while(ptr != end_ptr)
+ {
+ len = 0;
+ for(i = 0; i < 3; ++i)
+ {
+ if (ptr != end_ptr)
+ {
+ in[i] = (unsigned char) *ptr++;
+ ++len;
+ }
+ else
+ {
+ in[i] = 0;
+ for(++i; i < 3; ++i)
+ in[i] = 0;
+ }
+ }
+ if(len)
+ {
+ encodeblock(in, out, len);
+ for(i = 0; i < 4; ++i)
+ output.append(out[i]);
+ ++blocksout;
+ }
+ if(blocksout >= (B64_DEF_LINE_SIZE/4) || ptr == end_ptr)
+ {
+ if(blocksout)
+ {
+ output.append('\r');
+ output.append('\n');
+ }
+ blocksout = 0;
+ }
+ }
+
+ trace::exiting("scribo::convert::to_base64");
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+# undef B64_DEF_LINE_SIZE
+
+ } // end of namespace scribo::convert
+
+} // end of namespace scribo
+
+#endif // ! SCRIBO_CONVERT_TO_BASE64_HH
diff --git a/scribo/tests/Makefile.am b/scribo/tests/Makefile.am
index 1cb222b..09768b1 100644
--- a/scribo/tests/Makefile.am
+++ b/scribo/tests/Makefile.am
@@ -29,6 +29,7 @@ EXTRA_DIST = \
SUBDIRS = \
binarization \
+ convert \
core \
filter \
preprocessing \
diff --git a/scribo/tests/core/Makefile.am b/scribo/tests/convert/Makefile.am
similarity index 84%
copy from scribo/tests/core/Makefile.am
copy to scribo/tests/convert/Makefile.am
index 356cc31..c4c912c 100644
--- a/scribo/tests/core/Makefile.am
+++ b/scribo/tests/convert/Makefile.am
@@ -1,5 +1,4 @@
-# Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
-# (LRDE).
+# Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE).
#
# This file is part of Olena.
#
@@ -20,8 +19,9 @@
include $(top_srcdir)/scribo/tests/tests.mk
-check_PROGRAMS = line_info
+check_PROGRAMS = \
+ base64
-line_info_SOURCES = line_info.cc
+base64_SOURCES = base64.cc
TESTS = $(check_PROGRAMS)
diff --git a/scribo/tests/convert/base64.cc b/scribo/tests/convert/base64.cc
new file mode 100644
index 0000000..18d08d9
--- /dev/null
+++ b/scribo/tests/convert/base64.cc
@@ -0,0 +1,89 @@
+// Copyright (C) 2011 EPITA Research and Development Laboratory (LRDE).
+//
+// This file is part of Olena.
+//
+// Olena is free software: you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation, version 2 of the License.
+//
+// Olena is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Olena. If not, see <http://www.gnu.org/licenses/>.
+
+/// \file
+
+#include <cstdio>
+#include <cstdlib>
+
+#include <mln/core/image/image2d.hh>
+#include <mln/data/compare.hh>
+
+#include <mln/io/pbm/load.hh>
+#include <mln/io/pgm/load.hh>
+
+#include <mln/value/int_u.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/debug/iota.hh>
+
+#include <mln/value/int_u16.hh>
+
+#include <scribo/convert/to_base64.hh>
+#include <scribo/convert/from_base64.hh>
+
+#include "tests/data.hh"
+
+using namespace mln;
+
+int main()
+{
+
+ // PBM
+ {
+ image2d<bool> ima;
+ io::pbm::load(ima, SCRIBO_IMG_DIR "/wildly.pbm");
+
+ util::array<unsigned char> out64;
+ scribo::convert::to_base64(ima, out64);
+
+ image2d<bool> outbin(ima.domain());
+ scribo::convert::from_base64(out64, outbin);
+
+ mln_assertion(outbin == ima);
+ }
+
+ // PGM (8bits)
+ {
+ image2d<value::int_u8> ima;
+ io::pgm::load(ima, SCRIBO_IMG_DIR "/text_to_group.pgm");
+
+ util::array<unsigned char> out64;
+ scribo::convert::to_base64(ima, out64);
+
+ image2d<value::int_u8> outbin(ima.domain());
+ scribo::convert::from_base64(out64, outbin);
+
+ mln_assertion(outbin == ima);
+ }
+
+ // PGM (30bits)
+ {
+ image2d<value::int_u<30> > ima(3, 3);
+ debug::iota(ima, 100000);
+
+ util::array<unsigned char> out64;
+ scribo::convert::to_base64(ima, out64);
+
+ image2d<value::int_u<30> > outbin(ima.domain());
+ scribo::convert::from_base64(out64, outbin);
+
+ mln_assertion(outbin == ima);
+ }
+
+
+ return 0;
+}
--
1.5.6.5
1
0