My old project for strange attractors, new approach
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

70 lines
1.6 KiB

//
// Tonemapper.hpp
// AwesomeAttractorND
//
// Created by Joshua Moerman on 10/28/11.
// Copyright 2011 Vadovas. All rights reserved.
//
#ifndef AwesomeAttractorND_Tonemapper_hpp
#define AwesomeAttractorND_Tonemapper_hpp
#include <algorithm>
13 years ago
#include <numeric>
#include <cmath>
namespace Tonemappers {
13 years ago
struct Normalizer {
Normalizer()
: max(0)
{}
template <typename C>
void analyse(C const & canvas){
13 years ago
max = *std::max_element(canvas.begin(), canvas.end());
}
template <typename C, typename I>
void process(C const & canvas, I & image){
13 years ago
for (typename C::const_iterator it = canvas.begin(); it != canvas.end(); ++it) {
const double grayscale = get_value(*it);
image << typename I::pixel(grayscale, grayscale, grayscale);
}
}
13 years ago
protected:
double get_value(unsigned int n){
return (double) n / (double) max;
}
unsigned int max;
};
13 years ago
struct GammaCorrector : public Normalizer {
template <typename C>
void analyse(C const & canvas){
Normalizer::analyse(canvas);
const unsigned int sum = std::accumulate(canvas.begin(), canvas.end(), 0);
const double average = sum / (double) canvas.size();
power = -2.5/std::log(average/max);
}
template <typename C, typename I>
void process(C const & canvas, I & image){
for (typename C::const_iterator it = canvas.begin(); it != canvas.end(); ++it) {
const double grayscale = get_value(*it);
image << typename I::pixel(grayscale, grayscale, grayscale);
}
}
protected:
double get_value(unsigned int n){
return std::pow(Normalizer::get_value(n), power);
}
double power;
};
}
#endif