Revert "Add utils::span wrapper (#9318)"

This reverts commit 686eb30d41.
This commit is contained in:
pentarctagon 2024-09-08 10:25:36 -05:00
parent 5c9065eb7e
commit 08d3f3be88
3 changed files with 22 additions and 37 deletions

View file

@ -21,15 +21,22 @@
#include "color_range.hpp"
#include "utils/span.hpp"
#include <array>
#include <cassert>
#include <sstream>
#ifdef __cpp_lib_span
#include <span>
#endif
namespace
{
std::vector<color_t> recolor_range_impl(const color_range& new_range, utils::span<const color_t> old_rgb)
#ifdef __cpp_lib_span
std::vector<color_t> recolor_range_impl(const color_range& new_range, std::span<const color_t> old_rgb)
#else
template<typename Container>
std::vector<color_t> recolor_range_impl(const color_range& new_range, const Container& old_rgb)
#endif
{
std::vector<color_t> clist;
clist.reserve(old_rgb.size());

View file

@ -16,7 +16,6 @@
#include "sdl/surface.hpp"
#include "sdl/utils.hpp"
#include "utils/span.hpp"
#include <algorithm>
#include <array>
@ -62,6 +61,16 @@ surface array_to_surface(const std::array<uint32_t, w * h>& arr)
return surf;
}
static std::vector<uint32_t> surface_to_vec(const surface& surf)
{
const_surface_lock lock{surf};
const uint32_t* const pixels = lock.pixels();
std::vector<uint32_t> pixel_vec;
const int surf_size = surf->w * surf->h;
std::copy(pixels, pixels + surf_size, std::back_inserter(pixel_vec));
return pixel_vec;
}
BOOST_AUTO_TEST_SUITE(sdl)
BOOST_AUTO_TEST_CASE(test_scale_sharp_nullptr)
@ -82,8 +91,7 @@ BOOST_AUTO_TEST_CASE(test_scale_sharp_round)
{
surface src = array_to_surface<4, 4>(img_4x4);
surface result = scale_surface_sharp(src, 2, 2);
const_surface_lock lock{result};
auto result_pixels = utils::span(lock.pixels(), result.area());
std::vector<uint32_t> result_pixels = surface_to_vec(result);
BOOST_CHECK_EQUAL_COLLECTIONS(
result_pixels.begin(), result_pixels.end(), img_4x4_to_2x2_result.begin(), img_4x4_to_2x2_result.end());
}
@ -92,8 +100,7 @@ BOOST_AUTO_TEST_CASE(test_scale_sharp_fractional)
{
surface src = array_to_surface<4, 4>(img_4x4);
surface result = scale_surface_sharp(src, 3, 2);
const_surface_lock lock{result};
auto result_pixels = utils::span(lock.pixels(), result.area());
std::vector<uint32_t> result_pixels = surface_to_vec(result);
BOOST_CHECK_EQUAL_COLLECTIONS(
result_pixels.begin(), result_pixels.end(), img_4x4_to_3x2_result.begin(), img_4x4_to_3x2_result.end());
}

View file

@ -1,29 +0,0 @@
/*
Copyright (C) 2024 by the Battle for Wesnoth Project http://www.wesnoth.org/
This program 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; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#pragma once
#ifdef __cpp_lib_span
#include <span>
#else
#include <boost/core/span.hpp>
#endif
namespace utils
{
#ifdef __cpp_lib_span
using std::span;
#else
using boost::span;
#endif
} // end namespace utils