|
| 1 | +#include "../build/rmkit.h" |
| 2 | + |
| 3 | +class App: |
| 4 | + public: |
| 5 | + |
| 6 | + def open_image(string full_path): |
| 7 | + fb := framebuffer::get() |
| 8 | + fb->clear_screen() |
| 9 | + int iw, ih |
| 10 | + int channels // an output parameter |
| 11 | + decoded := (uint8_t*) stbi_load(full_path.c_str(), &iw, &ih, &channels, 4) |
| 12 | + |
| 13 | + nw, nh := fb->get_display_size() |
| 14 | + debug "RESIZING TO", nw, nh, channels |
| 15 | + dst := (uint8_t*) malloc(nw * nh * 4) |
| 16 | + |
| 17 | + aspect_ratio := std::min(nw / (float) iw, nh / (float) ih) |
| 18 | + |
| 19 | + fw := aspect_ratio * iw |
| 20 | + fh := aspect_ratio * ih |
| 21 | + |
| 22 | + image := image_data{(uint32_t*) decoded, (int) iw, (int) ih, 4} |
| 23 | + util::resize_image(image, fw, fh, 999) |
| 24 | + fb->draw_bitmap(image,0,0) |
| 25 | + |
| 26 | + |
| 27 | + def run(): |
| 28 | + ui::MainLoop::refresh() |
| 29 | + ui::MainLoop::redraw() |
| 30 | + |
| 31 | + |
| 32 | +def main(int argc, char *argv[]): |
| 33 | + App app |
| 34 | + string img = "src/dithering_demo/colorspace.png" |
| 35 | + fb := framebuffer::get() |
| 36 | + fb->dither = framebuffer::DITHER::BAYER_2 |
| 37 | + if argc > 1: |
| 38 | + img = argv[1] |
| 39 | + else: |
| 40 | + print "Usage:", argv[0], "<image file>" |
| 41 | + |
| 42 | + app.open_image(img) |
| 43 | + app.run() |
0 commit comments