Skip to content

Commit

Permalink
refs #25: added MosaicGenerator, made Floyd-Steinberg subclass MG
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaswagner committed Jun 3, 2018
1 parent e7acd0d commit 3095d63
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ set(source_dir src)

set(sources
${source_dir}/main.cpp
${source_dir}/mosaic.hpp
${source_dir}/algorithms/floyd-steinberg.cpp
${source_dir}/algorithms/floyd-steinberg.hpp
${source_dir}/mollusc.cpp
Expand Down
4 changes: 2 additions & 2 deletions src/algorithms/floyd-steinberg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const Mollusc& getClosestColor(const std::vector<Mollusc>& molluscs, const QVect
return molluscs[closestIndex];
}

QImage* createMosaic(const QImage& input, const std::vector<Mollusc>& molluscs, int scale)
QImage* FloydSteinberg::createMosaic(const QImage& input, int scale)
{
auto scaled = input.scaledToWidth(input.width() / scale, Qt::SmoothTransformation);

Expand All @@ -53,7 +53,7 @@ QImage* createMosaic(const QImage& input, const std::vector<Mollusc>& molluscs,
auto oldColor = QColor(scaled.pixel(x, y));
auto oldVector = toVec3(oldColor) + errorStorage[x + 1 + y * width];

const Mollusc& mollusc = getClosestColor(molluscs, oldVector);
const Mollusc& mollusc = getClosestColor(m_molluscs, oldVector);
auto newVector = toVec3(mollusc.m_color);

if (mollusc.m_imageName.compare("NONE") != 0)
Expand Down
9 changes: 8 additions & 1 deletion src/algorithms/floyd-steinberg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
#include <vector>
#include <QImage>
#include "../mollusc.hpp"
#include "../mosaic.hpp"

QImage* createMosaic(const QImage& input, const std::vector<Mollusc>& molluscs, int scale);
class FloydSteinberg : MosaicGenerator
{
public:
FloydSteinberg(const std::vector<Mollusc>& molluscs) : MosaicGenerator(molluscs) { };

QImage * createMosaic(const QImage& input, int scale);
};
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ int main(int argc, char *argv[])
// white mollusc for background
molluscs.push_back(Mollusc("NONE;#FFFFFF;0.0;1.0;NONE;NONE;NONE;NONE;NONE;NONE;NONE;NONE;NONE;NONE;NONE;NONE;NONE;NONE"));

QImage* result = createMosaic(image, molluscs, scale);
auto mosaic = FloydSteinberg(molluscs);
auto result = mosaic.createMosaic(image, scale);

result->save(output);

Expand Down
16 changes: 16 additions & 0 deletions src/mosaic.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#pragma once

#include <vector>
#include <QImage>
#include "mollusc.hpp"

class MosaicGenerator
{
public:
MosaicGenerator(const std::vector<Mollusc>& molluscs) : m_molluscs{ molluscs } { };

virtual QImage * createMosaic(const QImage& input, int scale) = 0;

protected:
const std::vector<Mollusc>& m_molluscs;
};

0 comments on commit 3095d63

Please sign in to comment.