blob: cd7f09c4c266dd74337e18f96443052ee285a6df [file] [log] [blame]
Ed Tanousb4d29f42017-03-24 16:39:25 -07001
Ed Tanousb4d29f42017-03-24 16:39:25 -07002#include <fcntl.h>
3#include <unistd.h>
Ed Tanous1ff48782017-04-18 12:45:08 -07004#include <chrono>
5#include <fstream>
6#include <iomanip>
7#include <iostream>
8#include <thread>
9#include <vector>
Ed Tanousb4d29f42017-03-24 16:39:25 -070010
Ed Tanous93f987d2017-04-17 17:52:36 -070011#include <stdio.h>
12#include <stdlib.h>
Ed Tanousd5f39992017-04-18 13:41:22 -070013
Ed Tanous01250f22017-04-18 17:49:51 -070014//#define BUILD_CIMG
Ed Tanous93f987d2017-04-17 17:52:36 -070015#ifdef BUILD_CIMG
16#define cimg_display 0
17#include <CImg.h>
18#endif
Ed Tanous1ccd57c2017-03-21 13:15:58 -070019
Ed Tanous93f987d2017-04-17 17:52:36 -070020#include <ast_jpeg_decoder.hpp>
21#include <ast_video_puller.hpp>
Ed Tanous1ccd57c2017-03-21 13:15:58 -070022
23int main() {
Ed Tanous93f987d2017-04-17 17:52:36 -070024 std::cout << "Started\n";
25 AstVideo::RawVideoBuffer out;
26 bool have_hardware = false;
Ed Tanous1ff48782017-04-18 12:45:08 -070027 if (access("/dev/video", F_OK) != -1) {
Ed Tanous93f987d2017-04-17 17:52:36 -070028 AstVideo::VideoPuller p;
29 p.initialize();
30 out = p.read_video();
31 } else {
32 FILE *fp = fopen("/home/ed/screendata.bin", "rb");
33 if (fp) {
34 size_t newLen = fread(out.buffer.data(), sizeof(char),
35 out.buffer.size() * sizeof(long), fp);
36 if (ferror(fp) != 0) {
37 fputs("Error reading file", stderr);
38 }
39 fclose(fp);
40 out.buffer.resize(newLen);
41 out.mode = AstVideo::YuvMode::YUV444;
42 out.width = 800;
43 out.height = 600;
44 out.y_selector = 0;
45 out.uv_selector = 0;
Ed Tanous93f987d2017-04-17 17:52:36 -070046 }
47 }
48
49 FILE *fp = fopen("/tmp/screendata.bin", "wb");
Ed Tanous1ff48782017-04-18 12:45:08 -070050 fwrite(out.buffer.data(), sizeof(char), out.buffer.size(), fp);
Ed Tanous93f987d2017-04-17 17:52:36 -070051
52 AstVideo::AstJpegDecoder d;
53 std::cout << "MODE " << static_cast<int>(out.mode);
54 d.decode(out.buffer, out.width, out.height, out.mode, out.y_selector,
55 out.uv_selector);
Ed Tanous1ff48782017-04-18 12:45:08 -070056#ifdef BUILD_CIMG
Ed Tanous93f987d2017-04-17 17:52:36 -070057 cimg_library::CImg<unsigned char> image(out.width, out.height, 1,
58 3 /*numchannels*/);
59 for (int y = 0; y < out.height; y++) {
60 for (int x = 0; x < out.width; x++) {
61 auto pixel = d.OutBuffer[x + (y * out.width)];
62 image(x, y, 0) = pixel.R;
63 image(x, y, 1) = pixel.G;
64 image(x, y, 2) = pixel.B;
65 }
66 }
67 image.save("/tmp/file2.bmp");
Ed Tanous1ff48782017-04-18 12:45:08 -070068#endif
Ed Tanous93f987d2017-04-17 17:52:36 -070069
Ed Tanous1ff48782017-04-18 12:45:08 -070070 std::cout << "Done!\n";
Ed Tanous1ccd57c2017-03-21 13:15:58 -070071
72 return 1;
Ed Tanous93f987d2017-04-17 17:52:36 -070073}