blob: 33885ee1174d123a6f43c68fca60cf51e44603a4 [file] [log] [blame]
Ed Tanousb4d29f42017-03-24 16:39:25 -07001#include <fcntl.h>
2#include <unistd.h>
Ed Tanous1ff48782017-04-18 12:45:08 -07003#include <chrono>
4#include <fstream>
5#include <iomanip>
6#include <iostream>
7#include <thread>
8#include <vector>
Ed Tanousb4d29f42017-03-24 16:39:25 -07009
Ed Tanous93f987d2017-04-17 17:52:36 -070010#include <stdio.h>
11#include <stdlib.h>
Ed Tanousd5f39992017-04-18 13:41:22 -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
22int main() {
Ed Tanous93f987d2017-04-17 17:52:36 -070023 std::cout << "Started\n";
24 AstVideo::RawVideoBuffer out;
25 bool have_hardware = false;
Ed Tanous1ff48782017-04-18 12:45:08 -070026 if (access("/dev/video", F_OK) != -1) {
Ed Tanouse2fc45a2017-04-26 09:19:10 -070027 AstVideo::SimpleVideoPuller p;
Ed Tanous93f987d2017-04-17 17:52:36 -070028 p.initialize();
29 out = p.read_video();
30 } else {
31 FILE *fp = fopen("/home/ed/screendata.bin", "rb");
32 if (fp) {
33 size_t newLen = fread(out.buffer.data(), sizeof(char),
34 out.buffer.size() * sizeof(long), fp);
35 if (ferror(fp) != 0) {
36 fputs("Error reading file", stderr);
37 }
38 fclose(fp);
39 out.buffer.resize(newLen);
40 out.mode = AstVideo::YuvMode::YUV444;
41 out.width = 800;
42 out.height = 600;
43 out.y_selector = 0;
44 out.uv_selector = 0;
Ed Tanous93f987d2017-04-17 17:52:36 -070045 }
46 }
47
48 FILE *fp = fopen("/tmp/screendata.bin", "wb");
Ed Tanous1ff48782017-04-18 12:45:08 -070049 fwrite(out.buffer.data(), sizeof(char), out.buffer.size(), fp);
Ed Tanous93f987d2017-04-17 17:52:36 -070050
51 AstVideo::AstJpegDecoder d;
52 std::cout << "MODE " << static_cast<int>(out.mode);
53 d.decode(out.buffer, out.width, out.height, out.mode, out.y_selector,
54 out.uv_selector);
Ed Tanous1ff48782017-04-18 12:45:08 -070055#ifdef BUILD_CIMG
Ed Tanous93f987d2017-04-17 17:52:36 -070056 cimg_library::CImg<unsigned char> image(out.width, out.height, 1,
57 3 /*numchannels*/);
58 for (int y = 0; y < out.height; y++) {
59 for (int x = 0; x < out.width; x++) {
60 auto pixel = d.OutBuffer[x + (y * out.width)];
61 image(x, y, 0) = pixel.R;
62 image(x, y, 1) = pixel.G;
63 image(x, y, 2) = pixel.B;
64 }
65 }
66 image.save("/tmp/file2.bmp");
Ed Tanous1ff48782017-04-18 12:45:08 -070067#endif
Ed Tanous93f987d2017-04-17 17:52:36 -070068
Ed Tanous1ff48782017-04-18 12:45:08 -070069 std::cout << "Done!\n";
Ed Tanous1ccd57c2017-03-21 13:15:58 -070070
71 return 1;
Ed Tanous93f987d2017-04-17 17:52:36 -070072}