2015-03-13 16:52:03 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Artem Pavlenko
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include <mapnik/image_any.hpp>
|
|
|
|
|
|
|
|
namespace mapnik {
|
|
|
|
|
|
|
|
namespace detail {
|
|
|
|
|
|
|
|
struct get_bytes_visitor
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
unsigned char* operator()(T & data)
|
|
|
|
{
|
2015-05-04 12:49:11 +02:00
|
|
|
return data.bytes();
|
2015-03-13 16:52:03 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-05 14:12:29 +02:00
|
|
|
struct get_bytes_visitor_const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
template <typename T>
|
2015-05-05 14:12:29 +02:00
|
|
|
unsigned char const* operator()(T const& data) const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
2015-05-05 14:12:29 +02:00
|
|
|
return data.bytes();
|
2015-03-13 16:52:03 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-05 14:12:29 +02:00
|
|
|
struct get_dtype_visitor
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
template <typename T>
|
2015-05-05 14:12:29 +02:00
|
|
|
image_dtype operator()(T const& data) const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
2015-05-05 14:12:29 +02:00
|
|
|
return data.get_dtype();
|
2015-03-13 16:52:03 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct get_width_visitor
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
std::size_t operator()(T const& data) const
|
|
|
|
{
|
|
|
|
return data.width();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct get_height_visitor
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
std::size_t operator()(T const& data) const
|
|
|
|
{
|
|
|
|
return data.height();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct get_premultiplied_visitor
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
bool operator()(T const& data) const
|
|
|
|
{
|
|
|
|
return data.get_premultiplied();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct get_painted_visitor
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
bool operator()(T const& data) const
|
|
|
|
{
|
|
|
|
return data.painted();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct get_any_size_visitor
|
|
|
|
{
|
|
|
|
template <typename T>
|
2015-05-04 10:57:57 +02:00
|
|
|
std::size_t operator()(T const& data) const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
2015-05-04 10:57:57 +02:00
|
|
|
return data.size();
|
2015-03-13 16:52:03 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct get_any_row_size_visitor
|
|
|
|
{
|
|
|
|
template <typename T>
|
2015-05-04 10:57:57 +02:00
|
|
|
std::size_t operator()(T const& data) const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
2015-05-04 10:57:57 +02:00
|
|
|
return data.row_size();
|
2015-03-13 16:52:03 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct get_offset_visitor
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
double operator() (T const& data) const
|
|
|
|
{
|
|
|
|
return data.get_offset();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct get_scaling_visitor
|
|
|
|
{
|
|
|
|
template <typename T>
|
|
|
|
double operator() (T const& data) const
|
|
|
|
{
|
|
|
|
return data.get_scaling();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct set_offset_visitor
|
|
|
|
{
|
|
|
|
set_offset_visitor(double val)
|
|
|
|
: val_(val) {}
|
|
|
|
template <typename T>
|
|
|
|
void operator() (T & data)
|
|
|
|
{
|
|
|
|
data.set_offset(val_);
|
|
|
|
}
|
2015-05-05 14:12:29 +02:00
|
|
|
private:
|
2015-03-13 16:52:03 +01:00
|
|
|
double val_;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct set_scaling_visitor
|
|
|
|
{
|
|
|
|
set_scaling_visitor(double val)
|
|
|
|
: val_(val) {}
|
|
|
|
template <typename T>
|
|
|
|
void operator() (T & data)
|
|
|
|
{
|
|
|
|
data.set_scaling(val_);
|
|
|
|
}
|
2015-05-05 14:12:29 +02:00
|
|
|
private:
|
2015-03-13 16:52:03 +01:00
|
|
|
double val_;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace detail
|
|
|
|
|
2015-03-13 22:34:49 +01:00
|
|
|
MAPNIK_DECL image_any::image_any(int width,
|
2015-05-05 14:12:29 +02:00
|
|
|
int height,
|
|
|
|
image_dtype type,
|
|
|
|
bool initialize,
|
|
|
|
bool premultiplied,
|
|
|
|
bool painted)
|
2015-03-13 16:52:03 +01:00
|
|
|
: image_base(std::move(create_image_any(width, height, type, initialize, premultiplied, painted))) {}
|
|
|
|
|
2015-05-04 12:49:11 +02:00
|
|
|
MAPNIK_DECL unsigned char const* image_any::bytes() const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
return util::apply_visitor(detail::get_bytes_visitor_const(),*this);
|
|
|
|
}
|
|
|
|
|
2015-05-04 12:49:11 +02:00
|
|
|
MAPNIK_DECL unsigned char* image_any::bytes()
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
return util::apply_visitor(detail::get_bytes_visitor(),*this);
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:34:49 +01:00
|
|
|
MAPNIK_DECL std::size_t image_any::width() const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
return util::apply_visitor(detail::get_width_visitor(),*this);
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:34:49 +01:00
|
|
|
MAPNIK_DECL std::size_t image_any::height() const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
return util::apply_visitor(detail::get_height_visitor(),*this);
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:34:49 +01:00
|
|
|
MAPNIK_DECL bool image_any::get_premultiplied() const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
return util::apply_visitor(detail::get_premultiplied_visitor(),*this);
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:34:49 +01:00
|
|
|
MAPNIK_DECL bool image_any::painted() const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
return util::apply_visitor(detail::get_painted_visitor(),*this);
|
|
|
|
}
|
|
|
|
|
2015-05-04 10:57:57 +02:00
|
|
|
MAPNIK_DECL std::size_t image_any::size() const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
return util::apply_visitor(detail::get_any_size_visitor(),*this);
|
|
|
|
}
|
|
|
|
|
2015-05-04 10:57:57 +02:00
|
|
|
MAPNIK_DECL std::size_t image_any::row_size() const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
return util::apply_visitor(detail::get_any_row_size_visitor(),*this);
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:34:49 +01:00
|
|
|
MAPNIK_DECL double image_any::get_offset() const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
return util::apply_visitor(detail::get_offset_visitor(),*this);
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:34:49 +01:00
|
|
|
MAPNIK_DECL double image_any::get_scaling() const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
return util::apply_visitor(detail::get_scaling_visitor(),*this);
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:34:49 +01:00
|
|
|
MAPNIK_DECL image_dtype image_any::get_dtype() const
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
return util::apply_visitor(detail::get_dtype_visitor(),*this);
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:34:49 +01:00
|
|
|
MAPNIK_DECL void image_any::set_offset(double val)
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
util::apply_visitor(detail::set_offset_visitor(val),*this);
|
|
|
|
}
|
|
|
|
|
2015-03-13 22:34:49 +01:00
|
|
|
MAPNIK_DECL void image_any::set_scaling(double val)
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
util::apply_visitor(detail::set_scaling_visitor(val),*this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-05-04 10:57:57 +02:00
|
|
|
MAPNIK_DECL image_any create_image_any(int width,
|
2015-05-05 14:12:29 +02:00
|
|
|
int height,
|
|
|
|
image_dtype type,
|
|
|
|
bool initialize,
|
|
|
|
bool premultiplied,
|
|
|
|
bool painted)
|
2015-03-13 16:52:03 +01:00
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
2015-05-05 14:12:29 +02:00
|
|
|
case image_dtype_gray8:
|
2015-03-13 16:52:03 +01:00
|
|
|
return image_any(std::move(image_gray8(width, height, initialize, premultiplied, painted)));
|
2015-05-05 14:12:29 +02:00
|
|
|
case image_dtype_gray8s:
|
2015-03-13 16:52:03 +01:00
|
|
|
return image_any(std::move(image_gray8s(width, height, initialize, premultiplied, painted)));
|
2015-05-05 14:12:29 +02:00
|
|
|
case image_dtype_gray16:
|
2015-03-13 16:52:03 +01:00
|
|
|
return image_any(std::move(image_gray16(width, height, initialize, premultiplied, painted)));
|
2015-05-05 14:12:29 +02:00
|
|
|
case image_dtype_gray16s:
|
2015-03-13 16:52:03 +01:00
|
|
|
return image_any(std::move(image_gray16s(width, height, initialize, premultiplied, painted)));
|
2015-05-05 14:12:29 +02:00
|
|
|
case image_dtype_gray32:
|
2015-03-13 16:52:03 +01:00
|
|
|
return image_any(std::move(image_gray32(width, height, initialize, premultiplied, painted)));
|
2015-05-05 14:12:29 +02:00
|
|
|
case image_dtype_gray32s:
|
2015-03-13 16:52:03 +01:00
|
|
|
return image_any(std::move(image_gray32s(width, height, initialize, premultiplied, painted)));
|
2015-05-05 14:12:29 +02:00
|
|
|
case image_dtype_gray32f:
|
2015-03-13 16:52:03 +01:00
|
|
|
return image_any(std::move(image_gray32f(width, height, initialize, premultiplied, painted)));
|
2015-05-05 14:12:29 +02:00
|
|
|
case image_dtype_gray64:
|
2015-03-13 16:52:03 +01:00
|
|
|
return image_any(std::move(image_gray64(width, height, initialize, premultiplied, painted)));
|
2015-05-05 14:12:29 +02:00
|
|
|
case image_dtype_gray64s:
|
2015-03-13 16:52:03 +01:00
|
|
|
return image_any(std::move(image_gray64s(width, height, initialize, premultiplied, painted)));
|
2015-05-05 14:12:29 +02:00
|
|
|
case image_dtype_gray64f:
|
2015-03-13 16:52:03 +01:00
|
|
|
return image_any(std::move(image_gray64f(width, height, initialize, premultiplied, painted)));
|
2015-05-05 14:12:29 +02:00
|
|
|
case image_dtype_null:
|
2015-03-13 16:52:03 +01:00
|
|
|
return image_any(std::move(image_null()));
|
2015-05-05 14:12:29 +02:00
|
|
|
case image_dtype_rgba8:
|
|
|
|
case IMAGE_DTYPE_MAX:
|
|
|
|
default:
|
2015-03-13 16:52:03 +01:00
|
|
|
return image_any(std::move(image_rgba8(width, height, initialize, premultiplied, painted)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // end mapnik ns
|