Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 1 | #include <video.h> |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 2 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 3 | #include <iomanip> |
Ed Tanous | b4d29f4 | 2017-03-24 16:39:25 -0700 | [diff] [blame] | 4 | #include <iostream> |
| 5 | #include <chrono> |
| 6 | #include <thread> |
| 7 | #include <vector> |
| 8 | #include <fstream> |
| 9 | #include <fcntl.h> |
| 10 | #include <unistd.h> |
| 11 | |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame^] | 12 | #include <stdio.h> |
| 13 | #include <stdlib.h> |
| 14 | #define BUILD_CIMG |
| 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; |
| 27 | if( access( "/dev/video", F_OK ) != -1 ) { |
| 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; |
| 46 | |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | FILE *fp = fopen("/tmp/screendata.bin", "wb"); |
| 51 | fwrite(out.buffer.data(), sizeof(char), |
| 52 | out.buffer.size(), fp); |
| 53 | |
| 54 | AstVideo::AstJpegDecoder d; |
| 55 | std::cout << "MODE " << static_cast<int>(out.mode); |
| 56 | d.decode(out.buffer, out.width, out.height, out.mode, out.y_selector, |
| 57 | out.uv_selector); |
| 58 | #ifdef BUILD_CIMG |
| 59 | cimg_library::CImg<unsigned char> image(out.width, out.height, 1, |
| 60 | 3 /*numchannels*/); |
| 61 | for (int y = 0; y < out.height; y++) { |
| 62 | for (int x = 0; x < out.width; x++) { |
| 63 | auto pixel = d.OutBuffer[x + (y * out.width)]; |
| 64 | image(x, y, 0) = pixel.R; |
| 65 | image(x, y, 1) = pixel.G; |
| 66 | image(x, y, 2) = pixel.B; |
| 67 | } |
| 68 | } |
| 69 | image.save("/tmp/file2.bmp"); |
| 70 | #endif |
| 71 | |
| 72 | std::cout << "Done!\n"; |
| 73 | |
Ed Tanous | 1ccd57c | 2017-03-21 13:15:58 -0700 | [diff] [blame] | 74 | |
| 75 | return 1; |
Ed Tanous | 93f987d | 2017-04-17 17:52:36 -0700 | [diff] [blame^] | 76 | } |