2015-04-24 12:40:22 +00:00
|
|
|
#include "catch.hpp"
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <mapnik/image.hpp>
|
|
|
|
#include <mapnik/image_reader.hpp>
|
|
|
|
#include <mapnik/image_util.hpp>
|
|
|
|
#include <mapnik/util/fs.hpp>
|
|
|
|
#include <vector>
|
|
|
|
#include <algorithm>
|
|
|
|
#if defined(HAVE_CAIRO)
|
|
|
|
#include <mapnik/cairo/cairo_context.hpp>
|
|
|
|
#include <mapnik/cairo/cairo_image_util.hpp>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
TEST_CASE("image io") {
|
|
|
|
|
|
|
|
SECTION("readers") {
|
|
|
|
|
|
|
|
std::string should_throw;
|
|
|
|
boost::optional<std::string> type;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
#if defined(HAVE_JPEG)
|
2015-04-30 13:57:47 +00:00
|
|
|
should_throw = "./test/data/images/blank.jpg";
|
2015-04-24 12:40:22 +00:00
|
|
|
REQUIRE( mapnik::util::exists( should_throw ) );
|
|
|
|
type = mapnik::type_from_filename(should_throw);
|
|
|
|
REQUIRE( type );
|
2015-05-11 20:51:39 +00:00
|
|
|
REQUIRE_THROWS(std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type)));
|
2015-04-24 12:40:22 +00:00
|
|
|
#endif
|
|
|
|
|
2015-05-11 20:51:39 +00:00
|
|
|
REQUIRE_THROWS(mapnik::image_rgba8 im(-10,-10)); // should throw rather than overflow
|
2015-04-24 12:40:22 +00:00
|
|
|
|
|
|
|
#if defined(HAVE_CAIRO)
|
|
|
|
mapnik::cairo_surface_ptr image_surface(
|
|
|
|
cairo_image_surface_create(CAIRO_FORMAT_ARGB32,256,257),
|
|
|
|
mapnik::cairo_surface_closer());
|
|
|
|
mapnik::image_rgba8 im_data(cairo_image_surface_get_width(&*image_surface), cairo_image_surface_get_height(&*image_surface));
|
|
|
|
im_data.set(1);
|
|
|
|
REQUIRE( (unsigned)im_data(0,0) == unsigned(1) );
|
|
|
|
// Should set back to fully transparent
|
|
|
|
mapnik::cairo_image_to_rgba8(im_data, image_surface);
|
|
|
|
REQUIRE( (unsigned)im_data(0,0) == unsigned(0) );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_PNG)
|
2015-04-30 13:57:47 +00:00
|
|
|
should_throw = "./test/data/images/blank.png";
|
2015-04-24 12:40:22 +00:00
|
|
|
REQUIRE( mapnik::util::exists( should_throw ) );
|
|
|
|
type = mapnik::type_from_filename(should_throw);
|
|
|
|
REQUIRE( type );
|
2015-05-11 20:51:39 +00:00
|
|
|
REQUIRE_THROWS(std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type)));
|
2015-04-24 12:40:22 +00:00
|
|
|
|
2015-04-30 13:57:47 +00:00
|
|
|
should_throw = "./test/data/images/xcode-CgBI.png";
|
2015-04-24 12:40:22 +00:00
|
|
|
REQUIRE( mapnik::util::exists( should_throw ) );
|
|
|
|
type = mapnik::type_from_filename(should_throw);
|
|
|
|
REQUIRE( type );
|
2015-05-11 20:51:39 +00:00
|
|
|
REQUIRE_THROWS(std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type)));
|
2015-04-24 12:40:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_TIFF)
|
2015-04-30 13:57:47 +00:00
|
|
|
should_throw = "./test/data/images/blank.tiff";
|
2015-04-24 12:40:22 +00:00
|
|
|
REQUIRE( mapnik::util::exists( should_throw ) );
|
|
|
|
type = mapnik::type_from_filename(should_throw);
|
|
|
|
REQUIRE( type );
|
2015-05-11 20:51:39 +00:00
|
|
|
REQUIRE_THROWS(std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type)));
|
2015-04-24 12:40:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_WEBP)
|
2015-04-30 13:57:47 +00:00
|
|
|
should_throw = "./test/data/images/blank.webp";
|
2015-04-24 12:40:22 +00:00
|
|
|
REQUIRE( mapnik::util::exists( should_throw ) );
|
|
|
|
type = mapnik::type_from_filename(should_throw);
|
|
|
|
REQUIRE( type );
|
2015-05-11 20:51:39 +00:00
|
|
|
REQUIRE_THROWS(std::unique_ptr<mapnik::image_reader> reader(mapnik::get_image_reader(should_throw,*type)));
|
2015-04-24 12:40:22 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
catch (std::exception const & ex)
|
|
|
|
{
|
|
|
|
std::clog << ex.what() << "\n";
|
|
|
|
REQUIRE(false);
|
|
|
|
}
|
|
|
|
|
2015-05-11 23:19:24 +00:00
|
|
|
} // END SECTION
|
|
|
|
|
|
|
|
|
|
|
|
} // END TEST_CASE
|