parent
e10065fa13
commit
c6bbf4274a
2 changed files with 63 additions and 46 deletions
@ -0,0 +1,59 @@ |
||||
#pragma once |
||||
|
||||
#include <math.h> |
||||
#include <iostream> |
||||
|
||||
#include "Renderer.hpp" |
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION |
||||
#include "stb_image_write.hpp" |
||||
|
||||
namespace massivedynamic { |
||||
typedef uint32_t Color; |
||||
|
||||
class PixelRenderer : public Renderer { |
||||
protected: |
||||
std::vector<Color> bitmap; |
||||
|
||||
void drawPixelScaled(size_t x, size_t y, Color color) { |
||||
size_t pixelSize = floor(static_cast<float>(this->targetSize) / static_cast<float>(this->sourceSize + 2)); |
||||
|
||||
if (pixelSize < 1) { |
||||
std::cerr << "ERROR: output file size is too small" << std::endl; |
||||
exit(1); |
||||
} |
||||
|
||||
size_t absoluteX = pixelSize * x; |
||||
size_t absoluteY = pixelSize * y; |
||||
|
||||
for (size_t localY = absoluteY + pixelSize; localY < absoluteY + pixelSize + pixelSize; localY++) { |
||||
for (size_t localX = absoluteX + pixelSize; localX < absoluteX + pixelSize + pixelSize; localX++) { |
||||
size_t absPos = localY * this->targetSize + localX; |
||||
this->bitmap.at(absPos) = color; |
||||
} |
||||
} |
||||
} |
||||
public: |
||||
enum Colors : Color { |
||||
BLACK = 0xFF000000, |
||||
WHITE = 0xFFFFFFFF |
||||
}; |
||||
|
||||
PixelRenderer(const std::vector<bool>& pixels, size_t sourceSize, size_t targetSize) : Renderer(pixels, sourceSize, targetSize) { |
||||
if (this->targetSize == 0) |
||||
this->targetSize = (sourceSize + 2) * 2; |
||||
this->bitmap = std::vector<Color>(this->targetSize * this->targetSize, Colors::WHITE); |
||||
} |
||||
|
||||
void generateBuffer() { |
||||
for (size_t y = 0; y < sourceSize; y++) { |
||||
for (size_t x = 0; x < sourceSize; x++) { |
||||
if (!pixels.at(y * sourceSize + x)) |
||||
continue; |
||||
this->drawPixelScaled(x, y, Colors::BLACK); |
||||
} |
||||
} |
||||
|
||||
} |
||||
}; |
||||
|
||||
} |
Loading…
Reference in new issue