blob: bc4d75b1a466a8e12d0a6b9def267e4a0ea25e54 [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 Tanous911ac312017-08-15 09:37:42 -070010#include <cstdio>
11#include <cstdlib>
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 AstVideo::RawVideoBuffer out;
24 bool have_hardware = false;
Ed Tanous1ff48782017-04-18 12:45:08 -070025 if (access("/dev/video", F_OK) != -1) {
Ed Tanouse2fc45a2017-04-26 09:19:10 -070026 AstVideo::SimpleVideoPuller p;
Ed Tanous93f987d2017-04-17 17:52:36 -070027 p.initialize();
28 out = p.read_video();
29 } else {
30 FILE *fp = fopen("/home/ed/screendata.bin", "rb");
Ed Tanous911ac312017-08-15 09:37:42 -070031 if (fp != nullptr) {
Ed Tanous93f987d2017-04-17 17:52:36 -070032 size_t newLen = fread(out.buffer.data(), sizeof(char),
33 out.buffer.size() * sizeof(long), fp);
34 if (ferror(fp) != 0) {
35 fputs("Error reading file", stderr);
36 }
37 fclose(fp);
38 out.buffer.resize(newLen);
39 out.mode = AstVideo::YuvMode::YUV444;
40 out.width = 800;
41 out.height = 600;
42 out.y_selector = 0;
43 out.uv_selector = 0;
Ed Tanous93f987d2017-04-17 17:52:36 -070044 }
45 }
46
47 FILE *fp = fopen("/tmp/screendata.bin", "wb");
Ed Tanous1ff48782017-04-18 12:45:08 -070048 fwrite(out.buffer.data(), sizeof(char), out.buffer.size(), fp);
Ed Tanous93f987d2017-04-17 17:52:36 -070049
50 AstVideo::AstJpegDecoder d;
Ed Tanous93f987d2017-04-17 17:52:36 -070051 d.decode(out.buffer, out.width, out.height, out.mode, out.y_selector,
52 out.uv_selector);
Ed Tanous1ff48782017-04-18 12:45:08 -070053#ifdef BUILD_CIMG
Ed Tanous93f987d2017-04-17 17:52:36 -070054 cimg_library::CImg<unsigned char> image(out.width, out.height, 1,
55 3 /*numchannels*/);
56 for (int y = 0; y < out.height; y++) {
57 for (int x = 0; x < out.width; x++) {
58 auto pixel = d.OutBuffer[x + (y * out.width)];
59 image(x, y, 0) = pixel.R;
60 image(x, y, 1) = pixel.G;
61 image(x, y, 2) = pixel.B;
62 }
63 }
64 image.save("/tmp/file2.bmp");
Ed Tanous1ff48782017-04-18 12:45:08 -070065#endif
Ed Tanous93f987d2017-04-17 17:52:36 -070066
Ed Tanous1ff48782017-04-18 12:45:08 -070067 std::cout << "Done!\n";
Ed Tanous1ccd57c2017-03-21 13:15:58 -070068
69 return 1;
Ed Tanous93f987d2017-04-17 17:52:36 -070070}