|
| 1 | +#include "test.h" |
| 2 | +#include <libvisual/libvisual.h> |
| 3 | +#include <fstream> |
| 4 | + |
| 5 | +namespace |
| 6 | +{ |
| 7 | + LV::VideoPtr load_raw_image (std::string const& path, int width, int height, VisVideoDepth depth) |
| 8 | + { |
| 9 | + auto image {LV::Video::create (width, height, depth)}; |
| 10 | + |
| 11 | + std::size_t const content_bytes_per_row = image->get_width () * image->get_bpp (); |
| 12 | + |
| 13 | + { |
| 14 | + std::ifstream input {path, std::ios::binary}; |
| 15 | + |
| 16 | + for (int y = 0; y < image->get_height (); y++) { |
| 17 | + auto pixel_row_ptr = static_cast<char*> (image->get_pixel_ptr (0, y)); |
| 18 | + input.read (pixel_row_ptr, content_bytes_per_row); |
| 19 | + } |
| 20 | + } |
| 21 | + |
| 22 | +#if VISUAL_LITTLE_ENDIAN == 1 |
| 23 | + auto byteswapped_image {LV::Video::create (width, height, depth)}; |
| 24 | + byteswapped_image->flip_pixel_bytes (image); |
| 25 | + |
| 26 | + return byteswapped_image; |
| 27 | +#else |
| 28 | + return image; |
| 29 | +#endif |
| 30 | + } |
| 31 | + |
| 32 | + void test_png_load () |
| 33 | + { |
| 34 | + { |
| 35 | + auto png_image {LV::Video::create_from_file ("../images/additive-colors-rgb24.png")}; |
| 36 | + LV_TEST_ASSERT (png_image); |
| 37 | + |
| 38 | + auto raw_image {load_raw_image ("../images/additive-colors-rgb24.raw", |
| 39 | + png_image->get_width (), |
| 40 | + png_image->get_height (), |
| 41 | + VISUAL_VIDEO_DEPTH_24BIT)}; |
| 42 | + |
| 43 | + LV_TEST_ASSERT (png_image->has_same_content (raw_image)); |
| 44 | + } |
| 45 | + |
| 46 | + { |
| 47 | + auto png_image {LV::Video::create_from_file ("../images/additive-colors-argb32.png")}; |
| 48 | + LV_TEST_ASSERT (png_image); |
| 49 | + |
| 50 | + auto raw_image {load_raw_image ("../images/additive-colors-argb32.raw", |
| 51 | + png_image->get_width (), |
| 52 | + png_image->get_height (), |
| 53 | + VISUAL_VIDEO_DEPTH_32BIT)}; |
| 54 | + |
| 55 | + LV_TEST_ASSERT (png_image->has_same_content (raw_image)); |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +int main (int argc, char* argv[]) |
| 61 | +{ |
| 62 | + LV::System::init (argc, argv); |
| 63 | + |
| 64 | + auto video = LV::Video::create (640, 480, VISUAL_VIDEO_DEPTH_16BIT); |
| 65 | + |
| 66 | + test_png_load (); |
| 67 | + |
| 68 | + LV::System::destroy (); |
| 69 | +} |
0 commit comments