blob: 4f375ca025ddb131cebfed0f21bcb739be492938 [file] [log] [blame]
Ed Tanous1ccd57c2017-03-21 13:15:58 -07001#include <video.h>
Ed Tanousb4d29f42017-03-24 16:39:25 -07002
Ed Tanous1ccd57c2017-03-21 13:15:58 -07003#include <iomanip>
Ed Tanousb4d29f42017-03-24 16:39:25 -07004#include <iostream>
5#include <chrono>
6#include <thread>
7#include <vector>
8#include <fstream>
9#include <fcntl.h>
10#include <unistd.h>
11
Ed Tanous93f987d2017-04-17 17:52:36 -070012#include <stdio.h>
13#include <stdlib.h>
14#define BUILD_CIMG
15#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;
27 if( access( "/dev/video", F_OK ) != -1 ) {
28 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;
46
47 }
48 }
49
50 FILE *fp = fopen("/tmp/screendata.bin", "wb");
51 fwrite(out.buffer.data(), sizeof(char),
52 out.buffer.size(), fp);
53
54 AstVideo::AstJpegDecoder d;
55 std::cout << "MODE " << static_cast<int>(out.mode);
56 d.decode(out.buffer, out.width, out.height, out.mode, out.y_selector,
57 out.uv_selector);
58 #ifdef BUILD_CIMG
59 cimg_library::CImg<unsigned char> image(out.width, out.height, 1,
60 3 /*numchannels*/);
61 for (int y = 0; y < out.height; y++) {
62 for (int x = 0; x < out.width; x++) {
63 auto pixel = d.OutBuffer[x + (y * out.width)];
64 image(x, y, 0) = pixel.R;
65 image(x, y, 1) = pixel.G;
66 image(x, y, 2) = pixel.B;
67 }
68 }
69 image.save("/tmp/file2.bmp");
70 #endif
71
72 std::cout << "Done!\n";
73
Ed Tanous1ccd57c2017-03-21 13:15:58 -070074
75 return 1;
Ed Tanous93f987d2017-04-17 17:52:36 -070076}