blob: 849c75d539ec9ea13ed4fa44f684ea897c02f6b5 [file] [log] [blame]
Ed Tanousb4d29f42017-03-24 16:39:25 -07001#include <fcntl.h>
2#include <unistd.h>
Ed Tanous1abe55e2018-09-05 08:30:59 -07003
Ed Tanous1ff48782017-04-18 12:45:08 -07004#include <chrono>
Ed Tanous1abe55e2018-09-05 08:30:59 -07005#include <cstdio>
6#include <cstdlib>
Ed Tanous1ff48782017-04-18 12:45:08 -07007#include <fstream>
8#include <iomanip>
9#include <iostream>
10#include <thread>
11#include <vector>
Ed Tanousb4d29f42017-03-24 16:39:25 -070012
Ed Tanous01250f22017-04-18 17:49:51 -070013//#define BUILD_CIMG
Ed Tanous93f987d2017-04-17 17:52:36 -070014#ifdef BUILD_CIMG
15#define cimg_display 0
16#include <CImg.h>
17#endif
Ed Tanous1ccd57c2017-03-21 13:15:58 -070018
Ed Tanous93f987d2017-04-17 17:52:36 -070019#include <ast_jpeg_decoder.hpp>
20#include <ast_video_puller.hpp>
Ed Tanous1ccd57c2017-03-21 13:15:58 -070021
Ed Tanous1abe55e2018-09-05 08:30:59 -070022int main()
23{
24 ast_video::RawVideoBuffer out;
25 bool have_hardware = false;
26 if (access("/dev/video", F_OK) != -1)
27 {
28 ast_video::SimpleVideoPuller p;
29 p.initialize();
30 out = p.readVideo();
Ed Tanous93f987d2017-04-17 17:52:36 -070031 }
Ed Tanous1abe55e2018-09-05 08:30:59 -070032 else
33 {
34 FILE *fp = fopen("/home/ed/screendata.bin", "rb");
35 if (fp != nullptr)
36 {
37 size_t newLen = fread(out.buffer.data(), sizeof(char),
38 out.buffer.size() * sizeof(long), fp);
39 if (ferror(fp) != 0)
40 {
41 fputs("Error reading file", stderr);
42 }
43 fclose(fp);
44 out.buffer.resize(newLen);
45 out.mode = ast_video::YuvMode::YUV444;
46 out.width = 800;
47 out.height = 600;
48 out.ySelector = 0;
49 out.uvSelector = 0;
50 }
51 }
Ed Tanous93f987d2017-04-17 17:52:36 -070052
Ed Tanous1abe55e2018-09-05 08:30:59 -070053 FILE *fp = fopen("/tmp/screendata.bin", "wb");
54 fwrite(out.buffer.data(), sizeof(char), out.buffer.size(), fp);
Patrick Venture6141c8b2018-10-16 13:11:39 -070055 fclose(fp);
Ed Tanous93f987d2017-04-17 17:52:36 -070056
Ed Tanous1abe55e2018-09-05 08:30:59 -070057 ast_video::AstJpegDecoder d;
58 d.decode(out.buffer, out.width, out.height, out.mode, out.ySelector,
59 out.uvSelector);
Ed Tanous1ff48782017-04-18 12:45:08 -070060#ifdef BUILD_CIMG
Ed Tanous1abe55e2018-09-05 08:30:59 -070061 cimg_library::CImg<unsigned char> image(out.width, out.height, 1,
62 3 /*numchannels*/);
63 for (int y = 0; y < out.height; y++)
64 {
65 for (int x = 0; x < out.width; x++)
66 {
67 auto pixel = d.outBuffer[x + (y * out.width)];
68 image(x, y, 0) = pixel.r;
69 image(x, y, 1) = pixel.g;
70 image(x, y, 2) = pixel.b;
71 }
Ed Tanous93f987d2017-04-17 17:52:36 -070072 }
Ed Tanous1abe55e2018-09-05 08:30:59 -070073 image.save("/tmp/file2.bmp");
Ed Tanous1ff48782017-04-18 12:45:08 -070074#endif
Ed Tanous93f987d2017-04-17 17:52:36 -070075
Ed Tanous1abe55e2018-09-05 08:30:59 -070076 std::cout << "Done!\n";
Ed Tanous1ccd57c2017-03-21 13:15:58 -070077
Ed Tanous1abe55e2018-09-05 08:30:59 -070078 return 1;
Ed Tanous93f987d2017-04-17 17:52:36 -070079}