Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 1 | #include <fcntl.h> |
| 2 | #include <unistd.h> |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 3 | #include <chrono> |
| 4 | #include <fstream> |
| 5 | #include <iomanip> |
| 6 | #include <iostream> |
| 7 | #include <thread> |
| 8 | #include <vector> |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 9 | |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 10 | #include <cstdio> |
| 11 | #include <cstdlib> |
Ed Tanous | d5f3999 | 2017-04-18 13:41:22 -0700 | [diff] [blame] | 12 | |
Ed Tanous | 01250f2 | 2017-04-18 17:49:51 -0700 | [diff] [blame] | 13 | //#define BUILD_CIMG |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 14 | #ifdef BUILD_CIMG |
| 15 | #define cimg_display 0 |
| 16 | #include <CImg.h> |
| 17 | #endif |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 18 | |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 19 | #include <ast_jpeg_decoder.hpp> |
| 20 | #include <ast_video_puller.hpp> |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 21 | |
| 22 | int main() { |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 23 | ast_video::RawVideoBuffer out; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 24 | bool have_hardware = false; |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 25 | if (access("/dev/video", F_OK) != -1) { |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 26 | ast_video::SimpleVideoPuller p; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 27 | p.initialize(); |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 28 | out = p.readVideo(); |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 29 | } else { |
| 30 | FILE *fp = fopen("/home/ed/screendata.bin", "rb"); |
Ed Tanous | 911ac31 | 2017-08-15 09:37:42 -0700 | [diff] [blame] | 31 | if (fp != nullptr) { |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 32 | 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 Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 39 | out.mode = ast_video::YuvMode::YUV444; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 40 | out.width = 800; |
| 41 | out.height = 600; |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 42 | out.ySelector = 0; |
| 43 | out.uvSelector = 0; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 44 | } |
| 45 | } |
| 46 | |
| 47 | FILE *fp = fopen("/tmp/screendata.bin", "wb"); |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 48 | fwrite(out.buffer.data(), sizeof(char), out.buffer.size(), fp); |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 49 | |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 50 | ast_video::AstJpegDecoder d; |
| 51 | d.decode(out.buffer, out.width, out.height, out.mode, out.ySelector, |
| 52 | out.uvSelector); |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 53 | #ifdef BUILD_CIMG |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 54 | 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 Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame^] | 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; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | image.save("/tmp/file2.bmp"); |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 65 | #endif |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 66 | |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 67 | std::cout << "Done!\n"; |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 68 | |
| 69 | return 1; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 70 | } |