seam-carving/src/utils.hpp

34 lines
1.1 KiB
C++

#include <random>
// Get index for any table indexed by [width*(i : height) + (j : width)], but a
// : dim_long, b : dim_large
#define im_index(a, b) (vertical ? (width * a + b) : (width * b + a))
bool nearly_equal(float a, float b);
std::pair<int, float> operator+(std::pair<int, float>& p1, std::pair<int, float>& p2);
void operator+=(std::pair<int, float>& p1, std::pair<int, float>& p2);
bool does_seam_remove_mask(std::vector<std::pair<int, float>> energy, int width, int height, int nbChannels,
std::vector<int> opt_seam, bool vertical);
std::vector<std::pair<int, float>> mask_energy(std::vector<float> energy,
int width, int height, unsigned char* mask);
// Unfortunately, std::cout << (std::pair<>) does not work and can't be rewritten
std::string str_of_e(std::pair<int, float> energy);
std::string str_of_e(float energy);
namespace limits {
struct max_energy {
template<class T> operator T() {
return std::numeric_limits<T>::max();
}
operator std::pair<int, float>() {
return {3, std::numeric_limits<float>::max()};
}
};
}