-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScreen.cpp
More file actions
36 lines (32 loc) · 1 KB
/
Copy pathScreen.cpp
File metadata and controls
36 lines (32 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
//
// Created by Peter Zdankin on 26.03.18.
//
#include "Screen.hpp"
#include "LodePNG.hpp"
void encodeOneStep(const char* filename, std::vector<unsigned char>& image, unsigned width, unsigned height)
{
//Encode the image
unsigned error = lodepng::encode(filename, image, width, height);
//if there's an error, display it
if(error) std::cout << "encoder error " << error << ": "<< lodepng_error_text(error) << std::endl;
}
void Screen::setPixel(uint64_t x, uint64_t y, Point c){
data[4 * (width * y + x) + 0] = (uint8_t)(c.getX()* 255.0);
data[4 * (width * y + x) + 1] = (uint8_t)(c.getY()* 255.0);
data[4 * (width * y + x) + 2] = (uint8_t)(c.getZ()* 255.0);
data[4 * (width * y + x) + 3] = (uint8_t)(255.0);
}
uint64_t Screen::getWidth() const{
return width;
}
uint64_t Screen::getHeight() const{
return height;
}
void Screen::clear(){
for(auto& i: data){
i = 0;
}
}
void Screen::save(const char *filename){
encodeOneStep(filename, data, width, height);
}