-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloadimage.cpp
More file actions
61 lines (51 loc) · 1.5 KB
/
loadimage.cpp
File metadata and controls
61 lines (51 loc) · 1.5 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <cstdlib>
#include "Adafruit_GFX.h"
#include "displayax206.hpp"
#include "updateoptimizer.hpp"
#include "image.hpp"
int main(int argc, char **argv)
{
if (argc != 2)
{
std::cout << "Usage:: loadimage <imagefilename>" << std::endl;
exit(1);
}
DisplayAx206 ax206;
if (!ax206.Open())
{
std::cout << "failed to open USB" << std::endl;
}
size_t width = 0;
size_t height = 0;
if (!ax206.GetDimensions(width, height))
{
std::cout << "Device get dimensions failed - replug USB connection" << std::endl;
exit(1);
}
std::cout << "Reported LCD width=" << width << " height=" << height << std::endl;
GFXcanvas16 canvas(width, height);
UpdateOptimizer updater(width, height);
const size_t filenameLen = strlen(argv[1]) + 1;
wchar_t* filename = new wchar_t[filenameLen];
mbstowcs(filename, argv[1], filenameLen);
Image image(width, height);
if (image.Load(filename))
{
for (size_t y = 0; y < height; ++y)
{
for (size_t x = 0; x < width; ++x)
{
canvas.drawPixel(x, y, image.GetPixel(x, y));
}
}
ax206.SetBrightness(ax206.GetMaxBrightness());
updater.TransferToDisplay(canvas.getBuffer(), ax206);
}
else
{
std::cout << "Image size doesn't match LCD! Use paint to scale your image to " << width << "x" << height << "." << std::endl;
}
ax206.Close();
return 0;
}