void Scene::computeColorsAntialiasing(std::function<void(int, int, ColorCRef)> paint, int threadCount, int level) { upto(threadCount, 1); downto(threadCount, 4); std::vector< std::vector <ColorFloat> > m(screen.width, std::vector<ColorFloat> (screen.height, ColorFloat())); computeColors([paint, &m](int x, int y, ColorCRef c) { m[x][y] = c; paint(x, y, c); }, threadCount); if (level > 1) { for (int x = 1; x + 1 < screen.width; x++) { for (int y = 1; y + 1 < screen.height; y++) { int badness = 0; for (int dx : {-1, 1}) for (int dy : {-1, 1}) badness += (m[x][y] - m[x + dx][y + dy]).norm(); if (badness > badnessLimit) { paint(x, y, Color(255, 0, 0)); } } } int taskCount = 10; ThreadPool pool; for (int t = 0; t < taskCount; t++) pool.addTask([this, &paint, &m, level, t, taskCount]() { multiThreadAntialiasePart(paint, m, level, t, taskCount); }); pool.executeAll(threadCount); } }
Colormap::Colormap() { hue = 0.0f; saturation = 1.0; numberOfColors = COL_256; map.resize(COL_256); map[0] = BLACK; map[255] = WHITE; texture = 0; computeColors(); }
void Colormap::putColor(RGB color, unsigned int position) { map[position] = color; computeColors(); }
void Colormap::setNumberOfColors(int n) { numberOfColors = n; computeColors(); }
void Colormap::setSaturation(float s) { saturation = s; computeColors(); }
void Colormap::setHue(float h) { hue = h; computeColors(); }