mock: levels.txt automatisch generieren
[hackover2013-badge-firmware.git] / vanity / vanity-convert.cc
1 #include <SFML/Graphics/Image.hpp>
2
3 #include <cmath>
4 #include <fstream>
5 #include <iostream>
6 #include <numeric>
7
8 #include <badge/ui/display.h>
9
10 double square(double x) { return x * x; }
11
12 int main(int argc, char *argv[]) {
13 if(argc != 2) {
14 std::cerr << "Usage: " << argv[0] << " [ FILE ]\n";
15 return -1;
16 }
17
18 sf::Image img;
19 if(!img.loadFromFile(argv[1])) {
20 std::cerr << "Could not open file.\n";
21 return -2;
22 }
23
24 if(img.getSize().x != BADGE_DISPLAY_WIDTH ||
25 img.getSize().y != BADGE_DISPLAY_HEIGHT) {
26 std::cerr << "Image must be " << BADGE_DISPLAY_WIDTH << "x" << BADGE_DISPLAY_HEIGHT << " pixels.\n";
27 return -3;
28 }
29
30 badge_framebuffer fb = { { { 0 } } };
31
32 for(unsigned x = 0; x < BADGE_DISPLAY_WIDTH; ++x) {
33 for(unsigned y = 0; y < BADGE_DISPLAY_HEIGHT; ++y) {
34 sf::Color c = img.getPixel(x, y);
35
36 if(std::sqrt(0.241 * square(c.r / 255.) + 0.691 * square(c.g / 255.) + 0.068 * square(c.b / 255.)) < 0.5) {
37 badge_framebuffer_pixel_on(&fb, x, y);
38 }
39 }
40 }
41
42 std::ofstream out("vanity.dat", std::ios::out | std::ios::binary);
43
44 if(out) {
45 out.write(static_cast<char const *>(static_cast<void const *>(&fb)), sizeof(fb));
46 }
47
48 return 0;
49 }
This page took 0.045191 seconds and 5 git commands to generate.