Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 1 | #include <fcntl.h> |
| 2 | #include <unistd.h> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 3 | |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 4 | #include <chrono> |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 5 | #include <cstdio> |
| 6 | #include <cstdlib> |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 7 | #include <fstream> |
| 8 | #include <iomanip> |
| 9 | #include <iostream> |
| 10 | #include <thread> |
| 11 | #include <vector> |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -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 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 22 | int main() |
| 23 | { |
| 24 | ast_video::RawVideoBuffer out; |
| 25 | bool have_hardware = false; |
| 26 | if (access("/dev/video", F_OK) != -1) |
| 27 | { |
| 28 | ast_video::SimpleVideoPuller p; |
| 29 | p.initialize(); |
| 30 | out = p.readVideo(); |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 31 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 32 | else |
| 33 | { |
| 34 | FILE *fp = fopen("/home/ed/screendata.bin", "rb"); |
| 35 | if (fp != nullptr) |
| 36 | { |
| 37 | size_t newLen = fread(out.buffer.data(), sizeof(char), |
| 38 | out.buffer.size() * sizeof(long), fp); |
| 39 | if (ferror(fp) != 0) |
| 40 | { |
| 41 | fputs("Error reading file", stderr); |
| 42 | } |
| 43 | fclose(fp); |
| 44 | out.buffer.resize(newLen); |
| 45 | out.mode = ast_video::YuvMode::YUV444; |
| 46 | out.width = 800; |
| 47 | out.height = 600; |
| 48 | out.ySelector = 0; |
| 49 | out.uvSelector = 0; |
| 50 | } |
| 51 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 52 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 53 | FILE *fp = fopen("/tmp/screendata.bin", "wb"); |
| 54 | fwrite(out.buffer.data(), sizeof(char), out.buffer.size(), fp); |
Patrick Venture | 6141c8b | 2018-10-16 13:11:39 -0700 | [diff] [blame] | 55 | fclose(fp); |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 56 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 57 | ast_video::AstJpegDecoder d; |
| 58 | d.decode(out.buffer, out.width, out.height, out.mode, out.ySelector, |
| 59 | out.uvSelector); |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 60 | #ifdef BUILD_CIMG |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 61 | cimg_library::CImg<unsigned char> image(out.width, out.height, 1, |
| 62 | 3 /*numchannels*/); |
| 63 | for (int y = 0; y < out.height; y++) |
| 64 | { |
| 65 | for (int x = 0; x < out.width; x++) |
| 66 | { |
| 67 | auto pixel = d.outBuffer[x + (y * out.width)]; |
| 68 | image(x, y, 0) = pixel.r; |
| 69 | image(x, y, 1) = pixel.g; |
| 70 | image(x, y, 2) = pixel.b; |
| 71 | } |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 72 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 73 | image.save("/tmp/file2.bmp"); |
Ed Tanous | 1ff4878 | 2017-04-18 12:45:08 -0700 | [diff] [blame] | 74 | #endif |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 75 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 76 | std::cout << "Done!\n"; |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 77 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 78 | return 1; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame] | 79 | } |