blob: 7055d35dfce3e07d07bcfcc79dbd1d431a1a02aa [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 Tanous55c7b7a2018-05-22 15:27:24 -070023 ast_video::RawVideoBuffer out;
Ed Tanous93f987d2017-04-17 17:52:36 -070024 bool have_hardware = false;
Ed Tanous1ff48782017-04-18 12:45:08 -070025 if (access("/dev/video", F_OK) != -1) {
Ed Tanous55c7b7a2018-05-22 15:27:24 -070026 ast_video::SimpleVideoPuller p;
Ed Tanous93f987d2017-04-17 17:52:36 -070027 p.initialize();
Ed Tanous55c7b7a2018-05-22 15:27:24 -070028 out = p.readVideo();
Ed Tanous93f987d2017-04-17 17:52:36 -070029 } 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);
Ed Tanous55c7b7a2018-05-22 15:27:24 -070039 out.mode = ast_video::YuvMode::YUV444;
Ed Tanous93f987d2017-04-17 17:52:36 -070040 out.width = 800;
41 out.height = 600;
Ed Tanous55c7b7a2018-05-22 15:27:24 -070042 out.ySelector = 0;
43 out.uvSelector = 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
Ed Tanous55c7b7a2018-05-22 15:27:24 -070050 ast_video::AstJpegDecoder d;
51 d.decode(out.buffer, out.width, out.height, out.mode, out.ySelector,
52 out.uvSelector);
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++) {
Ed Tanous55c7b7a2018-05-22 15:27:24 -070058 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;
Ed Tanous93f987d2017-04-17 17:52:36 -070062 }
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}