<commit_before>#pragma once

#include <cstdint>
#include <type_traits>
#include <memory>

namespace sti
{
namespace detail
{

template <typename pixel_type_t>
static void normalize_image(const uint8_t *src, pixel_type_t *dst, const int width, const int height)
{
    const auto henk = static_cast<pixel_type_t>(1.0) / static_cast<pixel_type_t>(255.0);
    for (auto i = 0; i < width * height; ++i)
        dst[i] = src[i] * henk;
}

template <>
static void normalize_image<uint8_t>(const uint8_t *src, uint8_t *dst, const int width, const int height)
{
    std::memmove(dst, src, width * height);
}

template <typename T>
static void denormalize_image(const T *src, uint8_t *dst, const int width, const int height)
{
    std::memmove(dst, src, width * height);
}

template <>
static void denormalize_image<float>(const float *src, uint8_t *dst, const int width, const int height)
{
    const auto henk = 255.f;
    for (auto i = 0; i < width * height; ++i)
        // \todo fix missing clamp here
        dst[i] = static_cast<uint8_t>(src[i] * henk);
}

template <>
static void denormalize_image<double>(const double *src, uint8_t *dst, const int width, const int height)
{
    const auto henk = 255.0;
    for (auto i = 0; i < width * height; ++i)
        // \todo fix missing clamp here
        dst[i] = static_cast<uint8_t>(src[i] * henk);
}

} // namespace detail
} // namespace sti<commit_msg>Ported Steven's changes from image_detail and did some cleanups.<commit_after>#pragma once

#include <sti/utility.hpp>
#include <sti/pixel_values.hpp>
#include <cstdint>
#include <memory>

namespace sti
{
namespace detail
{

template <typename pixel_type_t>
static void normalize_image(const uint8_t *src, pixel_type_t *dst, const int width, const int height)
{
    constexpr auto min_value = pixel_values<pixel_type_t>::min_value() + 1;
    constexpr auto max_value = pixel_values<pixel_type_t>::max_value();

    const auto factor = min_value / max_value;
    for (auto i = 0; i < width * height; ++i)
        dst[i] = src[i] * factor;
}

template <>
static void normalize_image<uint8_t>(const uint8_t *src, uint8_t *dst, const int width, const int height)
{
    std::memmove(dst, src, width * height);
}

template <typename T>
static void denormalize_image(const T *src, uint8_t *dst, const int width, const int height)
{
    std::memmove(dst, src, width * height);
}

template <>
static void denormalize_image<float>(const float *src, uint8_t *dst, const int width, const int height)
{
    constexpr auto factor = 255.0f;
    constexpr auto min_value = static_cast<float>(pixel_values<uint8_t>::min_value());
    constexpr auto max_value = static_cast<float>(pixel_values<uint8_t>::max_value());
    for (auto i = 0; i < width * height; ++i)
        dst[i] = static_cast<uint8_t>(utility::clamp<float>(src[i] * factor, min_value, max_value));
}

template <>
static void denormalize_image<double>(const double *src, uint8_t *dst, const int width, const int height)
{
    constexpr auto factor = 255.0;
    constexpr auto min_value = static_cast<float>(pixel_values<uint8_t>::min_value());
    constexpr auto max_value = static_cast<float>(pixel_values<uint8_t>::max_value());
    for (auto i = 0; i < width * height; ++i)
        dst[i] = static_cast<uint8_t>(sti::utility::clamp<double>(src[i] * factor, min_value, max_value));
}

} // namespace detail
} // namespace sti
{'fraction_non_alphanumeric': 0.1286688407945449, 'fraction_numerical': 0.014823599169878446, 'mean_word_length': 4.43317230273752, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 44, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3685542', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1159, 'n_words': 336}