Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 1 | |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 2 | #include <fcntl.h> |
| 3 | #include <unistd.h> |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 4 | #include <chrono> |
| 5 | #include <fstream> |
| 6 | #include <iomanip> |
| 7 | #include <iostream> |
| 8 | #include <thread> |
| 9 | #include <vector> |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 10 | |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
Ed Tanous | d5f3999 | 2017-04-18 13:41:22 -0700 | [diff] [blame] | 13 | |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame^] | 14 | //#define BUILD_CIMG |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 15 | #ifdef BUILD_CIMG |
| 16 | #define cimg_display 0 |
| 17 | #include <CImg.h> |
| 18 | #endif |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 19 | |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 20 | #include <ast_jpeg_decoder.hpp> |
| 21 | #include <ast_video_puller.hpp> |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 22 | |
| 23 | int main() { |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 24 | std::cout << "Started\n"; |
| 25 | AstVideo::RawVideoBuffer out; |
| 26 | bool have_hardware = false; |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 27 | if (access("/dev/video", F_OK) != -1) { |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 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; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | |
| 49 | FILE *fp = fopen("/tmp/screendata.bin", "wb"); |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 50 | fwrite(out.buffer.data(), sizeof(char), out.buffer.size(), fp); |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 51 | |
| 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 Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 56 | #ifdef BUILD_CIMG |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 57 | 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 Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 68 | #endif |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 69 | |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 70 | std::cout << "Done!\n"; |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 71 | |
| 72 | return 1; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 73 | } |