mapnik/benchmark/compare_images.hpp
Blake Thompson badb0c9a97 This is a complete removal of code that utilizes image_32 in the library. It is a sweeping change that does some of the following:
* Changes all agg_renderers to use a image_data_any variant (only image_data_rgba8 is implemented currently)
* Changes the marker and marker_cache to use image_data_any images
* Changes the symbolizers so that they must be aware of the source data type they are attempting to render and the render type that is expected to be rendered into.
* Moves many utilities into image_utils, that were previously in image_32.

The kicker is that this still isn't working perfectly yet, but I am commiting so I don't have tears in case everything is lost on my computer.

Ref #2633
2015-01-20 18:30:10 -06:00

47 lines
1.6 KiB
C++

#ifndef __MAPNIK_COMPARE_IMAGES_HPP__
#define __MAPNIK_COMPARE_IMAGES_HPP__
#include <mapnik/graphics.hpp>
#include <mapnik/image_data.hpp>
#include <mapnik/image_util.hpp>
#include <mapnik/image_reader.hpp>
using namespace mapnik;
namespace benchmark {
bool compare_images(std::string const& src_fn,std::string const& dest_fn)
{
std::unique_ptr<mapnik::image_reader> reader1(mapnik::get_image_reader(dest_fn,"png"));
if (!reader1.get())
{
throw mapnik::image_reader_exception("Failed to load: " + dest_fn);
}
std::unique_ptr<mapnik::image_reader> reader2(mapnik::get_image_reader(src_fn,"png"));
if (!reader2.get())
{
throw mapnik::image_reader_exception("Failed to load: " + src_fn);
}
image_data_rgba8 const& dest = util::get<image_data_rgba8>(reader1->read(0,0,reader1->width(), reader1->height()));
image_data_rgba8 const& src = util::get<image_data_rgba8>(reader1->read(0,0,reader1->width(), reader1->height()));
unsigned int width = src.width();
unsigned int height = src.height();
if ((width != dest.width()) || height != dest.height()) return false;
for (unsigned int y = 0; y < height; ++y)
{
const unsigned int* row_from = src.getRow(y);
const unsigned int* row_to = dest.getRow(y);
for (unsigned int x = 0; x < width; ++x)
{
if (row_from[x] != row_to[x]) return false;
}
}
return true;
}
}
#endif // __MAPNIK_COMPARE_IMAGES_HPP__