diff options
Diffstat (limited to 'src/pixels.cpp')
| -rw-r--r-- | src/pixels.cpp | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/src/pixels.cpp b/src/pixels.cpp index 5aac4a6..fcdfac7 100644 --- a/src/pixels.cpp +++ b/src/pixels.cpp @@ -5,39 +5,37 @@ #include <fstream> #include <iostream> -Pixels& Pixels::operator+=(const Pixels& other) +Pixels& Pixels::operator+=( + const Pixels& other) { - std::transform( - std::execution::par, - pixels.begin(), - pixels.end(), - other.pixels.begin(), - pixels.begin(), - // [](auto& toAdd) { return dst += src; }); - std::plus<>() - ); + std::transform(std::execution::par, + pixels.begin(), + pixels.end(), + other.pixels.begin(), + pixels.begin(), + // [](auto& toAdd) { return dst += src; }); + std::plus<>()); return *this; } -Pixels& Pixels::operator/=(const float divider) +Pixels& Pixels::operator/=( + const float divider) { - std::for_each( - std::execution::par_unseq, - pixels.begin(), - pixels.end(), - [divider](auto& pixel) { pixel /= divider; } - ); + std::for_each(std::execution::par_unseq, + pixels.begin(), + pixels.end(), + [divider](auto& pixel) { pixel /= divider; }); return *this; } -std::optional<Pixels> Pixels::load(const QString& filename) +std::optional<Pixels> Pixels::load( + const QString& filename) { const std::filesystem::path filepath{filename.toStdString()}; - if (!std::filesystem::exists(filepath)) - { + if (!std::filesystem::exists(filepath)) { std::cerr << "no such file: " << filepath << std::endl; return {}; @@ -52,8 +50,7 @@ std::optional<Pixels> Pixels::load(const QString& filename) ifs.read(reinterpret_cast<char*>(&result), sizeof(Pixels)); ifs.close(); - if (!ifs) - { + if (!ifs) { std::cerr << "cannot read " << filepath << std::endl; return {}; @@ -62,14 +59,14 @@ std::optional<Pixels> Pixels::load(const QString& filename) return result; } -bool Pixels::save(const QString& filename) +bool Pixels::save( + const QString& filename) { const std::filesystem::path filepath{filename.toStdString()}; const auto parent_path = filepath.parent_path(); - if (!std::filesystem::exists(parent_path) && - !std::filesystem::create_directories(parent_path)) - { + if (!std::filesystem::exists(parent_path) + && !std::filesystem::create_directories(parent_path)) { std::cerr << "cannot create parent directory for file " << filepath << std::endl; @@ -84,8 +81,7 @@ bool Pixels::save(const QString& filename) ofs.write(reinterpret_cast<const char*>(this), sizeof(Pixels)); ofs.close(); - if (!ofs) - { + if (!ofs) { std::cerr << "cannot write " << filepath << std::endl; return false; @@ -96,7 +92,12 @@ bool Pixels::save(const QString& filename) Pixels::operator bool() const { - return std::find_if(pixels.cbegin(), pixels.cend(), [](const auto& p) { - return !qFuzzyIsNull(p) && !std::isnan(p); - }) != pixels.cend(); + bool result = std::find_if(pixels.cbegin(), + pixels.cend(), + [](const auto& p) { + return !qFuzzyIsNull(p) && !std::isnan(p); + }) + != pixels.cend(); + // std::cout << __func__ << ":\t" << (result ? "true" : "false") << std::endl; + return result; } |
