#ifndef STACKER_POST_PROCESSING_TPP
#define STACKER_POST_PROCESSING_TPP

template <typename T>
std::shared_ptr<ImageBuffer<T>> Stacker<T>::applyPostProcessing(const std::shared_ptr<ImageBuffer<T>> &frame)
{
    auto result = frame;

    // Apply background adjustment if explicitly set
    if (m_settings->isBackgroundAdjustmentSet() && m_settings->getBackgroundAdjustment() > 0.0f)
    {
        result = applyBackgroundAdjustment(result, m_settings->getBackgroundAdjustment());
    }

    // Apply contrast adjustment if explicitly set and not at the "no change" value (100% in internal range)
    if (m_settings->isContrastAdjustmentSet() && std::abs(m_settings->getContrastAdjustment() - 100.0f) > 0.01f)
    {
        result = applyContrastAdjustment(result, m_settings->getContrastAdjustment());
    }

    // Apply saturation adjustment if explicitly set and not at the "no change" value (100% in internal range)
    if (m_settings->isSaturationAdjustmentSet() && std::abs(m_settings->getSaturationAdjustment() - 100.0f) > 0.01f)
    {
        result = applySaturationAdjustment(result, m_settings->getSaturationAdjustment());
    }

    // Apply compression if explicitly set
    if (m_settings->isCompressionPercentageSet() && m_settings->getCompressionPercentage() > 0.0f)
    {
        result = applyCompression(result, m_settings->getCompressionPercentage());
    }

    // Apply local histogram equalization if explicitly set
    if (m_settings->isLocalHistEqSet() && m_settings->getLocalHistEqWindowSize() > 0)
    {
        result = applyLocalHistogramEqualization(result, m_settings->getLocalHistEqWindowSize(),
                 m_settings->getLocalHistEqClipLimit());
    }

    // Apply median filter if explicitly set
    if (m_settings->isMedianFilterSizeSet() && m_settings->getMedianFilterSize() > 0)
    {
        result = applyMedianFilter(result, m_settings->getMedianFilterSize());
    }

    // Apply denoising if explicitly set
    if (m_settings->isDenoisingSet() && m_settings->getDenoisingMethod() != StackerSettings::DenoisingMethod::None)
    {
        result = applyDenoising(result, m_settings->getDenoisingMethod(), m_settings->getDenoisingStrength());
    }

    return result;
}

#endif // STACKER_POST_PROCESSING_TPP
