* demo/xml2doc/image_crop.cc: Create opacity mask.
* scribo/io/xml/internal/extended_page_xml_visitor.hh: Add bbox
information in region tag.
---
scribo/ChangeLog | 9 +++
scribo/demo/xml2doc/image_crop.cc | 60 +++++++++++++-------
.../io/xml/internal/extended_page_xml_visitor.hh | 21 ++++++-
3 files changed, 67 insertions(+), 23 deletions(-)
diff --git a/scribo/ChangeLog b/scribo/ChangeLog
index a213078..efc42cf 100644
--- a/scribo/ChangeLog
+++ b/scribo/ChangeLog
@@ -1,3 +1,12 @@
+2011-05-05 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
+
+ Make use of opacity in PDF output.
+
+ * demo/xml2doc/image_crop.cc: Create opacity mask.
+
+ * scribo/io/xml/internal/extended_page_xml_visitor.hh: Add bbox
+ information in region tag.
+
2011-05-04 Guillaume Lazzara <lazzara(a)fidji.lrde.epita.fr>
Small fixes in Scribo.
diff --git a/scribo/demo/xml2doc/image_crop.cc b/scribo/demo/xml2doc/image_crop.cc
index ba30d8a..7d61f75 100644
--- a/scribo/demo/xml2doc/image_crop.cc
+++ b/scribo/demo/xml2doc/image_crop.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.
//
@@ -16,10 +17,13 @@
#include <limits.h>
+#include <scribo/core/macros.hh>
#include <scribo/preprocessing/crop.hh>
#include <mln/value/rgb8.hh>
#include <mln/core/alias/box2d.hh>
#include <mln/core/image/image2d.hh>
+#include <mln/util/couple.hh>
+#include <mln/draw/line.hh>
#include <mln/io/magick/save.hh>
#include <mln/io/magick/load.hh>
#include <mln/io/ppm/all.hh>
@@ -28,6 +32,7 @@
#include "loader.hh"
#include "common.hh"
+#include <mln/io/pbm/save.hh>
ImageCrop::ImageCrop(const QString& xml, const QString& img,
const QString& output)
@@ -270,7 +275,14 @@ bool ImageCrop::crop_regions(bool temp)
QDomNode coords = region.firstChild();
QString id = region.toElement().attribute("id", "none");
- // qDebug() << region.toElement().tagName();
+ // Retrieve region bbox.
+ using namespace mln;
+ def::coord
+ x_min = region.toElement().attribute("x_min").toInt(),
+ y_min = region.toElement().attribute("y_min").toInt(),
+ x_max = region.toElement().attribute("x_max").toInt(),
+ y_max = region.toElement().attribute("y_max").toInt();
+ box2d box = make::box2d(y_min, x_min, y_max, x_max);
while (!coords.isNull() &&
!coords.toElement().tagName().contains("coords"))
coords = coords.nextSibling();
@@ -279,44 +291,52 @@ bool ImageCrop::crop_regions(bool temp)
break;
QDomNode point = coords.firstChild();
- int x_max = 0;
- int y_max = 0;
- int x_min = INT_MAX;
- int y_min = INT_MAX;
+ // For each row, store first and last column of the line
+ // to be set as object. The rest will be considered as
+ // transparent.
+ util::array<util::couple<def::coord, def::coord> >
+ p_mask(box.nrows(),
+ util::couple<def::coord, def::coord>(x_max + 1, x_min - 1));
+
+ // Compute opacity mask for image region.
while (!point.isNull())
{
int x = point.toElement().attribute("x", "none").toInt();
int y = point.toElement().attribute("y", "none").toInt();
- if (x < x_min)
- x_min = x;
- if (x > x_max)
- x_max = x;
-
- if (y < y_min)
- y_min = y;
- if (y > y_max)
- y_max = y;
+ if (p_mask(y - y_min).first() > x)
+ p_mask(y - y_min).first() = x;
+ if (p_mask(y - y_min).second() < x)
+ p_mask(y - y_min).second() = x;
point = point.nextSibling();
}
- using namespace mln;
- box2d box = make::box2d(y_min, x_min, y_max, x_max);
-
+ // Crop image in input.
image2d<value::rgb8> crop = scribo::preprocessing::crop(ima_, box);
+ // Build image mask.
+ image2d<bool> opacity_mask(box);
+ {
+ data::fill(opacity_mask, true);
+ for_all_elements(e, p_mask)
+ draw::line(opacity_mask,
+ point2d(e + y_min, p_mask(e).first()),
+ point2d(e + y_min, p_mask(e).second()),
+ false);
+ }
+
if (temp)
{
QTemporaryFile tmp(output_dir_ + id + ".XXXXXX.png");
tmp.open();
region_map_[id] = tmp.fileName();
tmp.setAutoRemove(false);
- io::magick::save(crop, tmp.fileName().toStdString());
+ io::magick::save(crop, opacity_mask, tmp.fileName().toStdString());
}
else
- io::magick::save(crop, QString(output_dir_ + id + ".png").toStdString());
+ io::magick::save(crop, opacity_mask, QString(output_dir_ + id +
".png").toStdString());
}
region = region.nextSibling();
}
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 b463677..eaf08ac 100644
--- a/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
+++ b/scribo/scribo/io/xml/internal/extended_page_xml_visitor.hh
@@ -166,7 +166,12 @@ namespace scribo
{
output << " <whitespace_separator_region id=\"wss"
<< info.id()
- << "\">" << std::endl;
+ << "\""
+ << " x_min=\"" << info.bbox().pmin().col() <<
"\""
+ << " y_min=\"" << info.bbox().pmin().row() <<
"\""
+ << " x_max=\"" << info.bbox().pmax().col() <<
"\""
+ << " y_max=\"" << info.bbox().pmax().row() <<
"\""
+ << ">" << std::endl;
internal::print_box_coords(output, info.bbox(), " ");
@@ -179,7 +184,12 @@ namespace scribo
output << " <separator_region id=\"sr" <<
info.id()
<< "\" sep_orientation=\"0.000000\" "
<< " sep_colour=\"Black\" "
- << " sep_bgcolour=\"White\">" << std::endl;
+ << " sep_bgcolour=\"White\""
+ << " x_min=\"" << info.bbox().pmin().col() <<
"\""
+ << " y_min=\"" << info.bbox().pmin().row() <<
"\""
+ << " x_max=\"" << info.bbox().pmax().col() <<
"\""
+ << " y_max=\"" << info.bbox().pmax().row() <<
"\""
+ << ">" << std::endl;
internal::print_box_coords(output, info.bbox(), " ");
@@ -195,7 +205,12 @@ namespace scribo
<< "\" img_colour_type=\"24_Bit_Colour\""
<< " img_orientation=\"0.000000\" "
<< " img_emb_text=\"No\" "
- << " img_bgcolour=\"White\">" << std::endl;
+ << " img_bgcolour=\"White\""
+ << " x_min=\"" << info.bbox().pmin().col() <<
"\""
+ << " y_min=\"" << info.bbox().pmin().row() <<
"\""
+ << " x_max=\"" << info.bbox().pmax().col() <<
"\""
+ << " y_max=\"" << info.bbox().pmax().row() <<
"\""
+ << ">" << std::endl;
internal::print_image_coords(output,
((elt_edge | info.bbox())
--
1.5.6.5